Skip to main content

PurseHeadlessCheckout

Properties

amountSplit

amountSplit: Readable<PurseHeadlessCheckoutPaymentSplit[]>;

Splits represent the repartition between the primary payment method and the secondary payment methods.

PurseHeadlessCheckoutPaymentSplit

Example

headlessCheckout.amountSplit.subscribe((splits: PurseHeadlessCheckoutPaymentSplit[]) => {
console.log('The payment composition changed', splits);
});

isPaymentFulfilled

readonly isPaymentFulfilled: Readable<boolean>;

This property indicates if the payment can be submitted.

Example

headlessCheckout.isPaymentFulfilled.subscribe((isFulfilled: boolean) => {
if(isFulfilled) {
enablePayButton();
}else{
disablePayButton();
}
});

paymentMethods

readonly paymentMethods: Writable<PurseHeadlessCheckoutPaymentMethod[]>;

List of available payment methods for the checkout. This property is a Writable object containing an array of PurseCheckoutPaymentMethod. Each payment-element in the array represents a payment method with its associated properties.

Example

headlessCheckout.paymentMethods.subscribe((methods: PurseCheckoutPaymentMethod[]) => {
console.log('The payment methods changed', methods);
// Perhaps update the UI with the new methods
});

paymentTokens

readonly paymentTokens: Writable<PurseHeadlessCheckoutPaymentToken[]>;

List of available payment tokens for the checkout. This property is a Writable object containing an array of PurseCheckoutPaymentToken. Each payment-element in the array represents a payment token with its associated properties.

Example

headlessCheckout.paymentTokens.subscribe((tokens: PurseCheckoutPaymentToken[]) => {
console.log('The payment tokens changed', tokens);
// Perhaps update the UI with the new tokens
});

remainingAmountToPay

remainingAmountToPay: Readable<number>;

The remaining amount to pay represents the amount that is left to pay after the secondary payment method(s) has been used.

Example

headlessCheckout.remainingAmountToPay.subscribe((amount: number) => {
console.log('Perhaps update the text in your pay button', amount);
});

Methods

clearPrimarySplit()

clearPrimarySplit(): void;

Clears the primary split from the amount share. Nothing happens if the primary split is already cleared.

Returns

void

Example

headlessCheckout.clearPrimarySplit();

deleteAllTokens()

deleteAllTokens(): Promise<void>;

Remove all tokens from the provided wallet session

Returns

Promise<void>

Throws

If the wallet session is missing

Throws

If deleting the tokens fails

Example

headlessCheckout.deleteAllTokens();

setSession()

Call Signature

setSession(widgetData): Promise<void>;

Updates the session with the provided session data.

Parameters
ParameterTypeDescription
widgetDatastringThe session data. Can be either an encoded string (V2) or a payment session object (V1).
Returns

Promise<void>

Example
headlessCheckout.setSession(paymentSession);

Call Signature

setSession(widgetData): Promise<void>;

Updates the session with the provided session data.

Parameters
ParameterTypeDescription
widgetDataPaymentSessionModelThe session data. Can be either an encoded string (V2) or a payment session object (V1).
Returns

Promise<void>

Example
headlessCheckout.setSession(paymentSession);

setWalletSession()

setWalletSession(walletSession): undefined | Promise<Wallet<WalletActions>>;

Sets the wallet session. The wallet session is used to retrieve and manage the user's stored card tokens.

Parameters

ParameterTypeDescription
walletSessionWalletSessionModel

Returns

undefined | Promise<Wallet<WalletActions>>

Throws

If setting the wallet session fails

Example

headlessCheckout.setWalletSession(walletSession);

submitPayment()

submitPayment(): Promise<void>;

Submits the current payment configuration for processing. This will validate and process all payment methods in the current split configuration.

Returns

Promise<void>

Throws

If:

  • No payment methods are configured
  • Payment validation fails
  • Payment processing fails
  • The total amount does not match the session amount

Example

try {
// Configure payment methods and amounts
await primaryMethod.setAsPrimarySource();
await secondaryToken.take(50.00);

// Submit the payment
await checkout.submitPayment();
console.log('Payment successful!');
} catch (error) {
console.error('Payment failed:', error);
}

teardown()

teardown(): void;

Cleans up resources and removes event listeners.

Returns

void

Example

headlessCheckout.teardown();