Developer guide

Accept payments with the RahatiPay API

From a verified merchant account to your first paid invoice. Set up Test first, then Production, then connect your server.

Last updated: November 2026

Overview

How RahatiPay works

Meet Mirale. She's on your shop, your-shop.dz, with two T-shirts in her cart, and she clicks Pay. Your server asks us for a payment link and sends her there. She pays, and you hear about it twice. We call your server with a webhook, and the payment shows up in the RahatiPay app. If you want, we then send Mirale back to a page of your choice, her order page for example. The rest of this guide builds exactly that.

The path of one payment, from the order to the notification. The dashed arrow is optional.
Follow every invoice

Every invoice your server creates shows up in the RahatiPay mobile app and in the web dashboard, with its status. You can filter by day and see at a glance what is pending, paid or failed.

The Invoices screen of the RahatiPay mobile app, on three phones
Mobile app
The Invoices page of the RahatiPay web dashboard
Web dashboard
Step 1

Verified merchant account

Before Mirale can pay you, we need to know who you are, so you need a merchant account that we have verified. Signing up and getting verified happens in the mobile app and has its own guide. Everything below assumes that's done.

Step 2

Set up the dashboard

Your server needs keys to talk to us, and you get them from the dashboard. Sign in at https://rahatipay.dz/dashboard, then open Developers in the left menu. There are two cards, Test and Production, each with an Open link.

The Developers section with the Test and Production cards
The Developers section, one card per environment.

You set up both the same way. Start with Test. Payments there are fake, so you can try anything without risk. Once everything works, open Production and repeat the same steps, plus one extra (see Test vs Production).

Set up an environment

rp_test_ · rp_prod_
  1. Create your API key

    Click Create test key. In Production the button is called Generate API key.

    The Test environment page with the Create test key button
    The Test page before you have a key.

    The key appears once, in the Your new API key window. Click Copy and put it in your project's environment file, not in your code. Add that file to .gitignore so it never ends up on GitHub.

    The Your new API key window with the Copy button
    Copy it now. You won't see it again.
    Lost your key?Click Regenerate key. The old key stops working right away, so your server's calls fail until the new key is in your environment file. Invoices you already created and payments in progress carry on as normal.
  2. Add your webhook URL

    The webhook URL is the route on your server where we send payment events (paid or failed). Type it in Webhook URL, in the Webhook box, and click Save. The first time you save, the Your webhook signing secret window shows your webhook secret. It starts with whsec_ and, like the key, you only see it once. Copy it next to your API key. Your server uses it to check that a request really comes from us.

    The Your webhook signing secret window over the Webhook box
    The webhook secret, shown once after the first save.
    Developing on your laptop?We can't reach localhost. Expose your local server with a tunnel such as ngrok and use the https address it gives you as your webhook URL. If the tunnel address changes, update the webhook URL too.
    EventSent when
    invoice.paidThe payment went through.
    invoice.payment_failedA payment attempt failed. It isn't final. The customer can try again, and invoice.paid may still follow.
    webhook.testYou clicked Send test event.

    Here's what your server receives when an invoice is paid.

    Regenerating the secretSame story as the API key. After Regenerate secret, we sign every event with the new secret right away. Update your environment file straight after, or your server will reject them.
  3. Send a test event

    When your webhook route is ready, click Send test event at the bottom of the Webhook box. We send a fake event (webhook.test) to your URL, and you can check that your server got it.

  4. Check your webhook deliveries

    Webhook deliveries, at the top right of the page, lists every event we sent to your webhook, test events included. Each row is one attempt, with your server's HTTP status, the attempt number and how long it took. You can search by Order ID or Event ID, or show only Succeeded or Failed attempts. When your server didn't react to a payment, look here first.

    The Webhook deliveries list with HTTP 400 and HTTP 200 attempts
    For order test-1794646727299 the server answered 400 three times, so we stopped after attempt 3 of 3. For order test-1794646799211 it answered 200 on the first try.

Test vs Production

TestProduction
Base URLhttps://sandbox.rahatipay.comhttps://rahatipay.com
API keyrp_test_…, from Create test key. Valid 7 days, and you can remove it with Delete key.rp_prod_…, from Generate API key.
PaymentsFake, nothing is charged.Real, paid out to your bank account.
Payout accountNot needed.Required (see below).
Webhook secretIts own.Its own, separate from Test.
Test data lasts 7 daysWe delete test invoices and webhook deliveries after 7 days, the same as the test key. Create a new test key whenever you need one. Keys don't cross over either. Production refuses a test key, and the sandbox refuses a production key.

Production has one more box at the bottom of the page, Integration settings. Under Payout account, pick the bank account that should receive the money (only your registered, verified accounts are listed) and click Save. Until you do, the API won't create invoices and answers 400 PAYOUT_ACCOUNT_NOT_CONFIGURED.

The Integration settings box with the Payout account selector
Production only. The payout account, under Integration settings.
Step 3

Create an invoice and get its status

Now for your server. It talks to us over HTTPS, at the base URL that goes with your key.

EnvironmentBase URLKey
Testhttps://sandbox.rahatipay.comrp_test_…
Productionhttps://rahatipay.comrp_prod_…
RouteDoes
POST {baseUrl}/v1/gateway/invoicesCreates an invoice.
POST your webhook URLLives on your server and receives the payment events.
GET {baseUrl}/v1/gateway/invoices/{orderId}Returns an invoice's status, by your order id.

Two types of invoice

Every invoice is one of two types, set with invoiceType. The difference is what you send us and what your customer sees.

instantdetailled
You sendOne total, in amount.A list of lines, in items (at least one). No amount.
The totalThe amount you sent.We compute it. Each line is its price × quantity, plus that line's VAT.
VATNot broken down. tvaAmount is 0.Each line has its own rate, and tvaAmount is the sum.
Your customer seesOne amount to pay.Each line, in a Products table and a Services table, then the total.
Good forCharging a total you already know, like a cart total or a booking.An invoice that shows what was bought, with VAT per line.

Both need a total of at least 100 DZD. Sending items with an instant invoice, or amount with a detailled one, is refused with 400 VALIDATION_FAILED.

Here is Mirale's order as a detailled invoice. Two T-shirts at 1,000 DZD with 19% VAT give 2,000 + 380 = 2,380 DZD.

Try it first from your terminal

You don't need any code yet. Create Mirale's invoice with curl and your test key. The response has a checkoutUrl. Open it in your browser and you'll see what Mirale sees.

The checkoutUrl opens the invoice page with a Pay Invoice button.

The invoice page with the Pay Invoice button
The invoice page of an instant invoice, with one total to pay.

In production, Pay Invoice opens the SATIM payment gateway. The sandbox doesn't charge any card. Instead it shows a page that works like the SATIM gateway, with a test card whose fields are locked.

  • Paiement (Pay) makes the payment succeed. The invoice is paid, your webhook gets invoice.paid, and the browser goes back to your returnUrl if you sent one.
  • Annuler (Cancel) makes it fail. Your webhook gets invoice.payment_failed, and the invoice can still be paid on a new attempt.
The simulated card payment page with a locked test card and the Paiement, Réinitialiser and Annuler buttons
The sandbox's simulated SATIM gateway, in French.

a) The controller

You'll write two files. The first is the controller, which receives calls from your front end and from us. It has three routes, and we'll go through them one by one.

Create rahatipay.controller. The exact file name and folder depend on your framework and are shown above the code. For now it only holds the imports the routes need.

Route 1Create the payment link

Your front end calls this route with the order id when the customer clicks Pay. Your server reads the order from your own database, including the price. Never take the amount from the browser, anyone can change it. The route then asks the service for a payment link and returns it, and your front end redirects the customer there.

Clicking Pay twice is fine. The same orderId gives back the same link. Once the order is paid, we answer 409 ORDER_ALREADY_PAID.

Route 2Receive the webhook

A few seconds after a payment, we call your webhook URL with an invoice.paid event. The route checks the signature before trusting it, because anyone can call a URL, but only we know your webhook secret. Then it marks the order paid and answers 200.

Answer fast. If you answer anything other than 2xx, or nothing at all, we send the event again, up to 3 attempts 10 seconds apart. So the same event can arrive twice, and marking an order paid a second time must do no harm.

Worth knowingIf you have slow work to do after a payment, like sending an email or generating a PDF, answer 200 first and do it in the background. And read the body exactly as it arrived, before your framework parses the JSON. A re-serialized body no longer matches the signature, and that's the usual cause of a signature check that never passes.

Route 3Check an invoice's status

Normally the webhook tells you the order was paid. If your server missed it, because it was down for example, this route asks us for the order's state by its id and passes our answer back as is.

HelperHandling errors

Routes 1 and 3 pass their errors to this helper. A 404 (unknown order) or a 409 (already paid) means something to your front end, so those go through. Anything else points to a problem in your server's setup, a wrong key for example. It gets logged and your front end receives a 502.

b) The service, the DTO and the models

The second file is the service, the only place that talks to RahatiPay. Create rahatipay-gateway.service (again, the name depends on your framework). It starts with its settings, read from the environment file from Step 2, and an error type that holds what we answered (HTTP status, errorCode and message).

HelperCalling RahatiPay

Every call goes through one helper. It puts your API key in the Authorization header, gives up after 10 seconds, and turns an error response into the error type above.

Method 1createInvoice

Route 1 calls this. It sends the invoice (the DTO, described below) and returns the response model with the checkoutUrl.

Method 2verifyWebhookSignature

This is how Route 2 knows a request really comes from us. Every webhook carries a Rahati-Signature header that looks like t=…,v1=…. t is when we sent it, in Unix seconds. v1 is an HMAC-SHA256 in hex of t, a dot, and the raw body, with your webhook secret as the key. The method computes the same value and compares the two. It also rejects events older than 5 minutes, so nobody can replay a captured request later.

Method 3getInvoiceStatus

Route 3 calls this one. It fetches the invoice by your order id and returns the status model described below.

The request: create-invoice.dto

The DTO (data transfer object) describes the order to us, who the customer is and what they're paying for.

FieldTypeRequiredDescription
orderIdstringyesYour own order id. Letters, digits, _ and -, up to 100 characters.
customerNamestringyesThe customer's name.
customerPhoneNumberstringyesAn Algerian phone number, e.g. 0555123456.
invoiceTypeinstant | detailledyesinstant for one total amount, detailled for a list of items.
amountnumberinstant onlyTotal in DZD, at least 100, up to 2 decimals.
itemsarraydetailled onlyThe invoice lines (fields below). We compute the total from them.
returnUrlstringnoAn https:// page we send your customer back to, only after a successful payment. We add ?orderId= with your order id to it.
Item fieldTypeRequiredDescription
namestringyesThe item's name.
unitPricenumberyesPrice of one unit in DZD, at least 1, up to 2 decimals.
quantitynumbernoA whole number, at least 1.
tvanumbernoVAT rate in %, from 0 to 99.99.
typeproduct | serviceyesProduct or service.

The response: create-invoice-response.model

Creating an invoice gives you a payment link, checkoutUrl. Send your customer there to pay.

The status: invoice-status.model

getInvoiceStatus returns the invoice in the same shape as the data field of a webhook.

FieldTypeDescription
orderIdstringYour order id.
invoiceNumberstring | nullOur invoice number.
statuspending | success | failurepending if not paid yet, success if paid, failure if the last payment attempt failed.
currencyDZDAlways DZD.
amountnumberTotal in DZD, VAT included.
tvaAmountnumberThe VAT part of amount.
feeAmountnumberThe fee your customer paid on top of amount, or 0 if you cover it.
itemsarrayThe invoice lines.
approvalCode, authorizationResponseIdstring, optionalThe bank's authorization details for the payment.
checkoutUrlstringThe payment link.
createdAt, paidAtdate (ISO 8601)When the invoice was created and paid. paidAt only appears once it's paid.

c) Errors

Every error we return has the same body.

HTTPerrorCodeMeaning
400VALIDATION_FAILEDA field is missing or invalid, and message tells you which.
400AMOUNT_BELOW_MINIMUMThe total is below 100 DZD.
400PAYOUT_ACCOUNT_NOT_CONFIGUREDNo payout bank account is chosen in the dashboard.
401INVALID_API_KEYThe key is wrong, was regenerated, or has expired.
401TEST_KEY_ON_PRODUCTIONAn rp_test_ key was sent to https://rahatipay.com.
403ACCOUNT_SUSPENDED, ACCOUNT_SCHEDULED_FOR_DELETIONYour account can't accept payments.
404ORDER_NOT_FOUNDNo invoice with this orderId.
409ORDER_ALREADY_PAIDThis orderId is already paid.
429RATE_LIMITEDToo many requests per second. Wait a moment and try again.