Alokai

setPaymentMethodOnCart

Set payment method on cart.

Signature

declare function setPaymentMethodOnCart(
	context: Context,
	input: SetPaymentMethodOnCartInput,
	customQuery?: CustomQuery,
	customHeaders?: CustomHeaders
): Promise<FetchResult<SetPaymentMethodOnCartMutation>>;

Parameters

NameRequiredTypeDescription
contextRequiredContext
inputRequiredSetPaymentMethodOnCartInput
customQueryOptionalCustomQuery
customHeadersOptionalCustomHeaders

Referenced Types

Examples

Simple usage:

import { sdk } from '~/sdk.config.ts';

// set payment method on cart
const result = await sdk.magento.setPaymentMethodOnCart({
  cart_id: 'some-cart-id',
  payment_method: {
    code: 'checkmo'
  }
});

Creating a custom GraphQL query for setting payment method on cart

module.exports = {
  integrations: {
    magento: {
      customQueries: {
        'set-payment-method-on-cart-custom-query': ({ variables, metadata }) => ({
           variables,
           query: `
             mutation setPaymentMethodOnCart($input: SetPaymentMethodOnCartInput) {
               setPaymentMethodOnCart(input: $input) {
                 cart {
                   ${metadata.fields}
                 }
               }
             }`
        }),
      },
    }
  }
};

Using a custom GraphQL query to set payment method on cart

import { sdk } from '~/sdk.config.ts';
// reduce the amount of fields returned by the query, when compared to the default query
const customQuery = {
  setPaymentMethodOnCart: 'set-payment-method-on-cart-custom-query',
  metadata: {
    fields: 'id email'
  }
};

const result = await sdk.magento.setPaymentMethodOnCart({
  cart_id: 'some-cart-id',
  payment_method: {
    code: 'checkmo'
  }
}, customQuery);

// result will contain only the fields specified in the custom query.

On this page