Skip to Content
Docs

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:

Authenticate and confirm a charge

Follow these steps to create a 3DS charge and handle issuer challenges.

  1. 1

    Create a charge with 3DS

    Send a POST request to /v1/charges with:

    • Browser metadata: Every browser_details field under source_data.card.authentication_context is required (customer_ip_address is 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, so 10000 is $100.00), currency, and the payment source (raw card details or a stored token).
    • 3DS flow: Set payment_method_options.authentication_options.type to "three_ds", then set three_ds.flow_indicator.type to "challenge" (with challenge.type set to "mandated") to require a challenge, or to "frictionless" to request a frictionless flow with an optional frictionless.sca_exemption_type (low_value, transaction_risk_analysis, or secure_corporate_process). The issuer makes the final decision and can still challenge a payment sent as frictionless.

    If this charge is the initial transaction for a recurring payment sequence, add "setup_future_usage": "off_session" inside your source_data object.

    {
      "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"
              }
            }
          }
        }
      }
    }

    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.

  2. 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 return requires_authentication. In every case, create the linked authentication session with the ID of the resource that requires authentication.

    Send a POST request to /v1/sessions/authentication/linked with 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 a charge.succeeded or charge.failed webhook. Use this if your fulfillment logic is webhook-driven.
      • false: Pay.com redirects the customer to your return_url without capturing funds. Your server must then call POST /v1/charges/{charge_id}/confirm to 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"
    }
  3. 3

    Redirect the customer

    Show the bank challenge to the customer in one of three ways:

    Redirect the customer to the url from the linked authentication session. The customer completes the bank challenge on that page.

  4. 4

    Confirm the transaction (only with confirm: false)

    If you created the linked session with confirm: false, finalize the charge by calling POST /v1/charges/{charge_id}/confirm once the customer reaches your return_url. With confirm: true (the default), skip this step and wait for the webhook. Calling confirm on a charge that Pay.com already authorized returns a 400 error.

    • 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 your return_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 your return_url without capturing funds. Once the customer lands on your return_url, finalize the charge by sending a POST request 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)"

    The confirm request returns one of two outcomes:

    OutcomeDescription
    succeededThe charge completed successfully
    Payment method errorAuthentication failed or the card was declined

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.authenticated and authentication_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 has confirm: 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:

FieldValue
Card number5200000000001096
Expiration dateAny future date (for example, 12/2028)
CVVAny 3-digit number (for example, 123)

Challenge OTP codes (entered by the cardholder in the challenge UI, not sent through the API):

CodeOutcome
1234Authentication passes, and the charge can be confirmed
3333Authentication 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.
Was this page helpful?