PHP code example of andriichuk / laravel-billing

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

    

andriichuk / laravel-billing example snippets


use Andriichuk\LaravelBilling\Concerns\Billable;

class User extends Authenticatable
{
    use Billable;
}

$user->billingCustomer();
$user->billingCustomer('stripe');

$user->subscriptions()->latest()->get();
$user->subscription('default', driver: 'bluesnap');
$user->subscribed('default', price: 'price-123', driver: 'stripe');

use Andriichuk\LaravelBilling\Billing;

Billing::extend('acme', function ($app, array $config) {
    return new AcmeBillingDriver(/* provider dependencies */);
});

$driver = Billing::driver();
$acme = Billing::driver('acme');
$same = $user->billing('acme');

$customer = $user->createBillingCustomer(
    driver: 'acme',
    name: $user->name,
    email: $user->email,
    metadata: ['account_tier' => 'pro'],
    providerOptions: ['locale' => 'en'],
);

$customer = $user->syncBillingCustomer('acme', name: 'Updated Name');

$subscription = $user->newSubscription('default', 'price-123')
    ->driver('acme')
    ->quantity(5)
    ->trialDays(14)
    ->paymentMethod('pm-opaque-reference')
    ->withMetadata(['team' => 'platform'])
    ->withProviderOptions(['provider_specific_key' => 'value'])
    ->idempotencyKey('subscription:user:'.$user->getKey())
    ->create();

use Andriichuk\LaravelBilling\Enums\Capability;

if (Billing::driver('acme')->supports(Capability::Refunds)) {
    // Resolve the driver and use its SupportsRefunds contract.
}

use Andriichuk\LaravelBilling\Contracts\ResolvesReconciliationBillables;

$this->app->bind(ResolvesReconciliationBillables::class, AccountBillingResolver::class);
bash
php artisan vendor:publish --tag=billing-config
php artisan vendor:publish --tag=billing-migrations
php artisan migrate
text
POST /billing/webhooks/{driver}
bash
php artisan queue:work --queue=billing,default
php artisan billing:webhooks:retry --driver=acme
php artisan billing:webhooks:prune --dry-run
php artisan billing:webhooks:prune --days=90 --force
bash
php artisan billing:reconcile
php artisan billing:reconcile --driver=acme
php artisan billing:reconcile --model=subscription
php artisan billing:reconcile --model=subscription --id=123
php artisan billing:reconcile --driver=acme --dry-run
php artisan billing:reconcile --driver=acme --cursor=123 --page-size=250
php artisan billing:reconcile --driver=acme --since="2026-09-01T00:00:00Z"
php artisan billing:reconcile --model=subscription --id=123 --force