Skip to content

paymentCreate

Mutationin Payment

Pay a cart or an order. This never creates an order.

Against an order it is the only route to one left unpaid -- a checkout that created the order and then failed to take payment, an order released from approval, or one the provider reported as failed.

Against a cart it takes the money first, and the cart is locked for the duration of this call alone: it is frozen before the payment is created and released again if any step fails, so either a payment was started or the cart is exactly as it was.

A PaymentSdkAction is the exception: the cart stays frozen while the provider's component is open, until paymentDetailsSubmit or paymentCancel. A frozen cart still takes what does not change its prices -- the shipping address, the billing address, the email and the shipping method -- and refuses changes to its lines. It also keeps the tax rates it was frozen with, so an address in a country taxed differently can fail the order.

Arguments

ArgumentTypeDescription
targetPaymentTargetInput!
paymentContextPaymentContextInput!

Returns

PaymentCreateResponse!

FieldTypeDescription
nextPaymentNextWhat the shopper does next, when payment creation succeeded
paymentErrors[PaymentCreateError!]Error details if payment creation failed

Example

mutation {
paymentCreate(
target: { id: "8a9f0e1c-4b2d-4f6a-9c3e-1d5b7a2f8c40", type: ORDER }
paymentContext: {
method: {
internalId: "pm-123"
provider: "stripe"
}
successUrl: "https://mystore.com/checkout/success"
failureUrl: "https://mystore.com/checkout/failure"
cancelUrl: "https://mystore.com/checkout/cancelled"
}
) {
next {
... on PaymentRedirect {
redirectUrl
}
... on PaymentComplete {
order {
id
}
}
}
paymentErrors {
... on PaymentError {
code
message
}
}
}
}

The query is the example the schema documents. The response shows its shape with placeholder values.

Served by

@evolve-framework/commercetoolsResolved
@evolve-framework/medusaResolved
@evolve-framework/sfccResolved

Used by

The storefront packages that send it, in these GraphQL documents: