我正在尝试将paytm支付网关集成在cakephp中。
PaytmController.php 页面代码
public function pgredirect($id = null)
{
if($id != '') {
$baseId = explode('@@', $id);
foreach ($baseId as $key => $value) {
$orderId[] = base64_decode($value);
}
$customer_id = $this->Auth->user('id');
$orderDetails = $this->Orders->find('all',[
'conditions' =>[
'Orders.id IN' => $orderId,
'Orders.customer_id' => $customer_id
],
'contain' => [
'Restaurants' => [
'fields' => [
'Restaurants.id',
'Restaurants.restaurant_name',
],
],
'Carts'
]
])->hydrate(false)->toArray();
if (!empty($orderDetails)) {
$this->set(compact('orderDetails'));
} else {
return $this->redirect(BASE_URL);
}
} else {
return $this->redirect(BASE_URL);
}
}
pgredirect.ctp
header("Pragma: no-cache");
header("Cache-Control: no-cache");
header("Expires: 0");
require_once("lib/config_paytm.php");
require_once("lib/encdec_paytm.php");
$checkSum = "";
$paramList = array();
foreach($orderDetails as $value) {
$ORDER_ID = $value['order_number'];
$CUST_ID = $value['customer_id'];
$INDUSTRY_TYPE_ID = 'Retail';
$CHANNEL_ID = "WEB";
$TXN_AMOUNT = $value['order_grand_total'];
}
// Create an array having all required parameters for creating checksum.
$paramList["MID"] = PAYTM_MERCHANT_MID;
$paramList["ORDER_ID"] = $ORDER_ID;
$paramList["CUST_ID"] = $CUST_ID;
$paramList["INDUSTRY_TYPE_ID"] = $INDUSTRY_TYPE_ID;
$paramList["CHANNEL_ID"] = $CHANNEL_ID;
$paramList["TXN_AMOUNT"] = $TXN_AMOUNT;
$paramList["WEBSITE"] = PAYTM_MERCHANT_WEBSITE;
$paramList["CALLBACK_URL"] = BASE_URL.'paytm/pgresponse';
pgresponse.ctp
<?php
header("Pragma: no-cache");
header("Cache-Control: no-cache");
header("Expires: 0");
// following files need to be included
require_once("lib/config_paytm.php");
require_once("lib/encdec_paytm.php");
$paytmChecksum = "";
$paramList = array();
$isValidChecksum = "FALSE";
$paramList = $_POST;
$paytmChecksum = isset($_POST["CHECKSUMHASH"]) ?
$_POST["CHECKSUMHASH"] : ""; //Sent by Paytm pg
//Verify all parameters received from Paytm pg to your application.
Like
MID received from paytm pg is same as your application’s MID,
TXN_AMOUNT
and ORDER_ID are same as what was sent by you to Paytm PG for
initiating transaction etc.
//will return TRUE or FALSE string.
$isValidChecksum = verifychecksum_e(
$paramList,
PAYTM_MERCHANT_KEY,
$paytmChecksum
);
if($isValidChecksum == "TRUE") {
echo "<b>Checksum matched and following are the transaction details:
</b>" . "<br/>";
if ($_POST["STATUS"] == "TXN_SUCCESS") {
echo "<b>Transaction status is success</b>" . "<br/>";
//Process your transaction here as success transaction.
//Verify amount & order id received from Payment gateway with your
application's order id and amount.
}
else {
echo "<b>Transaction status is failure</b>" . "<br/>";
}
if (isset($_POST) && count($_POST)>0 )
{
foreach($_POST as $paramName => $paramValue) {
echo "<br/>" . $paramName . " = " . $paramValue;
}
}
}
else {
echo "<b>Checksum mismatched.</b>";
//Process transaction as suspicious.
}
?>