Before diving into implementation details, it's important to understand the core concepts and terminology used in Purse Headless Checkout for managing payment methods.
Payment Methods vs. Payment Tokens
Payment Methods
A payment method represents a type of payment that can be used (e.g., credit card, gift card, PayPal). Payment methods are available options that customers can choose from during checkout.
const methods = checkout.paymentMethods.value;
const creditCardMethod = methods.find((method) => method.method === "creditcard");
Payment Tokens
A payment token represents a saved or registered payment instrument that can be reused. Tokens are created when:
- A customer saves a payment method for future use
- A gift card is added to the session
- A customer uses a previously saved payment method
const tokens = checkout.paymentTokens.value;
Primary vs. Secondary Payment Methods
Primary Methods
A single primary method is used for the main payment and always takes the remainder of the balance. Examples include:
- Credit/debit cards
- Digital wallets (Apple Pay, Google Pay, PayPal)
- Bank transfers
method.setAsPrimarySource();
Secondary Methods
Secondary methods are applied to the outstanding balance to complement the primary payment. Examples include:
- Gift cards
- Loyalty cards
- Store credit
Unlike primary methods, multiple secondary methods can be used in a single transaction.
if (method.isSecondary) {
}
Payment Sessions
Client Session (PaymentSession)
A client session contains the transaction details such as:
- Available payment methods and their settings
- Transaction context (amount, currency, etc.)
Update the client session when cart details change:
await checkout.setSession(newSession);
Wallet Session
A wallet session is required to manage saved payment methods. It enables:
- Editing token names
- Deleting saved tokens
await checkout.setWalletSession(walletSession);
Use a PaymentSession for checkout flows and a WalletSession for managing saved payment methods in account settings.
Payment Elements
A payment element is a UI component that handles secure payment data entry. The SDK provides payment elements for:
- Credit card details (PAN, expiry, CVV)
- CVV entry for saved cards
- Alternative Payment Methods like BNPL or Installments
const paymentElement = method.getPaymentElement();
paymentElement.appendTo(document.getElementById("form"));
Payment elements are hosted securely and handle:
- PCI-compliant data collection
- Input validation
- Error messaging
- Styling customization
Registration and Tokenization
Registration
Registration is the process of saving a payment method for future use. When a payment method is registered:
- The payment details are securely tokenized
- A reusable token is created
- The token can be used in future transactions
method.register(true, {name: "My Visa Card"});
Registration State
You can track the registration state using reactive variables:
method.registration.subscribe((registration) => {
if (registration.registered) {
console.log(`Will be saved as: ${registration.name}`);
}
});
Registration Availability
Not all payment methods support registration. Check with your account manager to enable this feature for specific payment methods.
Payment Splits
A payment split defines how the total amount is divided among different payment sources.
Primary Split
The primary split represents the main payment source. Only one primary method can be in the primary split at a time.
checkout.clearPrimarySplit();
Secondary Split
The secondary split contains supplementary payment sources (e.g., gift cards). Multiple secondary methods can be in the split simultaneously.
await token.take(amount);
token.removeFromSplit();
Reactive Variables
The SDK uses reactive variables that automatically notify subscribers when values change. This enables real-time UI updates.
checkout.paymentMethods.subscribe((methods) => {
displayMethods(methods);
});
checkout.paymentTokens.subscribe((tokens) => {
displayTokens(tokens);
});
Validation
Built-in Validation
Payment elements include built-in validation for:
- Card number format
- Expiry date validity
- CVV length
- Required fields
Next Steps
Now that you understand the core concepts, explore the implementation guides: