= ($_SESSION['api_token_expires'] - $token_refresh_buffer)) { $data = json_encode(array("clientID" => clientID, "clientsecret" => clientsecret), JSON_UNESCAPED_UNICODE); $responses = ioAPIv2('/v2/authorization', $data,''); if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = '400';} if (isset($responses['token']) && isset($responses['token_valid'])) { $_SESSION['api_token'] = $responses['token']; $_SESSION['api_token_expires'] = strtotime($responses['token_valid']); $clientsecret = $responses['token']; } else { $clientsecret = $responses['token'] ?? ''; } } else { $clientsecret = $_SESSION['api_token']; } // Set JSON header header('Content-Type: application/json'); // Get order ID from request $order_id = $_GET['order_id'] ?? null; if (!$order_id) { echo json_encode(['error' => 'No order ID provided']); exit; } // Check transaction status $transaction_data = ioAPIv2('/v2/transactions/txn_id='.$order_id,'',$clientsecret); $transaction = json_decode($transaction_data, true); if ($transaction && isset($transaction[0])) { $payment_status_code = $transaction[0]['payment_status'] ?? 0; // Map payment status codes: 1 = Paid, 101 = Pending, 102 = Failed, 103 = Expired, 999 = Cancelled if ($payment_status_code == 1) { $payment_status = 'success'; } elseif ($payment_status_code == 101) { $payment_status = 'pending'; } elseif (in_array($payment_status_code, [102, 103, 999])) { $payment_status = 'failed'; } else { $payment_status = 'processing'; } echo json_encode([ 'status' => $payment_status, 'payment_status_code' => $payment_status_code ]); } else { echo json_encode([ 'status' => 'processing', 'payment_status_code' => 101 ]); } ?>