Overview
ThepaymentMethodId parameter allows you to specify which payment method should be used for a transaction. This gives you control over the payment experience and enables features like forcing specific payment methods, building custom selectors, or pre-selecting based on user preferences.
The
paymentMethodId is required when creating a payment session. Use getPaymentsMethods() to retrieve available payment method IDs.How it works
1
Retrieve available payment methods
Use
getPaymentsMethods() to fetch all available payment methods for your account.2
Select a payment method
Choose the appropriate payment method based on your business logic (currency, country, user preference, etc.).
3
Use the payment method ID
Pass the
id property of the selected payment method as the paymentMethodId parameter in createSession().4
Payment is processed
The customer will be directed to pay using the specified payment method.
Implementation
Example with payment method selection
Payment method object structure
When you callgetPaymentsMethods(), each payment method object contains the following properties:
| Property | Type | Description | Example |
|---|---|---|---|
id | string | Unique identifier used as paymentMethodId in createSession() | 'pm_card', 'pm_bank_transfer' |
name | string | Human-readable name to display to users | 'Credit Card', 'Bank Transfer' |
type | string | Payment type category | 'card', 'bank_transfer', 'wallet' |
currencies | string[] | List of supported currency codes (ISO 4217) | ['USD', 'EUR', 'GBP'] |
countries | string[] | List of supported country codes (ISO 3166-1 alpha-2) | ['US', 'FR', 'DE'] |
Common use cases
| Use Case | Description | Implementation |
|---|---|---|
| Force specific payment type | Only allow card payments, bank transfers, etc. | Filter methods array by type property: methods.find(m => m.type === 'card') |
| Filter by currency | Show only payment methods supporting a specific currency | Use getPaymentsMethods({ currencies: 'USD' }) or filter by currencies array |
| Filter by country | Show only payment methods available in customer’s country | Use getPaymentsMethods({ countries: 'FR' }) or filter by countries array |
| Custom payment selector | Build a UI to let users choose their payment method | Loop through methods array and display each name with a selector button |
| Save user preference | Remember and reuse customer’s preferred payment method | Store the id from their previous choice and reuse it in subsequent transactions |
| Multi-currency support | Dynamically load payment methods based on selected currency | Call getPaymentsMethods() with different currencies parameter when currency changes |
Filtering options
ThegetPaymentsMethods() method accepts optional filters:
| Filter | Type | Description | Example |
|---|---|---|---|
currencies | string | string[] | Filter by one or multiple currency codes | 'USD' or ['USD', 'EUR'] |
countries | string | string[] | Filter by one or multiple country codes | 'FR' or ['FR', 'DE', 'ES'] |