duan3019 2019-06-17 10:14 采纳率: 100%
浏览 66

付费整合在Payfort

I'm working on Payfort API integration, and facing a problem with integrating using PHP. The link which I have followed mistake is in merchant reference. Where to get this reference?

<?php
$merchant_reference = 'TEST81003';
$redirectUrl = 'https://sbpaymentservices.payfort.com/FortAPI/paymentApi';
$return_url = 'https://love.ae/admin/public/login';

$requestParams = array(
'command' => 'PURCHASE',
'access_code' => 'bSCrsxniHsJqWtQ9ki15',
'merchant_identifier' => 'xPzUtIjC',
'merchant_reference' => 'TEST81003',
'amount' => 1050*100,
'currency' => 'AED',
'language' => 'en',
'customer_email' => 'alraqbani@gmail.com',
'token_name' => 'ali',
'return_url' => 'https://love.ae/admin/public/login',
'card_security_code' => '123',
);

// calculating signature
$shaString = '';
ksort($requestParams);
$SHARequestPhrase   = '$2y$10$IGSCjOlk9';
$SHAResponsePhrase   = '$2y$10$Ll6DBCeeH';
$SHAType       = 'sha256';
foreach ($requestParams as $k => $v) {
$shaString .= "$k=$v";
}

if (1 == 1)
$shaString = $SHARequestPhrase . $shaString . $SHARequestPhrase;
else
$shaString = $SHAResponsePhrase . $shaString . $SHAResponsePhrase;

$signature = hash($SHAType, $shaString);

$requestParams['signature'] = hash($SHAType, $shaString);

// calling payfort api using curl
//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
$useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0";
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json;charset=UTF-8',
//'Accept: application/json, application/*+json',
//'Connection:keep-alive'
));
curl_setopt($ch, CURLOPT_URL, $redirectUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); // The number of seconds to wait while trying to connect
//curl_setopt($ch, CURLOPT_TIMEOUT, Yii::app()->params['apiCallTimeout']); // timeout in seconds
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestParams));

$response = curl_exec($ch);
print_r($response);

curl_close($ch);

return $response;
?>

{"amount":"105000","response_code":"00044","signature":"e85cd4511c0b21649871c3b857d8782a1f4c326325cb04891720a2bb1bae400c","merchant_identifier":"xPzUtIjC","access_code":"bSCrsxniHsJqWtQ9ki15","language":"en","command":"PURCHASE","response_message":"Token name does not exist","merchant_reference":"TEST81003","customer_email":"alraqbani@gmail.com","currency":"AED","status":"00"}

   <?php
   $merchant_reference = 'TEST81003';
   $redirectUrl = 'https://sbpaymentservices.payfort.com/FortAPI/paymentApi';
   $return_url = 'https://love.ae/admin/public/login';

   $requestParams = array(
   'command' => 'PURCHASE',
   'access_code' => 'bSCrsxniHsJqWtQ9ki15',
   'merchant_identifier' => 'xPzUtIjC',
   'merchant_reference' => 'TEST81003',
   'amount' => 1050*100,
   'currency' => 'AED',
   'language' => 'en',
   'customer_email' => 'alraqbani@gmail.com',
   'token_name' => 'ali',
   'return_url' => 'https://love.ae/admin/public/login',
    'card_security_code' => '123',
   );

// calculating signature
    $shaString = '';
    ksort($requestParams);
    $SHARequestPhrase   = '$2y$10$IGSCjOlk9';
    $SHAResponsePhrase   = '$2y$10$Ll6DBCeeH';
    $SHAType       = 'sha256';
    foreach ($requestParams as $k => $v) {
    $shaString .= "$k=$v";
    }

    if (1 == 1)
    $shaString = $SHARequestPhrase . $shaString . $SHARequestPhrase;
    else
    $shaString = $SHAResponsePhrase . $shaString . $SHAResponsePhrase;

    $signature = hash($SHAType, $shaString);

    $requestParams['signature'] = hash($SHAType, $shaString);

    // calling payfort api using curl
    //open connection
    $ch = curl_init();

    //set the url, number of POST vars, POST data
    $useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 
    Firefox/20.0";
    curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json;charset=UTF-8',
     //'Accept: application/json, application/*+json',
     //'Connection:keep-alive'
     ));
    curl_setopt($ch, CURLOPT_URL, $redirectUrl);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_FAILONERROR, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
    //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); // The number of seconds to 
    wait while trying to connect
    //curl_setopt($ch, CURLOPT_TIMEOUT, Yii::app()->params['apiCallTimeout']); 
    // timeout in seconds
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestParams));

    $response = curl_exec($ch);
    print_r($response);

    curl_close($ch);

    return $response;
    ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭