@konplit-services/common 1.0.362 → 1.0.364
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/build/events/Settlements-events/interfaces/index.d.ts +1 -0
- package/build/events/Settlements-events/interfaces/index.js +1 -0
- package/build/events/Settlements-events/interfaces/settlement-transaction-id-updated.interface.d.ts +11 -0
- package/build/events/Settlements-events/interfaces/settlement-transaction-id-updated.interface.js +2 -0
- package/build/events/subjects.d.ts +1 -0
- package/build/events/subjects.js +1 -0
- package/build/helper/money.d.ts +24 -11
- package/build/helper/money.js +32 -14
- package/package.json +1 -1
|
@@ -11,3 +11,4 @@ export * from "./settlement-transfer-verify-nibss.interface";
|
|
|
11
11
|
export * from "./settlement-pay-merchant-nibss-created.interface";
|
|
12
12
|
export * from "./settlement-transfer-reserved-nibss.interface";
|
|
13
13
|
export * from "./settlement-manual-trigger.interface";
|
|
14
|
+
export * from "./settlement-transaction-id-updated.interface";
|
|
@@ -27,3 +27,4 @@ __exportStar(require("./settlement-transfer-verify-nibss.interface"), exports);
|
|
|
27
27
|
__exportStar(require("./settlement-pay-merchant-nibss-created.interface"), exports);
|
|
28
28
|
__exportStar(require("./settlement-transfer-reserved-nibss.interface"), exports);
|
|
29
29
|
__exportStar(require("./settlement-manual-trigger.interface"), exports);
|
|
30
|
+
__exportStar(require("./settlement-transaction-id-updated.interface"), exports);
|
package/build/events/Settlements-events/interfaces/settlement-transaction-id-updated.interface.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { StreamEvent, StreamName, Subjects } from "../../subjects";
|
|
2
|
+
export interface SettlementTransactionIdEvent {
|
|
3
|
+
subject: Subjects.SettlementTransactionIdUpdated;
|
|
4
|
+
streamName: StreamName.name;
|
|
5
|
+
streamEvents: StreamEvent.Event;
|
|
6
|
+
data: {
|
|
7
|
+
merchantId: string;
|
|
8
|
+
transactionId: string;
|
|
9
|
+
settlementId: string;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -63,6 +63,7 @@ export declare enum Subjects {
|
|
|
63
63
|
SettlementTransferReservedNIBSS = "events.settlement.transfer.reserved.nibss",
|
|
64
64
|
SettlementTransferWallet = "events.settlement.transfer.wallet",
|
|
65
65
|
SettlementTransactionUpdated = "events.settlement.transaction.updated",
|
|
66
|
+
SettlementTransactionIdUpdated = "events.settlement.transaction.id.updated",
|
|
66
67
|
TransferInitiation = "events.transfer.initiation",
|
|
67
68
|
TransferFundReserved = "events.transfer.reserved",
|
|
68
69
|
TransferFailed = "events.transfer.failed",
|
package/build/events/subjects.js
CHANGED
|
@@ -80,6 +80,7 @@ var Subjects;
|
|
|
80
80
|
Subjects["SettlementTransferReservedNIBSS"] = "events.settlement.transfer.reserved.nibss";
|
|
81
81
|
Subjects["SettlementTransferWallet"] = "events.settlement.transfer.wallet";
|
|
82
82
|
Subjects["SettlementTransactionUpdated"] = "events.settlement.transaction.updated";
|
|
83
|
+
Subjects["SettlementTransactionIdUpdated"] = "events.settlement.transaction.id.updated";
|
|
83
84
|
//TRANSFERS
|
|
84
85
|
Subjects["TransferInitiation"] = "events.transfer.initiation";
|
|
85
86
|
Subjects["TransferFundReserved"] = "events.transfer.reserved";
|
package/build/helper/money.d.ts
CHANGED
|
@@ -6,26 +6,39 @@ export declare const formatMoneyToNumber: (money: ReturnType<typeof dinero>) =>
|
|
|
6
6
|
export declare const sumMoney: (a: ReturnType<typeof dinero>, b: ReturnType<typeof dinero>) => import("dinero.js").Dinero<number>;
|
|
7
7
|
export declare const subtractMoney: (a: ReturnType<typeof dinero>, b: ReturnType<typeof dinero>) => import("dinero.js").Dinero<number>;
|
|
8
8
|
/**
|
|
9
|
-
* Multiplies a Dinero.js monetary amount by a factor, typically for percentage-based calculations.
|
|
10
|
-
* The scale is dynamically calculated based on the number of decimal places in the factor,
|
|
11
|
-
* plus 2 for the percentage conversion (÷100) and 2 for scaling (*100).
|
|
9
|
+
* Multiplies a Dinero.js monetary amount by a given factor, typically used for percentage-based calculations.
|
|
12
10
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
11
|
+
* This function dynamically calculates the multiplication scale based on the number of decimal places
|
|
12
|
+
* in the factor to maintain precision, then adjusts for percentage scaling by adding 2 to the scale
|
|
13
|
+
* (because factor is a percentage, i.e., factor% = factor/100).
|
|
14
|
+
*
|
|
15
|
+
* The input amount is expected to be in the smallest currency unit (e.g., kobo for NGN, cents for USD).
|
|
16
|
+
*
|
|
17
|
+
* @param a - The Dinero.js monetary amount object, representing money in minor units.
|
|
18
|
+
* @param factor - The multiplier factor, typically a percentage (e.g., 1.4 means 1.4%).
|
|
19
|
+
* Can be any positive decimal number, including those with many decimal places (e.g., 1.00054).
|
|
20
|
+
*
|
|
21
|
+
* @returns A new Dinero.js object representing the result of the multiplication (e.g., the fee or adjusted amount).
|
|
22
|
+
*
|
|
23
|
+
* @throws Error if the calculation results in an invalid amount (e.g., exceeding Number.MAX_SAFE_INTEGER).
|
|
17
24
|
*
|
|
18
25
|
* @example
|
|
19
|
-
* // Calculate 1.4% fee on
|
|
26
|
+
* // Calculate a 1.4% fee on ₦71.00 (7100 kobo)
|
|
20
27
|
* const amount = dinero({ amount: 7100, currency: NGN });
|
|
21
28
|
* const result = multiplyMoney(amount, 1.4);
|
|
22
|
-
* //
|
|
29
|
+
* // result.amount = 994 (kobo) which is ₦9.94
|
|
23
30
|
*
|
|
24
31
|
* @example
|
|
25
|
-
* // Calculate 0.05% fee on
|
|
32
|
+
* // Calculate a 0.05% fee on ₦100.00 (10000 kobo)
|
|
26
33
|
* const amount = dinero({ amount: 10000, currency: NGN });
|
|
27
34
|
* const result = multiplyMoney(amount, 0.05);
|
|
28
|
-
* //
|
|
35
|
+
* // result.amount = 5 (kobo) which is ₦0.05
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // Calculate a 1.00054% fee on ₦2500.00 (250000 kobo)
|
|
39
|
+
* const amount = dinero({ amount: 250000, currency: NGN });
|
|
40
|
+
* const result = multiplyMoney(amount, 1.00054);
|
|
41
|
+
* // result.amount ≈ 2501 (kobo) which is approximately ₦25.01
|
|
29
42
|
*/
|
|
30
43
|
export declare const multiplyMoney: (a: ReturnType<typeof dinero>, factor: number) => import("dinero.js").Dinero<number>;
|
|
31
44
|
export declare const divideMoney: (money: ReturnType<typeof dinero>, divisor: number) => import("dinero.js").Dinero<number>;
|
package/build/helper/money.js
CHANGED
|
@@ -28,36 +28,54 @@ const subtractMoney = (a, b) => {
|
|
|
28
28
|
};
|
|
29
29
|
exports.subtractMoney = subtractMoney;
|
|
30
30
|
/**
|
|
31
|
-
* Multiplies a Dinero.js monetary amount by a factor, typically for percentage-based calculations.
|
|
32
|
-
* The scale is dynamically calculated based on the number of decimal places in the factor,
|
|
33
|
-
* plus 2 for the percentage conversion (÷100) and 2 for scaling (*100).
|
|
31
|
+
* Multiplies a Dinero.js monetary amount by a given factor, typically used for percentage-based calculations.
|
|
34
32
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
33
|
+
* This function dynamically calculates the multiplication scale based on the number of decimal places
|
|
34
|
+
* in the factor to maintain precision, then adjusts for percentage scaling by adding 2 to the scale
|
|
35
|
+
* (because factor is a percentage, i.e., factor% = factor/100).
|
|
36
|
+
*
|
|
37
|
+
* The input amount is expected to be in the smallest currency unit (e.g., kobo for NGN, cents for USD).
|
|
38
|
+
*
|
|
39
|
+
* @param a - The Dinero.js monetary amount object, representing money in minor units.
|
|
40
|
+
* @param factor - The multiplier factor, typically a percentage (e.g., 1.4 means 1.4%).
|
|
41
|
+
* Can be any positive decimal number, including those with many decimal places (e.g., 1.00054).
|
|
42
|
+
*
|
|
43
|
+
* @returns A new Dinero.js object representing the result of the multiplication (e.g., the fee or adjusted amount).
|
|
44
|
+
*
|
|
45
|
+
* @throws Error if the calculation results in an invalid amount (e.g., exceeding Number.MAX_SAFE_INTEGER).
|
|
39
46
|
*
|
|
40
47
|
* @example
|
|
41
|
-
* // Calculate 1.4% fee on
|
|
48
|
+
* // Calculate a 1.4% fee on ₦71.00 (7100 kobo)
|
|
42
49
|
* const amount = dinero({ amount: 7100, currency: NGN });
|
|
43
50
|
* const result = multiplyMoney(amount, 1.4);
|
|
44
|
-
* //
|
|
51
|
+
* // result.amount = 994 (kobo) which is ₦9.94
|
|
45
52
|
*
|
|
46
53
|
* @example
|
|
47
|
-
* // Calculate 0.05% fee on
|
|
54
|
+
* // Calculate a 0.05% fee on ₦100.00 (10000 kobo)
|
|
48
55
|
* const amount = dinero({ amount: 10000, currency: NGN });
|
|
49
56
|
* const result = multiplyMoney(amount, 0.05);
|
|
50
|
-
* //
|
|
57
|
+
* // result.amount = 5 (kobo) which is ₦0.05
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* // Calculate a 1.00054% fee on ₦2500.00 (250000 kobo)
|
|
61
|
+
* const amount = dinero({ amount: 250000, currency: NGN });
|
|
62
|
+
* const result = multiplyMoney(amount, 1.00054);
|
|
63
|
+
* // result.amount ≈ 2501 (kobo) which is approximately ₦25.01
|
|
51
64
|
*/
|
|
52
65
|
const multiplyMoney = (a, factor) => {
|
|
53
66
|
const decimalPlaces = getDecimalPlaces(factor);
|
|
54
|
-
const scale = decimalPlaces
|
|
55
|
-
const multiplierAmount = Math.round(factor *
|
|
56
|
-
return (0, dinero_js_1.multiply)(a, { amount: multiplierAmount, scale });
|
|
67
|
+
const scale = decimalPlaces;
|
|
68
|
+
const multiplierAmount = Math.round(factor * Math.pow(10, scale));
|
|
69
|
+
return (0, dinero_js_1.multiply)(a, { amount: multiplierAmount, scale: scale + 2 });
|
|
57
70
|
};
|
|
58
71
|
exports.multiplyMoney = multiplyMoney;
|
|
59
72
|
function getDecimalPlaces(num) {
|
|
60
73
|
const str = num.toString();
|
|
74
|
+
// Handle exponential notation (e.g., 1e-7)
|
|
75
|
+
if (str.includes("e-")) {
|
|
76
|
+
const [, exp] = str.split("e-");
|
|
77
|
+
return parseInt(exp, 10);
|
|
78
|
+
}
|
|
61
79
|
const decimalIndex = str.indexOf(".");
|
|
62
80
|
if (decimalIndex === -1)
|
|
63
81
|
return 0;
|