@fire-spark/payments 0.3.2 → 0.3.3

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 CHANGED
@@ -490,6 +490,25 @@ type RedemptionGroup = {
490
490
  amount: number;
491
491
  details: RedemptionDetails;
492
492
  };
493
+ /**
494
+ * Points / balance paid with a REDEMPTION tender, not a discount (D16):
495
+ * it never discounts lines nor has a `redemption_steps` entry.
496
+ */
497
+ declare const isPaymentRedeem: (redeem: {
498
+ payment_id?: string | null;
499
+ }) => boolean;
500
+ /** Discount redeems: the ones replayed into `redemption_steps`. */
501
+ declare const discountRedeems: <T extends {
502
+ payment_id?: string | null;
503
+ }>(redeem: readonly T[]) => T[];
504
+ /**
505
+ * Payment redeems pay the whole order, so no real tender is needed: the
506
+ * intent is only REDEMPTION tenders and the order advances on its own.
507
+ */
508
+ declare const paymentRedeemsCoverTotal: (redeem: readonly PaymentRedeemLike[], totals: {
509
+ total: number;
510
+ currency: string;
511
+ }) => boolean;
493
512
  /**
494
513
  * Groups payment redeems (`payment_id` set) into one entry per
495
514
  * `payment_id`, in first-appearance order. Discount redeems are skipped.
@@ -669,4 +688,4 @@ declare const scopedPaymentStorage: (storage: PaymentStorage, paymentId: string)
669
688
  /** For tests and web previews; apps provide AsyncStorage or localStorage. */
670
689
  declare const memoryPaymentStorage: () => PaymentStorage;
671
690
  //#endregion
672
- export { ACTIVE_INTENT_STATUSES, AllocateTenderInput, AllocateTendersInput, AllocateTendersResult, AllocatedTender, AllocationError, CURRENCY_DECIMALS, ChargeConversion, DEFAULT_PAYMENT_POLICY, DELIVERY_FEE_BASED_ON, DIGITAL_COLLECT_AT, type DeviceField, MergePaymentTenderOutcome, MergePaymentTenderResult, NEXT_STATUSES, PARTIAL_APPROVAL_ERROR, PAYMENT_ERROR_CODES, PAYMENT_ERROR_DEFAULTS, type PaymentAction, type PaymentAdapter, type PaymentAdapterCapabilities, type PaymentAmount, type PaymentCardType, type PaymentCollectAt, type PaymentContext, type PaymentCustomer, type PaymentEntryMode, type PaymentEnvironment, PaymentError, PaymentErrorCode, PaymentErrorDictionary, PaymentErrorEntry, PaymentErrorReason, type PaymentIntentStatus, type PaymentMetadata, type PaymentMetadataPayment, type PaymentOperation, type PaymentPolicy, PaymentRedeemLike, type PaymentResult, type PaymentReversal, type PaymentServer, type PaymentStorage, PaymentTenderUpdate, type PaymentUI, REDEMPTION_METHOD, RawPaymentError, RedemptionDetails, RedemptionGroup, RedemptionReward, RulesTender, StandardPaymentError, TERMINAL_TENDER_STATUSES, TIP_FEE_BASED_ON, type TaxBreakdown, TaxLine, type TerminalContext, type TerminalOperation, type TerminalOperations, type TerminalResult, ValidateTendersResult, activeIntent, allocateTenders, amountTolerance, batchCloseDay, countTenderItems, createAttemptReference, createPaymentError, currencyDecimals, currentIntent, defaultReversalFor, definePaymentErrors, derivePaymentStatus, formatPaymentError, groupPaymentRedeems, isBatchCloseDue, isDeliveryFee, isIntentCovered, isMixedTenders, isPaymentError, isRealPaymentMethod, isRedemptionReserved, isScopePaid, isTenderSettled, isTerminalLocked, isTipFee, liveRealTenders, liveTenders, memoryPaymentStorage, mergePaymentTender, missingDeviceFields, nextIntentStatus, primaryTender, primaryTenderOf, prorateMinor, realTenders, redemptionDetailsOf, redemptionRewardsOf, resolvePaymentPolicy, resolveProviderEnvironment, roundTo, scopedPaymentStorage, taxBreakdown, tendersCoverage, tendersInScope, toChargeAmount, toPaymentAmount, toPaymentError, validateTendersAgainstRules, withTerminalLock };
691
+ export { ACTIVE_INTENT_STATUSES, AllocateTenderInput, AllocateTendersInput, AllocateTendersResult, AllocatedTender, AllocationError, CURRENCY_DECIMALS, ChargeConversion, DEFAULT_PAYMENT_POLICY, DELIVERY_FEE_BASED_ON, DIGITAL_COLLECT_AT, type DeviceField, MergePaymentTenderOutcome, MergePaymentTenderResult, NEXT_STATUSES, PARTIAL_APPROVAL_ERROR, PAYMENT_ERROR_CODES, PAYMENT_ERROR_DEFAULTS, type PaymentAction, type PaymentAdapter, type PaymentAdapterCapabilities, type PaymentAmount, type PaymentCardType, type PaymentCollectAt, type PaymentContext, type PaymentCustomer, type PaymentEntryMode, type PaymentEnvironment, PaymentError, PaymentErrorCode, PaymentErrorDictionary, PaymentErrorEntry, PaymentErrorReason, type PaymentIntentStatus, type PaymentMetadata, type PaymentMetadataPayment, type PaymentOperation, type PaymentPolicy, PaymentRedeemLike, type PaymentResult, type PaymentReversal, type PaymentServer, type PaymentStorage, PaymentTenderUpdate, type PaymentUI, REDEMPTION_METHOD, RawPaymentError, RedemptionDetails, RedemptionGroup, RedemptionReward, RulesTender, StandardPaymentError, TERMINAL_TENDER_STATUSES, TIP_FEE_BASED_ON, type TaxBreakdown, TaxLine, type TerminalContext, type TerminalOperation, type TerminalOperations, type TerminalResult, ValidateTendersResult, activeIntent, allocateTenders, amountTolerance, batchCloseDay, countTenderItems, createAttemptReference, createPaymentError, currencyDecimals, currentIntent, defaultReversalFor, definePaymentErrors, derivePaymentStatus, discountRedeems, formatPaymentError, groupPaymentRedeems, isBatchCloseDue, isDeliveryFee, isIntentCovered, isMixedTenders, isPaymentError, isPaymentRedeem, isRealPaymentMethod, isRedemptionReserved, isScopePaid, isTenderSettled, isTerminalLocked, isTipFee, liveRealTenders, liveTenders, memoryPaymentStorage, mergePaymentTender, missingDeviceFields, nextIntentStatus, paymentRedeemsCoverTotal, primaryTender, primaryTenderOf, prorateMinor, realTenders, redemptionDetailsOf, redemptionRewardsOf, resolvePaymentPolicy, resolveProviderEnvironment, roundTo, scopedPaymentStorage, taxBreakdown, tendersCoverage, tendersInScope, toChargeAmount, toPaymentAmount, toPaymentError, validateTendersAgainstRules, withTerminalLock };
package/dist/index.js CHANGED
@@ -1173,6 +1173,29 @@ const batchCloseDay = (now) => localDay(now);
1173
1173
  //#region src/redemptions.ts
1174
1174
  const SUM_DECIMALS = 6;
1175
1175
  const add = (a, b) => roundTo(a + b, SUM_DECIMALS);
1176
+ /**
1177
+ * Points / balance paid with a REDEMPTION tender, not a discount (D16):
1178
+ * it never discounts lines nor has a `redemption_steps` entry.
1179
+ */
1180
+ const isPaymentRedeem = (redeem) => {
1181
+ return Boolean(redeem.payment_id);
1182
+ };
1183
+ /** Discount redeems: the ones replayed into `redemption_steps`. */
1184
+ const discountRedeems = (redeem) => {
1185
+ return redeem.filter((item) => !isPaymentRedeem(item));
1186
+ };
1187
+ /**
1188
+ * Payment redeems pay the whole order, so no real tender is needed: the
1189
+ * intent is only REDEMPTION tenders and the order advances on its own.
1190
+ */
1191
+ const paymentRedeemsCoverTotal = (redeem, totals) => {
1192
+ const decimals = currencyDecimals(totals.currency);
1193
+ const paid = redeem.reduce((sum, item) => {
1194
+ return isPaymentRedeem(item) ? add(sum, item.amount ?? 0) : sum;
1195
+ }, 0);
1196
+ if (paid <= 0) return false;
1197
+ return roundTo(paid, decimals) >= roundTo(totals.total, decimals);
1198
+ };
1176
1199
  const rewardOf = (redeem) => {
1177
1200
  const r1 = {
1178
1201
  reward_id: redeem.reward_id,
@@ -1209,10 +1232,11 @@ const detailsOf = (rewards, program, loyalty_transaction_id) => {
1209
1232
  const groupPaymentRedeems = (redeem) => {
1210
1233
  const groups = /* @__PURE__ */ new Map();
1211
1234
  for (const item of redeem) {
1212
- if (!item.payment_id) continue;
1213
- const list = groups.get(item.payment_id) ?? [];
1235
+ if (!isPaymentRedeem(item)) continue;
1236
+ const payment_id = item.payment_id;
1237
+ const list = groups.get(payment_id) ?? [];
1214
1238
  list.push(item);
1215
- groups.set(item.payment_id, list);
1239
+ groups.set(payment_id, list);
1216
1240
  }
1217
1241
  return [...groups].map(([payment_id, items]) => {
1218
1242
  const program = items.find((item) => item.program)?.program;
@@ -1351,4 +1375,4 @@ const memoryPaymentStorage = () => {
1351
1375
  };
1352
1376
  };
1353
1377
  //#endregion
1354
- export { ACTIVE_INTENT_STATUSES, CURRENCY_DECIMALS, DEFAULT_PAYMENT_POLICY, DELIVERY_FEE_BASED_ON, DIGITAL_COLLECT_AT, NEXT_STATUSES, PARTIAL_APPROVAL_ERROR, PAYMENT_ERROR_CODES, PAYMENT_ERROR_DEFAULTS, PaymentError, REDEMPTION_METHOD, TERMINAL_TENDER_STATUSES, TIP_FEE_BASED_ON, activeIntent, allocateTenders, amountTolerance, batchCloseDay, countTenderItems, createAttemptReference, createPaymentError, currencyDecimals, currentIntent, defaultReversalFor, definePaymentErrors, derivePaymentStatus, formatPaymentError, groupPaymentRedeems, isBatchCloseDue, isDeliveryFee, isIntentCovered, isMixedTenders, isPaymentError, isRealPaymentMethod, isRedemptionReserved, isScopePaid, isTenderSettled, isTerminalLocked, isTipFee, liveRealTenders, liveTenders, memoryPaymentStorage, mergePaymentTender, missingDeviceFields, nextIntentStatus, primaryTender, primaryTenderOf, prorateMinor, realTenders, redemptionDetailsOf, redemptionRewardsOf, resolvePaymentPolicy, resolveProviderEnvironment, roundTo, scopedPaymentStorage, taxBreakdown, tendersCoverage, tendersInScope, toChargeAmount, toPaymentAmount, toPaymentError, validateTendersAgainstRules, withTerminalLock };
1378
+ export { ACTIVE_INTENT_STATUSES, CURRENCY_DECIMALS, DEFAULT_PAYMENT_POLICY, DELIVERY_FEE_BASED_ON, DIGITAL_COLLECT_AT, NEXT_STATUSES, PARTIAL_APPROVAL_ERROR, PAYMENT_ERROR_CODES, PAYMENT_ERROR_DEFAULTS, PaymentError, REDEMPTION_METHOD, TERMINAL_TENDER_STATUSES, TIP_FEE_BASED_ON, activeIntent, allocateTenders, amountTolerance, batchCloseDay, countTenderItems, createAttemptReference, createPaymentError, currencyDecimals, currentIntent, defaultReversalFor, definePaymentErrors, derivePaymentStatus, discountRedeems, formatPaymentError, groupPaymentRedeems, isBatchCloseDue, isDeliveryFee, isIntentCovered, isMixedTenders, isPaymentError, isPaymentRedeem, isRealPaymentMethod, isRedemptionReserved, isScopePaid, isTenderSettled, isTerminalLocked, isTipFee, liveRealTenders, liveTenders, memoryPaymentStorage, mergePaymentTender, missingDeviceFields, nextIntentStatus, paymentRedeemsCoverTotal, primaryTender, primaryTenderOf, prorateMinor, realTenders, redemptionDetailsOf, redemptionRewardsOf, resolvePaymentPolicy, resolveProviderEnvironment, roundTo, scopedPaymentStorage, taxBreakdown, tendersCoverage, tendersInScope, toChargeAmount, toPaymentAmount, toPaymentError, validateTendersAgainstRules, withTerminalLock };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fire-spark/payments",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Fire Spark payments contract: adapters, errors, amounts and policy",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -17,7 +17,7 @@
17
17
  }
18
18
  },
19
19
  "dependencies": {
20
- "@fire-spark/types": "^0.3.2"
20
+ "@fire-spark/types": "^0.3.3"
21
21
  },
22
22
  "devDependencies": {
23
23
  "tsdown": "^0.22.14",