Persist your own order first, put that order identifier in metadata, create the gateway transaction, then persist the returned transaction_id before redirecting the browser.
<?php$payload = [ 'amount' => 100.00, 'success_url' => 'https://merchant.example/payment/return', 'cancel_url' => 'https://merchant.example/payment/cancel', 'webhook_url' => 'https://merchant.example/webhooks/bds-payment', 'metadata' => ['order_id' => 'ORDER-1001'], 'cus_name' => 'Customer Name', 'cus_email' => 'customer@example.com', 'return_type' => 'GET',];$ch = curl_init('https://payment.bdscommerce.com/api/payment/create');curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_FOLLOWLOCATION => false, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_TIMEOUT => 15, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer YOUR_API_KEY', 'Content-Type: application/json', ], CURLOPT_POSTFIELDS => json_encode($payload),]);$response = curl_exec($ch);if ($response === false) { throw new RuntimeException(curl_error($ch)); }$data = json_decode($response, true, 512, JSON_THROW_ON_ERROR);curl_close($ch);// Save $data['transaction_id'] against ORDER-1001 before redirecting.// Then redirect the customer to $data['payment_url'].?>
Typical create response
{ "status": 1, "message": "Payment Link", "transaction_id": "...", "payment_url": "https://payment.bdscommerce.com/api/execute/..."}