pesafy 0.5.1 → 0.5.3

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # pesafy
2
2
 
3
+ ## 0.5.3
4
+
5
+ ### Patch Changes
6
+
7
+ - updated types,added test and updated the apis
8
+
9
+ ## 0.5.2
10
+
11
+ ### Patch Changes
12
+
13
+ - migrate from cjs/esm to only esm
14
+
3
15
  ## 0.5.1
4
16
 
5
17
  ### Patch Changes
@@ -40,14 +52,20 @@
40
52
 
41
53
  ### Patch Changes
42
54
 
43
- - C2B URL registration panel with per-shortcode tracking (Paybill + Buy Goods), dual registration support, and session-persisted status badges"
55
+ - C2B URL registration panel with per-shortcode tracking (Paybill + Buy Goods),
56
+ dual registration support, and session-persisted status badges"
44
57
 
45
58
  ## 0.3.12
46
59
 
47
60
  ### Patch Changes
48
61
 
49
- - 047c30f: The payload was always sending BillRefNumber: request.billRefNumber ?? "". For CustomerBuyGoodsOnline, Daraja treats any BillRefNumber field — even "" — as an invalid AccountReference and rejects the request (400 or 503). The fix conditionally includes the field only for Paybill
50
- - fix error handling and URLs only registered for 600977, never for 600000. The log shows registerC2BUrls shortCode=600977 but then simulateC2B shortCode=600000
62
+ - 047c30f: The payload was always sending BillRefNumber: request.billRefNumber
63
+ ?? "". For CustomerBuyGoodsOnline, Daraja treats any BillRefNumber field
64
+ even "" — as an invalid AccountReference and rejects the request (400 or 503).
65
+ The fix conditionally includes the field only for Paybill
66
+ - fix error handling and URLs only registered for 600977, never for 600000. The
67
+ log shows registerC2BUrls shortCode=600977 but then simulateC2B
68
+ shortCode=600000
51
69
 
52
70
  ## 0.3.11
53
71
 
@@ -59,7 +77,17 @@
59
77
 
60
78
  ### Patch Changes
61
79
 
62
- - Added Dynamic QR Code support to the pesafy SDK as a new mpesa/dynamic-qr module. This introduces three new files — types.ts, generate.ts, and index.ts — under src/mpesa/dynamic-qr/, implementing the Safaricom Daraja POST /mpesa/qrcode/v1/generate endpoint. The Mpesa class gains a new generateDynamicQR() method that handles token retrieval and delegates to the internal generateDynamicQR function, which validates all inputs (merchant name, reference, amount, transaction code, CPI, and size) before dispatching the request via the existing httpRequest utility. Three new public types — DynamicQRRequest, DynamicQRResponse, and QRTransactionCode — are exported from the root src/index.ts. No breaking changes were introduced; all existing APIs remain untouched.
80
+ - Added Dynamic QR Code support to the pesafy SDK as a new mpesa/dynamic-qr
81
+ module. This introduces three new files — types.ts, generate.ts, and index.ts
82
+ — under src/mpesa/dynamic-qr/, implementing the Safaricom Daraja POST
83
+ /mpesa/qrcode/v1/generate endpoint. The Mpesa class gains a new
84
+ generateDynamicQR() method that handles token retrieval and delegates to the
85
+ internal generateDynamicQR function, which validates all inputs (merchant
86
+ name, reference, amount, transaction code, CPI, and size) before dispatching
87
+ the request via the existing httpRequest utility. Three new public types —
88
+ DynamicQRRequest, DynamicQRResponse, and QRTransactionCode — are exported from
89
+ the root src/index.ts. No breaking changes were introduced; all existing APIs
90
+ remain untouched.
63
91
 
64
92
  ## 0.3.9
65
93
 
@@ -71,7 +99,15 @@
71
99
 
72
100
  ### Patch Changes
73
101
 
74
- - Fixed four blocking TypeScript compilation errors before prepublish by extending the `ErrorCode` union to include `API_ERROR`, `NETWORK_ERROR`, and `TIMEOUT`, which resolved type assignment issues in the HTTP layer. Consolidated a duplicate `PesafyError` class (previously split between `index.ts` and `types.ts`) into a single authoritative implementation that preserves all fields, including `requestId`, `toJSON()`, and stack trace handling. Also corrected `x-forwarded-for` IP extraction in the Express webhook handler using safe optional chaining to prevent potential undefined access from the `split()` result.
102
+ - Fixed four blocking TypeScript compilation errors before prepublish by
103
+ extending the `ErrorCode` union to include `API_ERROR`, `NETWORK_ERROR`, and
104
+ `TIMEOUT`, which resolved type assignment issues in the HTTP layer.
105
+ Consolidated a duplicate `PesafyError` class (previously split between
106
+ `index.ts` and `types.ts`) into a single authoritative implementation that
107
+ preserves all fields, including `requestId`, `toJSON()`, and stack trace
108
+ handling. Also corrected `x-forwarded-for` IP extraction in the Express
109
+ webhook handler using safe optional chaining to prevent potential undefined
110
+ access from the `split()` result.
75
111
 
76
112
  ## 0.3.7
77
113
 
@@ -95,7 +131,9 @@
95
131
 
96
132
  ### Patch Changes
97
133
 
98
- - f983f64: The /v2/simulate path is the most critical bug — it will cause persistent 500.003.1001 errors in sandbox just like the /v2/registerurl issue you already fixed.
134
+ - f983f64: The /v2/simulate path is the most critical bug — it will cause
135
+ persistent 500.003.1001 errors in sandbox just like the /v2/registerurl issue
136
+ you already fixed.
99
137
 
100
138
  ## 0.3.3
101
139
 
@@ -113,21 +151,67 @@
113
151
 
114
152
  ### Patch Changes
115
153
 
116
- - **C2B module rewrite & phone utility refactor** — Fixed `simulateC2B` where `CommandID` was hardcoded to `CustomerPayBillOnline`, making `CustomerBuyGoodsOnline` (Till) payments impossible. Corrected `BillRefNumber` logic so the field is omitted entirely for BuyGoods requests rather than defaulting to the string `"default"`, which caused a `400` from Daraja. Fixed `Msisdn` being sent as a quoted string instead of a JSON number as the spec requires. Removed the phantom `ConversationID` field from both `C2BSimulateResponse` and `C2BRegisterUrlResponse` — Daraja never returns this field for C2B, only `OriginatorCoversationID`. Extracted phone formatting into a shared `src/utils/phone.ts` module with two intentionally separate formatters: `formatSafaricomPhone` (strict, Safaricom/Airtel only, for STK Push) and `formatKenyanMsisdn` (permissive, all Kenyan networks, for C2B and B2C), eliminating duplicated logic across modules. Added the `C2BCommandId` union type and full callback payload types — `C2BValidationPayload`, `C2BConfirmationPayload`, and `C2BCallbackPayload` — to enable type-safe webhook handlers.
154
+ - **C2B module rewrite & phone utility refactor** — Fixed `simulateC2B` where
155
+ `CommandID` was hardcoded to `CustomerPayBillOnline`, making
156
+ `CustomerBuyGoodsOnline` (Till) payments impossible. Corrected `BillRefNumber`
157
+ logic so the field is omitted entirely for BuyGoods requests rather than
158
+ defaulting to the string `"default"`, which caused a `400` from Daraja. Fixed
159
+ `Msisdn` being sent as a quoted string instead of a JSON number as the spec
160
+ requires. Removed the phantom `ConversationID` field from both
161
+ `C2BSimulateResponse` and `C2BRegisterUrlResponse` — Daraja never returns this
162
+ field for C2B, only `OriginatorCoversationID`. Extracted phone formatting into
163
+ a shared `src/utils/phone.ts` module with two intentionally separate
164
+ formatters: `formatSafaricomPhone` (strict, Safaricom/Airtel only, for STK
165
+ Push) and `formatKenyanMsisdn` (permissive, all Kenyan networks, for C2B and
166
+ B2C), eliminating duplicated logic across modules. Added the `C2BCommandId`
167
+ union type and full callback payload types — `C2BValidationPayload`,
168
+ `C2BConfirmationPayload`, and `C2BCallbackPayload` — to enable type-safe
169
+ webhook handlers.
117
170
  - fbfa311: fix url patch and add elemt accountref
118
- - aa9c176: **C2B module rewrite & phone utility refactor** — Fixed `simulateC2B` where `CommandID` was hardcoded to `CustomerPayBillOnline`, making `CustomerBuyGoodsOnline` (Till) payments impossible. Corrected `BillRefNumber` logic so the field is omitted entirely for BuyGoods requests rather than defaulting to the string `"default"`, which caused a `400` from Daraja. Fixed `Msisdn` being sent as a quoted string instead of a JSON number as the spec requires. Removed the phantom `ConversationID` field from both `C2BSimulateResponse` and `C2BRegisterUrlResponse` — Daraja never returns this field for C2B, only `OriginatorCoversationID`. Extracted phone formatting into a shared `src/utils/phone.ts` module with two intentionally separate formatters: `formatSafaricomPhone` (strict, Safaricom/Airtel only, for STK Push) and `formatKenyanMsisdn` (permissive, all Kenyan networks, for C2B and B2C), eliminating duplicated logic across modules. Added the `C2BCommandId` union type and full callback payload types — `C2BValidationPayload`, `C2BConfirmationPayload`, and `C2BCallbackPayload` — to enable type-safe webhook handlers.
171
+ - aa9c176: **C2B module rewrite & phone utility refactor** — Fixed `simulateC2B`
172
+ where `CommandID` was hardcoded to `CustomerPayBillOnline`, making
173
+ `CustomerBuyGoodsOnline` (Till) payments impossible. Corrected `BillRefNumber`
174
+ logic so the field is omitted entirely for BuyGoods requests rather than
175
+ defaulting to the string `"default"`, which caused a `400` from Daraja. Fixed
176
+ `Msisdn` being sent as a quoted string instead of a JSON number as the spec
177
+ requires. Removed the phantom `ConversationID` field from both
178
+ `C2BSimulateResponse` and `C2BRegisterUrlResponse` — Daraja never returns this
179
+ field for C2B, only `OriginatorCoversationID`. Extracted phone formatting into
180
+ a shared `src/utils/phone.ts` module with two intentionally separate
181
+ formatters: `formatSafaricomPhone` (strict, Safaricom/Airtel only, for STK
182
+ Push) and `formatKenyanMsisdn` (permissive, all Kenyan networks, for C2B and
183
+ B2C), eliminating duplicated logic across modules. Added the `C2BCommandId`
184
+ union type and full callback payload types — `C2BValidationPayload`,
185
+ `C2BConfirmationPayload`, and `C2BCallbackPayload` — to enable type-safe
186
+ webhook handlers.
119
187
 
120
188
  ## 0.3.0
121
189
 
122
190
  ### Minor Changes
123
191
 
124
- - fe95c2b: The C2B M-Pesa implementation in the pesafy package has been comprehensively overhauled for full Daraja C2B v2 compliance, including a complete rewrite of types.ts with all 13 callback fields (C2BCallbackPayload), validation responses, rejection codes, and command/response unions; fixes to register-url.ts ensuring ValidationURL is always sent (defaulting to confirmationUrl); enhanced simulate.ts supporting both CustomerPayBillOnline and CustomerBuyGoodsOnline with proper BillRefNumber handling, amount validation, and Msisdn casting; new c2b index exports; root index public exports; and improved http client error reporting. Dashboard updates add c2bRegisterUrls and c2bSimulate actions in mpesaActions.ts, fix http.ts webhook handlers with 6 missing fields (TransactionType, TransTime, etc.), upsert logic via createTransaction, a new getByShortCode query in businesses.ts, and a complete C2B tab in PaymentsPage.tsx featuring URL registration, simulation forms, and unified transactions—addressing prior gaps like hardcoded commands, missing UI, incomplete types, and non-upserting handlers.
192
+ - fe95c2b: The C2B M-Pesa implementation in the pesafy package has been
193
+ comprehensively overhauled for full Daraja C2B v2 compliance, including a
194
+ complete rewrite of types.ts with all 13 callback fields (C2BCallbackPayload),
195
+ validation responses, rejection codes, and command/response unions; fixes to
196
+ register-url.ts ensuring ValidationURL is always sent (defaulting to
197
+ confirmationUrl); enhanced simulate.ts supporting both CustomerPayBillOnline
198
+ and CustomerBuyGoodsOnline with proper BillRefNumber handling, amount
199
+ validation, and Msisdn casting; new c2b index exports; root index public
200
+ exports; and improved http client error reporting. Dashboard updates add
201
+ c2bRegisterUrls and c2bSimulate actions in mpesaActions.ts, fix http.ts
202
+ webhook handlers with 6 missing fields (TransactionType, TransTime, etc.),
203
+ upsert logic via createTransaction, a new getByShortCode query in
204
+ businesses.ts, and a complete C2B tab in PaymentsPage.tsx featuring URL
205
+ registration, simulation forms, and unified transactions—addressing prior gaps
206
+ like hardcoded commands, missing UI, incomplete types, and non-upserting
207
+ handlers.
125
208
 
126
209
  ## 0.2.4
127
210
 
128
211
  ### Patch Changes
129
212
 
130
- - 4a535ef: Request failed with status 500 but swallows the actual Daraja error body — it parses it into data but never includes it in the error message.
213
+ - 4a535ef: Request failed with status 500 but swallows the actual Daraja error
214
+ body — it parses it into data but never includes it in the error message.
131
215
 
132
216
  ## 0.2.3
133
217
 
@@ -152,14 +236,14 @@
152
236
  ### Minor Changes
153
237
 
154
238
  - Add M-Pesa Express (STK Push) support
155
- - Add `processStkPush` to initiate STK Push payment prompts on a
156
- customer's phone via POST /mpesa/stkpush/v1/processrequest
157
- - Add `queryStkPush` to check the status of an STK Push transaction
158
- via POST /mpesa/stkpushquery/v1/query
239
+ - Add `processStkPush` to initiate STK Push payment prompts on a customer's
240
+ phone via POST /mpesa/stkpush/v1/processrequest
241
+ - Add `queryStkPush` to check the status of an STK Push transaction via POST
242
+ /mpesa/stkpushquery/v1/query
159
243
  - Add `StkPushRequest`, `StkPushResponse`, `StkQueryRequest`,
160
244
  `StkQueryResponse` and `TransactionType` types
161
- - Add `formatPhoneNumber` utility to normalize Kenyan phone numbers
162
- to 254 format
245
+ - Add `formatPhoneNumber` utility to normalize Kenyan phone numbers to 254
246
+ format
163
247
  - Add `getStkPushPassword` to generate Base64(Shortcode+Passkey+Timestamp)
164
248
  - Add `getTimestamp` helper for Daraja-formatted timestamps
165
249
  - Export all STK Push types and utilities from the package root