PHP code example of gusmanwidodo / laravel-billing-stripe

1. Go to this page and download the library: Download gusmanwidodo/laravel-billing-stripe 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/ */

    

gusmanwidodo / laravel-billing-stripe example snippets


use Gusmanwidodo\Billing\Facades\Billing;

// 1. Charge an invoice via Stripe Checkout -> pending intent with the hosted URL.
$intent = Billing::charge($invoice, provider: 'stripe');
return redirect($intent->meta['redirect_url']);   // Stripe Checkout page

// 2. Stripe webhook route — pass the RAW body + headers; the signature is verified.
Route::post('/webhooks/stripe', function (Illuminate\Http\Request $request) {
    try {
        Billing::handleWebhook('stripe', $request->getContent(), $request->headers->all());
    } catch (\RuntimeException $e) {
        abort(403); // signature verification failed
    }
    return response('', 200);
});

// 3. Refund a succeeded intent.
Billing::refund($intent);