Pay
Creating Payment Methods
Payment Method API

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.

Prerequisites

Before creating payment methods through the API, it's helpful to learn about the following topics.


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

import payload
pl = payload.Session('secret_key_3bW9...', api_version='v2')
 
# Create a card payment method
payment_method = pl.PaymentMethod.create(
    type='card',
    card={
        'card_number': '4111111111111111',
        'expiry': '12/25',
        'card_code': '123'
    },
    account_id='acct_customer123'
)
 
print(f"Payment Method ID: {payment_method.id}")
print(f"Description: {payment_method.description}")
print(f"Status: {payment_method.status}")

This example creates a card payment method with:

  1. type='card' specifies this is a card payment method
  2. card.card_number provides the full card number
  3. card.expiry sets the expiration date in MM/YY format
  4. card.card_code includes the CVV/CVC for validation
  5. account_id associates 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.

Create a bank account payment method

import payload
pl = payload.Session('secret_key_3bW9...', api_version='v2')
 
# Create a bank account payment method
payment_method = pl.PaymentMethod.create(
    type='bank_account',
    account_holder='John Doe',
    bank_account={
        'account_number': '123456789',
        'routing_number': '110000000',
        'account_type': 'checking'
    },
    account_id='acct_customer123'
)
 
print(f"Payment Method ID: {payment_method.id}")
print(f"Bank Name: {payment_method.bank_name}")
print(f"Account Type: {payment_method.bank_account['account_type']}")
print(f"Status: {payment_method.status}")

This example creates a bank account payment method with:

  1. type='bank_account' specifies this is a bank account payment method
  2. bank_account.account_number provides the bank account number
  3. bank_account.routing_number sets the 9-digit ABA routing number
  4. bank_account.account_type specifies checking or savings account
  5. account_id associates 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.


Adding Account Holder Information

Include account holder name and details when creating payment methods.

import payload
pl = payload.Session('secret_key_3bW9...', api_version='v2')
 
# Create a card payment method with account holder name
payment_method = pl.PaymentMethod.create(
    type='card',
    card={
        'card_number': '4111111111111111',
        'expiry': '12/25',
        'card_code': '123'
    },
    account_holder='John Doe',
    account_id='acct_customer123'
)
 
print(f"Payment Method ID: {payment_method.id}")
print(f"Account Holder: {payment_method.account_holder}")

This example includes:

  1. account_holder sets the name on the payment method
  2. For cards, this is the cardholder name
  3. For bank accounts, this is the account holder name
  4. 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.

import payload
 
pl = payload.Session('secret_key_3bW9...', api_version='v2')
 
# Create a card payment method with billing address
payment_method = pl.PaymentMethod.create(
    type='card',
    card={'card_number': '4111111111111111', 'expiry': '12/25', 'card_code': '123'},
    account_holder='John Doe',
    billing_address={
        'address_line_1': '123 Main St',
        'address_line_2': 'Apt 4B',
        'city': 'San Francisco',
        'state_province': 'CA',
        'postal_code': '94102',
        'country_code': 'US',
    },
    account_id='acct_customer123',
)
 
print(f"Payment Method ID: {payment_method.id}")
print(f"Billing Postal Code: {payment_method.billing_address['postal_code']}")

This example includes:

  1. billing_address.postal_code is required for AVS verification
  2. billing_address.address_line_1 provides the street address
  3. billing_address.city, state_province, and country_code complete the address
  4. 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.


Setting Account Defaults

Configure payment methods as defaults for specific transaction types.

import payload
pl = payload.Session('secret_key_3bW9...', api_version='v2')
 
# Create a payment method and set it as default for payments
payment_method = pl.PaymentMethod.create(
    type='card',
    card={
        'card_number': '4111111111111111',
        'expiry': '12/25',
        'card_code': '123'
    },
    account_id='acct_customer123',
    account_defaults={
        'paying': 'payments'  # Set as default for payment transactions
    }
)
 
print(f"Payment Method ID: {payment_method.id}")
print(f"Default for Payments: {payment_method.account_defaults['paying']}")
 
# Create another payment method as default for payouts
payout_method = pl.PaymentMethod.create(
    type='bank_account',
    account_holder='John Doe',
    bank_account={
        'account_number': '123456789',
        'routing_number': '110000000',
        'account_type': 'checking'
    },
    account_id='acct_customer123',
    account_defaults={
        'paying': 'payouts'  # Set as default for payout transactions
    }
)
 
print(f"Payout Method ID: {payout_method.id}")
print(f"Default for Payouts: {payout_method.account_defaults['paying']}")

This example configures:

  1. account_defaults.paying sets defaults for payment and payout transactions
  2. Use 'payments' for default payment method
  3. Use 'payouts' for default payout method
  4. 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.


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.

import payload
pl = payload.Session('secret_key_3bW9...', api_version='v2')
 
# Create a reusable payment method (keep_active defaults to true)
payment_method = pl.PaymentMethod.create(
    type='card',
    card={
        'card_number': '4111111111111111',
        'expiry': '12/25',
        'card_code': '123'
    },
    account_id='acct_customer123'
    # keep_active: true is the default - payment method remains active
)
 
print(f"Payment Method ID: {payment_method.id}")
print(f"Status: {payment_method.status}")
print("Can be reused: Yes (keep_active defaults to true)")

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.

import payload
pl = payload.Session('secret_key_3bW9...', api_version='v2')
 
# Create a single-use payment method
payment_method = pl.PaymentMethod.create(
    type='card',
    card={
        'card_number': '4111111111111111',
        'expiry': '12/25',
        'card_code': '123'
    },
    account_id='acct_customer123',
    keep_active=False  # Payment method will be deactivated after first use
)
 
print(f"Payment Method ID: {payment_method.id}")
print(f"Status: {payment_method.status}")
print("Single-use: Yes (keep_active: false)")

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.

import payload
pl = payload.Session('secret_key_3bW9...', api_version='v2')
 
# Create a payment method for payouts only
payout_method = pl.PaymentMethod.create(
    type='bank_account',
    account_holder='John Doe',
    bank_account={
        'account_number': '123456789',
        'routing_number': '110000000',
        'account_type': 'checking'
    },
    account_id='acct_customer123',
    transfer_type='receive_only'  # Can only receive payouts, not make payments
)
 
print(f"Payment Method ID: {payout_method.id}")
print(f"Transfer Type: {payout_method.transfer_type}")
 
# Create a payment method for payments only
payment_method = pl.PaymentMethod.create(
    type='card',
    card={
        'card_number': '4111111111111111',
        'expiry': '12/25',
        'card_code': '123'
    },
    account_id='acct_customer123',
    transfer_type='send_only'  # Can only make payments, not receive payouts
)
 
print(f"Payment Method ID: {payment_method.id}")
print(f"Transfer Type: {payment_method.transfer_type}")

This example configures:

  1. transfer_type='two_way' allows both sending and receiving funds (default)
  2. transfer_type='send_only' only allows payments from this method
  3. 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:

type
enum[string]
The type of payment method being created or referenced. This determines which additional fields are required and how the payment method can be used.
Values: card, bank_account, synthetic
account_id ID of Account
string
The unique identifier of the account that owns this payment method. This determines which account has access to use this payment method for transactions and defines the ownership and permissions associated with it. (ID prefix: acct)
Pattern: ^acct_[A-Za-z0-9]+$
account_holder
stringImmutable
The name of the business or individual who owns this payment method. For cards, this is the cardholder name. For bank accounts, this is the account holder name.
Max length: 128
description
string
A human-readable description or label for the payment method. This can be used to help identify the payment method in lists or for display purposes. This is typically autogenerated but can be provided to override the default.
keep_active
booleanImmutable
Determines whether this payment method should remain active after use. Set to false for single-use payment methods that should be automatically deactivated after their first successful transaction.
transfer_type
enum[string]Immutable
Specifies the allowed transfer directions for this payment method. This controls whether the payment method can be used to send funds, receive funds, or both.
Values: two_way, send_only, receive_only

Card Payment Method

Fields required for card payment methods:

card_number
stringImmutable
The full credit or debit card number. When retrieved, only the last 4 digits will be visible, with the first 12 digits masked for security.
Pattern: ^[0-9]+$
Max length: 19
Required if:
track1=null
type=card
expiry
string (date-time)
The expiration date of the card in MM/YY format. The card must not be expired at the time of submission.
Pattern: ^(0[1-9]|1[0-2])([0-9]{2}|[0-9]{4})$
Required if:
card[track1]=null
type=card
type
enum[string]
The type of card being used for the payment method. This determines how the card can be used for transactions. Can be provided to enforce the card type. If provided, an error or decline will throw if the card does not match type.
Values: credit, debit, prepaid

Bank Account Payment Method

Fields required for bank account payment methods:

account_number
stringImmutable
The bank account number associated with this payment method. When retrieved, only the last 4 digits will be visible, with the preceding digits masked for security.
Pattern: ^[0-9]+$
Max length: 32
routing_number
stringImmutable
The 9-digit ABA routing number that identifies the financial institution. When retrieved, only the last 4 digits will be visible for security purposes.
Pattern: ^[0-9]+$
Max length: 9
account_type
enum[string]Immutable
The type of bank account, either a checking account used for everyday transactions or a savings account used for storing funds.
Values: checking, savings
account_class
enum[string]Immutable
The classification of the bank account ownership, indicating whether this is a personal account owned by an individual or a business account owned by a company.
Values: personal, business

Billing Address

Fields for billing address information:

postal_code
string
Postal code of the address
Max length: 7
address_line_1
string
Street address of the address
Max length: 128
address_line_2
string
Unit number of the address
Max length: 56
city
string
City of the company
state_province
string
State of the address
Max length: 2
country_code
string
Country code of the address
Max length: 2

Account Defaults

Fields for configuring default payment methods:

paying
enum[string]
Specifies which types of paying transactions this payment method should be used for by default. Set to "payments" to use for collecting payments from the account holder, "payouts" to use for sending credits or refunds to the account holder, or "all" to use for both payment types. Will be used for any automatic invoice payments if selected as the default for payments.
Values: all, payments, payouts
funding
enum[string]
Specifies which types of funding transactions this payment method should be used for by default. Set to "deposits" to use for receiving funds into the account, "withdraws" to use for pulling funds from the account, or "all" to use for both funding types.
Values: all, deposits, withdraws

For complete field documentation, see:

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