Overview
Card tokenization converts sensitive card data into a secure token (nonce) that can be used to process payments. This approach ensures that card data never touches your servers, reducing your PCI compliance requirements.How Tokenization Works
1
Customer enters card details
Customer fills out the tokenization form with their card information
2
Approvely generates nonce
Card data is sent directly to Approvely’s secure servers, which return a one-time nonce token
3
Use nonce for payment
Your server uses the nonce token to process the payment via the charge endpoint
The nonce token is single-use and expires after a short period. It must be used immediately to process a payment.
Getting Your Tokenization Token
1
Log in to Control Panel
Access the Approvely Control Panel
2
Get Tokenization Token
Copy your Tokenization Token (also called API Key) from the Sources page
Setting Up Tokenization
Option 1: Using Python Local Server (Quick Test)
For quick testing, you can use a local HTML page:1
Create HTML file
Create a file named
approvely_tokenization.html with the tokenization form (see example below)2
Start local server
Open your command line in the folder with the HTML file and run:Or for a specific port:
3
Open in browser
Navigate to
http://127.0.0.1:8000/approvely_tokenization.html in your browserOption 2: Integrate into Your Application
Integrate the tokenization form directly into your application’s checkout page.HTML Tokenization Form Example
This example uses Approvely’s Hosted Tokenization, which provides a secure iframe for card data entry:How This Works
1
Load Tokenization Script
The Approvely tokenization script is loaded from their CDN
2
Initialize Hosted Tokenization
Create a
HostedTokenization instance with your public source key3
Mount Card Form
The card form is mounted as a secure iframe in the
#iframe-container div4
Customer Enters Card Data
Customer enters card details directly in the secure iframe (never touches your server)
5
Get Nonce Token
When user clicks “Get Token”, call
cardForm.getNonceToken() to get the nonce6
Send to Server
Send the nonce token to your server to process the charge
Key Features
- Secure Iframe: Card data is entered in Approvely’s secure iframe, never touching your server
- Real-time Validation: Card number and CVV are validated as the user types
- Masked Display: Shows masked card number and CVV for user confirmation
- Event Handling: Listen to
inputandchangeevents for real-time feedback
Test Card Data
Use these test cards in the sandbox environment:Successful Transaction
| Field | Value |
|---|---|
| Card Number | 4111 1111 1111 1111 |
| Cardholder Name | Any name (e.g., “John Doe”) |
| CVV | Any 3 digits (e.g., “123”) |
| Expiry Date | Any valid future date (e.g., “10/28”) |
| Amount | Any amount (e.g., “5.00”) |
Other Test Cards
Visa
Visa
Card Number:
4111 1111 1111 1111Result: Successful transactionMastercard
Mastercard
Card Number:
5555 5555 5555 4444Result: Successful transactionAmerican Express
American Express
Card Number:
3782 822463 10005CVV: 4 digits (e.g., “1234”)Result: Successful transactionDeclined Card
Declined Card
Card Number:
4000 0000 0000 0002Result: Card declinedCVV Numbers by Card Type
For testing purposes, use the following CVV numbers based on card type:| Card Type | CVV |
|---|---|
| Visa | 999 |
| Mastercard | 998 |
| Discover | 996 |
| Amex | 9997 |
| Diners | 996 |
| JCB | 996 |
Nonce Token Format
After successful tokenization, you’ll receive a nonce token in this format:Using the Nonce Token
Once you have the nonce token, immediately send it to your server to process the charge:Security Best Practices
Never Store Card Data
Never store raw card numbers, CVV, or full expiry dates on your servers
Use Nonce Immediately
Nonce tokens expire quickly. Use them immediately after generation
HTTPS Only
Always serve your tokenization form over HTTPS
Validate Client-Side
Validate card data format before sending to tokenization
Troubleshooting
Tokenization fails
Tokenization fails
Possible causes:
- Invalid tokenization token
- Incorrect card number format
- Network connectivity issues
- Verify your tokenization token is correct
- Ensure card number contains only digits
- Check browser console for error messages
Nonce expires before use
Nonce expires before use
Cause: Delay between tokenization and charge requestSolution:
- Process the charge immediately after receiving the nonce
- Don’t store nonces for later use
- If expired, re-tokenize the card
CORS errors
CORS errors
Cause: Tokenization script blocked by browserSolution:
- Ensure you’re using HTTPS
- Verify the Approvely script URL is correct
- Check browser console for specific CORS errors
Next Steps
Process Charges
Learn how to use the nonce token to process payments
