Merchant API Documentation
Create checkout sessions, query session status, and receive signed webhooks for payment updates. This API is designed for merchants integrating EcomTrade24 Pay into custom checkouts, platforms, or plugins (e.g., WooCommerce).
Base URL & Authentication
https://pay.ecomtrade24.com
Your API key is available in the Merchant Dashboard. Keep it private and never expose it in browser-side JavaScript. Use server-to-server requests only.
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
X-API-Key for compatibility, but prefer Authorization: Bearer.
1) Create a Checkout Session
POST /gateway/session.php
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
{
"merchant": "yourshop.com",
"merchant_ref": "YOUR_INTERNAL_ORDER_ID",
"purchase_id": "OPTIONAL_PURCHASE_REFERENCE",
"session_id": "OPTIONAL_EXTERNAL_SESSION_ID",
"amount": "5.00",
"currency": "EUR",
"return_url": "https://yourshop.com/payment/return",
"webhook_url": "https://yourshop.com/api/webhook/ecomtrade24",
"customer": {
"email": "[email protected]"
},
"meta": {
"cart_id": "optional",
"source": "optional"
}
}
merchantmust match your registered shop/domain in the Merchant Dashboard (normalized domain recommended).merchant_refshould be your unique order identifier. Use a stable value to prevent duplicates.amountandcurrencyare the exact order totals you expect to charge.return_urlis where the customer is redirected after checkout (success or final return step).webhook_urlcan be provided per session, or configured globally in your Merchant Dashboard.metais optional and returned back in status/webhook payloads (useful for internal mapping).
{
"ok": true,
"session_id": "SESSION_TOKEN",
"checkout_url": "https://pay.ecomtrade24.com/pay.php?merchant=yourshop.com&merchant_ref=YOUR_INTERNAL_ORDER_ID&session_id=SESSION_TOKEN&amount=5.00¤cy=EUR&return_url=...&webhook_url=...",
"expires_at": "YYYY-MM-DD HH:MM:SS"
}
checkout_url (server-side redirect or frontend button link).
Store session_id to reconcile status and webhooks.
2) Hosted Checkout via URL (Optional)
If you do not want to call the API first, you can start a hosted checkout directly by redirecting the customer to /pay.php.
This method is commonly used for simple integrations.
GET /pay.php
merchant=yourshop.com
merchant_ref=YOUR_INTERNAL_ORDER_ID
session_id=YOUR_SESSION_TOKEN
purchase_id=OPTIONAL_PURCHASE_REFERENCE
amount=5.00
currency=EUR
return_url=https%3A%2F%2Fyourshop.com%2Fpayment%2Freturn
webhook_url=https%3A%2F%2Fyourshop.com%2Fapi%2Fwebhook%2Fecomtrade24
session_id and purchase_id on your server as unique, unguessable identifiers
and store them with the order record.
3) Get Session Status
GET /gateway/session_status.php?session_id=SESSION_TOKEN
Authorization: Bearer YOUR_API_KEY
{
"ok": true,
"session": {
"session_id": "SESSION_TOKEN",
"merchant": "yourshop.com",
"merchant_ref": "YOUR_INTERNAL_ORDER_ID",
"purchase_id": "OPTIONAL_PURCHASE_REFERENCE",
"status": "created",
"amount": "5.00",
"currency": "EUR",
"created_at": "YYYY-MM-DD HH:MM:SS",
"updated_at": "YYYY-MM-DD HH:MM:SS",
"meta": {
"cart_id": "optional"
}
}
}
created— session created, payment not completed yetpending— payment initiated, awaiting confirmationpaid— payment completed successfully (final)failed— payment failed (final)expired— session expired before completion (final)canceled— customer canceled checkout (final)
paid as the only successful final state. For all other final states, keep the order unpaid.
4) Webhooks
Webhooks notify your system when a session changes state (e.g., paid).
Configure a default Webhook URL and Webhook Secret in the Merchant Dashboard, or provide a per-session webhook_url.
Header: X-Signature = HMAC-SHA256(raw_body, webhook_secret)
payment.session.createdpayment.session.updatedpayment.session.paidpayment.session.failedpayment.session.expiredpayment.session.canceled
{
"event": "payment.session.paid",
"sent_at": "YYYY-MM-DDTHH:MM:SSZ",
"data": {
"session_id": "SESSION_TOKEN",
"merchant": "yourshop.com",
"merchant_ref": "YOUR_INTERNAL_ORDER_ID",
"purchase_id": "OPTIONAL_PURCHASE_REFERENCE",
"status": "paid",
"amount": "5.00",
"currency": "EUR",
"meta": {
"cart_id": "optional"
}
}
}
<?php
// webhook.php
$secret = 'YOUR_WEBHOOK_SECRET';
$rawBody = file_get_contents('php://input');
$receivedSig = $_SERVER['HTTP_X_SIGNATURE'] ?? '';
$calculated = hash_hmac('sha256', $rawBody, $secret);
if (!hash_equals($calculated, $receivedSig)) {
http_response_code(401);
echo 'invalid signature';
exit;
}
$payload = json_decode($rawBody, true);
if (!is_array($payload)) {
http_response_code(400);
echo 'invalid json';
exit;
}
$event = $payload['event'] ?? '';
$data = $payload['data'] ?? [];
$sessionId = $data['session_id'] ?? '';
$merchantRef = $data['merchant_ref'] ?? '';
$status = $data['status'] ?? '';
// Important: Make your handler idempotent (webhooks may be retried).
// Always confirm final state by polling session_status if needed.
http_response_code(200);
echo 'ok';
200 quickly. Process heavy logic asynchronously.
Webhooks can be retried; always implement idempotency (e.g., store processed session_id + status).
Error Format
On errors, the API responds with an HTTP error status and a JSON body:
{
"ok": false,
"error": "error_code",
"message": "Human readable explanation"
}
400— invalid request (missing/invalid fields)401— unauthorized (missing/invalid API key)403— forbidden (domain not allowed, account disabled)404— endpoint not found429— rate limited500— server error
Quick cURL Examples
# Create session
curl -X POST "https://pay.ecomtrade24.com/gateway/session.php" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"merchant":"yourshop.com",
"merchant_ref":"YOUR_INTERNAL_ORDER_ID",
"session_id":"YOUR_SESSION_TOKEN",
"purchase_id":"OPTIONAL_PURCHASE_REFERENCE",
"amount":"5.00",
"currency":"EUR",
"return_url":"https://yourshop.com/payment/return",
"webhook_url":"https://yourshop.com/api/webhook/ecomtrade24",
"customer":{"email":"[email protected]"},
"meta":{"cart_id":"optional"}
}'
# Poll status
curl "https://pay.ecomtrade24.com/gateway/session_status.php?session_id=YOUR_SESSION_TOKEN" \
-H "Authorization: Bearer YOUR_API_KEY"
Integration Checklist
- Generate a unique
merchant_reffor each order and store it in your database. - Create a session via
POST /gateway/session.phpor build a/pay.phpredirect URL. - Redirect the customer to
checkout_url. - On return, call
GET /gateway/session_status.phpto confirm the final state. - Enable webhooks for instant updates and always verify
X-Signature. - Mark orders as paid only when status is
paid.