khidirdotid/xendit-laravel
最新稳定版本:v1.0.1
Composer 安装命令:
composer require khidirdotid/xendit-laravel
包简介
A Xendit Wrapper for Laravel
README 文档
README
A Xendit Wrapper for Laravel
Installation
-
Install the package
composer require khidirdotid/xendit-laravel
-
Publish the config file
php artisan vendor:publish --provider="KhidirDotID\Xendit\Providers\XenditServiceProvider" -
Add the Facade to your
config/app.phpintoaliasessection'Xendit' => KhidirDotID\Xendit\Facades\Xendit::class,
-
Add ENV data
XENDIT_API_KEY=
or you can set it through the controller
\Xendit::setXenditKey('XENDIT_API_KEY');
Usage
Invoice
- Get Redirection URL of a Payment Page
$data = [ 'external_id' => 'invoice-' . time(), 'amount' => 10000 ]; try { // Get Payment Page URL $paymentUrl = \Xendit::createInvoice($data); // Redirect to Payment Page return redirect()->away($paymentUrl['invoice_url']); } catch (\Throwable $th) { throw $th; }
Handle HTTP Notification
- Create route to handle notifications
Route::match(['GET', 'POST'], 'xendit.ipn', [PaymentController::class, 'xenditIpn'])->name('xendit.ipn');
- Create method in controller
public function xenditIpn(Request $request) { try { $response = \Xendit::getInvoiceById($request->invoice_id); if (in_array(strtolower($response['status']), ['paid', 'settled'])) { // TODO: Set payment status in merchant's database to 'success' } } catch (\Throwable $th) { throw $th; } }
- Except verify CSRF token in
app/Http/Middleware/VerifyCsrfToken.phpprotected $except = [ 'xendit/ipn' ];
统计信息
- 总下载量: 23
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-17