Headless Checkout (GraphQL)

Payment Base makes the contract-first checkout callable through the OXID GraphQL API, so a frontend that is not the OXID Twig theme – a separate web storefront, a native app, a kiosk – can take payments while the shop keeps full control of orders, provider accounts and money.

The provider-neutral part (basket → contract → early order → token → return → cancel) lives in Payment Base under src/Checkout/Headless/. Each provider module adds only its own start, return and cancel mutations, its return resolver and the public values its browser SDK needs.

Note

Requirements: Payment Base 1.3 or later, with the OXID GraphQL modules oxid-esales/graphql-base and oxid-esales/graphql-storefront installed and activated.

Guest checkout, the Order.paymentContract field, the hashed contract token and the client-config allow-list described below are part of the next Payment Base release after v1.3.0.

GraphQL is optional. The controllers, namespace mappers and permission providers are wired so that Payment Base activates on a shop without graphql-base; the mutations and queries simply do not exist there.

Why not placeOrder

The storefront’s core mutation placeOrder creates the order before the payment. Contract-first payments run the other way round (see Smart-Contract Lifecycle): the checkout creates a payment contract, the customer pays at the provider, and the provider’s webhook commits the contract and finishes the order.

placeOrder is therefore refused for every contract-first payment. The error names the mutation to call instead, for example:

Payment "oe_payments_mollie" is handled by the mollie checkout:
call mollieCheckoutStart instead of placeOrder

Payments that are not contract-first (invoice, cash on delivery …) still go the classic way: basketSetPayment, then placeOrder.

Choosing the payment method

The payment method is chosen by which start mutation the client calls. There is one mutation per provider, and each names its own OXID payment id, so the client does not have to call basketSetPayment first.

Mutation

Payment id of the order

Where the customer pays

stripeCheckoutStart

oe_payments_stripe_wallet

Stripe’s hosted page (uiMode: hosted, default) or Stripe Embedded Checkout in the client (uiMode: embedded, answers clientSecret)

mollieCheckoutStart

oe_payments_mollie

Mollie’s hosted page; the optional method argument (ideal, creditcard, klarna …) preselects a Mollie method

paypalCheckoutStart

oe_payments_paypal

PayPal’s approval page

mutation {
  mollieCheckoutStart(
    basketId: "…", confirmTermsAndConditions: true,
    returnUrl: "https://app.example.com/return", method: "ideal"
  ) { contractId contractToken orderNumber redirectUrl renderMode }
}
  • If the basket was set to a payment with basketSetPayment, the mutation must match it: stripeCheckoutStart on a basket set to oe_payments_mollie is refused with payment_not_supported. A basket without a payment takes the mutation’s payment.

  • To present a choice, a client lists the payments the shop offers with the storefront’s basket payment query, maps each contract-first id to its start mutation and keeps placeOrder for the rest.

The checkout, step by step

The flow is the same for every provider:

Step

Call

Answer

Open

<provider>CheckoutStart(basketId, confirmTermsAndConditions, returnUrl, cancelUrl?, …)

CheckoutStartResult { contractId, contractToken, providerName, orderNumber, redirectUrl, clientSecret, renderMode }. From here on the order exists (NOT_FINISHED) and the contract is PENDING.

Pay

The customer pays at the provider. The provider’s webhook commits the contract and finishes the order.

Paid ⇒ committed and paid. Authorization with manual capture ⇒ committed, paid once the merchant captures.

Read

<provider>CheckoutReturn(contractId, contractToken, …)

CheckoutReturnResult { status, orderId, orderNumber, contractState } with status = committed · pending · failed. Reports what the webhook left; without a webhook, the provider’s return resolver settles the payment itself.

Abandon

<provider>CheckoutCancel(contractId, contractToken)

CheckoutCancelResult { cancelled, contractId, contractState }. The attempt is retired, the early order cancelled.

Rules a client has to respect:

  • The return call is idempotent. Poll a pending answer for a few seconds before showing “pending” to the customer.

  • A second start for the same basket retires the first attempt: there is one open attempt per basket. Build a fresh basket for every attempt.

  • A committed contract deletes its basket. The next purchase starts with basketCreate.

  • The headless keys of the request (basketId, uiMode, headless, sessionId) cannot be overridden through a provider’s options (HeadlessStartRequest::$providerOptions, used for Mollie’s method).

Rights and the contract token

Payment Base registers two rights with graphql-base:

  • PAYMENT_CHECKOUT – start, return and cancel of every provider,

  • PAYMENT_CLIENT_CONFIG – the paymentClientConfig query (see below).

The contract token returned by the start is the client’s proof of ownership for return and cancel. Any bearer token with the right plus the matching contract token succeeds – also a different anonymous token after the browser was reopened. A wrong contract token changes nothing (invalid_token).

The database keeps only the token’s SHA-256 (HeadlessTokenHash, stored in oe_payments_contract.OXMETADATA.headless_token). The plaintext exists only in the start answer and in the client, so reading the database does not authorise a return or a cancel. The migration Version20261022100000 hashes plaintext values from older data in place; tokens that clients already hold keep working.

Return URLs

returnUrl and cancelUrl belong to the client. They must be absolute http(s) URLs on the shop’s own origin or on an origin listed in the setting sPaymentBaseHeadlessReturnOrigins (see Allowed return origins for headless clients). Anything else is refused with return_url_rejected / origin_not_allowed; the error message names the origin only, never the path or the query.

Every provider appends contract_id to the return URL. Stripe adds session_id, PayPal token and PayerID, Mollie nothing.

Sealed client configuration

A browser SDK needs some public provider values – Stripe’s publishable key, PayPal’s client id, Mollie’s profile id. They are not configured in the frontend. The shop hands them over sealed for one browser:

query {
  paymentClientConfig(provider: "stripe", clientPublicKey: "…") {
    v alg serverPublicKey salt iv issuedAt ciphertext
  }
}
  1. The client creates an ephemeral ECDH P-256 key pair and sends the public key (raw 65-byte uncompressed point, base64url without padding).

  2. The shop creates its own ephemeral key, derives the shared secret and from it HKDF-SHA256 with a random 32-byte salt. The additional data binds the envelope to the provider, the issue time and the bearer token id.

  3. The values are encrypted with AES-256-GCM and answered as an envelope { v, alg: "ECDH-P256+HKDF-SHA256+A256GCM", serverPublicKey, salt, iv, issuedAt, ciphertext }.

  4. The client derives the same key and decrypts. It refuses an envelope whose issuedAt is more than 120 seconds off its clock, or that was sealed for another provider or session.

The query needs PAYMENT_CLIENT_CONFIG and no login, so an anonymous token is enough. If the exchange fails, a client falls back to the provider’s hosted page – never to a hard-coded key.

Providing values from a PSP module

A provider module registers a ClientConfigProviderInterface service tagged payment_base.client_config_provider. It should implement the extension AllowListedClientConfigProviderInterface and declare its value names in publicValueNames() (Stripe publishableKey, PayPal clientId, Mollie profileId and testMode).

ClientConfigGuard then refuses any other name, whatever its value. In every case it refuses:

  • values shaped like a secret (sk_, rk_, whsec_, access_, Mollie live_ / test_ API keys),

  • names containing “secret” or naming an API key,

  • every value that is not a string or a bool.

A provider that implements only the base interface keeps working under these deny rules alone. Declare the names to get the allow-list.

Guest checkout

A customer without an account checks out with the anonymous token of query { token } (no credentials, group oxidanonymous). Payment Base grants that group the storefront’s basket rights (CREATE_BASKET, VIEW_BASKET, ADD_PRODUCT_TO_BASKET, REMOVE_BASKET_PRODUCT, ADD_VOUCHER, REMOVE_VOUCHER) plus PAYMENT_CHECKOUT and PAYMENT_CLIENT_CONFIG – but not PLACE_ORDER.

With an anonymous token the basket can be built, but the logged-in calls (basketSetPayment, basketSetDeliveryMethod, basketSetDeliveryAddress …) are not in the schema. The start mutation therefore carries what they would have set, in its guest argument:

input GuestCheckoutInput {
  email: String!
  invoiceAddress: GuestAddressInput!
  deliveryAddress: GuestAddressInput
}

input GuestAddressInput {
  firstName: String!
  lastName: String!
  street: String!
  streetNumber: String!
  zipCode: String!
  city: String!
  countryId: ID!
  salutation: String
  company: String
  additionalInfo: String
  stateId: ID
  phone: String
}

What HeadlessCheckoutService::start() does with it:

  1. It validates the request first: return URLs, basket, payment, terms.

  2. GuestUserServiceInterface provides the user: a new passwordless account, or the existing guest account of that e-mail address with the addresses of this checkout. The e-mail address of a registered account (one with a password) is refused with account_exists and nothing is changed – the customer has to log in.

  3. GuestBasketClaimInterface makes the guest the owner of the ownerless basket. A basket that already belongs to someone else is refused with basket_forbidden.

  4. From here on the checkout runs as for a logged-in customer.

The guest details are read only when the token’s user does not exist in the shop; for a logged-in customer they are ignored. Missing or invalid details – and an anonymous token without details – are refused with guest_details_required; the message names the field, never the value.

The input types are defined once, in Payment Base (GraphQL\DataType\GuestCheckoutInputFactory). GraphQL type names are schema-wide, so a provider module must not define its own copy: its start mutation just declares ?GuestDetails $guest = null. Because the value objects validate while GraphQLite resolves the arguments – before the provider’s controller runs – their refusals leave as GraphQL\Exception\GuestDetailsRefused, a graphql-base error with extensions.errorCode like every other refusal.

Important

Known gap: the order ships to the invoice address. A guest’s delivery address is stored (oxaddress, and OEGQL_DELADDRESSID where the storefront has the column), but the basket’s delivery address is not yet applied to the order. This applies to logged-in baskets as well.

Not covered: creating a password-protected account after checkout, newsletter opt-in, B2B fields.

Payment state on orders: Order.paymentContract

Payment Base extends graphql-storefront’s Order type (GraphQL\Relation\OrderRelationService) by one field, so an order list shows the payment state without a second request:

{ customer { orders { orderNumber paymentContract { state provider contractId updatedAt } } } }

Field

Meaning

state

The contract state: pending, committed, fulfilled, cancelled … (ContractState)

provider

stripe, paypal, mollie

contractId

The contract id. Not a credential – the contract token never leaves the start answer.

updatedAt

When the contract last changed (DateTime)

  • paymentContract is null for an order without a contract (placed through the Twig checkout or with a core payment).

  • Which orders a caller may read is decided by the storefront: the list hangs on customer { orders }. The extension exposes no provider ids and no payloads.

  • The field is mapped only when graphql-storefront is installed. Without it, the module activates and the schema builds without the field.

  • Each order costs one indexed contract lookup (ContractSummaryQuery). Page long order lists.

Error codes

Refusals are GraphQL errors with a stable extensions.errorCode (HeadlessCheckoutException):

Code

Meaning

basket_not_found

The basket given as basketId does not exist.

basket_forbidden

Guest checkout: the basket already belongs to another user.

payment_not_supported

The basket is set to a different payment than the mutation’s.

terms_not_confirmed

The shop requires terms consent and confirmTermsAndConditions was not true.

return_url_rejected

returnUrl or cancelUrl is not on an allowed origin.

user_not_found

The shop user for the checkout cannot be loaded.

provider_failed

The provider refused the checkout; providerCode carries details (for example MOLLIE_UI_MODE_UNSUPPORTED).

contract_not_found

Return or cancel for an unknown contract.

invalid_token

The contract token does not match.

no_return_resolver

The provider registers no return resolver.

guest_details_required

Guest details missing or invalid; the message names the field.

account_exists

Guest checkout with the e-mail address of a registered account.

Operating notes

Clear the GraphQL schema cache after installing, activating or updating Payment Base or a provider module:

vendor/bin/oe-console oe:graphql:cache-clear

The schema is cached on disk and never cleared automatically. Without this step a shop keeps answering with the old API, and a new mutation, query or field fails with Cannot query field "…".

Two things curl-level clients trip over:

  • OXID empties the basket for user agents it takes for search engines – curl’s default is one. Send a browser-like User-Agent.

  • The storefront hides fields that require a login from anonymous introspection.

Every provider module ships bin/graph-ql-cli-test.sh with the same commands (schema, start, pay, return, cancel, wrong-token, guard, demo, raw) and a bin/graph-ql-cli-test.md with the provider’s specifics.

Adding headless support to a PSP module

A provider module needs:

  • a GraphQL controller with <provider>CheckoutStart, …Return and …Cancel, guarded by PAYMENT_CHECKOUT and delegating to HeadlessCheckoutService; the result types are Payment Base’s,

  • a return resolver tagged oe.payment.return_resolver that settles a payment from the return parameters when the webhook has not arrived yet,

  • a ClientConfigProviderInterface service, ideally with the allow-list (see above), if its browser SDK needs public values,

  • a namespace mapper registering only its controllers – result and guest input types belong to Payment Base.

Important

The GraphQL glue registered in services.yaml (namespace mapper, permission provider) must mirror graphql-base’s interfaces without implementing them. Module activation compiles the container, which reflects every service class – on a shop without GraphQL the interface does not exist and the activation fails.