sahab-utils 1.7.5 → 1.7.6

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.
Files changed (2) hide show
  1. package/dist/ts/calcs.js +6 -6
  2. package/package.json +1 -1
package/dist/ts/calcs.js CHANGED
@@ -184,15 +184,16 @@ function getOrderTotalDiscountsAmount(order) {
184
184
  return getSahabDiscountsAmount(order) + getProviderDiscountsAmount(order);
185
185
  }
186
186
  function getCustomerTotalToPay(order) {
187
- const sahabExtraPaymentAmount = (order === null || order === void 0 ? void 0 : order.paymentType) === types_1.OrderPaymentType.CASH ? (order === null || order === void 0 ? void 0 : order.sahabExtraPaymentAmount) || 0 : 0;
188
- const orderTotal = getServicesTotal(order) + sahabExtraPaymentAmount;
187
+ const orderTotal = getServicesTotal(order) + cashSurcharge(order);
189
188
  const discounts = getSahabDiscountsAmount(order) + getProviderDiscountsAmount(order);
190
189
  return orderTotal - discounts;
191
190
  }
192
- /** Sahab's cash surcharge on this order (zero for online orders). */
191
+ /** Sahab's cash surcharge on this order (zero for online orders). Clamped to non-negative — a
192
+ * negative surcharge would let a client undercut the real service total on a cash order, which
193
+ * isn't caught by a payment gateway the way an online charge is. */
193
194
  function cashSurcharge(order) {
194
195
  var _a;
195
- return (order === null || order === void 0 ? void 0 : order.paymentType) === types_1.OrderPaymentType.CASH ? (0, utils_1.preventNaN)((_a = order === null || order === void 0 ? void 0 : order.sahabExtraPaymentAmount) !== null && _a !== void 0 ? _a : 0) : 0;
196
+ return (order === null || order === void 0 ? void 0 : order.paymentType) === types_1.OrderPaymentType.CASH ? Math.max(0, (0, utils_1.preventNaN)((_a = order === null || order === void 0 ? void 0 : order.sahabExtraPaymentAmount) !== null && _a !== void 0 ? _a : 0)) : 0;
196
197
  }
197
198
  /** Cash `paymentAmount` includes Sahab's surcharge, which is Sahab's revenue not the provider's —
198
199
  * it must come off before comparing to `minimumProviderAmount`, or it's double-counted in getSahabFees/getProviderProfits. */
@@ -216,9 +217,8 @@ function getProviderTransferAmount(order) {
216
217
  }
217
218
  }
218
219
  function getProviderProfits(order) {
219
- const sahabExtraPaymentAmount = (order === null || order === void 0 ? void 0 : order.paymentType) === types_1.OrderPaymentType.CASH ? (order === null || order === void 0 ? void 0 : order.sahabExtraPaymentAmount) || 0 : 0;
220
220
  return (order === null || order === void 0 ? void 0 : order.paymentType) === types_1.OrderPaymentType.CASH
221
- ? getCustomerTotalToPay(order) - sahabExtraPaymentAmount + getProviderTransferAmount(order)
221
+ ? getCustomerTotalToPay(order) - cashSurcharge(order) + getProviderTransferAmount(order)
222
222
  : getProviderTransferAmount(order);
223
223
  }
224
224
  function getOnlineProcessingFees(order) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sahab-utils",
3
- "version": "1.7.5",
3
+ "version": "1.7.6",
4
4
  "description": "This package contains types and utils functions",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",