PHP code example of aimeos / pagible-cashier

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

    

aimeos / pagible-cashier example snippets


return [
    'provider' => env('CMS_CASHIER_PROVIDER'),       // 'stripe', 'paddle', or 'mollie'
    'products' => [
        'price_xxx' => ['once' => true, 'action' => 'course_access', 'course_id' => '123'],
        'price_yyy' => ['action' => 'premium'],
    ],
];

use Laravel\Cashier\Events\WebhookHandled;

Event::listen(WebhookHandled::class, function ($event) {
    $payload = $event->payload;

    // One-time payment completed
    if (($payload['type'] ?? '') === 'checkout.session.completed') {
        $session = $payload['data']['object'] ?? [];
        $userId = $session['customer'] ?? null;
        $items = \Laravel\Cashier\Cashier::stripe()->checkout->sessions->allLineItems($session['id'] ?? '');
        $priceId = $items->data[0]->price->id ?? null;
        $product = config('cms.cashier.products')[$priceId] ?? [];

        if ($userId && $user = User::where('stripe_id', $userId)->first()) {
            // grant access based on $product config
        }
    }

    // Recurring payment succeeded
    if (($payload['type'] ?? '') === 'invoice.payment_succeeded') {
        $userId = $payload['data']['object']['customer'] ?? null;
        $priceId = $payload['data']['object']['lines']['data'][0]['price']['id'] ?? null;
        $product = config('cms.cashier.products')[$priceId] ?? [];

        if ($userId && $user = User::where('stripe_id', $userId)->first()) {
            // grant access based on $product config
        }
    }
});

use Laravel\Paddle\Events\WebhookHandled;

Event::listen(WebhookHandled::class, function ($event) {
    $payload = $event->payload;

    // One-time payment completed
    if (($payload['event_type'] ?? '') === 'transaction.completed') {
        $data = $payload['data'] ?? [];
        $userId = $data['customer_id'] ?? null;
        $priceId = $data['items'][0]['price']['id'] ?? null;
        $product = config('cms.cashier.products')[$priceId] ?? [];

        if ($userId && $user = User::where('paddle_id', $userId)->first()) {
            // grant access based on $product config
        }
    }

    // Recurring subscription activated
    if (($payload['event_type'] ?? '') === 'subscription.activated') {
        $data = $payload['data'] ?? [];
        $userId = $data['customer_id'] ?? null;
        $priceId = $data['items'][0]['price']['id'] ?? null;
        $product = config('cms.cashier.products')[$priceId] ?? [];

        if ($userId && $user = User::where('paddle_id', $userId)->first()) {
            // grant access based on $product config
        }
    }
});

use Laravel\CashierMollie\Events\OrderPaymentPaid;
use Laravel\CashierMollie\Events\FirstPaymentPaid;

// One-time payment completed
Event::listen(OrderPaymentPaid::class, function ($event) {
    if ($user = $event->order?->owner) {
        $priceId = $event->order->orderItems->first()?->orderable_id;
        $product = config('cms.cashier.products')[$priceId] ?? [];

        // grant access based on $product config
    }
});

// First recurring payment completed
Event::listen(FirstPaymentPaid::class, function ($event) {
    if ($user = $event->payment?->owner) {
        $priceId = $event->payment->orderItems->first()?->orderable_id;
        $product = config('cms.cashier.products')[$priceId] ?? [];

        // grant access based on $product config
    }
});
bash
php artisan cms:install:cashier