API authentication
When to use Basic auth, an account key, or both, and where the credentials are issued.
Every Payments API call is authenticated with one or both of two credentials:
- An API key and secret. Send these as HTTP Basic authentication, with the key as the username and the secret as the password. Together they can move money, so they stay on your server.
- An account key. Send this in the
accountKeyheader as plain text. It identifies an account, and on its own it can do very little, so it is safe to use in a browser.
Which combination you send decides what the call can do and which account it acts on. The three combinations are below.
Calls go to https://api.dhangodemo.com in sandbox and https://api.dhango.com in production. The API overview lists the headers and field names.
Create and rotate credentials
In the dashboard, open Accounts, open your platform account, and go to the API Credentials tab. Create a key and secret for the Payments API there. dhango shows the full secret only once, when you create it, so store it in a secret manager right away. The same tab has a separate control for regenerating the webhook HMAC key. See Webhooks.
Basic auth only
With Basic auth and no accountKey header, the call acts as the account that owns the key. Tokens and transactions created this way belong to that account. Keep the secret out of browsers and client applications.
Account key only
An account key on its own cannot take payments, which is why you can put it in a web page. With only accountKey, a call can:
- Create a token for that account.
- Read payer fees with
GET /v1/payerFees. - Submit a check validation, if the account has a check processor credential.
Any other request is rejected.
An inactive merchant stays limited to this set, even when you also send your platform key and secret. The broader access in the next section starts once the merchant is active.
Basic auth plus an account key
This is how your platform acts for a merchant. Send your platform key and secret, and set accountKey to the merchant. The merchant must be one your platform manages, and it must be a different account from your platform account.
Transactions from these calls are stored on the merchant. The token you charge can belong to the merchant or to your platform. Platform-owned tokens are how one saved payment method is used across several merchants. See Token ownership.
This request creates a token for a merchant with your platform credentials:
Make pay, refund, void, capture, payout, and account validation calls from your server. Account validation rejects a request that sends only the account key.
curl -s -u "$DHANGO_KEY:$DHANGO_SECRET" \ -H "Content-Type: application/json" \ -H "accountKey: $ACCOUNT_KEY" \ -d '{"card":{"cardHolder":"Ada Lovelace","cardNumber":"4242424242424242","expirationMonth":12,"expirationYear":2030}}' \ https://api.dhangodemo.com/v1/tokensconst auth = Buffer.from(process.env.DHANGO_KEY + ":" + process.env.DHANGO_SECRET).toString("base64");await fetch("https://api.dhangodemo.com/v1/tokens", { method: "POST", headers: { Authorization: "Basic " + auth, "Content-Type": "application/json", accountKey: process.env.ACCOUNT_KEY }, body: JSON.stringify({ card: { cardHolder: "Ada Lovelace", cardNumber: "4242424242424242", expirationMonth: 12, expirationYear: 2030 } })});import os, requestsauth = (os.environ["DHANGO_KEY"], os.environ["DHANGO_SECRET"])headers = {"accountKey": os.environ["ACCOUNT_KEY"]}response = requests.post( "https://api.dhangodemo.com/v1/tokens", auth=auth, headers=headers, json={ "card": { "cardHolder": "Ada Lovelace", "cardNumber": "4242424242424242", "expirationMonth": 12, "expirationYear": 2030 } },)response.raise_for_status()token_id = response.json()["id"]Idempotency
POST /v1/transactions/pay, /payout, /authorize, /{id}/capture, and /{id}/refund accept an Idempotency-Key header, so a retried request is not carried out twice. Generate a new value, such as a UUID, for each operation (up to 200 characters), and send that same value again when you retry it.
Error language
To get error messages in a specific language, send a culture header.