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"]
}'const response = await fetch('https://api.sandbox.pay.com/v1/sessions/payment', {
method: 'POST',
headers: {
// Basic auth: an empty username, then ":", then the key, in base64.
Authorization: `Basic ${Buffer.from(`:${process.env.PAY_COM_API_KEY}`).toString('base64')}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
amount: 2000,
currency: 'usd',
customer_reference_id: 'cust_ext_abc123',
payment_method_types: ['card'],
}),
});import os
import requests
response = requests.post(
"https://api.sandbox.pay.com/v1/sessions/payment",
auth=("", os.environ["PAY_COM_API_KEY"]),
json={
"amount": 2000,
"currency": "usd",
"customer_reference_id": "cust_ext_abc123",
"payment_method_types": ["card"],
},
){
"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"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.
| Status | When it happens | What to do |
|---|---|---|
400 Bad Request | The x-paycom-merchant-id header and the Basic auth username name different workspaces (merchant_conflict). | Send one of them. |
401 Unauthorized | The 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 Forbidden | The 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" }'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.