This example demonstrates how to implement Ghion USSD push functionality using JavaScript without the SDK. It uses only Node.js built-in modules for API authentication and requests.
- ✅ JavaScript implementation (no SDK dependencies)
- ✅ HMAC-SHA256 signature generation for API authentication
- ✅ Complete USSD push flow with YaYaWallet
- ✅ Payment initialization and status checking
- ✅ Error handling with helpful messages
- Node.js - Install Node.js (version 14 or higher)
- API Credentials - Get your API credentials from https://ghion.financial
- YaYaWallet Account - Have a phone number registered with YaYaWallet for testing
- Clone or navigate to this directory
- Install dependencies:
npm install
- Copy the example environment file:
cp .env.example .env
- Edit
.envand add your credentials:GHION_API_KEY=your_api_key_here GHION_API_SECRET=your_api_secret_here GHION_API_PASSPHRASE=your_passphrase_here TEST_PHONE_NUMBER=0912345678
Run the test script:
npm testOr directly with Node.js:
node ussd-push.jsThe script will automatically load environment variables from the .env file.
The script performs the following steps:
- Initialize Payment: Creates a payment session with specified amount and reference
- Submit USSD Push: Sends a USSD push request to the user's phone via YayaWallet
- Check Status: Retrieves the current payment status
The implementation uses HMAC-SHA256 signatures for API authentication:
const message = `${timestamp}${method}${path}${body}`;
const signature = crypto.createHmac('sha256', secret).update(message).digest('base64');Required headers:
X-Ghion-Key: Your API keyX-Ghion-Timestamp: Unix timestamp in secondsX-Ghion-Signature: HMAC-SHA256 signatureX-Ghion-Passphrase: Your passphrase
The script includes helpful error messages for common issues:
- User does not exist: Phone number not registered with YaYaWallet
- Authentication errors: Invalid API credentials
- Network errors: Connection issues
Endpoint: POST /checkout/initialize
Request Format:
{
"amount": 10,
"currency": "ETB",
"reference": "test_1789464322522",
"description": "Payment description",
"webhook_url": "https://your-domain.com/webhook",
"return_url": "https://your-domain.com/success",
"cancel_url": "https://your-domain.com/cancel",
"metadata": {
"customer_id": "12345",
"order_id": "order_123"
}
}Required Fields:
amount(number): Payment amountcurrency(string): Currency code (default: "ETB")reference(string): Unique payment reference
Optional Fields:
description(string): Payment descriptionwebhook_url(string): URL for payment status notificationsreturn_url(string): Redirect URL after successful paymentcancel_url(string): Redirect URL after cancelled paymentmetadata(object): Additional custom data
Response Format:
{
"id": "01a0a462-a864-7f3a-9915-abe214663ff6",
"amount": 10,
"currency": "ETB",
"reference": "test_1789464322522",
"status": "pending",
"available_channels": [
{
"name": "YaYa Wallet",
"id": "yayawallet"
},
{
"name": "Card",
"id": "card"
}
],
"created_at": "2026-09-14T12:00:00Z"
}Endpoint: POST /checkout/{paymentId}/pay/yayawallet
Request Format:
{
"phone_number": "0912345678"
}Required Fields:
phone_number(string): User's phone number (must be registered with YaYaWallet)
Response Format:
{
"status": "processing",
"transaction_id": "01a0a462-a864-7f3a-9915-abe214663ff6",
"message": "Payment request sent to YaYa Wallet. Please approve on your phone (*957#).",
"phone_number": "0912345678",
"channel": "yayawallet"
}Endpoint: GET /checkout/{paymentId}
Request Parameters:
paymentId(path parameter): Payment session ID
Response Format:
{
"id": "01a0a462-a864-7f3a-9915-abe214663ff6",
"amount": 10,
"currency": "ETB",
"reference": "test_1789464322522",
"status": "pending",
"message": "Payment is pending user approval",
"created_at": "2026-09-14T12:00:00Z",
"updated_at": "2026-09-14T12:05:00Z"
}Possible Status Values:
pending: Payment initiated, awaiting user actionprocessing: Payment is being processedcompleted: Payment successfully completedfailed: Payment failedcancelled: Payment was cancelled by user
To test the real USSD push flow with actual payments, you must:
-
Complete KYC on Ghion Dashboard
- Log in to your Ghion dashboard at https://ghion.financial
- Complete the Know Your Customer (KYC) verification process
- Submit required documents for identity verification
-
Go Live
- After KYC approval, request to go live
- Your account will be moved from sandbox to production mode
- Live transactions will be enabled
-
Test Phone Number Requirements
- The test phone number must be registered with YaYaWallet
- Ensure the phone number can receive USSD prompts
- The user should have sufficient balance in their YaYaWallet account
Sandbox Mode:
- Use for development and testing
- No real money transactions
- Simulated payment flows
- API endpoints remain the same
Production Mode:
- Requires completed KYC
- Real money transactions
- Actual USSD push to phones
- Same API endpoints with live data
After running the test:
- Check your phone for the YaYaWallet USSD prompt
- Approve the payment to complete the transaction
- Use the payment ID for further testing and monitoring
- This implementation uses Node.js built-in
cryptoandfetchmodules - No external dependencies required
- Suitable for understanding the API authentication mechanism
- For production use, consider adding retry logic and more robust error handling