This document describes the implemented Orange Money provider integration for the Mobile Money backend.
Overview
- File:
src/services/mobilemoney/providers/orange.ts - Purpose: Authenticate with Orange using OAuth2 (client_credentials), request collection (payment), check status, and perform disbursements (payouts).
Environment variables
ORANGE_BASE_URL(optional): Base URL for Orange API. Defaults tohttps://sandbox.orange.com.ORANGE_API_KEY: Client ID / API key (required).ORANGE_API_SECRET: Client secret (required).ORANGE_CURRENCY(optional): Currency code used for requests. Defaults toXAF.ORANGE_USE_HEADLESS_BROWSER: Use Playwright for web session login to handle JavaScript challenges and CAPTCHAs (default: false)ORANGE_HEADLESS: Run browser in headless mode (default: true)ORANGE_VIEWPORT_WIDTH: Browser viewport width (default: 1280)ORANGE_VIEWPORT_HEIGHT: Browser viewport height (default: 800)ORANGE_USER_AGENT: Custom user agent string (default: Chrome 120 on Windows)ORANGE_BROWSER_TIMEOUT_MS: Browser operation timeout in milliseconds (default: 30000)ORANGE_NAVIGATION_TIMEOUT_MS: Page navigation timeout in milliseconds (default: 30000)
Implemented behavior
- Authentication:
- Uses client credentials grant (
grant_type=client_credentials) against/oauth/token. - Caches access token and refreshes when expired (with small skew).
- Uses client credentials grant (
- requestPayment(phoneNumber, amount):
- Calls
POST /v1/payments/collectwith a generated reference and transaction details. - Returns
{ success: boolean, data?, error?, reference? }.
- Calls
- checkStatus(reference):
- Calls
GET /v1/payments/{reference}and returns{ success: boolean, data?, error? }.
- Calls
- sendPayout(phoneNumber, amount):
- Calls
POST /v1/payments/disbursewith generated reference. - Returns
{ success: boolean, data?, error?, reference? }.
- Calls
- Retries:
- Transient errors (HTTP 5xx, network/timeouts) are retried with exponential-ish backoff (linear backoff based on attempt).
Notes & limitations
- Endpoints (
/oauth/token,/v1/payments/collect,/v1/payments/disburse,/v1/payments/{ref}) are implemented as reasonable defaults commonly used by payments APIs, but you must confirm the exact Orange API paths and payload shapes against Orange's official documentation for your region/sandbox before using in production. - Error shapes returned by Orange are forwarded in the
{ error }field. The service using this provider should inspecterror.response.datato extract provider error details. - The implementation uses
ORANGE_BASE_URLso you can point to sandbox or production endpoints via environment configuration.
Sandbox testing
- Ensure
ORANGE_API_KEYandORANGE_API_SECRETare set in your.env. - Set
ORANGE_BASE_URLto the sandbox base URL provided by Orange (if different from the default). - Start the app (
npm run dev) and call the endpoints via existing transaction flows (e.g.,POST /api/transactions/depositwithprovider: "orange"). - Use
GET /api/transactions/:idto follow job status andcheckStatuswill be invoked by background jobs if configured.
Next steps (recommended)
- Confirm exact Orange API endpoint paths and payload fields and adjust the request shapes in
orange.tsaccordingly. - Add unit/integration tests that mock Orange responses (happy path, 4xx errors, 5xx transient errors) and assert retry/handling.
- Add stronger typed models for provider responses if desired.