@amanbel/payment-verifier-sdk
v1.0.2
Published
Ethiopian payment transaction verification SDK for Telebirr, CBE and Bank of Abyssinia.
Maintainers
Readme
Ethiopian Payment Verifier
A Node.js/TypeScript SDK for verifying Ethiopian payment transactions.
Currently supported providers:
- Telebirr
- Commercial Bank of Ethiopia (CBE)
- Bank of Abyssinia
- More Comming Soon
Installation
npm install @amanbel/ethiopian-payment-verifierUsage
The package provides a simple PaymentVerifier class that allows you to
verify payment transactions from supported Ethiopian payment providers.
1. Import the PaymentVerifier
import { PaymentVerifier } from "ethiopian-payment-verifier";2. Create an instance
Create a PaymentVerifier instance. No API URLs or provider configuration
are required.
const paymentVerifier = new PaymentVerifier();3. Verify a payment
Use the verify() method and provide the payment provider and transaction
number.
Telebirr
const result = await paymentVerifier.verify({
provider: "telebirr",
transactionNumber: "YOUR_TRANSACTION_NUMBER",
});CBE
const result = await paymentVerifier.verify({
provider: "cbe",
transactionNumber: "YOUR_RECEIPT_NUMBER",
});Bank of Abyssinia
const result = await paymentVerifier.verify({
provider: "abyssinia",
transactionNumber: "YOUR_TRANSACTION_NUMBER",
});4. Handle the verification result
The verify() method returns a result that indicates whether the payment
was successfully verified.
if (result.success) {
console.log("Payment verified successfully");
console.log(result.data);
} else {
console.error("Payment verification failed");
console.error(result.error);
}Complete Example
import { PaymentVerifier } from "ethiopian-payment-verifier";
async function verifyPayment() {
const paymentVerifier = new PaymentVerifier();
const result = await paymentVerifier.verify({
provider: "telebirr",
transactionNumber: "YOUR_TRANSACTION_NUMBER",
});
if (result.success) {
console.log("Payment verified successfully");
console.log("Payer:", result.data.payerName);
console.log("Amount:", result.data.totalPaidAmount);
console.log("Transaction:", result.data.invoiceNo);
console.log("Payment Date:", result.data.paymentDate);
console.log("Payment Provider:", result.data.payedFrom);
} else {
console.error("Payment verification failed:");
console.error(result.error.message);
}
}
verifyPayment();Supported Payment Providers
The following payment providers are currently supported:
| Provider | Value |
| ----------------- | ----------- |
| Telebirr | telebirr |
| CBE | cbe |
| Bank of Abyssinia | abyssinia |
Transaction Data
When a payment is successfully verified, the data property contains
standardized transaction information regardless of the payment provider.
{
payerName: string;
payerTelebirrNo: string;
transactionStatus: string;
invoiceNo: string;
paymentDate: string;
paymentReciever: string;
settledAmount: string;
serviceFee: string;
serviceFeeVAT: string;
totalPaidAmount: string;
paymentReason: string;
paymentChannel: string;
payedFrom: string;
}This allows your application to work with different payment providers using the same data structure.
For example:
if (result.success) {
const payment = result.data;
if (payment.transactionStatus === "success") {
console.log(`Received ${payment.totalPaidAmount}`);
}
}Using a Different Provider
The same PaymentVerifier instance can be used to verify payments from
different providers.
const paymentVerifier = new PaymentVerifier();
const telebirrPayment = await paymentVerifier.verify({
provider: "telebirr",
transactionNumber: "TELEBIRR_TRANSACTION",
});
const cbePayment = await paymentVerifier.verify({
provider: "cbe",
transactionNumber: "CBE_RECEIPT_NUMBER",
});
const abyssiniaPayment = await paymentVerifier.verify({
provider: "abyssinia",
transactionNumber: "ABYSSINIA_TRANSACTION",
});Error Handling
A failed verification does not require you to catch an exception in normal
usage. The result will contain success: false and an error.
const result = await paymentVerifier.verify({
provider: "cbe",
transactionNumber: "INVALID_TRANSACTION",
});
if (!result.success) {
console.log(result.error.message);
}You can also use try/catch to handle unexpected errors:
try {
const result = await paymentVerifier.verify({
provider: "telebirr",
transactionNumber: "YOUR_TRANSACTION_NUMBER",
});
if (result.success) {
console.log(result.data);
} else {
console.error(result.error.message);
}
} catch (error) {
console.error("Unexpected error:", error);
}