setPaymentMethodOnCart mutation
The setPaymentMethodOnCart mutation defines which payment method to apply to the cart. Adobe Commerce and Magento Open Source GraphQL supports the following offline payment methods:
banktransfercashondeliverycheckmofreepurchaseorderSupported online payment methods include:
- Braintree
- Braintree Vault
- PayPal Express Checkout
- PayPal Payflow Link
- PayPal Payflow Pro
- PayPal Payflow Pro Vault
- PayPal Payments Advanced
- PayPal Website Payments Pro Hosted Solution
- Express Checkout for other PayPal solutions
For all online payment methods, the payload must include an object that defines additional information specific to that payment method. For example, the payload for Braintree payment method includes the following object:
braintree: {
payment_method_nonce: "fake-nonce"
is_active_payment_token_enabler: false
}
Syntax
mutation: {setPaymentMethodOnCart(input: SetPaymentMethodOnCartInput): SetPaymentMethodOnCartOutput}}
Reference
The setPaymentMethodOnCart reference provides detailed information about the types and fields defined in this mutation.
Example usage
Offline payment method
The following example assigns the banktransfer payment method to the specified cart.
Request:
mutation {
setPaymentMethodOnCart(input: {
cart_id: "rMQdWEecBZr4SVWZwj2AF6y0dNCKQ8uH"
payment_method: {
code: "banktransfer"
}
}) {
cart {
selected_payment_method {
code
title
}
}
}
}
Response:
{
"data": {
"setPaymentMethodOnCart": {
"cart": {
"selected_payment_method": {
"code": "banktransfer",
"title": "Bank Transfer Payment"
}
}
}
}
}
Online payment method
The following example shows the setPaymentMethodOnCart mutation constructed for the Braintree payment method.
Request:
mutation {
setPaymentMethodOnCart(input: {
cart_id: "IeTUiU0oCXjm0uRqGCOuhQ2AuQatogjG"
payment_method: {
code: "braintree"
braintree: {
payment_method_nonce: "fake-nonce"
is_active_payment_token_enabler: false
}
}
}) {
cart {
selected_payment_method {
code
}
}
}
Response:
{
"data": {
"setPaymentMethodOnCart": {
"cart": {
"selected_payment_method": {
"code": "braintree"
}
}
}
}
}
Input attributes
The top-level SetPaymentMethodOnCartInput object is listed first. All child objects are listed in alphabetical order.
SetPaymentMethodOnCartInput attributes
The SetPaymentMethodOnCartInput object must contain the following attributes:
cart_idPaymentMethodInput attributes
The PaymentMethodInput object can contain the following attributes:
codepurchase_order_numberFor all online payment methods, the payload must include an object that defines additional information specific to that payment method.
Errors
Could not find a cart with ID "XXX"cart_id value does not exist in the quote_id_mask table.Required parameter "cart_id" is missing.cart_id argument is empty.Required parameter "code" for "payment_method" is missing.code argument is empty.The current user cannot perform operations on cart "XXX"The requested Payment Method is not available.payment_method argument payment method is disabled or does not exist.The shipping address is missing. Set the address and try again.setPaymentMethodOnCart mutation before setShippingAddressesOnCart. Set a shipping address first. GraphQL checkout tutorial shows the order placement sequence.