أمثلة
التدفّق الكامل — احصل على token ثمّ أنشئ دفعة — بعدّة لغات شائعة.
cURL
# 1) get an access token
curl -X POST {base_url}/authentication/token \
-H "Content-Type: application/json" \
-d '{"client_id":"YOUR_CLIENT_ID","secret_id":"YOUR_SECRET_ID"}'
# 2) create a payment with the token
curl -X POST {base_url}/payment/create \
-H "Authorization: Bearer ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"amount":"100.00","currency":"USD","return_url":"https://your-site.com/success","custom":"ORDER-123"}'
PHP (Guzzle)
$client = new \GuzzleHttp\Client(['base_uri' => '{base_url}/']);
// 1) token
$auth = json_decode($client->post('authentication/token', [
'json' => ['client_id' => $clientId, 'secret_id' => $secretId],
])->getBody(), true);
$token = $auth['data']['access_token'];
// 2) create payment
$pay = json_decode($client->post('payment/create', [
'headers' => ['Authorization' => "Bearer {$token}"],
'json' => [
'amount' => '100.00', 'currency' => 'USD',
'return_url' => 'https://your-site.com/success',
'custom' => 'ORDER-123',
],
])->getBody(), true);
header('Location: ' . $pay['data']['payment_url']); // redirect the customer
Node.js
const base = '{base_url}';
// 1) token
const auth = await (await fetch(`${base}/authentication/token`, {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ client_id: CLIENT_ID, secret_id: SECRET_ID }),
})).json();
const token = auth.data.access_token;
// 2) create payment
const pay = await (await fetch(`${base}/payment/create`, {
method: 'POST',
headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ amount: '100.00', currency: 'USD', return_url: 'https://your-site.com/success', custom: 'ORDER-123' }),
})).json();
res.redirect(pay.data.payment_url); // send the customer to checkout
Python
import os, requests
base = "{base_url}"
# 1) token
auth = requests.post(f"{base}/authentication/token", json={
"client_id": os.environ["ZOVO_CLIENT_ID"],
"secret_id": os.environ["ZOVO_SECRET"],
}).json()
token = auth["data"]["access_token"]
# 2) create payment
pay = requests.post(
f"{base}/payment/create",
headers={"Authorization": f"Bearer {token}"},
json={
"amount": "100.00", "currency": "USD",
"return_url": "https://your-site.com/success", "custom": "ORDER-123",
},
).json()
# send the customer to pay["data"]["payment_url"]