Saved cards and tokenization
DigetPay can save a customer's card so they don't have to enter it again next time. How this works depends on your integration:
| Integration | Who saves the card | How the saved card is used |
|---|---|---|
| Hosted Checkout | The customer, by ticking Save card for faster future payments on the DigetPay payment page | The saved card is shown to the customer the next time they pay on the DigetPay page |
| Embedded (S2S) | Your backend, by sending "saveToken": "Y" in Direct Sale | Your backend charges the returned token with Tokenization Sale |
Card numbers are never stored on your servers. DigetPay stores the card and gives you, at most, a token and the masked card number (for example
512345xxxxxx0008).
Hosted Checkout: Save card
With Hosted Checkout, the customer decides whether to save their card. You don't need to change your Create Payment Link request.
First payment: the customer saves the card
- Your backend creates a payment with
POST /payment/checkout/intiateand redirects the customer to theredirectUrl. - The customer enters their card details on the DigetPay payment page.
- The customer ticks Save card for faster future payments.
- The customer clicks Pay and completes the payment.
Next payment: the saved card is shown
- Your backend creates a new payment link for the same customer. Send the same
customerPhoneandcustomerEmailyou used before. - When the customer opens the payment page, their saved card is shown, for example Pay with Mastercard 0008, with its expiry date. The most recent saved card is marked Default.
- The customer selects the saved card and clicks Pay. To use a different card, the customer clicks + Add a card (and can go back with Back to saved cards).
Send the customer's real details. The saved card is linked to the customer details in the payment request. Always send the phone number and email of the customer who is actually paying. Never reuse one customer's details for another customer.
Confirm every payment with the Status API (
GET /payment/checkout/status?sessionId=...), whether the customer paid with a new or a saved card.
Embedded (S2S): Tokenization
With Embedded (S2S), your backend saves the card and charges it later, for example for subscriptions or repeat orders. The customer does not need to enter the card again.
PCI DSS required. The first payment (Direct Sale) sends raw card data from your backend. Your systems must be PCI DSS compliant.
Step 1: Save the card with Direct Sale
Send "saveToken": "Y" in Direct Sale:
{
"orderId": "SUB-2026-10-0001",
"amount": 0.11,
"currency": "SAR",
"paymentMethod": "card",
"auth": "N",
"saveToken": "Y",
"customer": {
"name": "Ahmed Emad Abd-Alfatah",
"email": "[email protected]",
"phone": "+966501223324"
},
"card": {
"cardNumber": "5123450000000008",
"cardHolder": "Ahmed Emad Abd-Alfatah",
"cardExpiryMonth": "01",
"cardExpiryYear": "2039",
"cardCvv": "100"
},
"successUrl": "https://yourstore.com/payment/success",
"failureUrl": "https://yourstore.com/payment/failure",
"hash": "COMPUTED_MD5_HASH"
}If the response has result: "REDIRECT", send the customer to 3-D Secure (render html or redirect to redirect_url). Then confirm the payment with Embedded Transaction Status.
Step 2: Store the token
When the payment succeeds, the token is returned in Card.Token:
"Card": {
"Number": "512345xxxxxx0008",
"Brand": "Mastercard",
"Token": "TKN-00000000-0000-0000-0000-000000000000"
}Store the token on your backend, linked to that customer.
Treat the token like a card. Anyone with the token and your API key can charge the card. Never expose the token in browser JavaScript, mobile apps, URLs or logs.
Step 3: Charge the saved card with Tokenization Sale
Send the token to Tokenization Sale whenever you need to charge the customer. Use a new orderId for each charge.
POST https://api.digetpay.com/v1/payment/s2s/tokenization/sale
x-api-key: YOUR_TEST_API_KEY
Content-Type: application/json
{
"orderId": "SUB-2026-11-0001",
"amount": 0.11,
"currency": "SAR",
"token": "TKN-00000000-0000-0000-0000-000000000000",
"successUrl": "https://yourstore.com/payment/callback"
}Check data.status in the response:
data.status | Meaning |
|---|---|
SUCCESS | The card was charged |
FAILED | The charge was declined. The reason is in message and data.transaction.error |
PENDING | Not final yet. Check again with Embedded Transaction Status |
A declined charge still returns HTTP
200. Always checkdata.status.
Store the paymentId from each charge. Use it with Embedded Transaction Status and Embedded Refund.
When a token stops working
A token can stop working if the card expires, is replaced, or is blocked by the issuer. The charge is then declined. Ask the customer to pay again with a Direct Sale and "saveToken": "Y" to get a new token, and replace the old token in your system.
Testing
Use your Test API Key and the Test Cards:
- Hosted Checkout: pay once with a Test Card and tick Save card for faster future payments. Create a second payment link with the same customer details and check that the saved card is shown.
- Embedded (S2S): make a Direct Sale with
"saveToken": "Y", then charge the returned token with Tokenization Sale.
Tokens created with your Test API Key work only in Test Mode. Tokens from Live Mode work only with your Live API Key.
Related
Updated about 1 month ago

