A type-safe Node.js SDK for the Ghion Finances payment gateway. Built with security, maintainability, and scalability in mind for developers maintaining or contributing to this repository.
- Type-Safe: Full TypeScript support with comprehensive type definitions
- Secure: HMAC-SHA256 authentication with timing-safe signature verification
- Robust: Comprehensive error handling with custom error classes
- Validated: Built-in input validation for all API requests
- Express-Ready: Seamless integration with Express.js middleware
- Retry Logic: Automatic retry for transient failures and rate limits
- Modern: Built with modern Node.js (18+) and TypeScript best practices
- Multi-Channel: Support for USSD, QR, OTP, and card payment methods
- Real-time: Built-in support for real-time payment status monitoring
- Bill Payment: Complete bill management API for creating, listing, and analyzing bills
- Auto-Generated Bill IDs: Support for optional bill_id with auto-generation
- Payment Reminders: Send payment reminders to customers via email and SMS
- Checkout Initiation: Programmatically generate payment links for bills
express-sdk/
├── src/
│ ├── client/ # HTTP client and API methods
│ ├── types/ # TypeScript type definitions
│ ├── errors/ # Custom error classes
│ ├── utils/ # Utility functions (crypto, validation)
├── examples/ # Usage examples (Express server, quick start)
├── tests/ # Test files (unit and integration)
├── docs/ # Additional documentation
└── dist/ # Compiled JavaScript output
- Node.js >= 18.0.0
- TypeScript >= 4.0.0
- Git
- npm or yarn
git clone https://github.com/yayawallet/ghion-node-sdk.git
cd ghion-node-sdknpm install- Define the types in
src/types/index.ts(Requests, Responses, Enums). - Add validation in
src/utils/validator.tsif necessary. - Implement the method in
src/client/GhionClient.tsusing the genericapiRequestmethod. - Export the types/methods in
src/index.ts. - Add unit tests in
tests/unit.test.ts. - Add integration tests in
tests/integration.test.ts(if applicable).
- Define the error class in
src/errors/index.ts. - Export the error in
src/index.ts. - Add tests in
tests/unit.test.ts.
Run all tests across the SDK (unit tests only):
npm testRun tests for specific packages:
# Unit tests
npm test tests/unit.test.ts
# Integration tests (requires credentials)
npm test tests/integration.test.tsGenerate coverage report:
npm run test:coverageCurrent Coverage:
- Unit tests cover client configuration, validation, crypto functions, and error handling
- Integration tests verify real API calls for payment and bill operations
Unit tests verify SDK logic without making API calls:
- Client configuration and instantiation
- Input validation functions
- Cryptographic signature generation
- Webhook signature verification
- Error type constructors
- Helper functions
Run unit tests:
npm test tests/unit.test.tsIntegration tests make real API calls to verify SDK functionality with the Ghion API.
Setup:
- Create a
.envfile in the examples/ directory:
GHION_API_KEY=your_api_key
GHION_API_SECRET=your_api_secret
GHION_API_PASSPHRASE=your_passphrase
TEST_PHONE_NUMBER=+251911234567
TEST_OTP_CODE=123456 # For OTP validation test- Run integration tests:
npm test tests/integration.test.tsIntegration Test Coverage:
- Initialize Payment: Tests payment initialization and channel availability
- QR Payment: Tests QR code generation and checkout retrieval
- OTP Payment: Tests OTP sending and validation (requires phone number)
- Payment Status: Tests payment status retrieval
- Bill Payment: Tests bill creation, listing, and management
Test Organization:
- Unit tests are located in
tests/unit.test.ts - Integration tests are located in
tests/integration.test.ts - Tests use Jest as the test runner
See the examples/ directory for complete working scripts:
# Quick start example
npx ts-node examples/quick-start.ts
# Express server example
npx ts-node examples/express-server.tsFor continuous integration, run:
# Run all tests with coverage
npm run test:coverage- Style: Use Prettier to format code before committing (
npm run format). - Linting: Use ESLint to ensure code quality (
npm run lint). - TypeScript: All code must be written in TypeScript with proper type definitions.
- Documentation: All exported functions, types, and constants must have proper JSDoc comments.
- Error Handling: Use the custom error types in
src/errorsinstead of generic errors. Never expose sensitive information in error messages. Redact sensitive data from logs.
- HMAC-SHA256 Authentication: All API requests are signed using HMAC-SHA256.
- Timing-Safe Comparison: Webhook signatures use timing-safe comparison to prevent timing attacks.
- Input Validation: All inputs are validated before being sent over the network.
- Sensitive Data Redaction: Error responses automatically redact sensitive information (API keys, passphrases, signatures).
Contributions are welcome! Please ensure:
- Code adheres to existing style (ESLint + Prettier).
- All tests pass (
npm test). - TypeScript types are properly defined.
- Documentation is updated.
- Changes are backwards compatible when possible.
Please open an issue to discuss proposed changes before creating a pull request.
For release guidelines, see RELEASE.md.
For developer usage guide, see DEVELOPER_GUIDE.md.
See LICENSE file for details.