Skip to content

GiftCardPaymentAdapter

Adapter in @evolve-framework/commercetools

Paying with a gift card, a partial method: it covers the smaller of the card's balance and what is left to pay, and several cards can sit on one cart beside the method that pays the rest.

import { GiftCardPaymentAdapter } from "@evolve-framework/commercetools/gift-card";
new GiftCardPaymentAdapter(options: GiftCardPaymentAdapterOptions)
OptionTypeDescription
clientFactoryClientFactory

The commercetools client its requests to the project go through, built with ClientFactory.create.

storeGiftCardStore

Where the cards live.

GiftCardStore4The fields of store.
FieldTypeDescription
checkBalance(card: GiftCardCredentials) => Promise<GiftCardBalance>

The balance available to spend. Throws InvalidGiftCardError.

reserve(card: GiftCardCredentials & { holdId: string; centAmount: number; currency: string; }) => Promise<void>

Hold centAmount of the card for holdId. Throws InvalidGiftCardError, or InsufficientBalanceError when less is available. Holding the same holdId again for the same amount changes nothing.

capture(args: { number: string; holdId: string; }) => Promise<void>

Take what holdId holds off the card. Nothing happens when it holds nothing.

release(args: { number: string; holdId: string; centAmount?: number | undefined; }) => Promise<void>

Give back centAmount of what holdId holds, or all of it. Nothing happens when it holds nothing.

MethodDescription
partialAmount( target: Cart | Order, methodArgs: Record<string, unknown>, ): Promise<number>How much of the cart the card can pay.
captureReserved(payment: Payment): Promise<void>Takes the amount held for this payment off the card it was reserved on.
releaseReserved( payment: Payment, centAmount?: number, ): Promise<void>Gives back centAmount of the amount held for this payment to the card, or all of it when centAmount is omitted.

Extends BasePaymentAdapter.