@singularity-payments/core 1.1.1 → 1.3.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 +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +29 -0
- package/dist/index.mjs +29 -0
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -262,6 +262,18 @@ interface DynamicQRResponse {
|
|
|
262
262
|
ResponseDescription: string;
|
|
263
263
|
QRCode: string;
|
|
264
264
|
}
|
|
265
|
+
interface C2BSimulateRequest {
|
|
266
|
+
shortcode?: string;
|
|
267
|
+
amount: number;
|
|
268
|
+
phoneNumber: string;
|
|
269
|
+
billRefNumber: string;
|
|
270
|
+
commandID?: "CustomerPayBillOnline" | "CustomerBuyGoodsOnline";
|
|
271
|
+
}
|
|
272
|
+
interface C2BSimulateResponse {
|
|
273
|
+
ConversationID: string;
|
|
274
|
+
OriginatorCoversationID: string;
|
|
275
|
+
ResponseDescription: string;
|
|
276
|
+
}
|
|
265
277
|
|
|
266
278
|
interface ParsedCallbackData {
|
|
267
279
|
merchantRequestId: string;
|
|
@@ -623,6 +635,10 @@ declare class MpesaClient {
|
|
|
623
635
|
* Handle B2C callback
|
|
624
636
|
*/
|
|
625
637
|
handleB2CCallback(callback: B2CCallback): Promise<object>;
|
|
638
|
+
/**
|
|
639
|
+
* Simulate C2B transaction (for testing in sandbox)
|
|
640
|
+
*/
|
|
641
|
+
simulateC2B(request: C2BSimulateRequest): Promise<C2BSimulateResponse>;
|
|
626
642
|
/**
|
|
627
643
|
* Handle B2B callback
|
|
628
644
|
*/
|
|
@@ -684,4 +700,4 @@ declare function encryptInitiatorPassword(initiatorPassword: string, certificate
|
|
|
684
700
|
*/
|
|
685
701
|
declare function validateSecurityCredential(credential: string): boolean;
|
|
686
702
|
|
|
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 };
|
|
703
|
+
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,18 @@ interface DynamicQRResponse {
|
|
|
262
262
|
ResponseDescription: string;
|
|
263
263
|
QRCode: string;
|
|
264
264
|
}
|
|
265
|
+
interface C2BSimulateRequest {
|
|
266
|
+
shortcode?: string;
|
|
267
|
+
amount: number;
|
|
268
|
+
phoneNumber: string;
|
|
269
|
+
billRefNumber: string;
|
|
270
|
+
commandID?: "CustomerPayBillOnline" | "CustomerBuyGoodsOnline";
|
|
271
|
+
}
|
|
272
|
+
interface C2BSimulateResponse {
|
|
273
|
+
ConversationID: string;
|
|
274
|
+
OriginatorCoversationID: string;
|
|
275
|
+
ResponseDescription: string;
|
|
276
|
+
}
|
|
265
277
|
|
|
266
278
|
interface ParsedCallbackData {
|
|
267
279
|
merchantRequestId: string;
|
|
@@ -623,6 +635,10 @@ declare class MpesaClient {
|
|
|
623
635
|
* Handle B2C callback
|
|
624
636
|
*/
|
|
625
637
|
handleB2CCallback(callback: B2CCallback): Promise<object>;
|
|
638
|
+
/**
|
|
639
|
+
* Simulate C2B transaction (for testing in sandbox)
|
|
640
|
+
*/
|
|
641
|
+
simulateC2B(request: C2BSimulateRequest): Promise<C2BSimulateResponse>;
|
|
626
642
|
/**
|
|
627
643
|
* Handle B2B callback
|
|
628
644
|
*/
|
|
@@ -684,4 +700,4 @@ declare function encryptInitiatorPassword(initiatorPassword: string, certificate
|
|
|
684
700
|
*/
|
|
685
701
|
declare function validateSecurityCredential(credential: string): boolean;
|
|
686
702
|
|
|
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 };
|
|
703
|
+
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: request.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: request.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
|
*/
|