Skip to Content
Docs

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:

RequestFieldToken for
Create a chargesource_data or payment_method_data with type: "encrypted_card"A card
Create a holdsource_data with type: "encrypted_card"A card
Create a payoutdestination_data or payout_method_data with type: "encrypted_card"A card
Create a payment methodtype: "encrypted_card" at the top levelA card
Charge or hold with a saved cardsource_data.token.encrypted_cvv, instead of token.cvvA CVV
Verify a payment methodencrypted_cvv, instead of cvvA 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…"
      }
    }
  }'

Amounts are in minor units, so 1000 is $10.00.

encrypted_card takes these members:

MemberRequiredDescription
dataYesThe PayCSE token.
billing_addressNoThe card's billing address.
three_dsNo3DS results, as for a raw card.
three_riNo3RI details, as for a raw card.
authentication_contextNoAuthentication 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:

  • data or encrypted_cvv isn't a compact token (five base64url segments, at most 4096 characters).
  • encrypted_card has a member other than those listed above, such as number or cvc. Card details go inside the token.
  • encrypted_card comes with a raw card or another payment method type in the same object, or under a type other than encrypted_card.
  • cvv and encrypted_cvv (or token.cvv and token.encrypted_cvv) are sent together.
  • A top-level encrypted_cvv is 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:

  • mid must be your Pay.com merchant ID, a string of 1 to 64 characters of A-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 as account_settings.id.
  • aud must be the environment you send it to: api.pay.com for live, api.sandbox.pay.com for the sandbox (see Encryption keys).
  • sid must be absent. With PayCSE.create(), leave out sessionId. On mobile, set the session ID claim to nil or null.
  • 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_codeMeaningWhat to do
cse_not_enabledEncrypted cards aren't enabled. Client-side encryption is off by default.Send the card another way until Pay.com enables it.
cse_unavailablePay.com can't process encrypted cards right now. Returned with 503.Retry later.
cse_malformedThe token isn't a well-formed compact token.Send the token exactly as the SDK made it.
cse_unsupported_headerThe 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_keyThe 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_failedThe 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_payloadThe decrypted payload doesn't match the format.Check the payload.
cse_wrong_typeA CVV token was sent as encrypted_card, or a card token as encrypted_cvv.Use encryptCard for cards and encryptCvc for CVVs.
cse_expirediat is more than 1200 seconds in the past.Encrypt again when the customer submits.
cse_not_yet_validThe token was made in the future, by more than 5 minutes.Check the device's clock.
cse_audience_mismatchThe token was made for another environment.Encrypt for the host you send it to.
cse_merchant_mismatchmid isn't your merchant ID.Encrypt with your own merchant ID.
cse_session_mismatchThe 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_replayedThe 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:

Membertype: "card"type: "cvc"Format
typeRequiredRequired"card", or "cvc" to re-collect a saved card's CVC.
numberRequired12 to 19 digits, no spaces or separators.
exp_monthRequiredTwo digits, "01" to "12".
exp_yearRequiredFour digits, for example "2030".
cvcOptionalRequired3 or 4 digits.
holder_nameOptional1 to 255 characters, no control characters.
iatRequiredRequiredWhen it was encrypted, an integer in seconds since the Unix epoch.
jtiRequiredRequiredA version 4 UUID, either case.
sidSee aboveSee aboveFor a session token, ps_ (or ss_ for a setup session) followed by 18 to 20 digits. Absent for your server.
midRequiredRequiredYour merchant ID, 1 to 64 characters of A-Z a-z 0-9 _ -.
audRequiredRequiredThe host you send it to.
sdkRequiredRequired<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.

Never log tokens or send them anywhere except Pay.com.

Was this page helpful?