The three ways to enrol
| Cart total | What happens |
|---|---|
| 0 (free courses, or a 100% coupon) | The order is saved as paid and the learner is enrolled at once. Free courses can also be enrolled from their page without the cart. |
| Card | The order is saved as Pending, the learner pays on Thawani's page, and the course opens only when our server asks Thawani and Thawani says the session is paid. |
| Bank transfer | The order is saved as Pending with the transfer details shown to the learner. An admin marks it paid in Dashboard > Orders, which enrols the learner. |
Prices, coupons and VAT are always computed on the server from the database. The browser's cart only holds course ids.
Thawani (cards)
- Create a merchant account at Thawani and get the secret and publishable keys (test keys first).
- Set them in
.env:
THAWANI_MODE="uat" # test environment; "live" for real payments
THAWANI_SECRET_KEY="..."
THAWANI_PUBLISHABLE_KEY="..."
- Restart, then switch on Card payments in Dashboard > Settings. The currency must be OMR.
The flow, in src/lib/thawani.ts and src/app/api/orders/route.ts:
POST /api/orderscreates the order and a Thawani checkout session for the server-computed total, and answers the payment page URL.- The learner pays; Thawani redirects to
/api/payments/thawani/return?order=CODE. - That route ignores the query string and asks Thawani for the session's status. Only
paidmarks the order paid and creates the enrolments. A cancelled session cancels the order and gives the coupon use back.
Thawani's minimum is 0.100 OMR.
Bank transfer
Switch it on in Settings and write the transfer details in both languages (bank, account name and number, what to write in the reference). Learners see them after placing the order and on their Orders page. Dashboard > Orders highlights waiting transfers; Transfer received: mark paid enrols the learner.
Coupons
Dashboard > Coupons: a percentage or a fixed amount, an optional minimum cart, usage limit and expiry date, and an on/off switch. The coupon use is counted in the same database transaction as the order with a conditional update, so a code limited to 50 uses cannot be used 51 times even with simultaneous checkouts. Cancelling an unpaid order gives the use back.
When a coupon covers several courses, the discount is shared between them in proportion to their prices (allocateDiscount in src/lib/pricing.ts); each order line stores what was really paid for it, which is what instructor earnings are based on.
VAT
Settings > VAT % (0 by default). VAT is added to the discounted amount and rounded to the baisa.
Refunds
Dashboard > Orders > a paid order > Refund removes the enrolments created by that order (with their progress and certificates) and marks it refunded. Return the money from your bank or the Thawani portal; the template does not call Thawani's refund API.
Instructor earnings
Settings > Instructor share % (70 by default). Each instructor sees their share of what learners paid for their courses on the Overview and Earnings pages.