SetPaymentMethodOnCheckoutMutation
Description
Sets the payment method on the checkout/cart. This mutation is a required step in the checkout process before placing an order.
Endpoint
mutation setPaymentMethodOnCheckout($cartId: String!, $paymentMethod: PaymentMethodInput!, $siteId: Int) {
setPaymentMethodOnCheckout(cartId: $cartId, paymentMethod: $paymentMethod, siteId: $siteId) {
# Return fields
}
}
Arguments
| Argument | Type | Required | Description |
|---|---|---|---|
| cartId | String | Yes | The unique identifier of the cart to set the payment method on. This ID is obtained from createGuestCart or createCustomerCart mutations. |
| paymentMethod | PaymentMethodInput | Yes | The payment method information to set on the cart. |
| siteId | Int | No | The site ID where the cart is created. Defaults to the store's default site ID if not provided. |
PaymentMethodInput
| Field | Type | Required | Description |
|---|---|---|---|
| code | String | Yes | The code of the payment method to use. This should be a valid payment method code configured in the store. |
Return Values
The mutation returns a CheckoutType object, which is the same as the CartType object returned by the CartQuery. For detailed information about the structure of these fields, refer to the CartQuery documentation.
Usage Example
mutation {
setPaymentMethodOnCheckout(
cartId: "abc123",
paymentMethod: {
code: "checkmo"
}
) {
billing_address {
firstname
lastname
}
shipping_address {
firstname
lastname
}
selected_payment_method {
code
title
}
}
}
Example Response
{
"data": {
"setPaymentMethodOnCheckout": {
"billing_address": {
"firstname": "John",
"lastname": "Doe"
},
"shipping_address": {
"firstname": "John",
"lastname": "Doe"
},
"selected_payment_method": {
"code": "checkmo",
"title": "Check / Money Order"
}
}
}
}
Notes
- This mutation must be called before attempting to place an order.
- The payment method code must be a valid payment method configured in the store. If an invalid payment method code is provided, an error will be thrown.
- Different payment methods may have different requirements or behaviors during the checkout process. Some payment methods may redirect the user to an external payment gateway after the order is placed.
- The available payment methods can be retrieved using the
checkoutPaymentMethodsquery. - For some payment methods, additional information may be required during the order placement process. This information is typically handled by the frontend application after the order is placed.
- If the payment method is changed, any previously selected payment method will be replaced.