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.
Link
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);
});
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);
});
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
| Parameter | Type | Description |
|---|
widgetData | string | The 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
| Parameter | Type | Description |
|---|
widgetData | LegacyPaymentSession | The 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
| Parameter | Type | Description |
|---|
walletSession | OnePayWalletSession | |
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
| Parameter | Type |
|---|
skipOnBeforeValidateHook? | boolean |
Returns
Promise<void>
Throws
Example
try {
await primaryMethod.setAsPrimarySource();
await secondaryToken.take(50.00);
await checkout.submitPayment();
console.log('Payment successful!');
} catch (error) {
console.error('Payment failed:', error);
}
Implementation of
HeadlessCheckout.submitPayment
teardown()
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
| Parameter | Type | Description |
|---|
checkoutParams | | string | PurseHeadlessCheckoutV1Params | The checkoutParams data for initializing the checkout. |
apiPaths? | APIPaths | dev purposes only to override the APi URL's |
Returns
PurseHeadlessCheckoutV1Params & object