<?php require_once("config/config.php"); // ตั้งค่าเซิร์ฟเวอร์รับคำขอชำระเงิน if ($_SERVER['REQUEST_METHOD'] === 'POST') { // รับข้อมูลการชำระเงินจากผู้ใช้งาน $amount = $_POST['amount']; $currency = $_POST['currency']; // ... // ตรวจสอบการชำระเงินและดำเนินการต่อ if (processPayment($amount, $currency)) { // การชำระเงินสำเร็จ http_response_code(200); echo json_encode(array('success' => true, 'message' => 'Payment successful')); } else { // การชำระเงินไม่สำเร็จ http_response_code(400); echo json_encode(array('success' => false, 'message' => 'Payment failed')); } } // ฟังก์ชันตรวจสอบและดำเนินการชำระเงิน function processPayment($amount, $currency) { // ทำการตรวจสอบข้อมูลการชำระเงินและดำเนินการตามเงื่อนไขที่กำหนด // ... // เรียกใช้ API ของ 2C2P เพื่อส่งคำขอชำระเงิน $apiUrl = $endpoint; //'https://payment-api.2c2p.com/payment/Charge/pay'; $merchantId = $officeid;//'YOUR_MERCHANT_ID'; $secretKey = $apikey;//'YOUR_SECRET_KEY'; $postData = array( 'version' => '9.6', 'merchant_id' => $merchantId, 'currency' => $currency, 'amount' => $amount, // ข้อมูลอื่น ๆ ที่ต้องการส่งให้กับ API ของ 2C2P // ... ); // สร้าง signature โดยใช้ secret key $signature = hash_hmac('sha256', implode('', $postData), $secretKey); $postData['signature'] = $signature; echo($postData); // ส่งคำขอชำระเงินไปยัง 2C2P API $ch = curl_init($apiUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); $response = curl_exec($ch); curl_close($ch); // ตรวจสอบผลลัพธ์การชำระเงินจาก 2C2P API if ($response === false) { // การส่งคำขอผิดพลาด return false; } var_dump($response); // ประมวลผลข้อมูลที่ได้รับจาก 2C2P API $paymentResult = json_decode($response, true); print_r($paymentResult); // ตรวจสอบสถานะการชำระเงิน /* if ($paymentResult['status'] === '000') { // ชำระเงินสำเร็จ return true; } else { // ชำระเงินไม่สำเร็จ return false; }*/ } ?>