Consuming payment gateway API in Laravel controller
Hi guys, I am doing a payment gateway integration for a Laravel 5.8 API project. So below is the logic I have come up with
User confirms they want to pay for a product
They hit this route Route::post('products/{product}/order', 'OrderController@store');
In the store method, I will consume the payment gateway initiate transaction API
Check the status of the transaction in the same controller method
Update the order table based on response from the gateway
Here's a summary version of OrderController
<?php
...
use GuzzleHttp\Client;
class OrderController extends Controller
{
public function store(Request $request, Product $product)
{
// if status is loaded, allow order
if ($product->status == 'loaded') {
// redirect user to payment gateway
$payment = new Client();
$uri = 'https://sandbox.gateway.com/api/v1/merchant/transactions/init-transaction';
$paylaod = ["amount" => 100"];
return $payment->post($uri, $paylaod);
// do something with returned object
}
}
}
When I run my code, I get 500 internal server error