PHP code example of jeanfprado / cashier

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

    

jeanfprado / cashier example snippets


Jeanfprado\Cashier\CashierServiceProvider::class,

'Cashier' => Jeanfprado\Cashier\Support\Facade\Cashier::class,

'model' => App\Models\User::class,



namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Jeanfprado\Cashier\Subscribable;
use Jeanfprado\Cashier\Contracts\Subscribable as SubscribableContract;

class User extends Authenticatable implements SubscribableContract
{
    use Subscribable;
}

use Jeanfprado\Cashier\Models\Product;
use Jeanfprado\Cashier\Models\Subscription;

$products = Product::whereIn('slug_name', ['extra-storage', 'additional-seats'])->get();

$subscription = $user->subscribe(
    $products,
    Subscription::TYPE_MONTHLY, // monthly, triennial, semestrial, yearly
    7 // optional trial days; falls back to config('cashier.trial_days')
);

$subscription->addProduct($product, 2);   // attach or increment quantity
$subscription->removeProduct($product);   // detach

$user->cancelSubscription();

if ($subscription->canGenerateBilling() && ! $subscription->hasBillingPending()) {
    $billing = $subscription->generateBilling();
}

$billing->markToPaid();
bash
php artisan vendor:publish --tag=cashier-config
bash
php artisan vendor:publish --tag=cashier-migrations
bash
php artisan migrate
bash
php artisan cashier:seed-products
bash
php artisan cashier:subscription-check
bash
php artisan migrate