2016-07-29 3 views
0

payfort payment api에서 작업 https://testfort.payfort.com/api/?#merchant-page tokinization이 수행 된 후 JSON을 사용하여 REST POST 요청에 문제가 있습니다. 내 코드는Payfort REST POST 요청 (JSON을 사용)

$requestParams=json_encode($requestParams); 
$service_url = 'https://sbpaymentservices.payfort.com/FortAPI/paymentApi'; 
$curl = curl_init($service_url); 
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST"); 
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestParams); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($requestParams))); 
$curl_response = curl_exec($curl); 

$의 curl_response 나는 당신이 잘못된 방향으로 (아마도)에서 JSON 데이터를 전송하고, payfort에 대한 특정 정보를 가지고 있지만없는 항상

enter image description here

+0

대신 원시 API를 사용하는 Payfort의 래퍼 : – Vuldo

+0

많이 검색가없는 경우, 당신이 링크를 공유 할 다음 찾을 경우, github에 내가 가진 – saad

+0

확인'payfort/시작 php'을 확인 전에도 확인했지만 다른 느낌입니다. 그들은 이것을 사용하기 위해 API 키가 필요합니다. 나는 내 방식이 성공해야하기를 바랍니다. 덕분에 – Vuldo

답변

0

이 사람은 결과

 $requestParams['signature'] = $signature; 
     $requestParams=json_encode($requestParams); 

     $result = file_get_contents('https://sbpaymentservices.payfort.com/FortAPI/paymentApi', null, stream_context_create(array(
       'http' => array(
       'method' => 'POST', 
       'header' => 'Content-Type: application/json' . "\r\n" 
       . 'Content-Length: ' . strlen($requestParams) . "\r\n", 
       'content' => $requestParams, 
       ), 
      ) 
     )); 

     $result=json_decode($result); 
0

거짓입니다.

$requestParams = json_encode($requestParams); 
/*other codes*/ 
curl_setopt($ch, CURLOPT_POSTFIELDS, 'json='.urlencode($requestParams)); 

urlencode를 사용하여 "json ="접두어를 추가하고 일부 특수 문자를 필터링/인코딩하려고 시도하지 마십시오.

+0

여전히 false, 컬 테스트가 성공했을 때 (심지어 에러가 발생하더라도) 응답을 줄 것입니다. – saad

+0

코드 끝 부분에'if (curl_error ($ ch)) echo curl_error ($ ch);'줄을 추가 할 수 있습니까? 결과를 공유 하시겠습니까? –

+0

뒤에 이미지를 공유 $ info = curl_getinfo ($ curl); var_export ($ info) – saad

0

저도 같은 문제에 직면했다에게 제공합니다. 아래 코드를 사용할 수 있습니다. 잘 작동합니다.

$merchant_reference = str_random(30); 
    $redirectUrl = 'https://sbpaymentservices.payfort.com/FortAPI/paymentApi'; 
    $return_url = 'enter_your_return_url_here'; 

    $requestParams = array(
     'command' => 'PURCHASE', 
     'access_code' => 'enter_your_acccess_code_here', 
     'merchant_identifier' => 'enter_your_merchant_identifier_here', 
     'merchant_reference' => enter_your_merchant_reference_here, 
     'amount' => enter_your_amount_here, 
     'currency' => 'AED', 
     'language' => enter_your_language_here, 
     'customer_email' => '[email protected]', 
     'token_name' => enter_your_token_name_here, 
     'return_url' => return_url, 
     'card_security_code' => enter_your_cvv_here, 
    ); 

    // calculating signature 
    $shaString = ''; 
    ksort($arrData); 
    $SHARequestPhrase = 'GLAM'; 
    $SHAResponsePhrase = 'GLAM'; 
    $SHAType  = 'sha256'; 
    foreach ($arrData as $k => $v) { 
     $shaString .= "$k=$v"; 
    } 

    if ($signType == 'request') 
     $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); 

    curl_close($ch); 

    return $response; 

이것은 완전한 payfort 응답입니다.