How to add payments to a Laravel app

Short answer

To add payments to a Laravel app, install Ruba’s PHP SDK with Composer, create a Checkout Session from a controller, redirect the buyer to the session URL, and confirm the sale with a verified webhook. Ruba is the Merchant of Record, so you need no Stripe account and no company. Ruba pays you to your own bank.

The plan

Nabeel in Sialkot runs a Laravel app that generates quotation PDFs. He wants to charge $12 a month. Stripe does not support Pakistan, so he looks for another way. Ruba has a PHP SDK that supports Laravel auto-discovery, according to its docs.

Four steps
  1. Step 1Install the SDKPHP 8.2 or newer.
  2. Step 2Create a sessionIn a controller.
  3. Step 3Redirect the buyerTo the session URL.
  4. Step 4Confirm by webhookVerified, then unlock.
Figure 1Based on Ruba’s PHP SDK and checkout docs. Build and test in the sandbox first.

Install

The SDK requires PHP 8.2 or newer and supports Laravel auto-discovery. Create an access token in the sandbox dashboard first, and keep it in your environment file, not in your code.

Terminal
composer require getruba/sdk
Figure 2From Ruba’s docs.

Send the buyer to checkout

A checkout session is a short-lived buying flow your server creates just before the buyer pays. Pass the product ID, a success URL and, if you have it, your own customer ID as the external customer ID. Redirect to the URL Ruba returns.

CheckoutController.php
<?php

namespace App\Http\Controllers;

use Ruba\Models\Components\CheckoutCreate;

class CheckoutController extends Controller
{
    public function __invoke()
    {
        $sdk = \Ruba\Ruba::builder()
            ->setServer('sandbox') // remove for production
            ->setSecurity(config('services.ruba.token'))
            ->build();

        $response = $sdk->checkouts->create(new CheckoutCreate(
            products: [config('services.ruba.product_id')],
            successUrl: route('thanks'),
            externalCustomerId: (string) auth()->id(),
        ));

        return redirect()->away($response->checkout->url);
    }
}
Figure 3Adapted from Ruba’s PHP SDK. The config keys are examples you would add to config/services.php.

Create the session when the buyer clicks, not in advance. The session URL is temporary.

Confirm with a webhook

Never unlock features only because the browser reached your success page. Ruba sends webhooks that follow the Standard Webhooks specification. Verify the signature using the raw request body and your endpoint’s signing secret, then queue the work and return a 2xx quickly.

In your Laravel routeYour side
  1. 1Public https routeNot localhost.
  2. 2Skip login and CSRF checksFor this one route.
  3. 3Read the raw bodyBefore any parsing.
  4. 4Queue a jobThen return 2xx.
Keep it small and fast.
From RubaTheir side
  1. 1Signed requestStandard Webhooks headers.
  2. 2RetriesUp to 10, with backoff.
  3. 3Events in orderPer endpoint.
  4. 4Kept 90 daysYou can redeliver.
Make your job idempotent.
Figure 4Laravel-specific habits and Ruba’s webhook rules.

Details are in how to handle Ruba webhooks.

Before you go live

Laravel launch list0 of 4
Tap each line you already have.
Figure 5Tap each line when it is done.

See the early-access deal. Ruba charges 4% + $0.50 per sale, plus 0.5% on subscriptions, with no monthly fee.

Ruba has a PHP SDK, so it fits. Nothing monthly to pay, and no company required. Approved during early access? Then 4% + $0.50 per sale is locked for your Laravel app while the account stays open and in good standing. If Ruba charges a fee it never told you about, it refunds it and pays you $100. Terms apply. See the early-access deal.

Questions people ask

Does Ruba have a PHP SDK?

Yes. Ruba has a PHP SDK that needs PHP 8.2 or newer, installs with composer require getruba/sdk, and supports Laravel auto-discovery. It follows a builder pattern and can point at the sandbox.

How do I start a checkout from Laravel?

Create a Checkout Session from your server with the product ID, then redirect the buyer to the returned url. The session URL is short-lived, so create it when the buyer clicks.

How do I know a payment succeeded?

Use a success redirect for the buyer’s page, and a webhook for your records. Verify the webhook signature, and do not unlock anything from the browser alone.

Do I need Stripe in Laravel?

No. Your Laravel app talks to Ruba, which is the Merchant of Record and pays you to your own bank.

How do I test?

Use Ruba’s sandbox: a separate environment with its own dashboard, API and checkout. Set the server to sandbox in the SDK, and use a sandbox access token.

Sources

We check these when we update this guide. Rules can change, so check them yourself before you decide.

A note from FaizanHi, I’m Faizan, the founder of Ruba. I built it so people anywhere, from Pakistan, India and Bangladesh to the UK, the EU and the US, can sell software to the world and get paid at home.I wrote these guides to be as fair as I can. But I built Ruba, so I’m about as neutral as a parent at a school play. That’s why every fact has a source you can check.
Early access is live.

Sellers approved now keep 4% + $0.50 per sale locked for as long as they sell, plus +$100 if we ever charge a fee we never told you about. No company and no monthly fee. You are paid to a bank in your own name, in PKR, INR, BDT or 51 other currencies, whenever you ask, from $10. A payout costs $2 up to $200.

Applying is not approval. Terms apply.
All guides

Can’t find your country or currency? Email support@getruba.com.

This guide is general information, not legal, tax or financial advice. Other companies named here set their own rules, which can change. Check their websites before you decide.