Documentation
¶
Overview ¶
Package acp provides shared Agentic Commerce Protocol types and HTTP helpers.
The protocol-specific packages are:
- github.com/sumup/acp/acpcheckout for seller-hosted checkout sessions;
- github.com/sumup/acp/acpcart for seller-hosted carts;
- github.com/sumup/acp/acppayment for delegated payment;
- github.com/sumup/acp/acpauthentication for delegated 3DS authentication;
- github.com/sumup/acp/acpfeed for the agent-hosted Feed API;
- github.com/sumup/acp/acpdiscovery for the public discovery document; and
- github.com/sumup/acp/acpwebhook for order events and webhook signing.
APIVersion identifies the stable ACP specification implemented by this module. HTTP handlers validate that version and make the supported version available in protocol-level version errors.
Index ¶
- Constants
- func ContextWithRequestContext(ctx context.Context, requestCtx *RequestContext) context.Context
- func ContextWithRequestContextFromRequest(r *http.Request) (context.Context, error)
- func WithInternal(err error) errorOption
- func WithOffendingParam(jsonPath string) errorOption
- func WithRetryAfter(d time.Duration) errorOption
- func WithStatusCode(status int) errorOption
- func WithSupportedVersions(versions []string) errorOption
- type Error
- func NewHTTPError(status int, typ ErrorType, code ErrorCode, message string, opts ...errorOption) *Error
- func NewInvalidRequestError(message string, opts ...errorOption) *Error
- func NewProcessingError(message string, opts ...errorOption) *Error
- func NewRateLimitExceededError(message string, opts ...errorOption) *Error
- func NewServiceUnavailableError(message string, opts ...errorOption) *Error
- type ErrorCode
- type ErrorType
- type RequestContext
Examples ¶
Constants ¶
const APIVersion = "2026-04-17"
APIVersion identifies the published Agentic Commerce Protocol version implemented by this module. Service handlers validate this value in the API-Version request header and emit it on their responses.
Variables ¶
This section is empty.
Functions ¶
func ContextWithRequestContext ¶
func ContextWithRequestContext(ctx context.Context, requestCtx *RequestContext) context.Context
ContextWithRequestContext returns a context containing requestCtx.
A nil requestCtx leaves ctx unchanged. A nil ctx is replaced with context.Background.
func ContextWithRequestContextFromRequest ¶
ContextWithRequestContextFromRequest reads and validates ACP headers from r, then returns a child of r.Context containing that metadata.
func WithInternal ¶
func WithInternal(err error) errorOption
WithInternal sets an internal error that can be retrieved from Error for telemetry purposes.
func WithOffendingParam ¶
func WithOffendingParam(jsonPath string) errorOption
WithOffendingParam sets the JSON path for the field that triggered the error.
func WithRetryAfter ¶
WithRetryAfter specifies how long clients should wait before retrying.
func WithStatusCode ¶
func WithStatusCode(status int) errorOption
WithStatusCode overrides the HTTP status code returned to the client.
func WithSupportedVersions ¶
func WithSupportedVersions(versions []string) errorOption
WithSupportedVersions sets the supported protocol versions returned to clients.
Types ¶
type Error ¶
type Error struct {
Type ErrorType `json:"type"`
Code ErrorCode `json:"code"`
Message string `json:"message"`
Param *string `json:"param,omitempty"`
SupportedVersions []string `json:"supported_versions,omitempty"`
Internal error `json:"-"`
// contains filtered or unexported fields
}
Error represents a structured ACP error payload.
func NewHTTPError ¶
func NewHTTPError(status int, typ ErrorType, code ErrorCode, message string, opts ...errorOption) *Error
NewHTTPError allows callers to control the status code explicitly.
Example ¶
package main
import (
"fmt"
"github.com/sumup/acp"
)
func main() {
err := acp.NewHTTPError(
409,
acp.InvalidRequest,
acp.IdempotencyConflict,
"idempotency key was already used with different parameters",
acp.WithOffendingParam("$.line_items"),
)
fmt.Println(err.StatusCode(), err.Type, err.Code, *err.Param)
}
Output: 409 invalid_request idempotency_conflict $.line_items
func NewInvalidRequestError ¶
NewInvalidRequestError builds a Bad Request ACP error payload.
func NewProcessingError ¶
NewProcessingError builds an Internal Server Error ACP error payload.
func NewRateLimitExceededError ¶
NewRateLimitExceededError builds a Too Many Requests ACP error payload.
func NewServiceUnavailableError ¶
NewServiceUnavailableError builds a Service Unavailable ACP error payload.
func (*Error) RetryAfter ¶
RetryAfter returns the duration clients should wait before retrying.
func (*Error) StatusCode ¶
StatusCode returns the HTTP status associated with the error.
type ErrorCode ¶
type ErrorCode string
ErrorCode is a machine-readable identifier for the specific failure.
const ( DuplicateRequest ErrorCode = "duplicate_request" // Safe duplicate with the same idempotency key. IdempotencyConflict ErrorCode = "idempotency_conflict" // Same idempotency key but different parameters. IdempotencyKeyRequired ErrorCode = "idempotency_key_required" // Idempotency-Key header is missing. IdempotencyInFlight ErrorCode = "idempotency_in_flight" // Request with same idempotency key is still processing. InvalidCard ErrorCode = "invalid_card" // Credential failed basic validation (such as length or expiry). InvalidSignature ErrorCode = "invalid_signature" // Signature is missing or does not match the payload. SignatureRequired ErrorCode = "signature_required" // Signed requests are required but headers were missing. StaleTimestamp ErrorCode = "stale_timestamp" // Timestamp skew exceeded the allowed window. MissingAuthorization ErrorCode = "missing_authorization" // Authorization header missing. InvalidAuthorization ErrorCode = "invalid_authorization" // Authorization header malformed or API key invalid. MissingAPIVersion ErrorCode = "missing_api_version" // API-Version header missing. UnsupportedAPIVersion ErrorCode = "unsupported_api_version" // API-Version is not supported by this server. TooManyRequests ErrorCode = "too_many_requests" )
type RequestContext ¶
type RequestContext struct {
// API Key used to make requests.
//
// Example: Bearer api_key_123
Authorization string
// The preferred locale for content like messages and errors.
//
// Example: en-US
AcceptLanguage string
// Information about the client making this request.
//
// Example: ChatGPT/2.0 (Mac OS X 15.0.1; arm64; build 0)
UserAgent string
// Key used to ensure requests are idempotent.
//
// Example: idempotency_key_123
IdempotencyKey string
// Unique key for each request for tracing purposes.
//
// Example: request_id_123
RequestID string
// Optional detached signature used to verify the request body.
//
// Example: eyJtZX...
Signature string
// Optional request-signing timestamp formatted as an RFC 3339 string.
//
// Example: 2025-09-25T10:30:00Z
Timestamp string
// API version.
//
// Example: 2026-04-17
APIVersion string
}
RequestContext carries the standard ACP headers.
func RequestContextFromContext ¶
func RequestContextFromContext(ctx context.Context) *RequestContext
RequestContextFromContext extracts the HTTP request metadata previously stored in the context.
func RequestContextFromRequest ¶
func RequestContextFromRequest(r *http.Request) (*RequestContext, error)
RequestContextFromRequest reads the standard ACP headers from r and validates that API-Version identifies the version implemented by this module.
Example ¶
package main
import (
"fmt"
"net/http/httptest"
"github.com/sumup/acp"
)
func main() {
req := httptest.NewRequest("POST", "/checkout_sessions", nil)
req.Header.Set("API-Version", acp.APIVersion)
req.Header.Set("Authorization", "Bearer api_key_123")
req.Header.Set("Idempotency-Key", "idem_123")
requestContext, err := acp.RequestContextFromRequest(req)
if err != nil {
panic(err)
}
fmt.Println(requestContext.APIVersion, requestContext.IdempotencyKey)
}
Output: 2026-04-17 idem_123
Directories
¶
| Path | Synopsis |
|---|---|
|
Package acpauth defines bearer-token authorization for ACP HTTP handlers.
|
Package acpauth defines bearer-token authorization for ACP HTTP handlers. |
|
Package acpauthentication serves the ACP Delegated Authentication API.
|
Package acpauthentication serves the ACP Delegated Authentication API. |
|
Package acpcart serves the seller-hosted ACP Cart API.
|
Package acpcart serves the seller-hosted ACP Cart API. |
|
Package acpcheckout serves the seller-hosted ACP Agentic Checkout API.
|
Package acpcheckout serves the seller-hosted ACP Agentic Checkout API. |
|
Package acpdiscovery serves the public ACP discovery document.
|
Package acpdiscovery serves the public ACP discovery document. |
|
Package acpfeed provides models and an HTTP client for the ACP Feed API.
|
Package acpfeed provides models and an HTTP client for the ACP Feed API. |
|
Package acppayment serves the ACP Delegated Payment API.
|
Package acppayment serves the ACP Delegated Payment API. |
|
Package acpwebhook sends ACP order lifecycle events to agent endpoints.
|
Package acpwebhook sends ACP order lifecycle events to agent endpoints. |
|
Package discount provides models generated from the stable ACP discount extension schema.
|
Package discount provides models generated from the stable ACP discount extension schema. |
|
examples
|
|
|
checkout
command
|
|
|
delegated_payment
command
|
|
|
Package extension provides models generated from the stable ACP extension registry schema.
|
Package extension provides models generated from the stable ACP extension registry schema. |
|
internal
|
|
|
Package signature provides low-level helpers for optional signed ACP request headers.
|
Package signature provides low-level helpers for optional signed ACP request headers. |