Scaffold a payment gateway integration (HyperPay/Moyasar) with checkout, webhook, and transaction tracking. Use when adding payment capabilities.
Integrates a Saudi-compatible payment gateway for processing earnest money, commissions, or subscription fees. Supports mada, Visa, Mastercard, and Apple Pay.
Create the transactions model via /add-prisma-model:
model transactions {
id String @id @default(uuid())
amount Decimal
currency String @default("SAR")
status String @default("PENDING") // PENDING, COMPLETED, FAILED, REFUNDED
gatewayRef String?
gatewayData Json?
entityType String // "deal", "subscription", "invoice"
entityId String
userId String
organizationId String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
Create payment service at apps/api/libs/payment-gateway.ts:
initiateCheckout(amount, currency, entityType, entityId) → returns checkout URLverifyPayment(gatewayRef) → returns statusprocessRefund(transactionId) → initiates refundCreate API routes at apps/api/routes/payments.ts:
POST /api/payments/initiate — create checkout session, return redirect URLPOST /api/payments/webhook — gateway callback (no auth, verify signature)GET /api/payments/transactions — list user/org transactionsPOST /api/payments/:id/refund — admin-only refundCreate checkout page at apps/web/src/pages/platform/checkout.tsx:
Add environment variables:
HYPERPAY_ENTITY_ID=...
HYPERPAY_ACCESS_TOKEN=...
HYPERPAY_BASE_URL=https://test.oppwa.com # sandbox
/typecheck passes