@managesome/eposmatic-toolkit 0.2.576 → 0.2.577
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/lib/constants/ENUMS.js
CHANGED
|
@@ -258,7 +258,7 @@ var PAYMENT_TYPE_ENUM;
|
|
|
258
258
|
exports.ALL_PAYMENT_TYPE_NAMES = Object.values(PAYMENT_TYPE_ENUM);
|
|
259
259
|
exports.PaymentTypeDescriptions = {
|
|
260
260
|
[PAYMENT_TYPE_ENUM.UNPAID]: 'Payment pending ❗',
|
|
261
|
-
[PAYMENT_TYPE_ENUM.PAY_LATER]: '
|
|
261
|
+
[PAYMENT_TYPE_ENUM.PAY_LATER]: 'Credit Bill 🕒',
|
|
262
262
|
[PAYMENT_TYPE_ENUM.CASH]: 'Pay with physical cash 💵',
|
|
263
263
|
[PAYMENT_TYPE_ENUM.CARD]: 'Pay using credit/debit card 💳',
|
|
264
264
|
[PAYMENT_TYPE_ENUM.JAZZCASH_PAY]: 'Pay using JazzCash mobile wallet 📱',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PAYMENT_EXTENSION_ENUM, PAYMENT_TYPE_ENUM } from '../../constants';
|
|
2
2
|
import { IOrderPayment } from '../../schemas';
|
|
3
|
-
export declare function getPaymentAmountPayed(payment: IOrderPayment,
|
|
3
|
+
export declare function getPaymentAmountPayed(payment: IOrderPayment, allowCreditPayments?: boolean): {
|
|
4
4
|
amountPaid: number;
|
|
5
5
|
changeAmount: number;
|
|
6
6
|
amountRefunded: number;
|
|
@@ -16,13 +16,13 @@ export declare function getOrderPaymentsDetails(grand_total: number | undefined,
|
|
|
16
16
|
existingPayments: IOrderPayment[];
|
|
17
17
|
};
|
|
18
18
|
export declare function getTotalCardCharges(payments: IOrderPayment[] | undefined): number;
|
|
19
|
-
export declare function getPaymentTypeTotalAmount(payments: IOrderPayment[] | undefined, paymentType: PAYMENT_TYPE_ENUM | string,
|
|
19
|
+
export declare function getPaymentTypeTotalAmount(payments: IOrderPayment[] | undefined, paymentType: PAYMENT_TYPE_ENUM | string, allowCreditPayments?: boolean): number;
|
|
20
20
|
export declare function getCardChargesAndAmountCollected(payments: IOrderPayment[] | undefined): {
|
|
21
21
|
cardCharges: number;
|
|
22
22
|
amountCollected: number;
|
|
23
23
|
amountPaid: number;
|
|
24
24
|
};
|
|
25
|
-
export declare function isOrderFullyPaid(grandTotal: number, payments: IOrderPayment[] | undefined,
|
|
25
|
+
export declare function isOrderFullyPaid(grandTotal: number, payments: IOrderPayment[] | undefined, allowCreditPayments?: boolean): boolean;
|
|
26
26
|
export declare function syncPayments(payments: IOrderPayment[]): IOrderPayment[];
|
|
27
27
|
export declare function getSortedPayments(payments: IOrderPayment[]): IOrderPayment[];
|
|
28
28
|
export declare function checkIfPaymentIsSpecialType(paymentType: string): boolean;
|
|
@@ -19,12 +19,12 @@ exports.getPaymentSmartTitle = getPaymentSmartTitle;
|
|
|
19
19
|
const bson_objectid_1 = __importDefault(require("bson-objectid"));
|
|
20
20
|
const constants_1 = require("../../constants");
|
|
21
21
|
const common_1 = require("./common");
|
|
22
|
-
function getPaymentAmountPayed(payment,
|
|
22
|
+
function getPaymentAmountPayed(payment, allowCreditPayments) {
|
|
23
23
|
if (payment.payment_type !== constants_1.PAYMENT_TYPE_ENUM.UNPAID &&
|
|
24
|
-
(payment.payment_id !== null ||
|
|
24
|
+
(payment.payment_id !== null || allowCreditPayments) &&
|
|
25
25
|
(payment.payment_status === constants_1.PAYMENT_STATUS_ENUM.SETTLED ||
|
|
26
26
|
payment.payment_status === constants_1.PAYMENT_STATUS_ENUM.REFUNDED ||
|
|
27
|
-
(
|
|
27
|
+
(allowCreditPayments &&
|
|
28
28
|
payment.payment_type === constants_1.PAYMENT_TYPE_ENUM.PAY_LATER &&
|
|
29
29
|
payment.payment_status === constants_1.PAYMENT_STATUS_ENUM.PENDING))) {
|
|
30
30
|
const cardFee = payment.card_details?.card_charges ?? 0;
|
|
@@ -97,11 +97,11 @@ function getTotalCardCharges(payments) {
|
|
|
97
97
|
return acc + payment.card_details.card_charges;
|
|
98
98
|
}, 0) ?? 0);
|
|
99
99
|
}
|
|
100
|
-
function getPaymentTypeTotalAmount(payments, paymentType,
|
|
100
|
+
function getPaymentTypeTotalAmount(payments, paymentType, allowCreditPayments) {
|
|
101
101
|
return (payments?.reduce((acc, payment) => {
|
|
102
102
|
if (payment.payment_type !== paymentType)
|
|
103
103
|
return acc;
|
|
104
|
-
return acc + getPaymentAmountPayed(payment,
|
|
104
|
+
return acc + getPaymentAmountPayed(payment, allowCreditPayments).totalAmountPaid;
|
|
105
105
|
}, 0) ?? 0);
|
|
106
106
|
}
|
|
107
107
|
function getCardChargesAndAmountCollected(payments) {
|
|
@@ -136,9 +136,9 @@ function getCardChargesAndAmountCollected(payments) {
|
|
|
136
136
|
amountPaid,
|
|
137
137
|
};
|
|
138
138
|
}
|
|
139
|
-
function isOrderFullyPaid(grandTotal, payments,
|
|
139
|
+
function isOrderFullyPaid(grandTotal, payments, allowCreditPayments) {
|
|
140
140
|
const amountPaidSoFar = payments?.reduce((acc, payment) => {
|
|
141
|
-
const totalAmountPaid = getPaymentAmountPayed(payment,
|
|
141
|
+
const totalAmountPaid = getPaymentAmountPayed(payment, allowCreditPayments).totalAmountPaid;
|
|
142
142
|
return acc + totalAmountPaid;
|
|
143
143
|
}, 0) ?? 0;
|
|
144
144
|
return Number(amountPaidSoFar.toFixed(2)) >= (0, common_1.parseNum)(grandTotal);
|
|
@@ -295,7 +295,7 @@ function getPaymentSmartTitle(paymentType) {
|
|
|
295
295
|
const getQRCodePaymentLink = (grandTotal, payments) => {
|
|
296
296
|
if (!grandTotal || !payments)
|
|
297
297
|
return null;
|
|
298
|
-
const isFullyPaid = isOrderFullyPaid(grandTotal, payments);
|
|
298
|
+
const isFullyPaid = isOrderFullyPaid(grandTotal, payments, true);
|
|
299
299
|
if (isFullyPaid)
|
|
300
300
|
return null;
|
|
301
301
|
let qrLink = undefined;
|