Creating Payment Methods via API
Learn how to create and manage payment methods programmatically through the Payment Method API
The Payment Method API allows you to create, update, and manage payment methods directly through your backend. This provides full control over payment method creation and enables you to build custom payment flows, batch operations, and integrations with your application logic. Use the Payment Method API when you need programmatic control over payment method management or server-to-server payment flows.
PCI Compliance and Security Required: Creating payment methods via API means your server handles sensitive payment data directly. You must be PCI DSS Level 1 compliant to process card numbers and CVV codes through your backend. Never log or store raw card numbers, expiry dates, CVV codes, or full bank account numbers. Use HTTPS for all API requests. Consider using Payment Method Form for PCI-compliant hosted forms that don't require your server to handle sensitive data.
Prerequisites
Before creating payment methods through the API, it's helpful to learn about the following topics.
Learn about payment methods
Understand payment method types, validation requirements, and security best practices.
Learn about accounts
Understand customer accounts and how payment methods are associated with account holders.
When to Use Payment Method API
Use the Payment Method API when you need direct, programmatic control over payment method creation and management from your backend. The API enables server-side payment method flows where you manage the entire payment method lifecycle through API calls.
The Payment Method API receives raw payment data through your backend and immediately tokenizes it for secure storage. While your server temporarily handles sensitive data during API calls, you must maintain PCI DSS compliance, use HTTPS, and never log or store raw payment information. Payload handles tokenization, validation, and secure storage after creation. You maintain complete control over payment method creation timing, account association, and integration with your business logic.
Common use cases
- Backend Payment Method Management: Create and manage payment methods server-side
- Batch Operations: Create multiple payment methods programmatically
- Migration from Other Systems: Import existing payment methods
- Custom Payment Flows: Build payment method experiences tailored to your needs
Creating Payment Methods
Create payment methods by providing card or bank account details.
Create a card payment method
This example creates a card payment method with:
-
type='card'specifies this is a card payment method -
card.card_numberprovides the full card number -
card.expirysets the expiration date in MM/YY format -
card.card_codeincludes the CVV/CVC for validation -
account_idassociates the payment method with a customer account
The response includes the payment method with masked card details, brand detection (Visa, Mastercard, etc.), and a unique payment method ID for future use.
Security Requirements: When creating card payment methods via API, ensure your integration is PCI DSS compliant. Never log or store raw card numbers, expiry dates, or CVV codes. Always use HTTPS for transmitting card data. Payload handles tokenization and secure storage after creation.
Create a bank account payment method
This example creates a bank account payment method with:
-
type='bank_account'specifies this is a bank account payment method -
bank_account.account_numberprovides the bank account number -
bank_account.routing_numbersets the 9-digit ABA routing number -
bank_account.account_typespecifies checking or savings account -
account_idassociates the payment method with a customer account
Bank account payment methods can be used for bank payments and payouts. The response includes masked account details and automatically determines the bank name from the routing number.
Security Requirements: When creating bank account payment methods via API, never log or store full bank account numbers. Always use HTTPS for transmitting account data. Payload handles tokenization and secure storage after creation.
Bank Account Verification: Bank accounts should be verified before processing payments to ensure account ownership and reduce reject rates. See Payment Method Verification for details on verification methods.
Adding Account Holder Information
Include account holder name and details when creating payment methods.
This example includes:
-
account_holdersets the name on the payment method - For cards, this is the cardholder name
- For bank accounts, this is the account holder name
- Helps with validation and record-keeping
Including account holder information improves payment processing success rates and provides better context for customer support and reconciliation.
Adding Billing Address
Include billing address information for address verification (AVS) and validation.
This example includes:
-
billing_address.postal_codeis required for AVS verification -
billing_address.address_line_1provides the street address -
billing_address.city,state_province, andcountry_codecomplete the address - Address verification helps reduce fraud and improve authorization rates
Billing addresses are used during payment processing to verify the cardholder's identity and reduce fraudulent transactions.
Address Verification: Including complete billing address information improves authorization rates and helps prevent fraud. The postal code is required for AVS validation.
Setting Account Defaults
Configure payment methods as defaults for specific transaction types.
This example configures:
-
account_defaults.payingsets defaults for payment and payout transactions - Use
'payments'for default payment method - Use
'payouts'for default payout method - Use
'all'to set as default for both payment types
When a payment method is set as a default, transactions can reference only the account ID without specifying a payment method ID, simplifying API calls.
Default Payment Methods: Only one payment method per account can be set as the default for each transaction type. Setting a new default automatically removes the default flag from the previous payment method.
Controlling Payment Method Reuse
Control whether payment methods can be reused for future transactions.
Payment method remains active after use
Create a payment method that can be used multiple times.
By default, payment methods remain active and can be used for multiple transactions. This is the recommended approach for:
- Recurring payments and subscriptions
- Customer saved payment methods
- Multi-transaction scenarios
- Customer payment method management
Payment method deactivates after first use
Create a payment method for one-time use only.
Setting keep_active: false creates a single-use payment method that is automatically
deactivated after the first successful transaction. This is useful for:
- One-time guest checkouts
- Temporary payment methods
- Security-sensitive scenarios requiring one-time use
- Compliance requirements mandating single-use methods
Specifying Transfer Type
Control the allowed transfer directions for payment methods.
This example configures:
-
transfer_type='two_way'allows both sending and receiving funds (default) -
transfer_type='send_only'only allows payments from this method -
transfer_type='receive_only'only allows payouts to this method
Transfer type restrictions help manage payment method usage and enforce business rules about which payment methods can be used for specific transaction types.
Schema Reference
The following fields are available when creating and managing payment methods:
Payment Method Configuration
Core fields used when creating payment methods:
typecard, bank_account, syntheticaccount_id ID of Account^acct_[A-Za-z0-9]+$account_holderdescriptionkeep_activetransfer_typetwo_way, send_only, receive_onlyCard Payment Method
Fields required for card payment methods:
card_number^[0-9]+$track1=nulltype=cardexpiry^(0[1-9]|1[0-2])([0-9]{2}|[0-9]{4})$card[track1]=nulltype=cardtypecredit, debit, prepaidBank Account Payment Method
Fields required for bank account payment methods:
account_number^[0-9]+$routing_number^[0-9]+$account_typechecking, savingsaccount_classpersonal, businessBilling Address
Fields for billing address information:
postal_codeaddress_line_1address_line_2citystate_provincecountry_codeAccount Defaults
Fields for configuring default payment methods:
payingall, payments, payoutsfundingall, deposits, withdrawsFor complete field documentation, see:
- Payment Methods API Reference - All payment method fields, properties, and methods
Next Steps
Enhance payment processing and payment method management
Process Transactions
Use Payment API to process payments with saved payment methods, send Payouts to payment methods, and create Inline Payment Methods during transactions.
Verify and Manage Payment Methods
Implement Payment Method Verification to verify bank accounts and cards, use Updating Payment Methods to modify existing payment methods, and explore Payment Method Types to understand different payment method options.
Build User Interfaces
Create Payment Method Form for embedded payment method collection, integrate Checkout Plugin for complete checkout experiences, and build Payment Form interfaces for custom payment flows.
Related articles
- Payment Methods - Overview of payment methods
- Payment Method Types - Card payment methods
- Payment Method Types - Bank account payment methods
- Payment Methods API Reference - Complete API reference