PHP code example of khidirdotid / xendit-laravel

1. Go to this page and download the library: Download khidirdotid/xendit-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

khidirdotid / xendit-laravel example snippets


    'Xendit' => KhidirDotID\Xendit\Facades\Xendit::class,
    

    \Xendit::setXenditKey('XENDIT_API_KEY');
    

    $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;
    }
    

    Route::match(['GET', 'POST'], 'xendit.ipn', [PaymentController::class, 'xenditIpn'])->name('xendit.ipn');
    

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

    protected $except = [
        'xendit/ipn'
    ];
    
bash
    php artisan vendor:publish --provider="KhidirDotID\Xendit\Providers\XenditServiceProvider"