0

我正在研究 Payfort API 集成,并面临使用 PHP 集成的问题。我遵循错误的链接在商家参考中。从哪里获得这个参考?

<?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;
    ?>
4

1 回答 1

2

Mercer_reference 是每个付款请求的唯一订单号。它可以是表的主键,也可以是唯一生成的。例如

$merchant_reference = '5000-'.time();

Mercer_reference 字母数字最大值:40

于 2019-10-30T10:07:39.500 回答