PHP code example of fullstack / stripe-product-manager

1. Go to this page and download the library: Download fullstack/stripe-product-manager 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/ */

    

fullstack / stripe-product-manager example snippets


return [
    'stripe' => [
        'secret_key' => env('STRIPE_SECRET_KEY'),
        'publishable_key' => env('STRIPE_PUBLISHABLE_KEY'),
        'webhook_secret' => env('STRIPE_WEBHOOK_SECRET'),
        'api_version' => env('STRIPE_API_VERSION', '2024-06-20'),
    ],

    'database' => [
        'prefix' => env('STRIPE_PRODUCT_MANAGER_DB_PREFIX', 'stripe_'),
        'tables' => [
            'products' => 'stripe_products',
            'prices' => 'stripe_prices',
            'customers' => 'stripe_customers',
            'invoices' => 'stripe_invoices',
            'transactions' => 'stripe_transactions',
            'coupons' => 'stripe_coupons',
            'discounts' => 'stripe_discounts',
            'promotion_codes' => 'stripe_promotion_codes',
            'tax_codes' => 'stripe_tax_codes',
            'tax_rates' => 'stripe_tax_rates',
            'sync_logs' => 'stripe_sync_logs',
        ],
    ],

    'sync' => [
        'enabled' => env('STRIPE_SYNC_ENABLED', true),
        'batch_size' => env('STRIPE_SYNC_BATCH_SIZE', 100),
        'retry_attempts' => env('STRIPE_SYNC_RETRY_ATTEMPTS', 3),
        'retry_delay' => env('STRIPE_SYNC_RETRY_DELAY', 5),
    ],

    'filament' => [
        'enabled' => env('STRIPE_FILAMENT_ENABLED', true),
        'panel' => env('STRIPE_FILAMENT_PANEL', 'admin'),
        'resources' => [
            'products' => true,
            'prices' => true,
            'customers' => true,
            'invoices' => true,
            'transactions' => true,
            'coupons' => true,
            'discounts' => true,
            'promotion_codes' => true,
            'tax_codes' => true,
            'tax_rates' => true,
        ],
    ],

    'logging' => [
        'enabled' => env('STRIPE_LOGGING_ENABLED', true),
        'channel' => env('STRIPE_LOGGING_CHANNEL', 'daily'),
        'level' => env('STRIPE_LOGGING_LEVEL', 'info'),
    ],
];

use Fullstack\StripeProductManager\Traits\HasStripePermissions;

class User extends Authenticatable
{
    use HasStripePermissions;

    // ... rest of your User model
}

// Check permissions
if ($user->canViewStripeProducts()) {
    // User can view products
}

if ($user->canCreateStripeProducts()) {
    // User can create products
}

// Check roles
if ($user->isStripeAdmin()) {
    // User is a Stripe admin
}

if ($user->hasStripeRole()) {
    // User has any Stripe role
}

// Guard-specific checks
if ($user->isStripeAdminForTenant()) {
    // User is a Stripe admin for tenant-admin guard
}

if ($user->isStripeAdminForSuper()) {
    // User is a Stripe admin for super-admin guard
}

if ($user->canViewStripeProductsForTenant()) {
    // User can view products for tenant-admin guard
}

// In your routes file
Route::middleware(['stripe.guard:tenant-admin'])->group(function () {
    Route::get('/stripe/products', [StripeController::class, 'index']);
});

Route::middleware(['stripe.guard:super-admin'])->group(function () {
    Route::get('/stripe/admin', [StripeAdminController::class, 'index']);
});

public function __construct()
{
    $this->middleware('stripe.guard:tenant-admin');
}
bash
composer vendor:publish --provider="Spatie\Permission\PermissionServiceProvider"
php artisan migrate
bash
php artisan vendor:publish --provider="Fullstack\StripeProductManager\StripeProductManagerServiceProvider"
bash
php artisan vendor:publish --provider="Fullstack\StripeProductManager\StripeProductManagerServiceProvider" --tag="stripe-product-manager-config"
bash
php artisan vendor:publish --provider="Fullstack\StripeProductManager\StripeProductManagerServiceProvider" --tag="stripe-product-manager-migrations"
bash
php artisan vendor:publish --provider="Fullstack\StripeProductManager\StripeProductManagerServiceProvider" --tag="stripe-product-manager-seeders"
bash
php artisan migrate
bash
php artisan db:seed --class="Fullstack\StripeProductManager\Database\Seeders\StripeProductManagerPermissionSeeder"