Payments¶
Source: pharmanet/lib/core/services/payment_service.dart
Integration¶
PharmaNet uses Chapa as its primary payment gateway for Ethiopian Birr (ETB) transactions.
Payment Use Cases¶
| Use Case | Flow | Location |
|---|---|---|
| Order Payment | Hosted checkout → callback → confirm | CheckoutPage → PaymentSuccessPage |
| Featured Product | Hosted checkout → callback → activate | SellerProductSelection (web) |
| Subscription | Hosted checkout → callback → activate | NewSubscription (web) |
ChapaService¶
Source: pharmanet/lib/core/services/payment_service.dart
| Method | Description |
|---|---|
initializePayment(amount, currency, email, firstName, lastName, txRef, callbackUrl, returnUrl) |
Create Chapa checkout session |
verifyPayment(txRef) |
Verify payment status |
Payment Flow¶
sequenceDiagram
participant App as Flutter App
participant CP as Chapa API
participant S as Supabase
App->>S: Create order (status: pending)
S-->>App: Order ID
App->>App: Generate tx_ref
App->>CP: Initialize payment
CP-->>App: Checkout URL
App->>App: Open URL in WebView/browser
User->>CP: Complete payment
CP-->>App: Redirect to callback URL
App->>S: Update payment + order status
App->>App: Navigate to success page
Transaction Reference¶
TxRef format: {prefix}_{timestamp}_{random}
// From chapa.js (web) / ChapaService (mobile)
const txRef = `PHARMA_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
Payment Statuses¶
| Status | Description |
|---|---|
pending |
Awaiting payment |
success |
Payment confirmed |
failed |
Payment declined |
cancelled |
User cancelled |
API¶
Source: pharmanet/lib/core/api/order_api.dart
| Method | Description |
|---|---|
updatePaymentStatus(orderId, status) |
Update after Chapa callback |
Related¶
- Cart & Checkout — Checkout flow
- Orders — Post-payment order management
- Admin: Payments — Admin transaction management