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-1.php

<?php

require_once("config/config.php");


// ข้อมูลเชื่อมต่อ 2C2P
$merchantId = $officeid;
$apiSecretKey = $apikey;
//$pacoEncryptionPublicKey = $pacoEncryptionPublicKey;
//$pacoSigningPublicKey = $pacoSigningPublicKey;



//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,
);*/

/*$app ="application/json";
$appson="application/son; charset=utf-8";
$headers = array(
                'Accept' => $app,
                'apiKey' => $apiSecretKey,
                'Content-Type' => $appson,
            );

$headersen=json_encode($headers);
var_dump($headersen);
echo($endpoint);*/


$datasend = array(  // ค่าที่ต้องส่ง อันนี้อาจต้องดูในคู่มือว่าตัวไหนจำเป็นต้องใส่บ้าง
   "amount"=> "2000.00",   
   "currency"=> "THB",  
   "description" => "Awesome Product",
   "source_type" => "card",    
   "reference_order"=> "11251513",
	"officeId"=> $merchantId
);

$body=json_encode($datasend);
var_dump($body);
echo($endpoint);

 $curl = curl_init();

                curl_setopt_array($curl, array(
                  //CURLOPT_URL => 'datagateway.ttbbank.com',
				  CURLOPT_URL => $endpoint,
                  CURLOPT_RETURNTRANSFER => true,
                  CURLOPT_ENCODING => '',
                  CURLOPT_MAXREDIRS => 10,
                  CURLOPT_TIMEOUT => 0,
                  CURLOPT_FOLLOWLOCATION => true,
                  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                  CURLOPT_CUSTOMREQUEST => 'POST',
                  CURLOPT_POSTFIELDS =>'{
  "paymentType": "CC",
  "paymentCategory": "ECOM",
  "orderNo": "TT1650866348558",
  "productDescription": "Merchant Test Tool 1650866348389",
  "mcpFlag": "N",
  "transactionAmount": {
    "currencyCode": "THB",
    "amount": "1",
    "decimalPlaces": 2,
    "amountText": "000000000100"
  },
  "channelCode": "WEBPAY",
  "request3dsFlag": "N",
  "autoRedirectDelayTimer": 5,
  "notificationURLs": {
    "confirmationURL": "http://confirmation-url2c2p.com",
    "failedURL": "http://failed-url2c2p.com",
    "cancellationURL": "http://cancellation-url2c2p.com",
    "backendURL": "http://backend-url2c2p.com"
  },
  "recurringPaymentDetails": {
    "rppFlag": "N"
  },
  "generalPayerDetails": {
    "personType": "General",
    "seqNo": 1,
    "personName": {
      "title": "Mr.",
      "firstName": "Merchant Test Tool User"
    }
  },
  "installmentPaymentDetails": {
    "ippFlag": "N"
  },
  "officeId": "2206",
  "apiRequest": {
    "requestMessageID": "3fd2e3e7-f5a9-4cee-5599-f0e7fffb995c",
    "requestDateTime": "2022-04-25T07:54:45.696Z",
    "language": "en-US"
  }
}',
  CURLOPT_HTTPHEADER => array(
    'Accept: application/json',
    'apiKey: 7068c343afa741ea978abe75a1b22d51',
    'Content-Type: application/json; charset=utf-8'
  ),
));

$response = curl_exec($curl);
$response1 = json_decode(json_encode($response), True); 
echo($response1["paymentPageURL"]);

curl_close($curl);


echo $response;

/*
                $response = curl_exec($curl);


  $data = json_decode(file_get_contents('php://input'), true);
  var_dump($data);
    
                $response1 = json_decode(json_encode($response), True);  

var_dump($response1);
                curl_close($curl);*/






/*
$ch = curl_init();
$post_string = json_encode($datasend);  
var_dump($post_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 
	'Accept: application/json',
	'apiKey: '.$apiSecretKey, // ใส่ Secret Key
	'Content-Type: application/json; charset=utf-8'       
 
  )                                                                       
);
$cc= curl_exec($ch);
$r1 = json_decode($cc);
var_dump(r1);
 
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt($ch, CURLOPT_SSLVERSION, 0 );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);



$data = curl_exec($ch);
$response = json_decode($data);


curl_close ($ch);

$response = json_decode(json_encode($response), True);  

var_dump($response);


*/


// ส่งข้อมูลไปยัง 2C2P Payment Gateway
/*$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headersen);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

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

//$data = json_decode(file_get_contents('php://input'), true);
$data1 = json_decode($response);
var_dump($data1);

// ตรวจสอบการตอบกลับจาก 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