TrustPayWay SDK (Node.js / TypeScript / JavaScript)
A simple, lightweight Node.js SDK for interacting with the TrustPayWay mobile payment API. Supports MTN, Orange, and others.
Built with TypeScript. Usable in both TypeScript and plain JavaScript projects.
🚀 Features
- 🔐 Authenticate via application token
- 💸 Initiate payments (MTN & Orange supported)
- 📊 Check payment status
- 🧩 Fully typed for TypeScript support
- ⚙️ Works in any Node.js project (TS or JS)
📦 Installation
npm install trustpayway-sdk
🧑💻 Usage
▶️ TypeScript Example
import { TrustPayWay } from 'trustpayway-sdk';
const tpw = new TrustPayWay({
baseUrl: 'https://mobilewallet.trustpayway.com',//https://test.trustpayway.com (for testing purposes)
appToken: 'your-app-token',
authToken: 'your-bearer-token',
network: 'orange', // or 'mtn'
});
async function run() {
const result = await tpw.processPayment({
amount: '100',
currency: 'XAF',
phone: '237600000000',
description: 'Invoice #123',
orderId: 'TPW-123',
notifUrl: 'https://webhook.site/your-webhook',
});
console.log('Transaction Response:', result);
}
💡 JavaScript (Vanilla Node.js) Example
const { TrustPayWay } = require('trustpayway-sdk');
const tpw = new TrustPayWay({
baseUrl: 'https://mobilewallet.trustpayway.com',//https://test.trustpayway.com (for testing purposes)
appToken: 'your-app-token',
authToken: 'your-bearer-token',
network: 'mtn', // or 'orange'
});
async function run() {
try {
const result = await tpw.processPayment({
amount: '100',
currency: 'XAF',
phone: '237600000000',
description: 'Invoice #123',
orderId: 'TPW-123',
notifUrl: 'https://webhook.site/your-webhook',
});
console.log('Transaction Response:', result);
} catch (error) {
console.error('Payment Failed:', error);
}
}
run();
📚 API Reference
new TrustPayWay(config)
Create a new SDK instance.
Parameters:
baseUrl
(string): API base URL (e.g.https://mobilewallet.trustpayway.com
)appToken
(string): Your application token from TrustPayWayauthToken
(string): Authorization token (Bearer)network
(string):'mtn'
or'orange'
getToken(): Promise<string>
Fetches a session token from TrustPayWay. Automatically called before processPayment()
or checkPaymentStatus()
if not already set.
processPayment(params): Promise<object>
Initiates a payment via mobile money.
Params:
amount
(string): Amount to chargecurrency
(string): e.g.'XAF'
phone
(string): Receiver phone (with country code)description
(string): Description for the transaction example Your APP NameorderId
(string): Unique order identifiernotifUrl
(string): Callback URL for status updates
checkPaymentStatus({ transactionId }): Promise<object>
Checks the status of a transaction.
Params:
transactionId
(string): The transaction ID returned byprocessPayment
📄 License
MIT
🔗 Links
- 📘 TrustPayWay Official Site
- 🧑💻 Author: TrustPayWay
- 🐛 Issues: GitHub Issues