PHP code example of conedevelopment / bazar-stripe

1. Go to this page and download the library: Download conedevelopment/bazar-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/ */

    

conedevelopment / bazar-stripe example snippets


    // config/bazar.php

    'gateway' => [
        'drivers' => [
            // ...
            'stripe' => [
                'test_mode' => env('STRIPE_TEST_MODE', false),
                'api_key' => env('STRIPE_API_KEY'),
                'secret' => env('STRIPE_SECRET'),
            ],
        ],
    ],

    // ...

namespace App\Listeners;

use Cone\Bazar\Stripe\WebhookInvoked;
use Stripe\Event;

class StripeWebhookHandler
{
    public function handle(WebhookInvoked $event): void
    {
        // https://stripe.com/docs/api/events/types
        $callback = match ($event->event->type) {
            'payment_intent.payment_failed' => function (Event $event): void {
                // mark transaction as failed
            },
            'payment_intent.succeeded' => function (Event $event): void {
                // mark transaction as completed and order as paid
            },
            default => function (): void {
                //
            },
        };

        call_user_func_array($callback, [$event->event]);
    }
}
sh
php artisan make:listener StripeWebhookHandler