@wtree/payload-ecommerce-coupon 3.79.3 → 3.79.5

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,15 +1,13 @@
1
1
  import { type CollectionConfig } from 'payload';
2
2
  import type { SanitizedCouponPluginOptions } from '../types';
3
3
  /**
4
- * Scaling policy:
5
- * - Admin inputs normal currency values (e.g. 100 means $100).
6
- * - Internally, maxPartnerCommissionPerOrder, maxCustomerDiscountPerOrder, and
7
- * minOrderAmount are stored in x100 (integer cents) form to avoid floating-point
8
- * drift on monetary cap fields.
9
- * - beforeChange → multiply by 100 before persisting.
10
- * - afterRead → divide by 100 before returning to admin / calculation code.
11
- * - partnerAmount / customerAmount per-rule fixed amounts are NOT scaled here;
12
- * they represent per-item fixed currency amounts and are stored as-is.
4
+ * Monetary policy:
5
+ * - Admin enters normal currency (e.g. 100 means AED 100).
6
+ * - Top-level caps and min order (maxPartnerCommissionPerOrder,
7
+ * maxCustomerDiscountPerOrder, minOrderAmount) are persisted as normal currency;
8
+ * calculateValues converts to integer cents internally via toCents().
9
+ * - Per-rule fixed amounts (partnerAmount / customerAmount) map to partnerSplit /
10
+ * customerSplit and are stored as-is in major units.
13
11
  */
14
12
  export declare const createReferralProgramsCollection: (pluginConfig: SanitizedCouponPluginOptions) => CollectionConfig;
15
13
  //# sourceMappingURL=createReferralProgramsCollection.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createReferralProgramsCollection.d.ts","sourceRoot":"","sources":["../../src/collections/createReferralProgramsCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAEzD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAA;AAsB5D;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,gCAAgC,GAC3C,cAAc,4BAA4B,KACzC,gBA2aF,CAAA"}
1
+ {"version":3,"file":"createReferralProgramsCollection.d.ts","sourceRoot":"","sources":["../../src/collections/createReferralProgramsCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAEzD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAA;AAsB5D;;;;;;;;GAQG;AAEH,eAAO,MAAM,gCAAgC,GAC3C,cAAc,4BAA4B,KACzC,gBA2aF,CAAA"}
package/dist/index.js CHANGED
@@ -88,7 +88,7 @@ const createCouponsCollection = (pluginConfig) => {
88
88
  type: "number",
89
89
  required: true,
90
90
  admin: {
91
- description: `If percentage, 10 means 10% (must be 0–100). If fixed, amount in ${defaultCurrency} with up to 2 decimal places (e.g. 10.99).`,
91
+ description: `Percentage: use 10 for 10%, or a decimal between 0 and 1 for a fraction of the cart (0.1 = 10%, 0.01 = 1%). Values from 1 upward are percent points (1 = 1%, 100 = 100%). Fixed: amount in ${defaultCurrency} (e.g. 10.99).`,
92
92
  step: .01
93
93
  }
94
94
  },
@@ -432,15 +432,13 @@ function toNumber(value) {
432
432
  return typeof value === "number" && Number.isFinite(value) ? value : null;
433
433
  }
434
434
  /**
435
- * Scaling policy:
436
- * - Admin inputs normal currency values (e.g. 100 means $100).
437
- * - Internally, maxPartnerCommissionPerOrder, maxCustomerDiscountPerOrder, and
438
- * minOrderAmount are stored in x100 (integer cents) form to avoid floating-point
439
- * drift on monetary cap fields.
440
- * - beforeChange → multiply by 100 before persisting.
441
- * - afterRead → divide by 100 before returning to admin / calculation code.
442
- * - partnerAmount / customerAmount per-rule fixed amounts are NOT scaled here;
443
- * they represent per-item fixed currency amounts and are stored as-is.
435
+ * Monetary policy:
436
+ * - Admin enters normal currency (e.g. 100 means AED 100).
437
+ * - Top-level caps and min order (maxPartnerCommissionPerOrder,
438
+ * maxCustomerDiscountPerOrder, minOrderAmount) are persisted as normal currency;
439
+ * calculateValues converts to integer cents internally via toCents().
440
+ * - Per-rule fixed amounts (partnerAmount / customerAmount) map to partnerSplit /
441
+ * customerSplit and are stored as-is in major units.
444
442
  */
445
443
  const createReferralProgramsCollection = (pluginConfig) => {
446
444
  const { collections, access, adminGroups, referralConfig, integration } = pluginConfig;
@@ -771,7 +769,9 @@ function calculateCouponDiscount({ coupon, cartTotal }) {
771
769
  const cartCents = toCents(cartTotal);
772
770
  let discountCents = 0;
773
771
  if (coupon.type === "percentage") {
774
- discountCents = Math.floor(cartCents * coupon.value / 100);
772
+ const v = coupon.value;
773
+ if (typeof v === "number" && v > 0 && v < 1) discountCents = Math.floor(cartCents * v);
774
+ else discountCents = Math.floor(cartCents * v / 100);
775
775
  if (coupon.maxDiscountAmount != null) {
776
776
  const maxCents = toCents(coupon.maxDiscountAmount);
777
777
  if (discountCents > maxCents) discountCents = maxCents;