Skip to main content

Laravel Subscription Billing with Crypto: A Cashier Tutorial

· 9 min read
OrcaRail
Crypto payment rails for web2 apps

Laravel subscription billing usually means Laravel Cashier with Stripe or Paddle: a Billable trait on the user model, newSubscription() to start a plan and subscribed() to check access. If your customers want to pay in crypto, Cashier OrcaRail gives you the same kind of API for USDC and USDT. Customers pay from their own wallet on a hosted pay page, and signed webhooks keep a local subscriptions table up to date.

This tutorial adds a monthly plan with a free trial to a Laravel app, step by step: install the package, add sandbox keys, start a subscription, protect paid routes, receive webhooks and test it all without real money.

What Cashier OrcaRail is​

Cashier OrcaRail is an open-source (MIT) Laravel package, orcarail/cashier-orcarail. It wraps the OrcaRail PHP SDK and supports PHP 8.1+ with Laravel 10, 11 and 12. This guide uses version 2.

If you have used Laravel Cashier for Stripe, most names will look familiar:

TaskCashier OrcaRail
Make a model billableuse Billable;
Start a subscription$user->newSubscription('default', $priceId)->create([...])
Add a free trial->trialDays(14) or ->trialUntil($date)
Check access$user->subscribed(), $user->onTrial()
Cancel$user->subscription()->cancelAtPeriodEnd() or ->cancel()
Take a one-off payment$user->checkout($priceId, [...])
Receive webhooksPOST /orcarail/webhook, signature checked for you

The big difference is how a renewal is paid. A card processor keeps a card on file and charges it. Nobody can take tokens from a crypto wallet without the owner's signature, so by default OrcaRail creates a payment link for each billing cycle and the customer pays it from their wallet. Recurring crypto payments explains the billing models in detail.

What you need​

  • A Laravel 10, 11 or 12 app where users log in.
  • An OrcaRail account at app.orcarail.com and a sandbox organization. A sandbox uses testnets and ak_test_ keys, so no real money moves.
  • A public HTTPS address for webhooks. OrcaRail refuses http:// webhook URLs and addresses it cannot reach from the internet, so in local development use a tunnel. See webhook configuration.

Step 1: Install the package​

composer require orcarail/cashier-orcarail
php artisan vendor:publish --tag=orcarail-cashier-config
php artisan migrate

The migration adds a subscriptions table. Each row links one of your users to an OrcaRail subscription and stores its status (orcarail_status), price ID, trial end and end date.

Step 2: Add your sandbox keys​

In the sandbox dashboard, create an API key and set its Webhook URL to https://your-app.example/orcarail/webhook. Then add the key and secret to .env:

ORCARAIL_API_KEY=ak_test_...
ORCARAIL_API_SECRET=sk_test_...
ORCARAIL_WEBHOOK_SECRET=sk_test_...

OrcaRail signs webhooks with the API key's secret, so ORCARAIL_WEBHOOK_SECRET is the same sk_test_ value as ORCARAIL_API_SECRET. Use live keys (ak_live_) only in production. While a sandbox key is set, Cashier::livemode() returns false.

Step 3: Make the User model billable​

use OrcaRail\Cashier\Billable;

class User extends Authenticatable
{
use Billable;
}

Step 4: Create a plan and start a subscription​

In the dashboard, open Products → Catalog, create a product such as "Pro" and give it a monthly price, for example 10 USD paid in USDC. The price ID is the last part of the address when you edit the price (…/products/prices/<price-id>/edit). You can also list prices with the PHP SDK.

Then start the subscription when a user picks the plan:

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Route::post('/subscribe', function (Request $request) {
$checkout = $request->user()
->newSubscription('default', 'your-price-id')
->trialDays(14)
->create([
'description' => 'Pro plan',
'return_url' => route('billing'),
'cancel_url' => route('billing'),
]);

// The hosted pay page for the first billing cycle.
$url = $checkout->url() ?? $checkout->subscription?->latestCheckoutUrl();

return $url ? redirect()->away($url) : redirect()->route('billing');
})->middleware('auth');

What happens next:

  • Cashier creates the subscription in OrcaRail with the user's email as the payer and saves a local row.
  • With a trial, the row starts as trialing, so the user gets access right away. Without a trial, it starts as incomplete and gives no access until the first payment arrives.
  • The customer lands on the pay page for the first cycle. There they confirm their email with a code. OrcaRail sends trial reminders and renewal emails only to confirmed emails. See trial periods.

No catalog price? Call ->withAmount([...]) with amount, currency, token_id, network_id and interval instead of passing a price ID. The token and network IDs come from Networks and tokens.

Step 5: Protect paid routes with subscribed()​

Add a small middleware:

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class EnsureSubscribed
{
public function handle(Request $request, Closure $next)
{
if (! $request->user()?->subscribed()) {
return redirect()->route('billing');
}

return $next($request);
}
}
use App\Http\Middleware\EnsureSubscribed;

Route::middleware(['auth', EnsureSubscribed::class])->group(function () {
Route::get('/reports', [ReportController::class, 'index']);
});

subscribed() reads the local row:

Local statusMeaningsubscribed()
trialingIn the free trialtrue until the trial ends
incompleteCreated, first cycle not paid yetfalse
activeThe current cycle is paidtrue
active with an end dateSet to cancel at the end of the periodtrue until that date
past_dueA renewal is latefalse
pausedBilling is pausedfalse
canceledEndedfalse

Want to give late payers a few extra days? Check $user->subscribed() || $user->subscription()?->pastDue() instead.

Step 6: Receive subscription webhooks​

Cashier registers POST /orcarail/webhook (change the path with ORCARAIL_WEBHOOK_PATH). It checks the x-webhook-timestamp and x-webhook-signature-v2 headers against your secret and rejects deliveries older than five minutes. The route is outside the web middleware group, so you don't need a CSRF exception.

Cashier applies these events to the local row:

EventWhat Cashier does
subscription.createdAdds the row if it is missing and copies the status
subscription.payment_link.paidReads the subscription from the API: a paid cycle makes it active
subscription.updatedCopies the new status and dates
subscription.paused, subscription.resumedCopies the paused or resumed status
subscription.canceledSets the status to canceled with an end date

For your own side effects, such as a receipt email, listen to Cashier's events:

use Illuminate\Support\Facades\Event;
use OrcaRail\Cashier\Events\WebhookHandled;

Event::listen(function (WebhookHandled $event) {
if (($event->payload['type'] ?? null) === 'subscription.payment_link.paid') {
// Send a receipt, update your analytics, ...
}
});

The full event list is in subscription webhooks, and the signature format in webhook signatures.

Step 7: Keep the local status in sync​

Some status changes don't arrive as an event that Cashier applies. For example, when a renewal stays unpaid, OrcaRail marks the subscription past_due, but the local row still says active. Sync open subscriptions on a schedule:

// routes/console.php (Laravel 11 and 12)
use Illuminate\Support\Facades\Schedule;
use OrcaRail\Cashier\Subscription;

Schedule::call(function () {
Subscription::query()
->whereNotIn('orcarail_status', ['canceled', 'completed'])
->eachById(fn (Subscription $subscription) => $subscription->syncOrcaRailStatus());
})->daily();

syncOrcaRailStatus() reads the subscription from the API and saves its status, trial end and end date. On Laravel 10, put the same closure in app/Console/Kernel.php.

Step 8: Cancel and resume​

$user->subscription()->cancelAtPeriodEnd(); // access until the paid period ends
$user->subscription()->cancel(); // ends it now
$user->subscription()->resume(); // restarts a paused subscription

Take one-off payments in Laravel​

Cashier also takes single payments, such as a setup fee or a one-time product:

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use OrcaRail\Cashier\Cashier;

Route::post('/buy', function (Request $request) {
return $request->user()->checkout('your-one-time-price-id', [
'return_url' => route('orders.return'),
]);
})->middleware('auth');

Route::get('/orders/return', function (Request $request) {
$payment = Cashier::completePayment((string) $request->query('payment_intent'));

return $payment->isCompleted()
? redirect()->route('orders.thanks')
: view('orders.pending'); // still processing: call completePayment() again later
})->name('orders.return');

Completing is required. Until your return route calls Cashier::completePayment(), the payment stays processing and no payment_intent.completed webhook is sent. For payment links without code, see crypto payment links.

Test it in the sandbox​

  1. Subscribe with a test user, but skip trialDays() so the first cycle is due now.
  2. On the sandbox pay page, click Simulate payment. You need no wallet and no test tokens. See simulate payments.
  3. The subscription.payment_link.paid webhook arrives and the row turns active.
  4. Check that $user->subscribed() now returns true and that your paid routes open.

Go live​

  1. Create the product and price again in your live organization. Sandbox catalogs stay in the sandbox.
  2. Put the ak_live_ key and its secret in your production .env, and set the live key's webhook URL.
  3. Add the withdrawal addresses where you receive payments.

The full checklist is in going live. Other ways to connect, such as the Node SDK and the WooCommerce plugin, are on the plugins page.

FAQ​

Does Laravel Cashier support crypto payments?​

The official Laravel Cashier packages work with Stripe and Paddle. Cashier OrcaRail is a separate open-source package that gives you the same style of API on OrcaRail, where customers pay in USDC, USDT or other tokens from their own wallet. The source is on GitHub.

Can customers pay with USDT in a Laravel app?​

Yes. Each price sets the token and network you receive, for example USDT on Polygon or USDC on Base. See Networks and tokens.

How do free trials work with Cashier OrcaRail?​

Call trialDays() or trialUntil() before create(). The subscription starts as trialing, and subscribed() is true until the trial ends. Then the customer pays the first cycle from its payment link, and the subscription.payment_link.paid webhook makes the row active.

Can renewals be charged automatically?​

Yes, with auto-charge. Pass 'collection_method' => 'auto_charge' to create(). The customer approves once from their wallet on an EVM chain or Solana and can revoke that approval at any time. See auto-charge and crypto payment gateways for SaaS.

Which Laravel versions does Cashier OrcaRail support?​

Laravel 10, 11 and 12 on PHP 8.1 or later.


Start in the sandbox · Cashier OrcaRail docs · Subscriptions