【发布时间】:2021-10-22 12:17:34
【问题描述】:
我正在尝试实施 Payhere 支付网关(位于斯里兰卡的本地网关)。根据他们的文档,我们可以提交如下数据。
<html>
<body>
<form method="post" action="https://sandbox.payhere.lk/pay/checkout">
<input type="hidden" name="merchant_id" value="121XXXX"> <!-- Replace your Merchant ID -->
<input type="hidden" name="return_url" value="http://sample.com/return">
<input type="hidden" name="cancel_url" value="http://sample.com/cancel">
<input type="hidden" name="notify_url" value="http://sample.com/notify">
<br><br>Item Details<br>
<input type="text" name="order_id" value="ItemNo12345">
<input type="text" name="items" value="Door bell wireless"><br>
<input type="text" name="currency" value="LKR">
<input type="text" name="amount" value="1000">
<br><br>Customer Details<br>
<input type="text" name="first_name" value="Saman">
<input type="text" name="last_name" value="Perera"><br>
<input type="text" name="email" value="samanp@gmail.com">
<input type="text" name="phone" value="0771234567"><br>
<input type="text" name="address" value="No.1, Galle Road">
<input type="text" name="city" value="Colombo">
<input type="hidden" name="country" value="Sri Lanka"><br><br>
<input type="submit" value="Buy Now">
</form>
</body>
</html>
这将重定向到网址“https://sandbox.payhere.lk/pay/checkout”并打开一个寡妇提交卡详细信息。
但我想做的是,从没有视图的控制器发送相关的 POST 数据(与上面的功能相同,但在数据库插入完成后通过控制器)
任何建议如何做到这一点。我曾尝试使用 HTTP 客户端,但由于上述网关重定向到外部 url 并弹出一个收集数据的窗口。
$client = new GuzzleHttp\Client();
$response = $client->request('POST', 'https://sandbox.payhere.lk/pay/checkout', [
'form_params' => [
"merchant_id" => '1218XXX',
"return_url" => route('admin.dashboard'),
"cancel_url" => 'key-app.test',
"notify_url" => route('notify'),
"order_id" => '1',
"items" => 'Test',
"currency" => 'LKR',
"amount" => '50.00',
"first_name" => 'Arafath',
"last_name" => 'a',
"email" => 'mhmaarafath@gmail.com',
"phone" => '0765245237',
"address" => 'Mount Lavinia',
"city" => 'Colombo',
"country" => 'Sri Lanka',
]
]);
return redirect('https://sandbox.payhere.lk/pay/checkout');
【问题讨论】: