How to handle Ruba webhooks in your app

Short answer

To handle Ruba webhooks, create an endpoint in the dashboard, keep the raw request body, verify the signature with your signing secret, put the work in a queue and return a 2xx within a couple of seconds. Ruba follows the Standard Webhooks specification, retries failures up to 10 times and pays you to your own bank as your sales grow.

Why webhooks

Ruba signs its webhooks to the Standard Webhooks spec, so your app can check each one. Ahmed in Rawalpindi runs a web app. When a customer pays, his app must unlock the plan. Asking Ruba every minute “did anyone pay?” is slow and wasteful. A webhook flips it: Ruba calls your app the moment something happens.

Here are the delivery rules in plain words.

The receiver, step by step

One webhook, in order
  1. ArrivesRaw body and headersKeep the body exactly as received.
  2. VerifyCheck the signatureWith your signing secret.
  3. QueueStore the workProcess it after answering.
  4. AnswerReturn 2xx fastWithin about 2 seconds.
Figure 1From Ruba’s webhook delivery docs.

Set up the endpoint in Settings, then Webhooks. New endpoints start with order.paid selected, and you must choose at least one event. Ruba generates a signing secret when you create the endpoint. Store it safely and never put it in client-side code.

Verify in TypeScript

Ruba’s TypeScript SDK has a validateEvent function. Use the raw body, not a parsed one, or the signature check will fail.

TypeScript with Express
import express, { Request, Response } from 'express'
import { validateEvent, WebhookVerificationError } from '@getruba/sdk/webhooks'

const app = express()

app.post('/webhook', express.raw({ type: 'application/json' }), (req: Request, res: Response) => {
  try {
    const event = validateEvent(
      req.body,
      req.headers,
      process.env['RUBA_WEBHOOK_SECRET'] ?? '',
    )

    // Queue event for processing.
    res.status(202).send('')
  } catch (error) {
    if (error instanceof WebhookVerificationError) {
      return res.status(403).send('')
    }
    throw error
  }
})
Figure 2From Ruba’s docs. Set RUBA_WEBHOOK_SECRET to your endpoint’s secret.

In a Next.js app, the @getruba/nextjs adapter’s Webhooks handler does this for you and gives typed callbacks such as onOrderPaid and onSubscriptionCanceled. For other languages, use a Standard Webhooks library or implement the specification.

What Ruba does when you fail

Error or non-2xxRetried
AttemptsUp to 10
SpacingExponential backoff
Your jobIdempotent handler
Redirects (3xx)Treated as failure

Great for Short outages. Ruba keeps trying.

Watch for Register the final URL, with no redirect.

Figure 3From Ruba’s delivery contract. Make processing idempotent, because retries can repeat an event.
Allowed
A public https URL
A tunnel for local work
Redelivering an event by hand
Not allowed
localhost as the URL
Redirects from the endpoint
Behind login middleware
Figure 4Endpoint rules from Ruba’s docs.

What to do next

Build in the sandbox first. Read how to test payments in the sandbox. When you are ready to sell, see the early-access deal. Ruba has no monthly fee and charges 4% + $0.50 per sale.

Verify the signature, then act on the event. You start with no company and pay no monthly fee. Your early-access rate for your Ruba integration is 4% + $0.50 per sale, locked as long as the account stays open and in good standing. If a fee ever turns up that Ruba never told you about, Ruba refunds it and pays you $100. Terms apply. See the early-access deal.

Questions people ask

How do I verify a webhook?

Ruba follows the Standard Webhooks specification. The TypeScript SDK and the JavaScript adapters verify signatures for you. Keep the raw request body, check the signature with your signing secret, reject failures, and return a 2xx quickly.

What happens if my endpoint is down?

A network error or non-success response is retried up to 10 times with exponential backoff. A response that takes longer than 10 seconds is timed out and retried. If 10 consecutive events exhaust every retry, Ruba pauses the endpoint and emails every member of the shop.

Can I use localhost?

No. Endpoint URLs must be public https URLs. For local work, use an https tunnel.

Are events delivered in order?

events are delivered in order per endpoint. Because retries happen, make your handler idempotent so a repeated event does no harm.

How long are events kept?

Ruba keeps events for 90 days. From the endpoint page you can redeliver an event or reset the signing secret.

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.