Alokai

addPaymentInstrumentToBasket

Adds a payment instrument to a basket.

This method communicates with the addPaymentInstrumentToBasket endpoint of the Vue Storefront API Middleware. In turn, it receives data from the addPaymentInstrumentToBasket or the Add payment instrument to basket endpoints exposed by SCAPI / OCAPI depending on the middleware configuration.

Signature

export declare function addPaymentInstrumentToBasket(
	props: BasketPaymentInstrumentAddParams & {
    basketId?: string;
}
): Promise<import("commerce-sdk/dist/checkout/checkout").ShopperBaskets.Basket>;

Parameters

NameRequiredTypeDescription
propsRequiredBasketPaymentInstrumentAddParams & { basketId?: string; }Parameter object which can be used with this method. Refer to its type definition to learn about possible properties.

Returns

Returns a representation of a Basket object.

Referenced Types

  • BasketPaymentInstrumentAddParams
  • ShopperBaskets.Basket

Examples

Adding a Credit Card payment instrument to a basket by BasketPaymentInstrumentAddParams.

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

const basket = await scapiClient.getBasket();
const body: BasketPaymentInstrumentAddParams = { amount: 10, paymentMethodId: 'CREDIT_CARD' };

const basket = await scapiClient.addPaymentInstrumentToBasket(
  basket.basketId,
  body
);

Adding a credit card details by paymentCard.

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

const basket = await scapiClient.getBasket();

const body: BasketPaymentInstrumentAddParams = {
 amount: 10,
 paymentMethodId: 'CREDIT_CARD',
paymentInstrumentId: "e0dc3254d8209e099914d007ce",
 paymentCard: {
  cardType: 'Visa',
  creditCardExpired: true,
  creditCardToken: 'undefined',
  expirationMonth: 1,
  expirationYear: 2023,
  holder: 'Test1 User1',
  maskedNumber: '************1111',
  numberLastDigits: '1111'
 }
};

const basket = await scapiClient.addPaymentInstrumentToBasket(
  basket.basketId,
  body
);

On this page