@singularity-payments/core 1.1.1 → 1.2.0

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/dist/index.d.mts CHANGED
@@ -262,6 +262,17 @@ interface DynamicQRResponse {
262
262
  ResponseDescription: string;
263
263
  QRCode: string;
264
264
  }
265
+ interface C2BSimulateRequest {
266
+ amount: number;
267
+ phoneNumber: string;
268
+ billRefNumber: string;
269
+ commandID?: "CustomerPayBillOnline" | "CustomerBuyGoodsOnline";
270
+ }
271
+ interface C2BSimulateResponse {
272
+ ConversationID: string;
273
+ OriginatorCoversationID: string;
274
+ ResponseDescription: string;
275
+ }
265
276
 
266
277
  interface ParsedCallbackData {
267
278
  merchantRequestId: string;
@@ -623,6 +634,10 @@ declare class MpesaClient {
623
634
  * Handle B2C callback
624
635
  */
625
636
  handleB2CCallback(callback: B2CCallback): Promise<object>;
637
+ /**
638
+ * Simulate C2B transaction (for testing in sandbox)
639
+ */
640
+ simulateC2B(request: C2BSimulateRequest): Promise<C2BSimulateResponse>;
626
641
  /**
627
642
  * Handle B2B callback
628
643
  */
@@ -684,4 +699,4 @@ declare function encryptInitiatorPassword(initiatorPassword: string, certificate
684
699
  */
685
700
  declare function validateSecurityCredential(credential: string): boolean;
686
701
 
687
- export { type AccountBalanceCallback, type AccountBalanceRequest, type AccountBalanceResponse, type B2BCallback, type B2BCommandID, type B2BRequest, type B2BResponse, type B2CCallback, type B2CCommandID, type B2CRequest, type B2CResponse, type BalanceIdentifierType, type C2BCallback, type C2BRegisterRequest, type C2BRegisterResponse, type CallbackHandlerOptions, type DynamicQRRequest, type DynamicQRResponse, type Environment, type GeneralTransactionStatusRequest, type GeneralTransactionStatusResponse, MpesaApiError, MpesaAuthError, MpesaCallbackHandler, MpesaClient, type MpesaClientOptions, type MpesaConfig, MpesaError, MpesaNetworkError, type MpesaPlugin, MpesaRateLimitError, MpesaTimeoutError, MpesaValidationError, type ParsedC2BCallback, type ParsedCallbackData, RateLimiter, type RateLimiterOptions, type RedisLike, RedisRateLimiter, type RetryOptions, type ReversalCallback, type ReversalRequest, type ReversalResponse, type STKCallback, type STKPushRequest, type STKPushResponse, type TransactionStatusCallback, type TransactionStatusRequest, type TransactionStatusResponse, encryptInitiatorPassword, retryWithBackoff, validateSecurityCredential };
702
+ export { type AccountBalanceCallback, type AccountBalanceRequest, type AccountBalanceResponse, type B2BCallback, type B2BCommandID, type B2BRequest, type B2BResponse, type B2CCallback, type B2CCommandID, type B2CRequest, type B2CResponse, type BalanceIdentifierType, type C2BCallback, type C2BRegisterRequest, type C2BRegisterResponse, type C2BSimulateRequest, type C2BSimulateResponse, type CallbackHandlerOptions, type DynamicQRRequest, type DynamicQRResponse, type Environment, type GeneralTransactionStatusRequest, type GeneralTransactionStatusResponse, MpesaApiError, MpesaAuthError, MpesaCallbackHandler, MpesaClient, type MpesaClientOptions, type MpesaConfig, MpesaError, MpesaNetworkError, type MpesaPlugin, MpesaRateLimitError, MpesaTimeoutError, MpesaValidationError, type ParsedC2BCallback, type ParsedCallbackData, RateLimiter, type RateLimiterOptions, type RedisLike, RedisRateLimiter, type RetryOptions, type ReversalCallback, type ReversalRequest, type ReversalResponse, type STKCallback, type STKPushRequest, type STKPushResponse, type TransactionStatusCallback, type TransactionStatusRequest, type TransactionStatusResponse, encryptInitiatorPassword, retryWithBackoff, validateSecurityCredential };
package/dist/index.d.ts CHANGED
@@ -262,6 +262,17 @@ interface DynamicQRResponse {
262
262
  ResponseDescription: string;
263
263
  QRCode: string;
264
264
  }
265
+ interface C2BSimulateRequest {
266
+ amount: number;
267
+ phoneNumber: string;
268
+ billRefNumber: string;
269
+ commandID?: "CustomerPayBillOnline" | "CustomerBuyGoodsOnline";
270
+ }
271
+ interface C2BSimulateResponse {
272
+ ConversationID: string;
273
+ OriginatorCoversationID: string;
274
+ ResponseDescription: string;
275
+ }
265
276
 
266
277
  interface ParsedCallbackData {
267
278
  merchantRequestId: string;
@@ -623,6 +634,10 @@ declare class MpesaClient {
623
634
  * Handle B2C callback
624
635
  */
625
636
  handleB2CCallback(callback: B2CCallback): Promise<object>;
637
+ /**
638
+ * Simulate C2B transaction (for testing in sandbox)
639
+ */
640
+ simulateC2B(request: C2BSimulateRequest): Promise<C2BSimulateResponse>;
626
641
  /**
627
642
  * Handle B2B callback
628
643
  */
@@ -684,4 +699,4 @@ declare function encryptInitiatorPassword(initiatorPassword: string, certificate
684
699
  */
685
700
  declare function validateSecurityCredential(credential: string): boolean;
686
701
 
687
- export { type AccountBalanceCallback, type AccountBalanceRequest, type AccountBalanceResponse, type B2BCallback, type B2BCommandID, type B2BRequest, type B2BResponse, type B2CCallback, type B2CCommandID, type B2CRequest, type B2CResponse, type BalanceIdentifierType, type C2BCallback, type C2BRegisterRequest, type C2BRegisterResponse, type CallbackHandlerOptions, type DynamicQRRequest, type DynamicQRResponse, type Environment, type GeneralTransactionStatusRequest, type GeneralTransactionStatusResponse, MpesaApiError, MpesaAuthError, MpesaCallbackHandler, MpesaClient, type MpesaClientOptions, type MpesaConfig, MpesaError, MpesaNetworkError, type MpesaPlugin, MpesaRateLimitError, MpesaTimeoutError, MpesaValidationError, type ParsedC2BCallback, type ParsedCallbackData, RateLimiter, type RateLimiterOptions, type RedisLike, RedisRateLimiter, type RetryOptions, type ReversalCallback, type ReversalRequest, type ReversalResponse, type STKCallback, type STKPushRequest, type STKPushResponse, type TransactionStatusCallback, type TransactionStatusRequest, type TransactionStatusResponse, encryptInitiatorPassword, retryWithBackoff, validateSecurityCredential };
702
+ export { type AccountBalanceCallback, type AccountBalanceRequest, type AccountBalanceResponse, type B2BCallback, type B2BCommandID, type B2BRequest, type B2BResponse, type B2CCallback, type B2CCommandID, type B2CRequest, type B2CResponse, type BalanceIdentifierType, type C2BCallback, type C2BRegisterRequest, type C2BRegisterResponse, type C2BSimulateRequest, type C2BSimulateResponse, type CallbackHandlerOptions, type DynamicQRRequest, type DynamicQRResponse, type Environment, type GeneralTransactionStatusRequest, type GeneralTransactionStatusResponse, MpesaApiError, MpesaAuthError, MpesaCallbackHandler, MpesaClient, type MpesaClientOptions, type MpesaConfig, MpesaError, MpesaNetworkError, type MpesaPlugin, MpesaRateLimitError, MpesaTimeoutError, MpesaValidationError, type ParsedC2BCallback, type ParsedCallbackData, RateLimiter, type RateLimiterOptions, type RedisLike, RedisRateLimiter, type RetryOptions, type ReversalCallback, type ReversalRequest, type ReversalResponse, type STKCallback, type STKPushRequest, type STKPushResponse, type TransactionStatusCallback, type TransactionStatusRequest, type TransactionStatusResponse, encryptInitiatorPassword, retryWithBackoff, validateSecurityCredential };
package/dist/index.js CHANGED
@@ -1189,6 +1189,35 @@ var MpesaClient = class {
1189
1189
  );
1190
1190
  }
1191
1191
  }
1192
+ /**
1193
+ * Simulate C2B transaction (for testing in sandbox)
1194
+ */
1195
+ async simulateC2B(request) {
1196
+ if (this.config.environment === "production") {
1197
+ throw new MpesaValidationError(
1198
+ "C2B simulation is only available in sandbox environment. In production, C2B transactions come from real customer payments."
1199
+ );
1200
+ }
1201
+ if (request.amount < 1) {
1202
+ throw new MpesaValidationError("Amount must be at least 1 KES");
1203
+ }
1204
+ if (!request.billRefNumber) {
1205
+ throw new MpesaValidationError("Bill reference number is required");
1206
+ }
1207
+ const phone = this.validateAndFormatPhone(request.phoneNumber);
1208
+ const payload = {
1209
+ ShortCode: this.config.shortcode,
1210
+ CommandID: request.commandID || "CustomerPayBillOnline",
1211
+ Amount: Math.floor(request.amount),
1212
+ Msisdn: phone,
1213
+ BillRefNumber: request.billRefNumber
1214
+ };
1215
+ return this.makeRequest(
1216
+ "/mpesa/c2b/v1/simulate",
1217
+ payload,
1218
+ `c2b:simulate:${phone}`
1219
+ );
1220
+ }
1192
1221
  /**
1193
1222
  * Handle B2B callback
1194
1223
  */
package/dist/index.mjs CHANGED
@@ -1140,6 +1140,35 @@ var MpesaClient = class {
1140
1140
  );
1141
1141
  }
1142
1142
  }
1143
+ /**
1144
+ * Simulate C2B transaction (for testing in sandbox)
1145
+ */
1146
+ async simulateC2B(request) {
1147
+ if (this.config.environment === "production") {
1148
+ throw new MpesaValidationError(
1149
+ "C2B simulation is only available in sandbox environment. In production, C2B transactions come from real customer payments."
1150
+ );
1151
+ }
1152
+ if (request.amount < 1) {
1153
+ throw new MpesaValidationError("Amount must be at least 1 KES");
1154
+ }
1155
+ if (!request.billRefNumber) {
1156
+ throw new MpesaValidationError("Bill reference number is required");
1157
+ }
1158
+ const phone = this.validateAndFormatPhone(request.phoneNumber);
1159
+ const payload = {
1160
+ ShortCode: this.config.shortcode,
1161
+ CommandID: request.commandID || "CustomerPayBillOnline",
1162
+ Amount: Math.floor(request.amount),
1163
+ Msisdn: phone,
1164
+ BillRefNumber: request.billRefNumber
1165
+ };
1166
+ return this.makeRequest(
1167
+ "/mpesa/c2b/v1/simulate",
1168
+ payload,
1169
+ `c2b:simulate:${phone}`
1170
+ );
1171
+ }
1143
1172
  /**
1144
1173
  * Handle B2B callback
1145
1174
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@singularity-payments/core",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },