Building Custom Payment Method Forms
Learn how to create fully-customized forms for saving payment methods with secure input fields
The Payment Method Form SDK provides secure, PCI-compliant input fields that you can embed into custom-built forms for collecting and saving payment method details. Unlike payment forms that immediately process a transaction, the Payment Method Form saves card or bank account information for future use without charging the customer. This gives you complete control over your form's HTML, styling, and user experience while keeping sensitive payment data secure through isolated secure input fields.
Use the Payment Method Form when you need full design control over your payment method collection experience. For a hosted checkout page, see Checkout Plugin. For direct API integration, see Payment Method API.
Prerequisites
Before building payment method forms, it's helpful to learn about the following topics.
How payment methods work
Learn how payment methods are used to store bank accounts for receiving payouts.
Enrolling accounts with entity verification
Learn how to create accounts with enhanced entity verification for payout recipients requiring business validation.
When to Use Payment Method Forms
Use the Payment Method Form SDK when you need to save payment method details for future use without immediately processing a payment. This is ideal for customer wallet management, subscription setup, and recurring payment scenarios where you want customers to save their payment information upfront.
By collecting payment details separately from transactions, you enable faster checkout experiences, recurring billing, and flexible payment management. The SDK handles sensitive data securely while giving you full control over the form design, layout, and user flow.
Common use cases
- Customer Wallet Management: Allow customers to add, update, and manage saved payment methods in account settings
- Subscription Setup: Collect payment methods during subscription signup without immediate billing
- Trial Period Enrollment: Save payment method during trial signup for automatic conversion to paid
- Recurring Payment Setup: Enable customers to save payment methods for automatic billing cycles
- Multiple Payment Methods: Let customers add and manage multiple payment options
- Payment Method Updates: Replace expired cards or update bank account information
- Tokenization for Future Use: Securely store payment details for future one-click purchases
How Payment Method Forms Work
Payment Method Forms use a combination of regular HTML inputs and secure input fields:
Secure Input Fields
Sensitive data like card numbers, CVV, account numbers, and routing numbers are rendered in
isolated iframes that communicate with Payload's secure environment. These fields appear as
<div> elements with special attributes.
Regular Input Fields
Non-sensitive data like account holder name, billing address, and account type use standard HTML
<input> elements with special attributes to identify them to the SDK.
Form Submission
When the form is submitted, the SDK collects data from both secure and regular fields, sends sensitive data directly to Payload's servers, and returns a payment method ID to your application.
PCI Compliance: Sensitive payment data never touches your server. The secure input fields communicate directly with Payload's PCI-compliant environment, keeping your application out of PCI scope.
Building a Payment Method Form
Creating a payment method form requires three steps: building the HTML form, creating an intent on your backend, and initializing the form with JavaScript.
This example shows the complete flow for building a custom payment method form:
- Backend: Create an intent with
type='payment_method_form'and configure payment method defaults - Frontend HTML: Build your form with
pl-form="payment_method"attribute and secure input fields usingpl-inputattributes - Frontend JavaScript: Initialize with
Payload(token)andnew Payload.Form(formElement), or use React components like<PaymentMethodForm>,<CardNumber>,<RoutingNumber> - Event Handling: Listen for
successorerrorevents (or use React props likeonSuccess,onError)
The secure input fields render as iframes that capture sensitive data without exposing it to your application.
Secure Input Fields
The Payment Method Form SDK provides secure input components for capturing sensitive payment data. These fields are rendered as isolated iframes that communicate directly with Payload's secure environment.
Card Input Fields
Use a single combined card input
The combined card input provides all card fields in one input element:
This creates a single input field that accepts card number, expiration, and CVV in a combined interface. This is the simplest option for collecting card details.
Use individual card input fields
Individual card fields give you more control over layout:
This creates three separate input fields for card number, expiration, and CVV, allowing you to arrange them in custom layouts that match your design system.
Use Google Pay for card collection
Google Pay allows customers to save payment methods using their Google account:
This creates a Google Pay button that opens Google's payment sheet. When the customer selects a
card from their Google Pay wallet, it's automatically saved as a payment method. The
.googlepay() method activates the button and includes a callback to detect if Google Pay is
available on the device.
Google Pay Availability: Google Pay is available on Chrome, Edge, and other Chromium-based browsers. The callback function allows you to hide the button if Google Pay is not supported on the user's device.
Use Apple Pay for card collection
Apple Pay allows customers to save payment methods using their Apple Wallet:
This creates an Apple Pay button that opens Apple's payment sheet. When the customer authorizes
with Face ID, Touch ID, or passcode, their selected card is saved as a payment method. The
.applepay() method activates the button and includes a callback to detect if Apple Pay is
available on the device.
Apple Pay Availability: Apple Pay is available on Safari for iOS, iPadOS, and macOS devices that support Apple Pay. The callback function allows you to hide the button if Apple Pay is not supported on the user's device.
Bank Account Input Fields
Use manual bank account entry
Manually enter routing number and account number:
This creates secure input fields for routing number and account number, along with selects for account type (checking/savings) and account class (personal/business).
Bank Account Verification: Bank accounts added through manual entry may require verification before use. See Payment Method Verification for details on verification methods like micro-deposits.
Use Plaid for instant bank connection
Plaid allows customers to connect their bank accounts by logging into their bank:
This creates a button that opens Plaid's Link interface. When the customer selects their bank
and logs in, their bank account is instantly connected and verified. The .plaid() method
activates the button and includes a callback to detect if Plaid is available and configured.
Instant Verification: Plaid-connected accounts are instantly verified, eliminating the need for micro-deposit verification and providing a faster enrollment experience. Plaid requires configuration in your Payload account settings.
Regular Input Fields
Non-sensitive data uses standard HTML inputs with pl-input attributes. These fields can be any
HTML input type and are used for account holder information, billing details, and configuration.
Account Holder Information
The account holder name is required for most payment methods and should match the name on the card or bank account.
Billing Address
Common billing fields:
-
billing_address[postal_code]- Postal/ZIP code (required for AVS) -
billing_address[address_line_1]- Street address -
billing_address[city]- City -
billing_address[state_province]- State/province -
billing_address[country_code]- Country code
Transfer Type Configuration
Control how the payment method can be used:
Transfer types:
-
send_only- Can only be used for payments (default for cards) -
receive_only- Can only be used for receiving payouts (common for bank accounts) -
two_way- Can be used for both payments and payouts
Handling Form Events
The Payment Method Form SDK emits events throughout the payment method creation lifecycle. Listen for these events to handle successful saves, errors, and validation.
Success Events
Error Events
Validation Events
Setting Account Defaults
Configure payment methods as defaults for specific transaction types. This enables automatic payment method selection for recurring billing, invoice payments, and payouts.
Default configurations:
-
account_defaults.paying: 'payments'- Default for collecting payments -
account_defaults.paying: 'payouts'- Default for receiving payouts -
account_defaults.paying: 'all'- Default for both payments and payouts
When a payment method is set as the default, transactions can reference only the account ID without specifying a payment method ID.
Pre-filling Form Values
Reduce form friction by pre-filling known information like account holder name or billing address from the customer's profile.
Pre-fill values in the intent's payment_method_template:
-
account_holder- Name of the account holder -
billing_address- Known billing address -
bank_account.currency- Bank account currency (USD/CAD) -
transfer_type- Payment method usage restrictions
Styling Secure Input Fields
You can style secure input fields to match your form's design using several approaches. While secure inputs are rendered in isolated iframes for PCI compliance, the SDK provides multiple ways to apply custom styling.
Extend Payload Classes
Style secure inputs by targeting Payload's default CSS classes:
Payload provides default classes that you can extend with custom CSS rules:
-
pl-input- Base input styling -
pl-input-sec- Secure field styling -
pl-focus- Focused input state -
pl-invalid- Invalid input state
Override Default Classes
Replace Payload's default classes with your own:
This is useful when integrating with CSS frameworks like Bootstrap or Tailwind.
Schema Reference
The following fields are available when configuring the Payment Method Form intent:
Intent Configuration
Configuration options passed when creating the payment method form intent on your backend:
payment_method_formpayment_method_templateaccount_defaultsfundingall, deposits, withdrawspayingall, payments, payoutsaccount_holderaccount_idbank_accountcurrencyUSD, CADbilling_addressaddress_line_1address_line_2citycountry_codepostal_codestate_provinceidtransfer_typesend_only, receive_only, two_wayNext Steps
Enhance payment processing and payment method management
Process Transactions
Use Payment API to process payments with saved payment methods, send Payouts to saved bank accounts, and set up Recurring Payments for automatic billing with saved methods.
Verify and Manage Payment Methods
Implement Payment Method Verification to verify bank accounts and cards, use Payment Method API to programmatically manage payment methods, and explore Updating Payment Methods to modify existing methods.
Build Payment Interfaces
Create Payment Form for collecting payment and processing immediately, integrate Checkout Plugin for pre-built checkout UI, and add Digital Wallets like Plaid, Apple Pay, and Google Pay.
Related articles
- Payment Methods - Overview of payment methods
- Payment Method API - Backend payment method creation
- Payment Form - Collect payment and process immediately
- Plaid Integration - Instant bank account connection
- Google Pay - Google Pay integration guide
- Apple Pay - Apple Pay integration guide
- Intents API Reference - Complete API reference
- Payment Methods API Reference - Payment method API details