b0y-101 Mini Shell


Current Path : E:/www/b-group.old/spfin - Copy/paymentall/
File Upload :
Current File : E:/www/b-group.old/spfin - Copy/paymentall/p2.php

<?php

//Endpoint: https://core.demo-paco.2c2p.com/api/1.0/Payment/prePaymentUi

//Office ID: 2206

//API key : 7068c343afa741ea978abe75a1b22d51


// ข้อมูลเชื่อมต่อ 2C2P
$merchantId = '2206';
$apiSecretKey = '7068c343afa741ea978abe75a1b22d51';
$pacoEncryptionPublicKey = file_get_contents('key/PACOEncryptionPublic.txt');
$pacoSigningPublicKey = file_get_contents('key/PACOSigningPublic.txt');


//echo("Hello");
//echo($merchantId);
//echo($apiSecretKey);
//echo($pacoEncryptionPublicKey);



// ข้อมูลการทำธุรกรรม
$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);

// ตราประทับข้อมูลด้วย PACO Signing Public Key
$signature = hash_hmac('sha256', $encryptedData, $pacoSigningPublicKey);



// สร้าง HTTP headers สำหรับส่งไปยัง 2C2P Payment Gateway
$headers = array(
    'Content-Type: application/json',
    'X-APIKEY: ' .$apiSecretKey, //$merchantId,
    'X-SIGNATURE: ' . $signature,
);

var_dump($headers);

// ส่งข้อมูลไปยัง 2C2P Payment Gateway
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://core.demo-paco.2c2p.com/api/1.0/Payment/prePaymentUi');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $encryptedData);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
var_dump($response);
curl_close($ch);

// ตรวจสอบการตอบกลับจาก 2C2P Payment Gateway
if ($response === FALSE) {
    // การส่งข้อมูลไม่สำเร็จ
	echo($response);
	echo($signature);
	print_r($_POST);
    echo 'Error calling 2C2P Payment Gateway';
} else {
    // การส่งข้อมูลสำเร็จ
    echo 'Successfully called 2C2P Payment Gateway';
	echo($response);
    // ทำการประมวลผลการตอบกลับที่ได้รับจาก 2C2P Payment Gateway
    // ...
}

?>

Copyright © 2019 by b0y-101