Send encrypted cards from your server
Send PayCSE tokens to the Pay.com API in encrypted_card and encrypted_cvv, and handle the errors they can return.
Your server can send a PayCSE token wherever the API takes a card, and a token for a CVV wherever it takes a saved card's CVV. Your server never sees the card. It forwards a token that only Pay.com can decrypt.
The token usually comes from your page, made with PayCSE.create(), or from your app's mobile SDK.
Where tokens are accepted
The API takes a PayCSE token in these requests and fields:
| Request | Field | Token for |
|---|---|---|
| Create a charge | source_data or payment_method_data with type: "encrypted_card" | A card |
| Create a hold | source_data with type: "encrypted_card" | A card |
| Create a payout | destination_data or payout_method_data with type: "encrypted_card" | A card |
| Create a payment method | type: "encrypted_card" at the top level | A card |
| Charge or hold with a saved card | source_data.token.encrypted_cvv, instead of token.cvv | A CVV |
| Verify a payment method | encrypted_cvv, instead of cvv | A CVV |
Send an encrypted card
encrypted_card is shaped like a card, with the card details replaced by data, the token. Non-card fields travel next to it in clear, as they do for a raw card.
curl -X POST https://api.sandbox.pay.com/v1/charges \
-u ':sk-pay-com-sandbox-…' \
-H "Content-Type: application/json" \
-d '{
"amount": 1000,
"currency": "usd",
"source_data": {
"type": "encrypted_card",
"encrypted_card": {
"data": "eyJhbGciOiJSU0EtT0FFUC0yNTYi…"
}
}
}'curl -X POST https://api.sandbox.pay.com/v1/payment_methods \
-u ':sk-pay-com-sandbox-…' \
-H "Content-Type: application/json" \
-d '{
"type": "encrypted_card",
"encrypted_card": {
"data": "eyJhbGciOiJSU0EtT0FFUC0yNTYi…"
},
"customer_reference_id": "cust_ext_abc123"
}'Amounts are in minor units, so 1000 is $10.00.
encrypted_card takes these members:
| Member | Required | Description |
|---|---|---|
data | Yes | The PayCSE token. |
billing_address | No | The card's billing address. |
three_ds | No | 3DS results, as for a raw card. |
three_ri | No | 3RI details, as for a raw card. |
authentication_context | No | Authentication context, as for a raw card. |
Pay.com decrypts the token, tokenizes the card, and processes the request as it does for a raw card. The response is the same as for a raw card.
Send an encrypted CVV
To charge a saved card with a CVV the customer typed again, send the CVV token in encrypted_cvv:
{
"amount": 1000,
"currency": "usd",
"source_data": {
"type": "token",
"token": {
"id": "tok_card_296645958265997326",
"encrypted_cvv": "eyJhbGciOiJSU0EtT0FFUC0yNTYi…"
}
}
}To verify a payment method with a CVV, send { "encrypted_cvv": "…" } instead of { "cvv": "…" }.
Rules
The API refuses these with a 400 (code: "invalid_parameters", with a message that names the field) before anything is decrypted:
dataorencrypted_cvvisn't a compact token (five base64url segments, at most 4096 characters).encrypted_cardhas a member other than those listed above, such asnumberorcvc. Card details go inside the token.encrypted_cardcomes with a raw card or another payment method type in the same object, or under atypeother thanencrypted_card.cvvandencrypted_cvv(ortoken.cvvandtoken.encrypted_cvv) are sent together.- A top-level
encrypted_cvvis sent anywhere except a payment method verification.
Tokens your server sends
A token is bound to who sends it. For a token your server sends with its API key:
midmust be your Pay.com merchant ID, a string of 1 to 64 characters ofA-Z a-z 0-9 _ -. Pay.com compares it exactly with the merchant your API key belongs to. It's the value a checkout session reports asaccount_settings.id.audmust be the environment you send it to:api.pay.comfor live,api.sandbox.pay.comfor the sandbox (see Encryption keys).sidmust be absent. WithPayCSE.create(), leave outsessionId. On mobile, set the session ID claim tonilornull.- Encrypt when the customer submits. A token is refused as expired once it's more than 1200 seconds old, and it's accepted only once.
Errors
Refusals use the API's usual error shape. When Pay.com can't accept the token itself, code is invalid_encrypted_card (or invalid_encrypted_cvv) and decline_code says why. The status is 400, except for cse_unavailable (503):
{
"error": {
"type": "invalid_request_error",
"code": "invalid_encrypted_card",
"message": "The encrypted card has expired. Encrypt it again.",
"decline_code": "cse_expired"
}
}decline_code | Meaning | What to do |
|---|---|---|
cse_not_enabled | Encrypted cards aren't enabled. Client-side encryption is off by default. | Send the card another way until Pay.com enables it. |
cse_unavailable | Pay.com can't process encrypted cards right now. Returned with 503. | Retry later. |
cse_malformed | The token isn't a well-formed compact token. | Send the token exactly as the SDK made it. |
cse_unsupported_header | The token's header isn't the PayCSE v1 header. | Make the token with Pay.com.js or the iOS or Android SDK, or follow the token format. |
cse_unknown_key | The key isn't in this environment's key set. It was rotated out, or it belongs to the other environment. | Fetch the keys again, encrypt again, and retry once. |
cse_decryption_failed | The token couldn't be decrypted. Pay.com doesn't say which step failed. | Encrypt again, and send the token exactly as it was made. |
cse_invalid_payload | The decrypted payload doesn't match the format. | Check the payload. |
cse_wrong_type | A CVV token was sent as encrypted_card, or a card token as encrypted_cvv. | Use encryptCard for cards and encryptCvc for CVVs. |
cse_expired | iat is more than 1200 seconds in the past. | Encrypt again when the customer submits. |
cse_not_yet_valid | The token was made in the future, by more than 5 minutes. | Check the device's clock. |
cse_audience_mismatch | The token was made for another environment. | Encrypt for the host you send it to. |
cse_merchant_mismatch | mid isn't your merchant ID. | Encrypt with your own merchant ID. |
cse_session_mismatch | The token's session binding doesn't match the request: a session token sent with an API key, a token for another session, or a token with no sid sent with a client_secret. | Leave out the session ID for tokens your server sends. |
cse_replayed | The token was already used. | Encrypt again for every request. |
The payload
The SDKs build the payload for you. If you encrypt with your own code, the plaintext is a UTF-8 JSON object with only these members, all card fields as strings:
| Member | type: "card" | type: "cvc" | Format |
|---|---|---|---|
type | Required | Required | "card", or "cvc" to re-collect a saved card's CVC. |
number | Required | 12 to 19 digits, no spaces or separators. | |
exp_month | Required | Two digits, "01" to "12". | |
exp_year | Required | Four digits, for example "2030". | |
cvc | Optional | Required | 3 or 4 digits. |
holder_name | Optional | 1 to 255 characters, no control characters. | |
iat | Required | Required | When it was encrypted, an integer in seconds since the Unix epoch. |
jti | Required | Required | A version 4 UUID, either case. |
sid | See above | See above | For a session token, ps_ (or ss_ for a setup session) followed by 18 to 20 digits. Absent for your server. |
mid | Required | Required | Your merchant ID, 1 to 64 characters of A-Z a-z 0-9 _ -. |
aud | Required | Required | The host you send it to. |
sdk | Required | Required | <platform>/<version>, for example server/1.0.0. Informational. |
Encrypt it as described in the token, with the key chosen as in Encryption keys. The AES-GCM additional authenticated data is the protected header segment exactly as it appears in the token.