2016-07-29 6 views
0

Arbeiten an der Zahlung Zahlung api https://testfort.payfort.com/api/?#merchant-page Ich habe ein Problem mit REST POST-Anfrage mit JSON nach tokinization durchgeführt wird. mein CodePayfort REST POST Anfrage mit 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

enter image description here

+0

Anstatt die rohe API zu verwenden, überprüfen Sie, ob es keinen Wrapper für Payfort gibt :) – Vuldo

+0

Gesucht viel, wenn Sie dann finden, teilen Sie den Link :) – saad

+0

Überprüfen Sie 'Payfort/Start-php' auf GitHub – Vuldo

Antwort

0

Dieses geben dem Ergebnis

 $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

Ich habe keine spezifischen Informationen über payfort immer falsch ist, aber sind Sie JSON-Daten in einer falschen Weise (vielleicht) zu senden.

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

Sie versuchen shuld "json =" Präfix und Filter/kodieren einige Sonderzeichen urlencode hinzuzufügen.

+0

immer noch falsch, testen Sie es auf Ihrer Seite gibt es Antwort (auch im Fehlerfall), wenn Curl erfolgreich ist – saad

+0

Können Sie 'if (curl_error ($ ch)) echo curl_error ($ ch);' Zeile bis zum Ende des Codes und teilen das Ergebnis? –

+0

Hat das Bild freigegeben nach $ info = curl_getinfo ($ curl); var_export ($ info) – saad

0

Ich war vor dem gleichen Problem. Sie können den folgenden Code verwenden. Es funktioniert gut.

$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; 

Dies ist die Antwort Sie die vollständige Payfort-Antwort.