Я написал файл Payment processor.php для получения параметров из системы электронной торговли, а затем отправки в PSP (поставщик платежных услуг), затем этот ответ Json от PSP будет декодирован, проверен, а ключи преобразованы и проанализированы в системе электронной торговли таким образом. :
header("Location: ".$hosturl."orderprocessor?
orderid=$custref&sig=".$_POST['SessionId']);
Прежде чем выдать товар в корзину пользователям.
$ hosturl был определен как
$ Hosturl = «локальный: 8080 / ЕКП /»;
в другом файле
Результат, который я получаю каждый раз, когда я оформляю корзину с файлом «Payment processor.php», это просто белый экран. Я должен видеть интерфейс PSP, чтобы получать данные карты пользователя вместо этого.
URL PSP является; » https://developers.paystack.co/reference#paystack-standard-x«Я следую примеру PHP cURL для справки.
Пожалуйста, помогите, если в моем коде обнаружены исправления.
Это мой файл Payment processor.php:
<?php require_once 'includes/config.inc.php' ?>
<?php
$parameters = array();
if (isset($_POST['amount'])) { /* came the LMS; about to send data to
Paystack */
$sig=hash_hmac("md5","amount=".urlencode($_POST['amount']).
"¤cy=".urlencode($_POST['currency']).
"&orderid=".urlencode($_POST['orderid']), $KEY);
$parameters['UserName']=$username;
$parameters['Password']=$password;
$parameters['reference']=$_POST['orderid'];
$parameters['Amount']=($_POST['amount'] * 100);
//should change SessionId' to be named reference
$parameters['SessionId']=$sig;
$parameters['SessionKey']=$encryptionKey;
$parameters['DL']="activ_purchase";
$parameters['ServerURL']=
base64_encode("http://localhost/nse/ecommerce/paystack.php");
$parameters['UserURL']=
base64_encode("http://localhost/nse/ecommerce/paystack.php");
$parameters['AccountNumber']=$accountnumber;
//$parameters['UserDeclinedURL']=
base64_encode($hosturl."externalpaymentcancel?
orderid=".$_POST['orderid']);
// print_r($parameters);
$cart=$_POST['cart'];
// var_dump($cart); die;
$cartitems=objectToArray(json_decode($cart));
foreach ( $cartitems['items'] as $item )
{
$productName=$item['description'];
$quantity=1;
$price=$item['price']['amount'];
$parameters['Reference4']=$productName." Qty
".$quantity." @ $".$price."\r\n" ;
}
// created parameters for Paystack $postdata here
$postdata = array('email' => '[email protected]',
'amount' => $parameters['Amount'],
'reference' => $parameters['reference'],
);
//$url = "https://api.paystack.co/transaction/initialize";
//My codes for $ch here
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$paystackUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($postdata)); //Post
Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = [
'Authorization: Bearer sk_test_*****************************',
'Content-Type: application/json'];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec ($ch);
curl_close ($ch);
//My code for $ch ends here
//starting to setup redirect url
if ($result) {
$request = json_decode($result, true);
//print_r($request);
foreach ($request as $input) {
if($input ['data']['reference']){
$sst=['data']['reference'];
break;
}
}
header('Location:'.$result['data']
['authorization_url'].$parameters['SessionId'].$sst);
}
//Use the $result array to get redirect URL paystack
//var_dump($result);
}
else {
$result = array();
$url = 'https://api.paystack.co/transaction/verify/'.$_GET['reference'];
// print_r($parameters);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt(
$ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer sk_test_*****************************']
);
$request = curl_exec($ch);
curl_close($ch);
if ($request) {
$result = json_decode($request, true);
// print_r($result);
if($result){
if($result['data']){
//something came in
if($result['data']['status'] == 'success'){
header("Location: ".$hosturl."orderprocessor?
orderid=$reference&sig=".$_POST['SessionId']);
//echo "success";
// the transaction was successful, you can deliver value
/*
@ also remember that if this was a card transaction, you can store
the
@ card authorization to enable you charge the customer
subsequently.
@ The card authorization is in:
@ $result['data']['authorization']['authorization_code'];
@ PS: Store the authorization with this email address used for this
transaction.
@ The authorization will only work with this particular email.
@ If the user changes his email on your system, it will be unusable
*/
echo "Transaction was successful";
}else{
// the transaction was not successful, do not deliver value'
// print_r($result); //uncomment this line to inspect the result,
to check why it failed.
echo "Transaction was not successful: Last gateway response was:
".$result['data']['gateway_response'];
}
}else{
echo $result['message'];
}
}else{
//print_r($result);
die("Something went wrong while trying to convert the request variable
to json. Uncomment the print_r command to see what is in the result
variable.");
}
}else{
echo "<html><head><meta http-equiv=\"refresh\"content=\"5;URL=$hosturl"."externalpaymentcancel?orderid=$custref\">
</head><body style=\"text-align:center; font-family:'Open Sans', Arial,
Helvetica, sans-serif;\"><p><img
src=\"/nd/repository/EKP000000414.jpg\" alt=\"Activ logo\" /></p>
<p>Unfortunately, we were unable to process your payment.</p><p>The
response from your financial institution was "$declinedmessage"
</p><p>You will be redirected to the LMS shortly.</p></body></html>";
}
//echo $payresult;
//if ($payresult=="1") {
//header("Location: ".$hosturl."orderprocessor?
orderid=$custref&sig=".$_POST['SessionId']);
//echo "success";
//} else {
//echo "fail";
//echo "<html><head><meta http-equiv=\"refresh\"content=\"5;URL=$hosturl"."externalpaymentcancel?orderid=$custref\">
</head><body style=\"text-align:center; font-family:'Open Sans', Arial,
Helvetica, sans-serif;\"><p><img
src=\"/nd/repository/EKP000000414.jpg\" alt=\"Activ logo\" /></p>
<p>Unfortunately, we were unable to process your payment.</p><p>The
response from your financial institution was "$declinedmessage"
</p><p>You will be redirected to the LMS shortly.</p></body></html>";
//header("Location: ".$hosturl."externalpaymentcancel?orderid=$custref");
// }
}
function objectToArray($d) {
if (is_object($d)) {
// Gets the properties of the given object
// with get_object_vars function
$d = get_object_vars($d);
}
if (is_array($d)) {
/*
* Return array converted to object
* Using __FUNCTION__ (Magic constant)
* for recursive call
*/
return array_map(__FUNCTION__, $d);
}
else {
// Return array
return $d;
}
}
?>
Задача ещё не решена.
Других решений пока нет …