Skip to main content

PurseHeadlessCheckout

Implements

Properties

__internal__

readonly __internal__: object;

Internal data dedicated to Purse usage.

session

session: PurseHeadlessCheckoutV1Params & object;
Type Declaration
apiPaths
apiPaths: APIPaths | undefined;

Implementation of

HeadlessCheckout.__internal__

amountSplit

amountSplit: Readable<PaymentSplit[]>;

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);
});

Implementation of

HeadlessCheckout.amountSplit


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();
}
});

Implementation of

HeadlessCheckout.isPaymentFulfilled


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
});

Implementation of

HeadlessCheckout.paymentMethods


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
});

Implementation of

HeadlessCheckout.paymentTokens


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);
});

Implementation of

HeadlessCheckout.remainingAmountToPay

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();

Implementation of

HeadlessCheckout.clearPrimarySplit


deleteAllTokens()

deleteAllTokens(): Promise<void>;

Remove all tokens from the provided wallet session

Returns

Promise<void>

Throws

Example

headlessCheckout.deleteAllTokens();

Implementation of

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>

Throws
Example
headlessCheckout.setSession(paymentSession);
Implementation of

HeadlessCheckout.setSession

Call Signature

setSession(widgetData): Promise<void>;

Updates the session with the provided session data.

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

Promise<void>

Throws
Example
headlessCheckout.setSession(paymentSession);
Implementation of

HeadlessCheckout.setSession


setWalletSession()

setWalletSession(walletSession): Promise<void>;

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

Parameters

ParameterTypeDescription
walletSessionOnePayWalletSession

Returns

Promise<void>

Throws

PurseHeadlessCheckoutError SET_WALLET_SESSION_FAILED
If setting the wallet session fails

Example

headlessCheckout.setWalletSession(walletSession);

Implementation of

HeadlessCheckout.setWalletSession


submitPayment()

submitPayment(skipOnBeforeValidateHook?): Promise<void>;

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

Parameters

ParameterType
skipOnBeforeValidateHook?boolean

Returns

Promise<void>

Throws

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);
}

Implementation of

HeadlessCheckout.submitPayment


teardown()

teardown(): void;

Cleans up resources and removes event listeners.

Returns

void

Example

headlessCheckout.teardown();

Implementation of

HeadlessCheckout.teardown


getConfigFromParams()

static getConfigFromParams(checkoutParams, apiPaths?): PurseHeadlessCheckoutV1Params & object;

Get the config from params

Parameters

ParameterTypeDescription
checkoutParams| string | PurseHeadlessCheckoutV1ParamsThe checkoutParams data for initializing the checkout.
apiPaths?APIPathsdev purposes only to override the APi URL's

Returns

PurseHeadlessCheckoutV1Params & object