khidirdotid / xendit-laravel
A Xendit Wrapper for Laravel
Fund package maintenance!
Saweria
v1.0.0
2024-09-17 07:34 UTC
Requires
- php: ^8.1
- illuminate/support: ^10.0|^11.0
- xendit/xendit-php: ^6.0
Requires (Dev)
- nunomaduro/collision: ^8.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
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.php
intoaliases
section'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.php
protected $except = [ 'xendit/ipn' ];