telebirr-nodejs 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +67 -36
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -10,20 +10,26 @@ A simple, opinionated Node.js SDK for integrating **Telebirr C2B payments** with
10
10
  npm install telebirr-nodejs
11
11
  ```
12
12
 
13
+ ---
14
+
13
15
  ## Required Configuration
14
16
 
15
17
  Telebirr requires credentials and callback URLs.
16
18
  You should never hard-code secrets. Always load them from process.env.
17
19
 
20
+ ---
21
+
18
22
  ### Required Credentials
19
23
 
20
- | Name | Description |
21
- | ---------------------- | ---------------------------- |
22
- | `FABRIC_APP_ID` | Fabric application ID |
23
- | `FABRIC_APP_SECRET` | Fabric application secret |
24
- | `MERCHANT_APP_ID` | Merchant application ID |
25
- | `MERCHANT_CODE` | Merchant code |
26
- | `MERCHANT_PRIVATE_KEY` | RSA private key (PEM string) |
24
+ | Name | Description |
25
+ | ---------------------- | -------------------------------------------------------------------------------------- |
26
+ | `FABRIC_APP_ID` | Fabric application ID (c4182ef8-9249-458a-985e-06d191f4d505 uuid-v4 string) |
27
+ | `FABRIC_APP_SECRET` | Fabric application secret ("fad0f06383c6297f54rr78694b974599" 32 hex character string) |
28
+ | `MERCHANT_APP_ID` | Merchant application ID (7606201678956824 16 integer character string) |
29
+ | `MERCHANT_CODE` | Merchant code ("000000" 6 integer character string) |
30
+ | `MERCHANT_PRIVATE_KEY` | RSA private key (PEM string) |
31
+
32
+ ---
27
33
 
28
34
  ### Required URLs
29
35
 
@@ -32,8 +38,12 @@ You should never hard-code secrets. Always load them from process.env.
32
38
  | `TELEBIRR_NOTIFY_URL` | Server-to-server callback URL |
33
39
  | `TELEBIRR_REDIRECT_URL` | User redirect URL after payment |
34
40
 
41
+ ---
42
+
35
43
  ### Basic Setup
36
44
 
45
+ ---
46
+
37
47
  ```bash
38
48
  import { TelebirrClient } from "telebirr-nodejs";
39
49
 
@@ -43,7 +53,7 @@ const client = new TelebirrClient({
43
53
  appSecret: process.env.FABRIC_APP_SECRET!,
44
54
  merchantAppId: process.env.MERCHANT_APP_ID!,
45
55
  merchantCode: process.env.MERCHANT_CODE!,
46
- privateKey: process.env.MERCHANT_PRIVATE_KEY!,
56
+ merchantPrivateKey: process.env.MERCHANT_PRIVATE_KEY!,
47
57
  notifyUrl: process.env.TELEBIRR_NOTIFY_URL!,
48
58
  redirectUrl: process.env.TELEBIRR_REDIRECT_URL!,
49
59
  http: true, // allow HTTP in simulator mode
@@ -51,6 +61,8 @@ const client = new TelebirrClient({
51
61
  });
52
62
  ```
53
63
 
64
+ ---
65
+
54
66
  ### Important
55
67
 
56
68
  MERCHANT_PRIVATE_KEY must be the full PEM string, including:
@@ -61,26 +73,28 @@ MERCHANT_PRIVATE_KEY must be the full PEM string, including:
61
73
  -----END RSA PRIVATE KEY-----
62
74
  ```
63
75
 
76
+ ---
77
+
64
78
  ### Example API Routes
65
79
 
66
- Below is a complete demo using three routes:
80
+ 1. POST /payment/initiate
81
+ 2. GET /payment/status
82
+ 3. POST /payment/refund
67
83
 
68
- POST /payment/initiate
69
- GET /payment/status/:merchOrderId
70
- POST /payment/refund
84
+ ---
71
85
 
72
- ### 1 Initiate Payment
86
+ ### 1. Initiate Payment
73
87
 
74
88
  Creates an order and redirects the user to the Telebirr checkout page.
75
89
 
76
90
  ```bash
77
91
  app.post("/payment/initiate", async (req, res) => {
78
92
  const checkoutUrl = await client.preOrder({
79
- merchOrderId: "order123",
80
- title: "Phone",
81
- amount: "12",
82
- callbackInfo: "from web checkout",
83
- });
93
+ merchOrderId: "order123",
94
+ title: "Phone",
95
+ amount: "12",
96
+ callbackInfo: "from web checkout",
97
+ });
84
98
 
85
99
  res.redirect(checkoutUrl);
86
100
  });
@@ -88,7 +102,9 @@ app.post("/payment/initiate", async (req, res) => {
88
102
 
89
103
  If you are using a frontend framework (for example React) and do not want to lose application state, return the checkout URL as JSON and let the frontend handle the redirection.
90
104
 
91
- ### 2 Query Payment Status
105
+ ---
106
+
107
+ ### 2. Query Payment Status
92
108
 
93
109
  Used to check the payment result using the merchant order ID.
94
110
 
@@ -102,7 +118,12 @@ app.get("/payment/status/:merchOrderId", async (req, res) => {
102
118
  });
103
119
  ```
104
120
 
105
- ### 3 Refund Payment
121
+ Please refer to Telebirr’s official documentation to correctly handle the query order json response:
122
+ https://developer.ethiotelecom.et/docs/H5%20C2B%20Web%20Payment%20Integration%20Quick%20Guide/queryOrder
123
+
124
+ ---
125
+
126
+ ### 3. Refund Payment
106
127
 
107
128
  Refunds a completed transaction.
108
129
 
@@ -117,10 +138,14 @@ app.post("/payment/refund", async (req, res) => {
117
138
  });
118
139
 
119
140
  res.json(refundData);
120
- });
141
+ });
142
+
121
143
  ```
122
144
 
123
- Refund amount must not exceed the original payment amount
145
+ Please refer to Telebirr’s official documentation to correctly handle the refund order json response:
146
+ https://developer.ethiotelecom.et/docs/H5%20C2B%20Web%20Payment%20Integration%20Quick%20Guide/RefundOrder
147
+
148
+ ---
124
149
 
125
150
  ### Simulator Mode
126
151
 
@@ -129,32 +154,37 @@ To use the simulator provided by this package, set the mode to simulate.
129
154
  ```bash
130
155
  import { TelebirrClient } from "telebirr-nodejs";
131
156
 
132
- const client = new TelebirrClient({
133
- mode: "simulate",
134
- notifyUrl: "https://example.com/notify",
135
- redirectUrl: "https://example.com/redirect",
136
- http: true,
137
- IntegrationOption: "C2B",
138
- });
157
+ const client = new TelebirrClient({
158
+ mode: "simulate",
159
+ notifyUrl: "https://example.com/notify",
160
+ redirectUrl: "https://example.com/redirect",
161
+ http: true,
162
+ IntegrationOption: "C2B",
163
+ });
164
+
139
165
  ```
140
166
 
141
167
  This simulator is for learning and development purposes only.
142
168
  The simulation server is provided by this package, not by Telebirr. For real testing, use Telebirr’s sandbox mode and whitelist your public IP address in the Telebirr portal.
143
169
 
170
+ ---
171
+
144
172
  ### Supported Features
145
173
 
146
- Fabric token handling
147
- RSA-SHA256 request signing
148
- C2B checkout
149
- Order query
150
- Refunds
151
- Simulator support
152
- Notify URL Handling
174
+ - Fabric token handling
175
+ - RSA-SHA256 request signing
176
+ - C2B checkout
177
+ - Order query
178
+ - Refunds
179
+ - Simulator support
180
+ - Notify URL Handling
153
181
 
154
182
  Please refer to Telebirr’s official documentation to correctly handle notify callbacks:
155
183
 
156
184
  https://developer.ethiotelecom.et/docs/H5%20C2B%20Web%20Payment%20Integration%20Quick%20Guide/Notify_Callback
157
185
 
186
+ ---
187
+
158
188
  ### RSA Key Generation
159
189
 
160
190
  You can generate private and public keys instantly.
@@ -168,6 +198,7 @@ generateKeys({
168
198
  publicKeyName: "telefy_public.pem",
169
199
  overwrite: false,
170
200
  });
201
+
171
202
  ```
172
203
 
173
204
  This will generate two .pem files in your root directory.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "telebirr-nodejs",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Unofficial Telebirr Node.js SDK.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",