<?php require_once("config/config.php"); $apiUrl = $endpoint; //$officeId = 'YOUR_OFFICE_ID'; //$apiKey = 'YOUR_API_KEY'; //$publicKey = 'YOUR_PUBLIC_KEY'; //$pacoEncryptionPublic = 'YOUR_PACO_ENCRYPTION_PUBLIC_KEY'; //$pacoSigningPublic = 'YOUR_PACO_SIGNING_PUBLIC_KEY'; // Prepare payment data /*$data = array( 'amount' => '100.00', 'currency' => 'THB', 'paymentDescription' => 'Payment Description', // Add other required parameters );*/ // ข้อมูลการทำธุรกรรม $transactionId = '1234567890'; // เลขอ้างอิงธุรกรรม $amount = 1000; // จำนวนเงินที่ต้องการชำระเงิน $currency = 'THB'; // สกุลเงิน $description = 'Payment for Order #123'; // รายละเอียดการชำระเงิน // สร้างข้อมูล Payload $payload = array( 'transaction_id' => $transactionId, 'amount' => $amount, 'currency' => $currency, 'description' => $description, ); // แปลงข้อมูลเป็นรูปแบบ JSON $jsonPayload = json_encode($payload); var_dump($jsonPayload); // เข้ารหัสข้อมูล Payload ด้วย PACO Encryption Public Key $encryptedPayload = openssl_public_encrypt(json_encode($payload), $encryptedData, $pacoEncryptionPublicKey); $encodedData = base64_encode($encryptedData); echo($encodedData); echo($encryptedPayload); // Generate the Signature $signature = hash_hmac('sha256', implode('', json_encode($payload)), $pacoSigningPublicKey); var_dump($signature); // Create the API request $requestData = array( 'paymentRequest' => json_encode($payload), 'signature' => $signature, ); // Set up headers $headers = array( 'Content-Type: application/json', 'Office-Id: ' . $officeid, 'Api-Key: ' . $apiKey, ); // Send the API request $ch = curl_init($apiUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestData)); $response = curl_exec($ch); curl_close($ch); // Process the API response if ($response === false) { echo 'Error: ' . curl_error($ch); } else { $responseData = json_decode($response, true); if (isset($responseData['paymentUrl'])) { $paymentUrl = $responseData['paymentUrl']; // Redirect the user to the payment URL header('Location: ' . $paymentUrl); exit; } else { echo 'Payment URL not found in the API response'; } } ?>