Skip to content

Code Samples ​

The 6 samples below are all tested and include:

  • HMAC signature generation
  • HTTP call wrappers with response checking (code / error_key)
  • Webhook signature verification

Pick the right one

Dependencies ​

LanguageDependenciesNotes
Pythonrequests (or httpx / urllib3)hmac / hashlib / secrets are stdlib
Node.jsNode.js ≥ 18 (native fetch)crypto is built-in
Gostdlib crypto/hmac / crypto/sha256 / net/httpNo third-party deps
JavaJDK 11+ stdlib (HttpClient / Mac / MessageDigest)Signing needs no third-party deps; the usage sample parses responses with Jackson (any JSON library works)
PHPPHP 7.4+ with curl extensionhash_hmac / random_bytes are built-in
cURLopenssl + awk (+ optional jq to check responses)Generic shell tools

Common Variables ​

APP_ID  = "cp_a1b2c3d4..."         # 31 chars, cp_ + 28 hex
SECRET  = "f1e2d3c4..."            # 64 hex chars
BASE    = "https://api.coinepay.net"

Don't hardcode

Samples have SECRET inline for clarity; production code should read from env vars / Vault / Secret Manager.

Handling Responses ​

Every endpoint returns the same envelope. All samples follow these rules:

  • Success is code == 0 (never 200). Read data only then.
  • Don't rely on the HTTP status alone: most business errors (40000, 40001, 50000) come back with HTTP 200 and a non-zero code.
  • Branch on error_key — a stable machine key present on every error. message is localized text for humans (English unless you send Accept-Language); never match on it.
  • 401 / 40100 openapi_invalid_credentials: signature, clock or credential problem — fix it and re-sign; retrying unchanged will not help.
  • 429 / 42900 too_many_requests: wait Retry-After seconds, then retry (same Idempotency-Key on write endpoints).
json
{ "code": 0, "message": "Success", "data": { "card_id": "card_12345", "status": 1, "status_desc": "pending" } }
{ "code": 40000, "message": "Insufficient balance", "error_key": "insufficient_balance" }

See Error Codes for the full error_key dictionary.

Released under MIT-equivalent terms.