setPaymentMethodOnCart mutation

The setPaymentMethodOnCart mutation defines which payment method to apply to the cart. Magento GraphQL supports the following payment methods:

Title Code
Bank Transfer Payment banktransfer
Cash on Delivery cashondelivery
Check / Money order checkmo
No Payment Information Required free
Purchase Order purchaseorder

Apply the setPaymentMethodOnCart mutation after setting the shipping address, shipping method, and after applying any discounts to the cart.

Syntax

mutation: {setPaymentMethodOnCart(input: SetPaymentMethodOnCartInput): SetPaymentMethodOnCartOutput}}

Example usage

The following example assigns the banktransfer payment method to the specified cart.

Request

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
mutation {
  setPaymentMethodOnCart(input: {
      cart_id: "rMQdWEecBZr4SVWZwj2AF6y0dNCKQ8uH"
      payment_method: {
          code: "banktransfer"
      }
  }) {
    cart {
      selected_payment_method {
        code
        title
      }
    }
  }
}

Response

1
2
3
4
5
6
7
8
9
10
11
12
{
  "data": {
    "setPaymentMethodOnCart": {
      "cart": {
        "selected_payment_method": {
          "code": "banktransfer",
          "title": "Bank Transfer Payment"
        }
      }
    }
  }
}

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:

Attribute Data Type Description
cart_id String! The unique ID that identifies the customer’s cart
payment_method PaymentMethodInput! An object containing the payment method code

PaymentMethodInput attributes

The PaymentMethodInput object can contain the following attributes:

Attribute Data Type Description
code String! The internal name for the payment method
purchase_order_number String The purchase order number. Optional for most payment methods

Output attributes

The SetPaymentMethodOnCartOutput object contains the Cart object.

Attribute Data Type Description
cart Cart! Describes the contents of the specified shopping cart

Cart object

Attribute Data Type Description
applied_coupon AppliedCoupon The AppliedCoupon object contains the code text attribute, which specifies the coupon code
available_payment_methods AvailablePaymentMethod Available payment methods
billing_address BillingCartAddress Contains the billing address specified in the customer’s cart
email String The customer’s email address
items CartItemInterface Contains the items in the customer’s cart
prices CartPrices Contains subtotals and totals
selected_payment_method SelectedPaymentMethod Selected payment method
shipping_addresses ShippingCartAddress Contains one or more shipping addresses

Cart query output provides more information about the Cart object.