@fire-spark/payments-cash 0.3.5 → 0.4.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.d.ts +1 -1
- package/dist/index.js +8 -6
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ type CashDetails = Extract<TenderDetails, {
|
|
|
9
9
|
method: "CASH";
|
|
10
10
|
}>;
|
|
11
11
|
/** `details` of a CASH tender; `tendered` below the amount is clamped. */
|
|
12
|
-
declare const cashDetails: (amount: number, tendered: number | null | undefined,
|
|
12
|
+
declare const cashDetails: (amount: number, tendered: number | null | undefined, _currency: string) => CashDetails;
|
|
13
13
|
type CashPaymentsOptions = {
|
|
14
14
|
/** Cash the customer hands over (e.g. typed by the cashier). */
|
|
15
15
|
tendered?: (ctx: PaymentContext) => number | null | Promise<number | null>;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { definePaymentErrors, money, moneyNumber } from "@fire-spark/payments";
|
|
2
2
|
//#region src/index.ts
|
|
3
3
|
/** Cash has no provider: nothing can fail remotely. */
|
|
4
4
|
const cashErrors = definePaymentErrors({});
|
|
@@ -8,13 +8,15 @@ const cashCapabilities = {
|
|
|
8
8
|
inPerson: true
|
|
9
9
|
};
|
|
10
10
|
/** `details` of a CASH tender; `tendered` below the amount is clamped. */
|
|
11
|
-
const cashDetails = (amount, tendered,
|
|
12
|
-
const
|
|
13
|
-
const
|
|
11
|
+
const cashDetails = (amount, tendered, _currency) => {
|
|
12
|
+
const due = money(amount);
|
|
13
|
+
const handed = money(tendered ?? amount);
|
|
14
|
+
const given = handed.lt(due) ? due : handed;
|
|
15
|
+
const change = moneyNumber(given.minus(due));
|
|
14
16
|
return {
|
|
15
17
|
method: "CASH",
|
|
16
|
-
tendered: given,
|
|
17
|
-
change
|
|
18
|
+
tendered: moneyNumber(given),
|
|
19
|
+
change
|
|
18
20
|
};
|
|
19
21
|
};
|
|
20
22
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fire-spark/payments-cash",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Fire Spark cash payments adapter (collected at the counter or the door)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@fire-spark/payments": "^0.
|
|
21
|
-
"@fire-spark/types": "^0.
|
|
20
|
+
"@fire-spark/payments": "^0.4.1",
|
|
21
|
+
"@fire-spark/types": "^0.4.1"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"tsdown": "^0.22.14",
|