Search Documentation
Search across all documentation pages, APIs and guides.
Card on File ( Automated Charging )
Card on File lets you save a customer's card once and charge it programmatically at any future point, without the customer needing to re-enter their details. Think of how Uber charges the passenger's card automatically at the end of every ride: the customer approves it once, and every charge after that is invisible to them.
What can I use it for?
Card on File is suitable for any product or business where you have known, registered customers and want to charge them on demand without asking them to manually enter card details every time.
Monthly subscription billing
Charge a fixed plan price on the 1st of every month. Customer approves once at signup, you handle every renewal silently. Works for Basic / Pro / Enterprise tiers.
Pay as you go
Tally API calls, data consumed, or seats used at period-end. Charge exactly what the customer owes, the token stays the same, only the amount changes each cycle.
In-app purchases on demand
Multiple in-app purchases or on-demand services without redirecting users to a payment page each time. Charge instantly when the user triggers an action.
One-click repeat purchases
Returning customers checkout in one click. No card re-entry, no redirect. Especially powerful for high-frequency buyers and loyalty programs.
How it works - 3 steps
The entire Card on File flow reduces to three things: get permission, store the token, charge when needed.
Your customer creates a profile on your platform. You redirect them to the OnePay secure card-entry page. They enter their card details and consent to future charges. OnePay returns a cus_ ID and a redirect_url.
After the customer completes card entry, call the List Cards endpoint to retrieve their tok_ token. Store this token in your database alongside the customer record. This is the only identifier you need for all future charges.
Whenever you need to charge the customer — on a schedule, on usage trigger, or on demand — make a single API call with their customer_id,token_id, and theamount. No customer interaction needed.
Billing models
Once you have a token, you control exactly how and when you charge. Two patterns cover virtually every business model:
Fixed price every billing cycle
Charge the exact same amount on a predictable schedule, weekly, monthly, or annually. Your system stores the next billing date and fires the charge endpoint automatically. No customer action, no payment page.
e.g. SaaS Pro plan at LKR 2,500/month cron fires on the 1st, chargestok_XXXXX for"2500.00". Customer sees a charge on their card statement. Nothing else needed.
Variable amount - pay as you go
Calculate the exact amount owed at the end of each billing period based on actual usage (API calls, data, seats, units). Charge precisely that amount. The token is reused, only the amount parameter changes each cycle.
e.g. API platform at LKR 0.50/call — tally 4,200 calls in April → chargetok_XXXXX for"2100.00". Next month: 6,100 calls → charge "3050.00". Token never changes.
Detailed API flow
Authorization header — different from the hash-based auth used by the Payment API. Format: Authorization: 2c4e7c3ee0013882.... Obtain from the merchant dashboard under API Keys.What is Card on File?
Tokenization is the process of replacing sensitive card data with a non-sensitive substitute, the token that has no exploitable value outside the system it was designed for.
When your customer enters their card details on the OnePay-hosted card page, those details are sent directly and securely to the card network (Visa or Mastercard) and the customer's issuing bank. The bank validates the card and returns a unique encrypted token back to OnePay. That token is what gets stored and what gets passed to your system as a tok_ ID.
If that token were ever intercepted or leaked, it would be useless; it cannot be used to reconstruct the original card number, and it can only be charged by the specific merchant account it was issued for. This is fundamentally different from storing an encrypted card number, which could theoretically be decrypted.
tok_ ID → you store only the token ID. No card numbers ever touch your server or OnePay's database.Base URL
All API requests should be made to the following base URL:
Authentication
All endpoints require authentication via an Authorization header and a strictly defined Content-Type.
| HEADER | VALUE | REQUIRED |
|---|---|---|
Authorization | Your Access Token (e.g. 2c4e7c3ee001...) | Yes |
Content-Type | application/json | Yes |
Customers
Manage your customer base. Each customer gets a unique cus_ prefixed ID. Customers can have one or more saved card tokens. All endpoints require the Authorization access token header.
List customers
Retrieves a list of all customers associated with the authenticated application. No query parameters required — authentication is via the Authorization header only.
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
status | number | 200 on success. |
data | array | Array of customer objects. |
data[].customer_id | string | Unique customer identifier, e.g. cus_907fa39a. |
data[].first_name | string | Customer's first name. |
data[].last_name | string | Customer's last name. |
data[].email | string | Customer's email address. |
data[].phone_number | string | Customer's phone number. |
data[].address | string | Customer's billing or physical address. |
Get customer details
Retrieves detailed information for a specific customer, including their associated cards and full transaction history.
| PARAMETER | TYPE | IN | DESCRIPTION |
|---|---|---|---|
customer_idrequired | string | Path | Unique customer identifier, e.g. cus_907fa39a. |
app_idrequired | string | Query | Your application identifier. |
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
data.customer_id | string | Unique customer identifier. |
data.first_name | string | Customer's first name. |
data.last_name | string | Customer's last name. |
data.email | string | Customer's email address. |
data.phone_number | string | Customer's phone number. |
data.address | string | Customer's billing or physical address. |
data.cards | array | Array of saved card token objects associated with this customer. |
data.transactions | array | Array of historical transaction objects for this customer. |
Create customer and request card token
Creates a new customer profile and returns a redirect_url. Redirect the customer to that URL so they can securely enter and save their card. OnePay handles all card data, your system only ever receives back a token.
| PARAMETER | TYPE | DESCRIPTION |
|---|---|---|
app_idrequired | string | Your application identifier. |
first_namerequired | string | Customer's first name. |
last_namerequired | string | Customer's last name. |
emailrequired | string | Customer's email address. |
phone_numberrequired | string | Phone number with country code, e.g. +94771234567. |
addressrequired | string | Customer's billing or physical address. |
redirect_urlrequired | string | The URL the customer will be redirected to after successfully adding their card. |
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
data.customer_id | string | The newly created customer ID (e.g. cus_907fa39a). Store this in your database. |
data.redirect_url | string | The secure OnePay-hosted URL where the customer enters their card details. |
data.first_name | string | Customer's first name as stored. |
data.last_name | string | Customer's last name as stored. |
data.email | string | Customer's email address. |
data.phone_number | string | Customer's phone number. |
data.address | string | Customer's address. |
Request token for existing customer
If a customer profile already exists in your system and they want to add a new card or update their payment method, pass their customer_idinstead of full profile details. OnePay will generate a fresh card-entry redirect for that customer.
customer_idinstead of the full profile fields. OnePay detects the existing profile and generates a new tokenization session for them.| PARAMETER | TYPE | DESCRIPTION |
|---|---|---|
app_idrequired | string | Your application identifier. |
customer_idrequired | string | Existing customer identifier, e.g. cus_907fa39a. |
redirect_urlrequired | string | The URL the customer will be redirected to after adding their new card. |
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
data.customer_id | string | The existing customer's ID, confirmed. |
data.redirect_url | string | New secure card-entry URL to redirect the customer to. |
Cards (Token)
Manage saved payment methods for your customers. Each saved card is identified by a tok_ prefixed token ID. Use this token to charge the card raw card numbers never pass through your system.
List customer cards
Retrieves all securely stored card tokens for a specific customer. Call this after the card-entry redirect completes to retrieve the new token_id and store it in your database for future charges.
| PARAMETER | TYPE | IN | DESCRIPTION |
|---|---|---|---|
customer_idrequired | string | Path | Unique customer identifier, e.g. cus_907fa39a. |
app_idrequired | string | Query | Your application identifier. |
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
data | array | Array of card token objects. |
data[].token_id | string | Secure card token identifier, e.g. tok_12345678. Use this for all charge requests. |
data[].card_type | string | Card network, e.g. Visa, Mastercard. |
data[].masked_number | string | Masked card number for display, e.g. **** **** **** 4242. |
data[].expiry | string | Card expiry in MM/YY format. |
data[].is_deleted | boolean | true if the card has been soft-deleted and cannot be used for charges. |
Get single card
Retrieves details for a specific saved card. Use the masked number, card type, and expiry to display the saved card in your UI e.g. "Visa ending in 4242, expires 12/27".
| PARAMETER | TYPE | IN | DESCRIPTION |
|---|---|---|---|
customer_idrequired | string | Path | Unique customer identifier. |
token_idrequired | string | Path | Secure card token, e.g. tok_12345678. |
app_idrequired | string | Query | Your application identifier. |
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
data.token_id | string | Secure card token identifier. |
data.card_type | string | Card network, e.g. Visa, Mastercard. |
data.masked_number | string | Masked card number, e.g. **** **** **** 4242. |
data.expiry | string | Expiry date in MM/YY format. |
data.is_deleted | boolean | true if the card has been soft-deleted. |
Delete card (soft delete)
Soft-deletes a saved card by setting is_deleted = true. The card token is immediately deactivated and cannot be used for any future charges. The customer profile and transaction history remain fully intact.
Deletion is irreversible. If the customer wants to pay again after a card is deleted, they must add a new card via the tokenization redirect flow.
| PARAMETER | TYPE | IN | DESCRIPTION |
|---|---|---|---|
customer_idrequired | string | Path | Unique customer identifier. |
token_idrequired | string | Path | The secure card token to be deleted. |
app_idrequired | string | Query | Your application identifier. |
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
status | number | 200 on successful deletion. |
message | string | Confirmation message. |
Charge a Card (Charge Token)
Charge a customer's saved card token for any amount triggered entirely from your server. No customer action required at payment time. This is the core of the auto-charging model.
| PARAMETER | TYPE | IN | DESCRIPTION |
|---|---|---|---|
customer_idrequired | string | Path | Unique customer identifier, e.g. cus_907fa39a. |
| PARAMETER | TYPE | DESCRIPTION |
|---|---|---|
app_idrequired | string | Your application identifier. |
token_idrequired | string | The saved card token to charge, e.g. tok_12345678. |
amountrequired | string | Amount to charge formatted as a string, e.g. "1000.00". |
currencyrequired | string | Currency code, e.g. LKR or USD. |
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
status | number | 200 on success. |
message | string | Confirmation message. |
data.transaction_id | string | Unique transaction identifier for this charge. |
data.status | boolean | true if the charge was successfully processed. |
data.amount | string | The amount charged. |
data.currency | string | Currency of the charge. |
data.token_id | string | The card token that was charged. |
BASIC CHARGE EXAMPLE
Charge a single saved card immediately. The foundation for all billing patterns.
FIXED BILLING EXAMPLE — SAME AMOUNT EVERY MONTH
Run this as a cron job on your chosen billing date. The amount is constant; only the timing changes.
VARIABLE BILLING EXAMPLE — PAY AS YOU GO
Calculate usage at period-end and charge exactly what was consumed. Token is constant; only the amount varies per customer per cycle.
Customer Transactions
Retrieve the full billing history for a specific customer. Useful for displaying payment history in your product dashboard, generating invoices, reconciling subscription charges, or auditing billing cycles.
| PARAMETER | TYPE | IN | DESCRIPTION |
|---|---|---|---|
customer_idrequired | string | Path | Unique customer identifier, e.g. cus_907fa39a. |
app_idrequired | string | Query | Your application identifier. |
| FIELD | TYPE | DESCRIPTION |
|---|---|---|
status | number | 200 on success. |
data | array | Array of transaction objects ordered by most recent first. |
data[].transaction_id | string | Unique identifier for the transaction. |
data[].amount | string | Amount charged for this transaction. |
data[].currency | string | Currency of the transaction. |
data[].status | boolean | true if the transaction was successful. |
data[].token_id | string | The card token used for this transaction. |
data[].created_at | string | ISO 8601 timestamp of when the transaction was created. |
On This Page