使用laravel支付

dgtucam1  于 6个月前  发布在  其他
关注(0)|答案(1)|浏览(48)

我有关于如何使用larevel明智的付款quustion有任何教程或步骤这样做,因为文件是不清楚的步骤,以及如何实现它的顺序在最简单的方式,有办法做付款使用结帐链接弗罗姆有一边不使用apis
根据文件

vulvrdjw

vulvrdjw1#

我可以分享我的代码明智的付款。你需要guzzlehttp/guzzle作出HTTP请求。

composer require guzzlehttp/guzzle

字符串
将凭据存储在.env文件中:

WISE_API_KEY=your_api_key_here


打造智慧服务:

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'];
}
}


在你的控制器中,你可以调用这个服务来获取结帐URL并重定向用户:

use App\Services\WiseService;

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


用户在Wise平台上完成支付后,Wise可能会将用户重定向回您的应用程序,并提供有关支付的一些数据。您应该有路由和逻辑来处理这些回调(webhook)。
查看Wise文档并根据需要修改代码。

相关问题