@managesome/eposmatic-toolkit 0.2.226 → 0.2.227

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.
@@ -1,4 +1,4 @@
1
- import { PAYMENT_EXTENSION_ENUM } from '../../constants';
1
+ import { PAYMENT_EXTENSION_ENUM, PAYMENT_TYPE_ENUM } from '../../constants';
2
2
  import { IOrderPayment } from '../../schemas';
3
3
  export declare function getPaymentAmountPayed(payment: IOrderPayment, allowUnverifiedPayments?: boolean): {
4
4
  amountPaid: number;
@@ -16,6 +16,7 @@ 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, allowUnverifiedPayments?: boolean): number;
19
20
  export declare function getCardChargesAndAmountCollected(payments: IOrderPayment[] | undefined): {
20
21
  cardCharges: number;
21
22
  amountCollected: number;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getPaymentAmountPayed = getPaymentAmountPayed;
7
7
  exports.getOrderPaymentsDetails = getOrderPaymentsDetails;
8
8
  exports.getTotalCardCharges = getTotalCardCharges;
9
+ exports.getPaymentTypeTotalAmount = getPaymentTypeTotalAmount;
9
10
  exports.getCardChargesAndAmountCollected = getCardChargesAndAmountCollected;
10
11
  exports.isOrderFullyPaid = isOrderFullyPaid;
11
12
  exports.syncPayments = syncPayments;
@@ -95,6 +96,13 @@ function getTotalCardCharges(payments) {
95
96
  return acc + payment.card_details.card_charges;
96
97
  }, 0) ?? 0);
97
98
  }
99
+ function getPaymentTypeTotalAmount(payments, paymentType, allowUnverifiedPayments) {
100
+ return (payments?.reduce((acc, payment) => {
101
+ if (payment.payment_type !== paymentType)
102
+ return acc;
103
+ return acc + getPaymentAmountPayed(payment, allowUnverifiedPayments).totalAmountPaid;
104
+ }, 0) ?? 0);
105
+ }
98
106
  function getCardChargesAndAmountCollected(payments) {
99
107
  let cardCharges = 0;
100
108
  let amountCollected = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.2.226",
3
+ "version": "0.2.227",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",