I am trying to implement Payhere payment gateway (Local gateway based in Sri Lanka). As per their documentation we could submit data as below.
<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>
This will redirect to url "https://sandbox.payhere.lk/pay/checkout" and opens a widow to submit card details.
But what I want to do is, send related POST data from a controller without a view (Same function as above, but through controller when after an database insertion done)
Any suggestion how to do this. I have tried using HTTP client, but since above gateway redirect to external url and popsup a window that's collect data.
$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');

