Rides paid by card (mada, Visa, Mastercard) and STC Pay top-ups
Built: 2026-11-02. Written for operators and for whoever maintains the code.
In Saudi Arabia most riders pay by mada or card, not cash. Careem and Uber both take the card at booking. RideKit now does the same, and cash is still offered.
- When the rider books, an amount a little over the fare is held on their card. The card is authorised but not charged.
- When the trip ends, the final fare is taken from the hold, and the rest is released.
- Nothing is charged for a ride that never happens.
What the rider sees
- On the confirm screen, the payment picker shows Card (mada, Visa, Mastercard) next to Cash and Wallet.
- Tapping Book opens Moyasar's card form for the hold. Above the form the app explains: "SAR 30.00 will be held on your card. You pay only the final fare; the rest is released when the trip ends."
- The rider completes 3-D Secure with their bank. The ride is booked only once the card is approved.
- If the rider backs out of the form, nothing is booked. If the booking fails after the card was approved, the hold is released at once.
- The receipt says "Paid via Card". Tips come from the wallet, as they do on a wallet ride.
The driver's trip screen says "Paid by card in the app. Don't collect cash." It shows the same kind of note for wallet rides.
How much is held
The hold is the larger of these two amounts:
- the fare estimate plus
bufferPct(20% by default), rounded up to a whole riyal; - the ride type's flat cancellation or no-show fee, so that a no-show is covered by the card. This applies only where the market charges flat fees. A share-of-fare fee is always below the fare, so the hold already covers it.
A promo comes off before the hold, and a child seat is added to it.
What happens to the hold
| How the ride ended | What happens to the hold |
|---|---|
| Completed | The final fare is taken, never more than the hold. The rest is released. A zero fare releases the whole hold. |
| Cancelled with a fee | The fee is taken. |
| Cancelled, no fee | The hold is released. |
| No driver found | The hold is released after 15 minutes. That gives the rider time to reopen the search by raising the fare. A raise that would go over the hold is refused. |
| Card approved but no ride booked | The hold is released after 30 minutes. |
Money flow. A card ride settles from the rider's wallet, like a wallet ride. The captured amount then comes into the wallet as a gateway top-up, so the two cancel out. The capture is recorded as a top-up charge, which means the refund console can refund it to the card.
If the fare is higher than the hold, only the hold is taken. The rest is owed on the wallet, like any metered overrun.
If the gateway refuses a capture or release:
- The ride still completes, and the driver is paid.
- The rider owes on the wallet until the capture goes through.
- A job retries every minute.
- After 10 failed attempts, the trip's page in the admin shows Needs attention with the gateway's reason and a Try again button.
Settings
Admin → Markets → (country) → Payments → Rides paid by card
| Setting | Default | Meaning |
|---|---|---|
| Riders can pay by card | On in Saudi Arabia, off elsewhere | Card appears in the app only once the Moyasar keys are saved in Admin → Providers. |
| Held over the estimate (%) | 20 | The margin held above the estimate, 0–100. |
| Furthest a card ride can be booked ahead (days) | 5 | An authorisation lapses after about 7 days (14 for mada). A ride scheduled further ahead than this cannot be paid by card. Allowed range: 0–13. |
Moyasar setup
- Keys. Admin → Providers → Moyasar needs both the secret key and the publishable key.
- Manual (authorise-only) payments. These must be enabled on your Moyasar account. Ask Moyasar support.
- mada acceptance. This is also switched on by Moyasar.
Check both with Moyasar before going live.
The trip page (Admin → Trips → a trip) shows a Card payment panel:
- the amount held;
- the amount taken and the amount released;
- the card network and the Moyasar payment id;
- the status;
- for a failed hold, the last error and Try again.
Wallet top-up: STC Pay and mada first
The wallet top-up form now offers:
- STC Pay (the rider's mobile number, then an OTP);
- cards, with mada listed first and then Visa and Mastercard.
Bug fixed in the same release. The Moyasar form refuses an on_completed
callback that is not an async function. It showed "Form configuration
issue" instead of the form. The top-up form had exactly that callback, so in
practice no Saudi top-up could ever be made. It is now fixed in both forms.
Not built yet
Apple Pay. It cannot run inside the WebView that hosts the Moyasar form. It needs:
- a native PassKit sheet (a Swift Expo module);
- an Apple Pay merchant ID and the matching entitlement;
- Moyasar's Apple Pay token flow.
This is the next step.
STC Pay for rides. STC Pay is a push payment: it cannot be held and charged later. It is offered for wallet top-ups only.
Other gateways. Card holds are implemented for Moyasar only. Stripe, Tap and others would implement the same
CardHoldProviderinterface.
Testing without Moyasar keys
The backend reads MOYASAR_API_BASE, which is meant for test installs only.
When it is set:
- the server sends its calls to that address instead of Moyasar;
- the app's card form is pointed at the same address.
The end-to-end run for this release used a local stand-in for Moyasar. It covered:
- the card form;
- a test bank's 3-D Secure page (approve or decline);
- capture and void, plus their failures;
- STC Pay OTP.
It has not been run against Moyasar's real test API. A buyer can do that
with sk_test_ / pk_test_ keys.
For maintainers
| Area | Files |
|---|---|
| Rules (pure, tested) | backend/src/payments/card-rides.ts, card-rides.spec.ts |
| Service and job | backend/src/payments/card-hold.service.ts |
| Endpoints | backend/src/payments/card-hold.controller.ts: GET /payments/card-holds/options, POST /payments/card-holds, POST /payments/card-holds/:id/confirm, POST /payments/card-holds/:id/release, GET /payments/admin/rides/:rideId/card, POST /payments/admin/rides/:rideId/card/retry |
| Gateway contract | CardHoldProvider in payment-provider.interface.ts; Moyasar implements fetchPayment, capturePayment, voidPayment |
| Hooks | booking, raise and cancel paths in rides.service.ts; completion in dispatch.service.ts |
| Rider app | app/(app)/pay-card-hold.tsx, src/lib/card-hold.ts, payment picker in confirm.tsx |
| Driver app | "paid in app" banner in app/(app)/trip.tsx |
| Admin | components/trip/CardPayment.tsx, components/markets/CardRidesCard.tsx |
| Migration | 128 (ride_card_holds) |
The server never trusts the app. Before a hold is accepted, the server reads the authorisation from Moyasar and checks:
- it is
authorized, notpaid; - it is for exactly the hold amount and currency;
- it carries this hold's id in its metadata.
The payment id can bind to one hold only, and a hold can bind to one ride only.