gpt4 book ai didi

php - 如何将 n 天才支付网关集成到 Laravel

转载 作者:行者123 更新时间:2023-12-04 10:57:13 24 4
gpt4 key购买 nike

请指导我如何将 ngenius-payment 网关集成到 Laravel 应用程序
他们的文档不足以与 Laravel 集成。
我打算选择从他们的网站付款,然后通过返回 URL 返回给我们。

下面是我从他们的文档中得到的 php 代码。但对整合到laravel 感到困惑。

 <?php



$postData = new StdClass();

$postData->action = "SALE";
$postData->amount = new StdClass();
$postData->amount->currencyCode = "AED";
$postData->amount->value = 100;

$outlet = "my-oulet-id";
$token = token_key(); //to ken generatig

$json = json_encode($postData);
$ch = curl_init();


curl_setopt($ch, CURLOPT_URL, 'https://api-gateway-uat.ngenius-
payments.com/transactions/outlets/".$outlet."/orders');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer ".$token,
"Content-Type: application/vnd.ni-payment.v2+json",
"Accept: application/vnd.ni-payment.v2+json"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);

$output = json_decode(curl_exec($ch));
$order_reference = $output->reference;
$order_paypage_url = $output->_links->payment->href;

curl_close ($ch);

function token_key(){
$apikey = "api-key"; // enter your API key here
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://identity-uat.ngenius-
payments.com/auth/realms/ni/protocol/openid-connect/token");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Basic ".$apikey,
"Content-Type: application/x-www-form-urlencoded"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
http_build_query(array('grant_type' =>
'client_credentials')));
$output = json_decode(curl_exec($ch));
$access_token = $output->access_token;
return $access_token;
}
?>

最佳答案

****Below Code May Help You .. It works for me Up to their payment window****
public function make_payment(){

$outletRef = "your-outlet-id"; // set your outlet reference/ID value here (example only)
$apikey = "your-application-key"; // set your service account API key (example only)


$idServiceURL = "https://identity-uat.ngenius-payments.com/auth/realms/ni/protocol/openid-connect/token"; // set the identity service URL (example only)
$txnServiceURL = "https://api-gateway-uat.ngenius-payments.com/transactions/outlets/".$outletRef."/orders"; // set the transaction service URL (example only)


$tokenHeaders = array("Authorization: Basic ".$apikey, "Content-Type: application/x-www-form-urlencoded");
$tokenResponse = invokeCurlRequest("POST", $idServiceURL, $tokenHeaders, http_build_query(array('grant_type' => 'client_credentials')));
$tokenResponse = json_decode($tokenResponse);

$access_token = $tokenResponse->access_token;

$order = new StdClass();

$order->action = "AUTH"; // Transaction mode ("AUTH" = authorize only, no automatic settle/capture, "SALE" = authorize + automatic settle/capture)
$order->amount->currencyCode = "AED"; // Payment currency ('AED' only for now)
$order->amount->value = 01*100; // Minor units (1000 = 10.00 AED)
$order->language = "en"; // Payment page language ('en' or 'ar' only)
$order->merchantOrderReference = time(); // Payment page language ('en' or 'ar' only)
//$order->merchantAttributes->redirectUrl = "http://premizer.com/test/pp.php"; // A redirect URL to a page on your site to return the customer to
//$order->merchantAttributes->redirectUrl = "http://192.168.0.111:8080/n-genius/pp.php"; // A redirect URL to a page on your site to return the customer to
$order->merchantAttributes->redirectUrl = "your page url wich u want to redirect after payment success";
// A redirect URL to a page on your site to return the customer to
//$order->merchantAttributes->redirectUrl = "http:// 192.168.0.111:8080/n-genius/pp.php"; // A redirect URL to a page on your site to return the customer to
$order = json_encode($order);


$orderCreateHeaders = array("Authorization: Bearer ".$access_token, "Content-Type: application/vnd.ni-payment.v2+json", "Accept: application/vnd.ni-payment.v2+json");
$orderCreateResponse = invokeCurlRequest("POST", $txnServiceURL, $orderCreateHeaders, $order);

$orderCreateResponse = json_decode($orderCreateResponse);
$paymentLink = $orderCreateResponse->_links->payment->href; // the link to the payment page for redirection (either full-page redirect or iframe)
$orderReference = $orderCreateResponse->reference; // the reference to the order, which you should store in your records for future interaction with this order

header("Location: ".$paymentLink); // execute redirect
//die();

function invokeCurlRequest($type, $url, $headers, $post) {

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

if ($type == "POST") {

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

}

$server_output = curl_exec ($ch);
// print_r($server_output);
// exit();
curl_close ($ch);

return $server_output;

}

}

Email them to get a valid test card details .. and check . all the very best .yo you

关于php - 如何将 n 天才支付网关集成到 Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59099986/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com