wise payment with laravel

260 Views Asked by At

I have qustion on how to use wise payment in larevel is there any tutorial or steps to do that because the documentation is not clear about the order of the steps and how to implement it in the most easy way And Is there way to do the payment using checkout link frome there side not using the apis

Following the documentation

1

There are 1 best solutions below

2
On

I can share my codes for wise payment. You need guzzlehttp/guzzle to make HTTP requests.

composer require guzzlehttp/guzzle

Store credentials in your .env file:

WISE_API_KEY=your_api_key_here

Create a Wise Service:

namespace App\Services;

use GuzzleHttp\Client;

class WiseService
{
    protected $client;

    public function __construct()
    {
        $this->client = new Client([
            'base_uri' => 'https://api.wise.com/', 
            'headers' => [
                'Authorization' => 'Bearer ' . env('WISE_API_KEY'),
                'Content-Type' => 'application/json',
            ],
        ]);
    }

    public function getCheckoutUrl($amount, $currency)
{
    $response = $this->client->post('checkout/create', [
        'json' => [
            'amount' => $amount,
            'currency' => $currency,
        ],
    ]);

    $data = json_decode($response->getBody(), true);
    
    return $data['checkout_url'];
}
}

In your controller, you can then call this service to get the checkout URL and redirect the user:

use App\Services\WiseService;

public function checkout(WiseService $wiseService)
{
    $url = $wiseService->getCheckoutUrl(100, 'USD');  
    return redirect($url);
}

After the user completes the payment on Wise's platform, Wise might redirect the user back to your application with some data about the payment. You should have routes and logic to handle these callbacks (webhooks).

Look at Wise documentation and modify codes if needed.