@singularity-payments/sveltekit 1.1.1 → 1.2.1
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.js +52 -0
- package/dist/index.mjs +52 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -54,6 +54,39 @@ function createMpesaHandlers(client) {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
|
+
/**
|
|
58
|
+
* C2B simulation handler (for testing)
|
|
59
|
+
* Simulates a C2B payment transaction
|
|
60
|
+
*/
|
|
61
|
+
simulateC2B: {
|
|
62
|
+
POST: async (event) => {
|
|
63
|
+
try {
|
|
64
|
+
const body = await event.request.json();
|
|
65
|
+
const { amount, phoneNumber, billRefNumber, commandID } = body;
|
|
66
|
+
if (!amount || !phoneNumber || !billRefNumber) {
|
|
67
|
+
return (0, import_kit.json)(
|
|
68
|
+
{
|
|
69
|
+
error: "Amount, phone number, and bill reference number are required"
|
|
70
|
+
},
|
|
71
|
+
{ status: 400 }
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
const response = await client.simulateC2B({
|
|
75
|
+
amount: Number(amount),
|
|
76
|
+
phoneNumber: String(phoneNumber),
|
|
77
|
+
billRefNumber: String(billRefNumber),
|
|
78
|
+
commandID
|
|
79
|
+
});
|
|
80
|
+
return (0, import_kit.json)(response);
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.error("C2B Simulate error:", error);
|
|
83
|
+
return (0, import_kit.json)(
|
|
84
|
+
{ error: error.message || "Request failed" },
|
|
85
|
+
{ status: 500 }
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
},
|
|
57
90
|
/**
|
|
58
91
|
* C2B validation handler
|
|
59
92
|
* Validates C2B transactions before they are processed
|
|
@@ -465,6 +498,25 @@ function createMpesaHandlers(client) {
|
|
|
465
498
|
const response = await client.stkQuery({ CheckoutRequestID });
|
|
466
499
|
return (0, import_kit.json)(response);
|
|
467
500
|
}
|
|
501
|
+
if (lastSegment === "simulate-c2b") {
|
|
502
|
+
const body = await event.request.json();
|
|
503
|
+
const { amount, phoneNumber, billRefNumber, commandID } = body;
|
|
504
|
+
if (!amount || !phoneNumber || !billRefNumber || !commandID) {
|
|
505
|
+
return (0, import_kit.json)(
|
|
506
|
+
{
|
|
507
|
+
error: "Amount, phone number, bill reference number, and command ID are required"
|
|
508
|
+
},
|
|
509
|
+
{ status: 400 }
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
const response = await client.simulateC2B({
|
|
513
|
+
amount,
|
|
514
|
+
phoneNumber,
|
|
515
|
+
billRefNumber,
|
|
516
|
+
commandID
|
|
517
|
+
});
|
|
518
|
+
return (0, import_kit.json)(response);
|
|
519
|
+
}
|
|
468
520
|
if (lastSegment === "b2c") {
|
|
469
521
|
const body = await event.request.json();
|
|
470
522
|
const {
|
package/dist/index.mjs
CHANGED
|
@@ -28,6 +28,39 @@ function createMpesaHandlers(client) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
|
+
/**
|
|
32
|
+
* C2B simulation handler (for testing)
|
|
33
|
+
* Simulates a C2B payment transaction
|
|
34
|
+
*/
|
|
35
|
+
simulateC2B: {
|
|
36
|
+
POST: async (event) => {
|
|
37
|
+
try {
|
|
38
|
+
const body = await event.request.json();
|
|
39
|
+
const { amount, phoneNumber, billRefNumber, commandID } = body;
|
|
40
|
+
if (!amount || !phoneNumber || !billRefNumber) {
|
|
41
|
+
return json(
|
|
42
|
+
{
|
|
43
|
+
error: "Amount, phone number, and bill reference number are required"
|
|
44
|
+
},
|
|
45
|
+
{ status: 400 }
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
const response = await client.simulateC2B({
|
|
49
|
+
amount: Number(amount),
|
|
50
|
+
phoneNumber: String(phoneNumber),
|
|
51
|
+
billRefNumber: String(billRefNumber),
|
|
52
|
+
commandID
|
|
53
|
+
});
|
|
54
|
+
return json(response);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
console.error("C2B Simulate error:", error);
|
|
57
|
+
return json(
|
|
58
|
+
{ error: error.message || "Request failed" },
|
|
59
|
+
{ status: 500 }
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
},
|
|
31
64
|
/**
|
|
32
65
|
* C2B validation handler
|
|
33
66
|
* Validates C2B transactions before they are processed
|
|
@@ -439,6 +472,25 @@ function createMpesaHandlers(client) {
|
|
|
439
472
|
const response = await client.stkQuery({ CheckoutRequestID });
|
|
440
473
|
return json(response);
|
|
441
474
|
}
|
|
475
|
+
if (lastSegment === "simulate-c2b") {
|
|
476
|
+
const body = await event.request.json();
|
|
477
|
+
const { amount, phoneNumber, billRefNumber, commandID } = body;
|
|
478
|
+
if (!amount || !phoneNumber || !billRefNumber || !commandID) {
|
|
479
|
+
return json(
|
|
480
|
+
{
|
|
481
|
+
error: "Amount, phone number, bill reference number, and command ID are required"
|
|
482
|
+
},
|
|
483
|
+
{ status: 400 }
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
const response = await client.simulateC2B({
|
|
487
|
+
amount,
|
|
488
|
+
phoneNumber,
|
|
489
|
+
billRefNumber,
|
|
490
|
+
commandID
|
|
491
|
+
});
|
|
492
|
+
return json(response);
|
|
493
|
+
}
|
|
442
494
|
if (lastSegment === "b2c") {
|
|
443
495
|
const body = await event.request.json();
|
|
444
496
|
const {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@singularity-payments/sveltekit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@sveltejs/kit": "^2.49.2",
|
|
40
|
-
"@singularity-payments/core": "1.
|
|
40
|
+
"@singularity-payments/core": "1.3.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/node": "^25.0.3",
|