Developers

Derash Pay API in five minutes

A single REST API to accept payments from every Ethiopian bank, mobile wallet and global card network. Test charges auto-succeed; live charges flow through real PSPs once your project is approved.

Base URL https://derashpay.co/api/v1 Auth Authorization: Bearer dp_secret_test_… Format JSON in / JSON out

Client libraries — one file, no build step

Download a single file into your project. PHP and Python need zero extra packages. Node.js uses built-in https and crypto (Node 14+). Flutter requires http and crypto from pub.dev.

PHP 7.4+ · no dependencies
Download
// 1. Copy DerashPay.php anywhere in your project
require 'DerashPay.php';

$dp = new DerashPay('dp_secret_test_...');

// Direct charge
$tx = $dp->createCharge(245000, 'ETB', 'telebirr', [
    'idempotency_key' => 'order_4827',
    'customer_email'  => 'buyer@example.com',
]);

// Hosted checkout — redirect customer to the URL we return
$session = $dp->createCheckoutSession(245000, 'ETB',
    'https://you.com/success', [
    'cancel_url'   => 'https://you.com/cancel',
    'allowed_psps' => ['telebirr', 'cbe', 'awash'],
]);
header('Location: ' . $session['url']);

// Verify an incoming webhook
$raw = file_get_contents('php://input');
$ok  = DerashPay::verifyWebhook(
    $raw,
    $_SERVER['HTTP_X_DERASHPAY_SIGNATURE'] ?? '',
    'whsec_...'
);
if (!$ok) { http_response_code(400); exit; }
$event = json_decode($raw, true);
Node.js 14+ · no dependencies
Download
// 1. Copy derashpay.js into your project
const { DerashPay } = require('./derashpay');

const dp = new DerashPay('dp_secret_test_...');

// Direct charge
const tx = await dp.createCharge(245000, 'ETB', 'telebirr', {
  idempotencyKey: 'order_4827',
  customerEmail:  'buyer@example.com',
});

// Hosted checkout
const session = await dp.createCheckoutSession(245000, 'ETB',
  'https://you.com/success', {
  cancelUrl:   'https://you.com/cancel',
  allowedPsps: ['telebirr', 'cbe', 'awash'],
});
res.redirect(session.url);

// Verify webhook — use express.raw() so body is a Buffer
app.post('/webhook', express.raw({ type: '*/*' }), (req, res) => {
  const ok = DerashPay.verifyWebhook(
    req.body,
    req.headers['x-derashpay-signature'],
    'whsec_...'
  );
  if (!ok) return res.sendStatus(400);
  const event = JSON.parse(req.body);
  res.sendStatus(200);
});
Python 3.7+ · no dependencies
Download
# 1. Copy derashpay.py into your project
from derashpay import DerashPay, DerashPayError

dp = DerashPay('dp_secret_test_...')

# Direct charge
tx = dp.create_charge(245000, 'ETB', 'telebirr',
    idempotency_key='order_4827',
    customer_email='buyer@example.com')

# Hosted checkout
session = dp.create_checkout_session(245000, 'ETB',
    'https://you.com/success',
    cancel_url='https://you.com/cancel',
    allowed_psps=['telebirr', 'cbe', 'awash'])
return redirect(session['url'])  # Flask / Django

# Verify webhook (Flask)
@app.post('/webhook')
def webhook():
    ok = DerashPay.verify_webhook(
        request.get_data(),
        request.headers.get('X-DerashPay-Signature', ''),
        'whsec_...')
    if not ok:
        abort(400)
    event = request.get_json(force=True)
    return '', 200
Flutter Dart 3+ · http + crypto
Download
# pubspec.yaml
dependencies:
  http:   ^1.2.0
  crypto: ^3.0.0

// Copy derashpay.dart into lib/
import 'package:your_app/derashpay.dart';

// ⚠ Never put secret keys in a Flutter app.
// Use checkout sessions — your backend creates the URL,
// Flutter just opens it with url_launcher or a WebView.

// On your Dart SERVER (dart_frog / shelf)
final dp = DerashPay('dp_secret_test_...');

final session = await dp.createCheckoutSession(
    245000, 'ETB', 'https://you.com/success',
    customerEmail: 'buyer@example.com',
    allowedPsps: ['telebirr', 'cbe']);

// In Flutter — open the URL
await launchUrl(Uri.parse(session['url']!));

AI prompt — paste into any LLM

Drop this into ChatGPT, Claude, Cursor or your AI of choice. Tell it your language. Get a production-ready Derash Pay client back in seconds.

Drop into any AI

API integration prompt

You are integrating the Derash Pay payment API. Write production-grade code to accept payments.

Base URL: https://derashpay.co/api/v1
Auth: HTTP header  Authorization: Bearer <secret_key>
Secret formats:
  dp_secret_test_<32 hex>   test mode (auto-succeeds)
  dp_secret_live_<32 hex>   live mode (real money)

Amounts are integers in MINOR units (santims/cents). ETB 1.00 = 100. NEVER use floats.

Endpoints:

GET /ping
  Returns: {"ok":true,"merchant_id":int,"project_id":int,"mode":"test"|"live","time":ISO8601,"env":string}

POST /charges
  Headers: Authorization, Content-Type: application/json, Idempotency-Key: <unique> (recommended)
  Body:
    { "amount":int_minor, "currency":"ETB"|"USD"|..., "psp":"telebirr"|"cbe"|"awash"|"dashen"|"boa"|"stripe"|"paypal"|"m_pesa"|"cbebirr"|"awashbirr"|"boa_card"|"zamzam"|"card_generic"|"local_banks"|"pss_cards"|"commercial",
      "description":"optional <=255", "customer_email":"optional",
      "customer_name":"optional", "customer_phone":"optional", "metadata"?:{} }
  Returns 201:
    { "id":"tx_...","object":"transaction","mode":"...","status":"succeeded"|"pending",
      "amount":int,"fee":int,"net":int,"currency":"...","psp":"...","created":unix_ts }
  Replay of same Idempotency-Key returns prior tx with "replay":true (no double-charge).

POST /checkout_sessions   (hosted checkout — don't build your own pay page)
  Body:
    { "amount":int_minor, "currency":"ETB", "return_url":"https://you/success",
      "cancel_url":"https://you/cancel"|optional, "description"?, "customer_email"?,
      "customer_name"?, "customer_phone"?, "allowed_psps"?: ["telebirr","cbe",...], "metadata"?:{} }
    return_url falls back to projects.settings_json.return_url if omitted.
  Returns 201:
    { "id":"cs_...","object":"checkout_session","url":"<base>/checkout/cs_...",
      "mode":..., "amount":..., "currency":..., "status":"open",
      "return_url":..., "cancel_url":..., "expires_at":ISO8601, "created":unix_ts }
  Redirect the browser to .url. After paying, customer is bounced to:
    return_url?cs=cs_...&tx=tx_...&status=succeeded|pending
  After cancel:
    cancel_url?cs=cs_...&status=cancelled

Errors (every non-2xx): {"error":{"code":"...","message":"..."}}
  401 auth_missing | auth_invalid
  403 account_suspended
  422 amount_too_low | amount_too_high | invalid_currency | missing_psp | psp_not_available
  503 maintenance
  405 method_not_allowed

Webhooks (callback URLs you add in Settings -> Webhooks):
  Headers: X-DerashPay-Signature: t=<unix>,v1=<hex hmac-sha256(t+'.'+body, endpoint_secret)>
           X-DerashPay-Event-Id, X-DerashPay-Event-Type
  Body: { "id":"evt_...", "type":"transaction.succeeded"|..., "mode":..., "data": {transaction} }
  Verify: recompute HMAC, compare in constant time, reject if abs(now - t) > 300.

YOUR TASK: write idiomatic integration code in <PASTE LANGUAGE HERE>. Deliver:
  1. A reusable client class (Authorization header + JSON + typed errors)
  2. ping() method
  3. createCharge(amount_minor, currency, psp, opts={}) with Idempotency-Key
  4. A webhook verifier function (signature check + 5-min replay protection)
  5. Error handling that surfaces the codes above
  6. One full charge example + one webhook handler example in a README

My secret key (use, don't echo): <PASTE YOUR TEST SECRET HERE>

1. Authentication

Send your secret key on every request as a Bearer token. Public keys (dp_public_test_…) are safe to expose; secret keys (dp_secret_test_…) are not. Get yours from API keys in the dashboard.

curl -L -H "Authorization: Bearer dp_secret_test_..." \
  https://derashpay.co/api/v1/ping
# 200 OK
{
  "ok":          true,
  "merchant_id": 1,
  "project_id":  1,
  "mode":        "test",
  "time":        "2026-06-01T...",
  "env":         "development"
}

The key resolves to a specific merchant + project + mode. Switching projects in the dashboard generates a new pair; live mode keys are only minted after admin approves the project.

2. Quick start — create a charge

Amounts are always integers in minor units: ETB 1.00 is 100, ETB 2,450.00 is 245000. Floats are not accepted — do the multiplication on your side.

Always set Idempotency-Key to something unique per logical charge (e.g. your order id). Replaying with the same key returns the same transaction; we never double-charge.

curl -L -X POST \
  -H "Authorization: Bearer dp_secret_test_..." \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order_4827" \
  -d '{
    "amount":   245000,
    "currency": "ETB",
    "psp":      "telebirr",
    "description":    "Order #4827",
    "customer_email": "buyer@example.com"
  }' \
  https://derashpay.co/api/v1/charges
# 201 Created  (test mode auto-succeeds)
{
  "id":       "tx_a8c3d7b9f1...",
  "object":   "transaction",
  "mode":     "test",
  "status":   "succeeded",
  "amount":   245000,
  "fee":      4532,
  "net":      240468,
  "currency": "ETB",
  "psp":      "telebirr",
  "created":  1748774400
}

3. Endpoints

MethodPathPurpose
GET/api/v1/pingVerify secret key · returns merchant / project / mode
POST/api/v1/chargesCreate a transaction directly from your server
POST/api/v1/checkout_sessionsCreate a hosted checkout session — returns a URL to redirect the customer to
GET/api/v1/transactionsList transactions with keyset pagination · filter by status, mode, PSP
POST/api/v1/refundsRefund a succeeded charge · test mode auto-succeeds

Rate limit: 60 requests per minute per API key. Exceeding returns 429 rate_limited with a Retry-After header.

Supported PSP codes

Pass one of these as the psp field on a charge. Disabled ones return psp_not_available.

  • telebirr
  • cbe
  • cbebirr
  • awash
  • awashbirr
  • dashen
  • boa
  • boa_card
  • zamzam
  • commercial
  • m_pesa
  • stripe
  • paypal
  • card_generic
  • local_banks
  • pss_cards

4. Hosted checkout

Don't want to build your own payment page? Create a checkout session from your server, redirect the customer to the URL we return, and we host the entire bank-picker UI for you. After they pay, their browser is bounced back to your return_url with the transaction details in the query string.

Create a session

curl -L -X POST \
  -H "Authorization: Bearer dp_secret_test_..." \
  -H "Content-Type: application/json" \
  -d '{
    "amount":     245000,
    "currency":   "ETB",
    "return_url": "https://your-site.com/payment/success",
    "cancel_url": "https://your-site.com/payment/cancelled",
    "description":    "Order #4827",
    "customer_email": "buyer@example.com",
    "allowed_psps": ["telebirr","cbe","awash"]
  }' \
  https://derashpay.co/api/v1/checkout_sessions
# 201 Created
{
  "id":         "cs_a8c3d7b9f1...",
  "object":     "checkout_session",
  "url":        "https://derashpay.co/checkout/cs_a8c3d7b9f1...",
  "mode":       "test",
  "amount":     245000,
  "currency":   "ETB",
  "status":     "open",
  "return_url": "https://your-site.com/payment/success",
  "cancel_url": "https://your-site.com/payment/cancelled",
  "expires_at": "2026-06-01T...",
  "created":    1748774400
}

Send the customer to the url field. They see a clean bank-picker page, choose a method, click Pay. After success, their browser comes back to:

https://derashpay.co/payment/success?cs=cs_...&tx=tx_...&status=succeeded

Defaults from the project

  • return_url — falls back to Settings → Checkout → Return URL
  • cancel_url — falls back to Settings → Checkout → Cancel URL
  • allowed_psps — falls back to Settings → Checkout → Banks shown on checkout

So in production you can keep your server payload minimal — just amount, currency, and customer details — and the per-project defaults fill the rest.

Session lifecycle

  • open → completed — customer paid (test mode auto-completes)
  • open → processing — live mode: PSP redirect in flight
  • open → cancelled — customer hit Cancel
  • open → expired — 30 minutes elapsed, link no longer usable

5. Webhooks — the callback URL

Add a callback URL in Settings → Webhooks. We POST a signed JSON event to it whenever something happens on a transaction.

Headers we send

Content-Type:            application/json
User-Agent:              DerashPay-Webhooks/1.0
X-DerashPay-Event-Id:    evt_<28 hex>
X-DerashPay-Event-Type:  transaction.succeeded
X-DerashPay-Signature:   t=<unix_ts>,v1=<hex hmac-sha256>

Event body

{
  "id":      "evt_a8c3d7b9f1...",
  "object":  "event",
  "type":    "transaction.succeeded",
  "created": 1748774400,
  "mode":    "test",
  "data": {
    "id":       "tx_...",
    "object":   "transaction",
    "status":   "succeeded",
    "amount":   245000,
    "fee":      4532,
    "net":      240468,
    "currency": "ETB",
    "psp":      "telebirr"
  }
}

Event types

  • transaction.created — new live charge accepted, PSP not yet completed
  • transaction.succeeded — PSP completed successfully
  • transaction.failed — PSP rejected or timed out (future)
  • refund.succeeded — refund processed (future)
  • test.ping — emitted by the "Send test event" button

Verifying the signature

Recompute the HMAC on your side and compare in constant time. Reject events older than ~5 minutes to prevent replay.

# Node.js example
const crypto = require('crypto');

function verify(req, secret) {
  const header  = req.headers['x-derashpay-signature']; // "t=...,v1=..."
  const m       = /^t=(\d+),v1=([a-f0-9]+)$/.exec(header);
  if (!m) return false;
  const [_, ts, given] = m;
  const expected = crypto
    .createHmac('sha256', secret)
    .update(ts + '.' + req.rawBody)
    .digest('hex');
  const sigOk = crypto.timingSafeEqual(Buffer.from(given), Buffer.from(expected));
  const fresh = Math.abs(Date.now() / 1000 - Number(ts)) < 300;
  return sigOk && fresh;
}

Need to confirm your endpoint is reachable? Hit Send test event next to your URL in Settings → Webhooks. We POST a test.ping event and show the HTTP status from your server in the deliveries table on the same page.

6. Errors

Every non-2xx response has the same shape:

{"error": {"code": "machine_code", "message": "human readable"}}
HTTPCodeFix
401auth_missingAdd Authorization: Bearer <secret>
401auth_invalidKey is wrong, revoked, or doesn't match this project
403account_suspendedAdmin suspended the merchant — contact support
405method_not_allowedWrong HTTP verb for that endpoint
422amount_too_low / amount_too_highOutside platform limits
422invalid_currencyUse a 3-letter ISO code (ETB, USD, EUR…)
422missing_pspThe psp field is required
422psp_not_availableThat PSP is disabled platform-wide
422not_refundable / already_refundedRefund precondition failed
429rate_limited60 req/min exceeded — check Retry-After header
503maintenancePlatform paused by admin — retry later

7. Testing

Test-mode keys (dp_secret_test_…) never move real money. POST /charges with a test key always returns "status":"succeeded" instantly, fires the transaction.succeeded webhook, and updates your dashboard's balance + revenue cards — perfect for end-to-end integration tests.

Live keys (dp_secret_live_…) require admin approval per project. Live charges return "status":"pending" and stay that way until the PSP wiring confirms them (next phase).

What to test

  • ✓ ping with your key → returns the right mode
  • ✓ charges with a fresh Idempotency-Key → 201
  • ✓ charges with the same Idempotency-Key twice → same tx_ id, "replay":true, dashboard total doesn't double
  • ✓ charges with bad currency / missing psp / low amount → 422 with the right code
  • ✓ Webhook endpoint receives transaction.succeeded with a valid X-DerashPay-Signature
  • ✓ "Send test event" in dashboard → your endpoint shows up in the deliveries table with HTTP 200

Ready to ship?

Generate your test keys, paste the AI prompt above, and you'll be live in an afternoon.

Create free account → Sign in