mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
7.3 KiB
7.3 KiB
TELEBIRR & WAAFI Payment Integration Flow
Overview
Complete payment flow for TELEBIRR and WAAFI integration using the /payments/initiate endpoint.
Payment Flow
1. Payment Method Selection
- User selects TELEBIRR or WAAFI from available payment methods
- Payment methods fetched from
/payments/methods - Extracts payment method ID for the request
2. Payment Initiation
Endpoint: POST /payments/initiate
Request:
{
"bookingId": "booking-uuid",
"method": "TELEBIRR" | "WAAFI",
"paymentMethodId": "payment-method-uuid",
"platform": "web"
}
Response:
{
"success": true,
"data": {
"intentId": "66aa30e2-52a2-4ad0-9043-df6df4a6fa4a",
"status": "REQUIRES_ACTION",
"clientAction": {
"url": "https://sandbox.waafipay.net/v2/hpp/token/2B68686270593243495535774B317263683930574A413D3D",
"type": "REDIRECT"
},
"merchantOrderId": "1781588440170af93c3b9"
},
"timestamp": "2026-06-16T05:40:41.004Z"
}
3. User Redirect
- App stores
intentIdin payment store - Updates payment status to
REQUIRES_ACTION - Redirects user to
clientAction.url - User completes payment on payment gateway
4. Callback Handling
TELEBIRR Success Callback
URL: /booking/payment/telebirr/success
Query Parameters:
merchantOrderId- Merchant order ID (primary reference)trxReforoutTradeNo- Transaction referenceresultCodeorcode- Result coderesultMsgormessage- Result messagemsisdn- Phone number (optional)bookingId- Booking UUID
Actions:
- Logs all query parameters
- Calls
PATCH /bookings/{bookingId}/confirmwith:{ "paymentReference": "merchantOrderId or trxRef", "paymentMethod": "TELEBIRR" } - Updates payment status to
SUCCEEDED - Redirects to
/booking/confirmation
TELEBIRR Failure Callback
URL: /booking/payment/telebirr/failure
Query Parameters:
merchantOrderId- Merchant order IDtrxReforoutTradeNo- Transaction referenceresultCodeorcode- Error coderesultMsgormessage- Error message
Actions:
- Logs all query parameters
- Updates payment status to
FAILED - Shows error message to user
- Provides options to retry or go back
WAAFI Success Callback
URL: /booking/payment/waafi/success
Query Parameters:
accountNo- Account number (e.g., "25377111111")cardNo- Card numbercurrency- Currency code (e.g., "DJF")orderId- Order ID (e.g., "1209631")referenceId- Reference ID (e.g., "17815888579838ddc23b3")responseCode- Response code ("0" for success)responseMsg- Response message (e.g., "Approved (sandbox mode)")state- Transaction state (e.g., "APPROVED")transactionId- Transaction ID (e.g., "1318559")txAmount- Transaction amount (e.g., "367.50")paymentMethod- Payment method type (e.g., "MWALLET_ACCOUNT")timestamp- Transaction timestampbookingId- Booking UUID
Example:
?accountNo=25377111111
&cardNo=25377111111
¤cy=DJF
&orderId=1209631
&referenceId=17815888579838ddc23b3
&responseCode=0
&responseMsg=Approved+(sandbox+mode)
&state=APPROVED
&transactionId=1318559
&txAmount=367.50
&paymentMethod=MWALLET_ACCOUNT
×tamp=2026-06-16T08:48:01+03:00
Actions:
- Logs all query parameters
- Calls
PATCH /bookings/{bookingId}/confirmwith:{ "paymentReference": "referenceId or transactionId", "paymentMethod": "WAAFI", "transactionDetails": { "transactionId": "1318559", "orderId": "1209631", "accountNo": "25377111111", "amount": "367.50", "currency": "DJF", "state": "APPROVED", "timestamp": "2026-06-16T08:48:01+03:00" } } - Updates payment status to
SUCCEEDED - Redirects to
/booking/confirmation
WAAFI Failure Callback
URL: /booking/payment/waafi/failure
Query Parameters:
referenceId- Reference IDresponseCode- Error coderesponseMsg- Error messageorderId- Order IDtransactionId- Transaction IDstate- Transaction statetxAmount- Transaction amountcurrency- Currency code
Actions:
- Logs all query parameters
- Updates payment status to
FAILED - Shows error message to user
- Provides options to retry or go back
Console Logs
When TELEBIRR or WAAFI payment is initiated, check browser console for:
=== TELEBIRR PAYMENT INITIATION ===
Request payload: {
bookingId: "...",
method: "TELEBIRR",
paymentMethodId: "...",
platform: "web"
}
=== TELEBIRR PAYMENT RESPONSE ===
Full response: {...}
Intent ID: "66aa30e2-52a2-4ad0-9043-df6df4a6fa4a"
Status: "REQUIRES_ACTION"
Client Action: {url: "...", type: "REDIRECT"}
Redirect URL: "https://sandbox.waafipay.net/v2/hpp/token/..."
Merchant Order ID: "1781588440170af93c3b9"
====================================
=== REDIRECTING TO TELEBIRR PAYMENT GATEWAY ===
Intent ID: 66aa30e2-52a2-4ad0-9043-df6df4a6fa4a
Status: REQUIRES_ACTION
Merchant Order ID: 1781588440170af93c3b9
Redirect URL: https://sandbox.waafipay.net/v2/hpp/token/...
=======================================
Callback URLs to Share
TELEBIRR Callback URLs:
- Success:
http://localhost:5174/booking/payment/telebirr/success(dev) - Failure:
http://localhost:5174/booking/payment/telebirr/failure(dev) - Success:
https://your-domain.com/booking/payment/telebirr/success(prod) - Failure:
https://your-domain.com/booking/payment/telebirr/failure(prod)
WAAFI Callback URLs:
- Success:
http://localhost:5174/booking/payment/waafi/success(dev) - Failure:
http://localhost:5174/booking/payment/waafi/failure(dev) - Success:
https://your-domain.com/booking/payment/waafi/success(prod) - Failure:
https://your-domain.com/booking/payment/waafi/failure(prod)
Files Modified
-
src/app/booking/payment/page.tsx- Added TELEBIRR and WAAFI payment initiation
- Handles redirect response
- Logs all payment data
-
src/lib/payment-store.ts- Added
REQUIRES_ACTIONstatus
- Added
-
src/types/index.ts- Updated
PaymentMethodinterface
- Updated
-
src/app/booking/payment/telebirr/success/page.tsx- Handles TELEBIRR success callback with merchantOrderId
-
src/app/booking/payment/telebirr/failure/page.tsx- Handles TELEBIRR failure callback with merchantOrderId
-
src/app/booking/payment/waafi/success/page.tsx- Handles WAAFI success callback with full transaction details
-
src/app/booking/payment/waafi/failure/page.tsx- Handles WAAFI failure callback
Testing Checklist
- Payment methods load from API
- TELEBIRR appears in payment options
- WAAFI appears in payment options
- Selecting TELEBIRR calls
/payments/initiate - Selecting WAAFI calls
/payments/initiate - Console logs show correct request/response
- User redirects to payment gateway
- Success callback confirms booking
- Failure callback shows error
- User can retry after failure
Notes
- Only TELEBIRR and WAAFI use
/payments/initiateendpoint - Other payment methods use
/payments/intentendpoint - Payment store supports
REQUIRES_ACTIONstatus - All callback query parameters are logged for debugging
- TELEBIRR uses
merchantOrderIdas primary reference - WAAFI uses
referenceIdortransactionIdas primary reference