PHP code example of orcarail / cashier-orcarail

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

    

orcarail / cashier-orcarail example snippets


use OrcaRail\Cashier\Billable;

class User extends Authenticatable
{
    use Billable;
}

use Illuminate\Http\Request;

Route::post('/subscribe', function (Request $request) {
    $checkout = $request->user()
        ->newSubscription('default', 'price_xxx')
        ->trialDays(14)
        ->create([
            'payer_email' => $request->user()->email,
            'return_url' => route('billing.return'),
            'cancel_url' => route('billing.cancel'),
        ]);

    return $checkout; // RedirectResponse to hosted pay URL
});

$user->subscribed();           // active / trialing / grace period
$user->onTrial();
$user->subscription()?->cancel();
$user->subscription()?->resume();

$user->newSubscription('default')
    ->withAmount([
        'amount' => '10.00',
        'currency' => 'usd',
        'token_id' => '...',
        'network_id' => '...',
        'interval' => 'month',
    ])
    ->create();

// Catalog price
return $user->checkout('price_xxx', [
    'return_url' => route('orders.return'),
]);

// Direct amount
return $user->charge([
    'amount' => '25.00',
    'currency' => 'usd',
    'tokenId' => '...',
    'networkId' => '...',
    'return_url' => route('orders.return'),
]);

use OrcaRail\Cashier\Cashier;

Cashier::ignoreMigrations();
Cashier::ignoreRoutes();
Cashier::useSubscriptionModel(App\Models\Subscription::class);

Cashier::api()->rates->list();
bash
php artisan vendor:publish --tag=orcarail-cashier-config
php artisan migrate