DuevanceAPI documentation

Authentication

Keys, request signing, scopes and replays.

Every API request is signed with your key's secret. The secret never travels: you prove you hold it by signing what you send, and we check the signature with our copy.

Keys

A key belongs to one project and one environment. Its prefix says which environment:

Sent in Duevance-KeySecretEnvironment
dv_test_key_…dv_test_sk_…Test: the fake acquirer, no money moves
dv_live_key_…dv_live_sk_…Live: real acquirers

A key whose prefix doesn't match the key we hold is refused (key_environment_mismatch), even when the signature is right.

Signing a request

Send three headers on every request:

HeaderValue
Duevance-KeyYour key, such as dv_test_key_0D4mXq…
Duevance-TimestampThe current time in Unix seconds
Duevance-SignatureThe lower-case hex HMAC-SHA256 of the string below, keyed with your secret

The signed string joins four parts with dots:

{timestamp}.{METHOD}.{path?query}.{sha256 hex of the body}
  • timestamp is the value of Duevance-Timestamp.
  • METHOD is upper case: GET, POST, PATCH, DELETE.
  • path?query is the path with its leading slash, plus ? and the query string when there is one, exactly as sent: same order, same encoding. GET /v1/payments?status=succeeded&limit=10 signs /v1/payments?status=succeeded&limit=10. We never re-sort or decode it first.
  • The body hash covers the exact bytes sent. A request without a body hashes the empty string: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.

The host and the other headers are not signed. The key's environment binds the request to its environment.

Clock skew

Duevance-Timestamp must be within 300 seconds of our clock, either way. Keep your servers on NTP.

Replays

A signature is accepted once. We remember every signature for 600 seconds (twice the skew), so a captured request can't be sent again while its timestamp would still pass. Sign each request afresh with the current timestamp.

Two different requests with identical bytes signed in the same second have the same signature, and the second is refused as a replay. A payment reference or a fresh timestamp makes them differ.

One exception keeps network retries safe: on the money endpoints, which require an Idempotency-Key, the exact same signed request with the same Idempotency-Key passes and receives the stored answer of the first one. The same bytes with another key are still a replay.

Scopes

ScopeAllows
readEvery GET
writeEverything, reads included: write implies read

A key with no scope can do nothing. A key missing the scope gets 403 with code insufficient_scope. Read-only keys suit reporting jobs and support tools.

Suspension

When the merchant or project is suspended, every request with its keys answers 403 with code account_suspended, and nothing is charged.

Rolling a key

Rolling issues a new key with the same scopes and shows its secret once. The old key keeps working for an overlap of at most 24 hours, so you can deploy the new secret without downtime; an overlap of zero revokes the old key at once. A revoked or expired key answers 401 with code invalid_key, like a key that never existed.

Authentication errors

All are 401 with type authentication_error, except where noted:

CodeCause
missing_credentialsOne of the three headers is missing or blank
invalid_keyThe key is unknown, revoked or expired
key_environment_mismatchThe dv_live_/dv_test_ prefix doesn't match the key
timestamp_out_of_rangeThe timestamp is not Unix seconds within 300 s of our clock
invalid_signatureThe signature doesn't match what was sent
replayed_requestThis signature was already used
insufficient_scope (403)The key lacks the scope
account_suspended (403)The merchant or project is suspended

Debugging a signature

When you get invalid_signature, print the exact string you signed and compare:

  1. Is the path the one you requested, with its leading slash and its query string in the order sent?
  2. Did you hash the bytes you sent, or a re-serialization of the same JSON? Serialize once.
  3. Is the method upper case, and the timestamp the same value as the header?