Create a charge with 3DS
Authenticate server-to-server card charges with 3D Secure using linked authentication sessions.
Authenticate server-to-server card charges with 3D Secure (3DS) by passing browser metadata on charge creation, linking an authentication session when the issuer requires a challenge, and confirming the payment after the customer returns. If you use Pay.com.js or a mobile SDK, checkout handles 3DS automatically.
Requirements
Before you start, make sure you have:
- Your API credentials and environment base URL (sandbox:
https://api.sandbox.pay.com/v1, with ansk-pay-com-sandbox-key). - A unique
idempotency-keyheader for eachPOSTrequest.
Authenticate and confirm a charge
Follow these steps to create a 3DS charge and handle issuer challenges.
- 1
Create a charge with 3DS
Send a
POSTrequest to/v1/chargeswith:- Browser metadata: Every
browser_detailsfield undersource_data.card.authentication_contextis required (customer_ip_addressis recommended). - Customer identity: The customer's email in
source_data.billing_details.email. It isn't required, but it raises 3DS approval rates. We also recommend full billing details. - Transaction details:
amount(in minor units, so10000is $100.00),currency, and the payment source (raw card details or a stored token). - 3DS flow: Set
payment_method_options.authentication_options.typeto"three_ds", then setthree_ds.flow_indicator.typeto"challenge"(withchallenge.typeset to"mandated") to require a challenge, or to"frictionless"to request a frictionless flow with an optionalfrictionless.sca_exemption_type(low_value,transaction_risk_analysis, orsecure_corporate_process). The issuer makes the final decision and can still challenge a payment sent as frictionless.
{ "amount": 10000, "currency": "usd", "source_data": { "type": "card", "card": { "number": "5200000000001096", "expiry_month": "12", "expiry_year": "2028", "cvv": "123", "name": "John Smith", "authentication_context": { "customer_ip_address": "203.0.113.45", "browser_details": { "accept_header": "*/*", "javascript_enabled": true, "language": "en-US", "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", "screen_width": 1920, "screen_height": 1080, "timezone_offset": "-300", "java_enabled": false, "color_depth": 24 } } }, "billing_details": { "name": "John Smith", "email": "john.smith@example.com", "phone": "+14155551234", "address": { "line1": "123 Main Street", "city": "San Francisco", "state": "CA", "postal_code": "94102", "country": "US" } } }, "customer_reference_id": "cust-john-smith-001", "description": "3DS Challenge test payment", "reference": "order-3ds-test-001", "payment_method_options": { "authentication_options": { "type": "three_ds", "three_ds": { "flow_indicator": { "type": "challenge", "challenge": { "type": "mandated" } } } } } }{ "id": "chrg_686511724072799232", "resource": "charge", "amount": 10000, "amount_human_readable": "100.00", "currency": "usd", "status": "requires_authentication", "customer": "cust_685217819876392961", "customer_reference_id": "cust-john-smith-001", "payment_method": "pm_card_686169133447908352", "payment_method_details": { "type": "card", "card": { "brand": "mastercard", "last4": "1096", "exp_month": "12", "exp_year": "2028", "three_d_secure": null } }, "reference": "order-3ds-test-001", "test_mode": true }Depending on the issuer's response, the API returns one of two statuses:
requires_authentication: The transaction needs a bank challenge to satisfy SCA (Strong Customer Authentication) requirements. The cardholder must be verified before the charge can proceed. Continue to the next step.succeeded: The issuer authenticated the cardholder without a challenge (frictionless flow), and the funds were captured. No further steps are required.
If you receive an API error response, the card was declined or the request data was invalid.
If you already authenticate with an external 3DS provider or your own MPI, pass its results (including
ds_trans_id) in the initial charge request instead. Pay.com passes them to the issuer for validation without triggering a new challenge. See External MPI. - Browser metadata: Every
- 2
Create a linked authentication session
When the charge status is
requires_authentication, you must link it to a new authentication session. Charges, holds, and payment methods can all returnrequires_authentication. In every case, create the linked authentication session with the ID of the resource that requires authentication.Send a
POSTrequest to/v1/sessions/authentication/linkedwith these parameters:resource: The charge ID returned in the previous step.return_url: The URL to redirect the customer to after the challenge completes.confirm: Controls whether Pay.com automatically confirms the transaction after authentication.true(the default, recommended): Pay.com authorizes the charge immediately after the customer completes the bank challenge, then sends acharge.succeededorcharge.failedwebhook. Use this if your fulfillment logic is webhook-driven.false: Pay.com redirects the customer to yourreturn_urlwithout capturing funds. Your server must then callPOST /v1/charges/{charge_id}/confirmto finalize. Use this when you need to run internal checks (such as fraud scoring or inventory verification) between 3DS completion and authorization.
{ "resource": "chrg_686511724072799232", "confirm": true, "return_url": "https://your-site.com/payment/complete" }{ "id": "sca_686512987359412224", "resource": "authentication_session", "amount": 10000, "amount_human_readable": "100.00", "currency": "usd", "status": "open", "client_secret": "eyJ...", "url": "https://sca.pay.com/authenticate?client_secret=eyJ...", "return_url": "https://your-site.com/payment/complete", "payment_method": "pm_card_686169133447908352", "reference": "order-3ds-test-001", "test_mode": true } - 3
Redirect the customer
Show the bank challenge to the customer in one of three ways:
Redirect the customer to the
urlfrom the linked authentication session. The customer completes the bank challenge on that page. - 4
Confirm the transaction (only with
confirm: false)If you created the linked session with
confirm: false, finalize the charge by callingPOST /v1/charges/{charge_id}/confirmonce the customer reaches yourreturn_url. Withconfirm: true(the default), skip this step and wait for the webhook. Calling confirm on a charge that Pay.com already authorized returns a400error.- If you used
confirm: true: Pay.com authorizes the charge before redirecting the customer. Listen for webhooks to fulfill the order. Don't rely only on the customer reaching yourreturn_url, because a browser crash could prevent the redirect while the charge still succeeds. - If you used
confirm: false: Pay.com redirects the customer to yourreturn_urlwithout capturing funds. Once the customer lands on yourreturn_url, finalize the charge by sending aPOSTrequest to/v1/charges/{charge_id}/confirm.
curl -X POST https://api.sandbox.pay.com/v1/charges/chrg_686511724072799232/confirm \ -u ':sk-pay-com-sandbox-…' \ -H "idempotency-key: $(uuidgen)"{ "id": "chrg_686511724072799232", "resource": "charge", "amount": 10000, "amount_human_readable": "100.00", "currency": "usd", "status": "succeeded", "payment_method": "pm_card_686169133447908352", "payment_method_details": { "type": "card", "card": { "brand": "mastercard", "last4": "1096", "three_d_secure": { "authentication_flow": "challenge", "eci": "02", "liability_shift": true, "result": "success", "result_reason": "authenticated", "version": "2.2.0" } } }, "reference": "order-3ds-test-001", "test_mode": true }The confirm request returns one of two outcomes:
Outcome Description succeededThe charge completed successfully Payment method error Authentication failed or the card was declined - If you used
Listen for webhooks
Because authorization happens asynchronously after the bank challenge, use webhooks to trigger your fulfillment logic, whichever confirm mode you used.
Subscribe to these events:
authentication_session.open: A linked authentication session was created.authentication_session.authenticatedandauthentication_session.failed: The customer passed or failed the challenge.charge.requires_confirmation: Authentication is complete, and the charge waits for your confirm call. Sent when the authentication session hasconfirm: false.charge.succeeded: The funds were captured. Use this to fulfill the order.charge.failed: The charge was declined after the challenge, for example because of insufficient funds or a failed 3DS result.
Verify the Pay-Signature header before processing any webhook event. See Verify webhook signatures.
Test your integration
Use these values in the sandbox to test the full 3DS challenge flow end to end. See the test cards reference for the complete list of test card numbers.
Test card for 3DS challenge:
| Field | Value |
|---|---|
| Card number | 5200000000001096 |
| Expiration date | Any future date (for example, 12/2028) |
| CVV | Any 3-digit number (for example, 123) |
Challenge OTP codes (entered by the cardholder in the challenge UI, not sent through the API):
| Code | Outcome |
|---|---|
1234 | Authentication passes, and the charge can be confirmed |
3333 | Authentication is denied |
To authenticate a card before you create a charge, see Standalone 3DS authentication. It has more test cards, including frictionless failure scenarios.
Next steps
- Request 3DS: Choose when 3D Secure runs, set the flow indicator, and restrict accepted ECI values.
- SCA exemptions and soft declines: Request SCA exemptions and configure the soft decline loop.
- Webhooks: Set up listeners for payment events and automate your fulfillment logic.
- Refund a charge: Return all or part of a 3DS charge to the customer.
- Create a payout: Send funds to a customer's card or account.