Skip to Content
Docs

Authentication

Authenticate your API requests with a secret API key, sent with HTTP Basic auth.

Every request to the Pay.com API is authenticated with a secret API key, sent over HTTPS with HTTP Basic auth. The key is the password, and the username stays empty. Your API key identifies your organization, so keep it on your servers and never expose it to browsers, mobile apps, or source control.

Each key works in one environment. A sandbox key (sk-pay-com-sandbox-…) works with https://api.sandbox.pay.com/v1, and a live key (sk-pay-com-live-…) with https://api.pay.com/v1. To create a key and keep it safe, see API keys.

Make an authenticated request

Send the key as the Basic auth password, with an empty username. This example creates a payment session in the sandbox:

curl https://api.sandbox.pay.com/v1/sessions/payment \
  -u ":$PAY_COM_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
    "amount": 2000,
    "currency": "usd",
    "customer_reference_id": "cust_ext_abc123",
    "payment_method_types": ["card"]
  }'

Response

{
  "id": "ps_217940156986951680",
  "resource": "payment_session",
  "amount": 2000,
  "currency": "usd",
  "client_secret": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
  "status": "open"
}

The response is shortened. See Create a payment session for every field.

Live keys for several workspaces

Every sandbox key, and any key for one chosen workspace, leaves the username empty. With a live key that serves several workspaces, or all of them, each request names its workspace. Put that workspace's merchant ID in the username.

curl https://api.pay.com/v1/charges/$CHARGE_ID \
  -u "$MERCHANT_ID:$PAY_COM_API_KEY"

To move to live, change the base URL to https://api.pay.com/v1 and use your live key. Nothing else about authentication changes. See Go live.

Authentication errors

When Pay.com can't authenticate a request, it responds with an HTTP error and the standard error object. The request isn't processed.

StatusWhen it happensWhat to do
400 Bad RequestThe x-paycom-merchant-id header and the Basic auth username name different workspaces (merchant_conflict).Send one of them.
401 UnauthorizedThe key is missing, isn't recognized (for example, it's mistyped or belongs to the other environment), or has stopped working.Check that the key is the Basic auth password and that its prefix matches the base URL.
403 ForbiddenThe key is recognized but isn't allowed to make this request. It's disabled, or its permissions, network access, or workspaces don't cover the request.Read error.code. See the key errors.
# A sandbox key sent to the live URL
curl https://api.pay.com/v1/sessions/payment \
  -u ':sk-pay-com-sandbox-…' \
  -H 'Content-Type: application/json' \
  -d '{ "amount": 2000, "currency": "usd" }'

Handle authentication errors by HTTP status. Don't retry a 401 or 403 with the same key. It fails the same way until the key or request changes.

Browsers and mobile apps

Your customers' devices never need your API key. To take payments in the browser with Pay.com.js, your server creates a session with its API key, for example with POST /v1/sessions/payment or POST /v1/sessions/tokenization. It then passes only the session's id and short-lived client_secret to the browser, where Pay.com.js uses them.

Was this page helpful?