'Error: Payfort Apple Pay service response error Failed to execute service?
I integrated Apple Pay service of Payfort using PHP but got error in response.
Failed to execute service
have applied all possible solutions including regenerating all the apple certificates. I have attached the code which i have used to send request to payfort. have encodes some apple payment token parameters to base64 because directly I'm getting invalid parameter errors .
<?php
$apple_data = base64_encode($_GET['apple_data']);
$apple_signature = base64_encode($_GET['apple_signature']);
$apple_transactionId = $_GET['apple_transactionId'];
$apple_ephemeralPublicKey = base64_encode($_GET['apple_ephemeralPublicKey']);
$apple_publicKeyHash = $_GET['apple_publicKeyHash'];
$apple_displayName = $_GET['apple_displayName'];
$apple_network = $_GET['apple_network'];
$apple_type = $_GET['apple_type'];
$merchant_reference=rand(0, getrandmax());
$SHA_Request_Phrase='***********';
$arrData = array(
'access_code' => '*******',
'amount' => 100,
'apple_data' => $apple_data,
'apple_signature' => $apple_signature,
'apple_header' => [
'apple_transactionId'=> $apple_transactionId,
'apple_ephemeralPublicKey'=> $apple_ephemeralPublicKey,
'apple_publicKeyHash'=> $apple_publicKeyHash,
],
'apple_paymentMethod' => [
'apple_displayName'=> $apple_displayName,
'apple_network'=> $apple_network,
'apple_type'=> $apple_type,
],
'command' => 'PURCHASE',
'currency' => 'SAR',
'customer_email' =>"[email protected]",
'customer_name' =>"test",
'digital_wallet'=>'APPLE_PAY',
'language' => 'en',
'merchant_identifier' => '****',
'merchant_reference' =>$merchant_reference,
'order_description' => 'Package payment',
'phone_number' =>'23232322',
'return_url' => 'https://applepay.epcreport.net',
);
$shaString = '';
ksort($arrData);
foreach ($arrData as $key => $value) {
if(is_array($value)){
$shaSubString = '{';
foreach ($value as $k => $v) {
$shaSubString .= "$k=$v, ";
}
$shaSubString = substr($shaSubString, 0, -2).'}';
$shaString .= "$key=$shaSubString";
}else{
$shaString .= "$key=$value";
}
}
$shaString = $SHA_Request_Phrase . $shaString . $SHA_Request_Phrase;
$signature = hash('sha256', $shaString);
$arrData['signature'] = $signature;
$arrData=json_encode($arrData);
$url="https://sbpaymentservices.payfort.com/FortAPI/paymentApi";
// create a new cURL resource
$ch = curl_init();
$headers = array("Content-Type: application/json");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, false );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $arrData);
if(curl_exec($ch) === false)
{
echo '{"curlError":"' . curl_error($ch) . '"}';
}
// close cURL resource, and free up system resources
curl_close($ch);
?>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
