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.
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.


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.
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.

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_-
Create your API key
Click Create test key. In Production the button is called Generate API key.

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
.gitignoreso it never ends up on GitHub.
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. -
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 webhook secret, shown once after the first save. Developing on your laptop?We can't reachlocalhost. 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.Event Sent when invoice.paidThe payment went through. invoice.payment_failedA payment attempt failed. It isn't final. The customer can try again, and invoice.paidmay 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. -
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. -
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.

For order test-1794646727299the server answered 400 three times, so we stopped after attempt 3 of 3. For ordertest-1794646799211it answered 200 on the first try.
Test vs Production
| Test | Production | |
|---|---|---|
| Base URL | https://sandbox.rahatipay.com | https://rahatipay.com |
| API key | rp_test_…, from Create test key. Valid 7 days, and you can remove it with Delete key. | rp_prod_…, from Generate API key. |
| Payments | Fake, nothing is charged. | Real, paid out to your bank account. |
| Payout account | Not needed. | Required (see below). |
| Webhook secret | Its own. | Its own, separate from Test. |
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.

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.
| Environment | Base URL | Key |
|---|---|---|
| Test | https://sandbox.rahatipay.com | rp_test_… |
| Production | https://rahatipay.com | rp_prod_… |
| Route | Does |
|---|---|
POST {baseUrl}/v1/gateway/invoices | Creates an invoice. |
| POST your webhook URL | Lives 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.
instant | detailled | |
|---|---|---|
| You send | One total, in amount. | A list of lines, in items (at least one). No amount. |
| The total | The amount you sent. | We compute it. Each line is its price × quantity, plus that line's VAT. |
| VAT | Not broken down. tvaAmount is 0. | Each line has its own rate, and tvaAmount is the sum. |
| Your customer sees | One amount to pay. | Each line, in a Products table and a Services table, then the total. |
| Good for | Charging 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.

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 yourreturnUrlif 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.

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.
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.
| Field | Type | Required | Description |
|---|---|---|---|
orderId | string | yes | Your own order id. Letters, digits, _ and -, up to 100 characters. |
customerName | string | yes | The customer's name. |
customerPhoneNumber | string | yes | An Algerian phone number, e.g. 0555123456. |
invoiceType | instant | detailled | yes | instant for one total amount, detailled for a list of items. |
amount | number | instant only | Total in DZD, at least 100, up to 2 decimals. |
items | array | detailled only | The invoice lines (fields below). We compute the total from them. |
returnUrl | string | no | An https:// page we send your customer back to, only after a successful payment. We add ?orderId= with your order id to it. |
| Item field | Type | Required | Description |
|---|---|---|---|
name | string | yes | The item's name. |
unitPrice | number | yes | Price of one unit in DZD, at least 1, up to 2 decimals. |
quantity | number | no | A whole number, at least 1. |
tva | number | no | VAT rate in %, from 0 to 99.99. |
type | product | service | yes | Product 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.
| Field | Type | Description |
|---|---|---|
orderId | string | Your order id. |
invoiceNumber | string | null | Our invoice number. |
status | pending | success | failure | pending if not paid yet, success if paid, failure if the last payment attempt failed. |
currency | DZD | Always DZD. |
amount | number | Total in DZD, VAT included. |
tvaAmount | number | The VAT part of amount. |
feeAmount | number | The fee your customer paid on top of amount, or 0 if you cover it. |
items | array | The invoice lines. |
approvalCode, authorizationResponseId | string, optional | The bank's authorization details for the payment. |
checkoutUrl | string | The payment link. |
createdAt, paidAt | date (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.
| HTTP | errorCode | Meaning |
|---|---|---|
| 400 | VALIDATION_FAILED | A field is missing or invalid, and message tells you which. |
| 400 | AMOUNT_BELOW_MINIMUM | The total is below 100 DZD. |
| 400 | PAYOUT_ACCOUNT_NOT_CONFIGURED | No payout bank account is chosen in the dashboard. |
| 401 | INVALID_API_KEY | The key is wrong, was regenerated, or has expired. |
| 401 | TEST_KEY_ON_PRODUCTION | An rp_test_ key was sent to https://rahatipay.com. |
| 403 | ACCOUNT_SUSPENDED, ACCOUNT_SCHEDULED_FOR_DELETION | Your account can't accept payments. |
| 404 | ORDER_NOT_FOUND | No invoice with this orderId. |
| 409 | ORDER_ALREADY_PAID | This orderId is already paid. |
| 429 | RATE_LIMITED | Too many requests per second. Wait a moment and try again. |