@wtree/payload-ecommerce-coupon 3.78.0 → 3.78.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/README.md +33 -6
- package/dist/client/hooks.d.ts +1 -1
- package/dist/client/hooks.d.ts.map +1 -1
- package/dist/client/index.d.ts +8 -8
- package/dist/client/index.d.ts.map +1 -1
- package/dist/collections/createCouponsCollection.d.ts +2 -2
- package/dist/collections/createCouponsCollection.d.ts.map +1 -1
- package/dist/collections/createReferralCodesCollection.d.ts +2 -2
- package/dist/collections/createReferralCodesCollection.d.ts.map +1 -1
- package/dist/collections/createReferralProgramsCollection.d.ts +2 -2
- package/dist/collections/createReferralProgramsCollection.d.ts.map +1 -1
- package/dist/components/PartnerDashboard/CommissionBreakdown.d.ts +2 -2
- package/dist/components/PartnerDashboard/CommissionBreakdown.d.ts.map +1 -1
- package/dist/components/PartnerDashboard/EarningsSummary.d.ts +2 -2
- package/dist/components/PartnerDashboard/EarningsSummary.d.ts.map +1 -1
- package/dist/components/PartnerDashboard/ProgramOverview.d.ts +3 -3
- package/dist/components/PartnerDashboard/ProgramOverview.d.ts.map +1 -1
- package/dist/components/PartnerDashboard/RecentReferrals.d.ts +3 -3
- package/dist/components/PartnerDashboard/RecentReferrals.d.ts.map +1 -1
- package/dist/components/PartnerDashboard/ReferralCodes.d.ts +3 -3
- package/dist/components/PartnerDashboard/ReferralCodes.d.ts.map +1 -1
- package/dist/components/PartnerDashboard/ReferralPerformance.d.ts +2 -2
- package/dist/components/PartnerDashboard/ReferralPerformance.d.ts.map +1 -1
- package/dist/components/PartnerDashboard/index.d.ts +1 -1
- package/dist/components/PartnerDashboard/index.d.ts.map +1 -1
- package/dist/endpoints/applyCoupon.d.ts +2 -2
- package/dist/endpoints/applyCoupon.d.ts.map +1 -1
- package/dist/endpoints/partnerStats.d.ts +2 -2
- package/dist/endpoints/partnerStats.d.ts.map +1 -1
- package/dist/endpoints/validateCoupon.d.ts +2 -2
- package/dist/endpoints/validateCoupon.d.ts.map +1 -1
- package/dist/hooks/recalculateCart.d.ts +2 -2
- package/dist/hooks/recalculateCart.d.ts.map +1 -1
- package/dist/index.d.ts +17 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -45
- package/dist/index.mjs.map +1 -1
- package/dist/plugin.d.ts +2 -2
- package/dist/plugin.d.ts.map +1 -1
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/utilities/calculateValues.d.ts +2 -2
- package/dist/utilities/calculateValues.d.ts.map +1 -1
- package/dist/utilities/getCartTotalWithDiscounts.d.ts.map +1 -1
- package/dist/utilities/migrateReferralRulesV2.d.ts.map +1 -1
- package/dist/utilities/pricing.d.ts.map +1 -1
- package/dist/utilities/pushTypeScriptProperties.d.ts +1 -1
- package/dist/utilities/pushTypeScriptProperties.d.ts.map +1 -1
- package/dist/utilities/recordCouponUsageForOrder.d.ts +2 -2
- package/dist/utilities/recordCouponUsageForOrder.d.ts.map +1 -1
- package/dist/utilities/sanitizePluginConfig.d.ts +1 -1
- package/dist/utilities/sanitizePluginConfig.d.ts.map +1 -1
- package/dist/utilities/userRoles.d.ts +3 -3
- package/dist/utilities/userRoles.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -362,10 +362,28 @@ type CouponPluginOptions = {
|
|
|
362
362
|
|
|
363
363
|
// Preferred policy-first API
|
|
364
364
|
policies?: {
|
|
365
|
-
canApplyCoupon?: (ctx: {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
365
|
+
canApplyCoupon?: (ctx: {
|
|
366
|
+
req: unknown
|
|
367
|
+
user?: unknown
|
|
368
|
+
payload?: unknown
|
|
369
|
+
}) => boolean | Promise<boolean>
|
|
370
|
+
canApplyReferral?: (ctx: {
|
|
371
|
+
req: unknown
|
|
372
|
+
user?: unknown
|
|
373
|
+
payload?: unknown
|
|
374
|
+
}) => boolean | Promise<boolean>
|
|
375
|
+
canViewPartnerStats?: (ctx: {
|
|
376
|
+
req: unknown
|
|
377
|
+
user?: unknown
|
|
378
|
+
payload?: unknown
|
|
379
|
+
requestedPartnerID?: string | number
|
|
380
|
+
}) => boolean | Promise<boolean>
|
|
381
|
+
canRecordOrderUsage?: (ctx: {
|
|
382
|
+
req: unknown
|
|
383
|
+
user?: unknown
|
|
384
|
+
payload?: unknown
|
|
385
|
+
order: unknown
|
|
386
|
+
}) => boolean | Promise<boolean>
|
|
369
387
|
}
|
|
370
388
|
|
|
371
389
|
// Integration-driven mapping
|
|
@@ -404,7 +422,12 @@ type CouponPluginOptions = {
|
|
|
404
422
|
getCartSubtotal?: (cart: unknown) => number
|
|
405
423
|
getCartTotal?: (cart: unknown) => number
|
|
406
424
|
isOrderPaid?: (order: unknown) => boolean
|
|
407
|
-
getProductUnitPrice?: (args: {
|
|
425
|
+
getProductUnitPrice?: (args: {
|
|
426
|
+
item: unknown
|
|
427
|
+
product: unknown
|
|
428
|
+
variant?: unknown
|
|
429
|
+
currencyCode?: string
|
|
430
|
+
}) => number
|
|
408
431
|
}
|
|
409
432
|
}
|
|
410
433
|
|
|
@@ -448,6 +471,7 @@ If you’re upgrading from older configs:
|
|
|
448
471
|
## Troubleshooting
|
|
449
472
|
|
|
450
473
|
### Build/lint mismatch after changes
|
|
474
|
+
|
|
451
475
|
Run:
|
|
452
476
|
|
|
453
477
|
```bash
|
|
@@ -457,12 +481,15 @@ bun test --runInBand
|
|
|
457
481
|
```
|
|
458
482
|
|
|
459
483
|
### Code applies but usage not incrementing
|
|
484
|
+
|
|
460
485
|
Expected behavior until order completion. Call record-order-usage on paid/completed order.
|
|
461
486
|
|
|
462
487
|
### Partner stats forbidden
|
|
488
|
+
|
|
463
489
|
Adjust `policies.canViewPartnerStats` to match your auth model.
|
|
464
490
|
|
|
465
491
|
### Per-customer limit not enforced
|
|
492
|
+
|
|
466
493
|
Pass `customerEmail` on validate/apply for coupons that define per-customer limits, and ensure order integration fields map to your schema.
|
|
467
494
|
|
|
468
495
|
---
|
|
@@ -493,4 +520,4 @@ Main exports include:
|
|
|
493
520
|
|
|
494
521
|
## License
|
|
495
522
|
|
|
496
|
-
MIT
|
|
523
|
+
MIT
|
package/dist/client/hooks.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/client/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/client/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAE1F,KAAK,aAAa,GACd,MAAM,GACN;IACE,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAoCL;;;;GAIG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,eAAe,EACxB,cAAc,CAAC,EAAE,aAAa,GAC7B,OAAO,CAAC,mBAAmB,CAAC,CAyD9B;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,EACZ,SAAS,CAAC,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,EACf,aAAa,CAAC,EAAE,MAAM,EACtB,cAAc,CAAC,EAAE,aAAa,GAC7B,OAAO,CAAC,mBAAmB,CAAC,CAuD9B;AAED,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,CAAC,EAAE,oBAAoB,CAAA;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACnC,cAAc,CAAC,EAAE,aAAa,GAC7B,OAAO,CAAC,oBAAoB,CAAC,CA4B/B"}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { PartnerDashboard } from
|
|
2
|
-
export { EarningsSummary } from
|
|
3
|
-
export { RecentReferrals } from
|
|
4
|
-
export { ReferralCodes } from
|
|
5
|
-
export { ReferralPerformance } from
|
|
6
|
-
export { ProgramOverview } from
|
|
7
|
-
export { CommissionBreakdown } from
|
|
8
|
-
export { useCouponCode, usePartnerStats, validateCouponCode } from
|
|
1
|
+
export { PartnerDashboard } from '../components/PartnerDashboard';
|
|
2
|
+
export { EarningsSummary } from '../components/PartnerDashboard/EarningsSummary';
|
|
3
|
+
export { RecentReferrals } from '../components/PartnerDashboard/RecentReferrals';
|
|
4
|
+
export { ReferralCodes } from '../components/PartnerDashboard/ReferralCodes';
|
|
5
|
+
export { ReferralPerformance } from '../components/PartnerDashboard/ReferralPerformance';
|
|
6
|
+
export { ProgramOverview } from '../components/PartnerDashboard/ProgramOverview';
|
|
7
|
+
export { CommissionBreakdown } from '../components/PartnerDashboard/CommissionBreakdown';
|
|
8
|
+
export { useCouponCode, usePartnerStats, validateCouponCode } from './hooks';
|
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAA;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAA;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAA;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oDAAoD,CAAA;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAA;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,oDAAoD,CAAA;AACxF,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CollectionConfig } from
|
|
2
|
-
import type { SanitizedCouponPluginOptions } from
|
|
1
|
+
import type { CollectionConfig } from 'payload';
|
|
2
|
+
import type { SanitizedCouponPluginOptions } from '../types';
|
|
3
3
|
export declare const createCouponsCollection: (pluginConfig: SanitizedCouponPluginOptions) => CollectionConfig;
|
|
4
4
|
//# sourceMappingURL=createCouponsCollection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCouponsCollection.d.ts","sourceRoot":"","sources":["../../src/collections/createCouponsCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"createCouponsCollection.d.ts","sourceRoot":"","sources":["../../src/collections/createCouponsCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAA;AAE5D,eAAO,MAAM,uBAAuB,GAClC,cAAc,4BAA4B,KACzC,gBAmKF,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CollectionConfig } from
|
|
2
|
-
import type { SanitizedCouponPluginOptions } from
|
|
1
|
+
import type { CollectionConfig } from 'payload';
|
|
2
|
+
import type { SanitizedCouponPluginOptions } from '../types';
|
|
3
3
|
export declare const createReferralCodesCollection: (pluginConfig: SanitizedCouponPluginOptions) => CollectionConfig;
|
|
4
4
|
//# sourceMappingURL=createReferralCodesCollection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createReferralCodesCollection.d.ts","sourceRoot":"","sources":["../../src/collections/createReferralCodesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"createReferralCodesCollection.d.ts","sourceRoot":"","sources":["../../src/collections/createReferralCodesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAA;AAM5D,eAAO,MAAM,6BAA6B,GACxC,cAAc,4BAA4B,KACzC,gBA+PF,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { SanitizedCouponPluginOptions } from
|
|
1
|
+
import { type CollectionConfig } from 'payload';
|
|
2
|
+
import type { SanitizedCouponPluginOptions } from '../types';
|
|
3
3
|
export declare const createReferralProgramsCollection: (pluginConfig: SanitizedCouponPluginOptions) => CollectionConfig;
|
|
4
4
|
//# sourceMappingURL=createReferralProgramsCollection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createReferralProgramsCollection.d.ts","sourceRoot":"","sources":["../../src/collections/createReferralProgramsCollection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
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;AA0B5D,eAAO,MAAM,gCAAgC,GAC3C,cAAc,4BAA4B,KACzC,gBAwZF,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommissionBreakdown.d.ts","sourceRoot":"","sources":["../../../src/components/PartnerDashboard/CommissionBreakdown.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"CommissionBreakdown.d.ts","sourceRoot":"","sources":["../../../src/components/PartnerDashboard/CommissionBreakdown.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,EAAE,YAAY,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAeD,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,CA0FlE,CAAA;AAED,eAAe,mBAAmB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EarningsSummary.d.ts","sourceRoot":"","sources":["../../../src/components/PartnerDashboard/EarningsSummary.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"EarningsSummary.d.ts","sourceRoot":"","sources":["../../../src/components/PartnerDashboard/EarningsSummary.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,YAAY,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAUD,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CA4B1D,CAAA;AAED,eAAe,eAAe,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import type { PartnerDashboardData } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { PartnerDashboardData } from '../../types';
|
|
3
3
|
export type ProgramOverviewProps = {
|
|
4
|
-
program: PartnerDashboardData[
|
|
4
|
+
program: PartnerDashboardData['program'];
|
|
5
5
|
};
|
|
6
6
|
export declare const ProgramOverview: React.FC<ProgramOverviewProps>;
|
|
7
7
|
export default ProgramOverview;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProgramOverview.d.ts","sourceRoot":"","sources":["../../../src/components/PartnerDashboard/ProgramOverview.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"ProgramOverview.d.ts","sourceRoot":"","sources":["../../../src/components/PartnerDashboard/ProgramOverview.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAEvD,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAA;CACzC,CAAA;AAED,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAmC1D,CAAA;AAED,eAAe,eAAe,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import type { PartnerStats } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { PartnerStats } from '../../types';
|
|
3
3
|
export type RecentReferralsProps = {
|
|
4
|
-
referrals: PartnerStats[
|
|
4
|
+
referrals: PartnerStats['recentReferrals'];
|
|
5
5
|
currency: string;
|
|
6
6
|
};
|
|
7
7
|
export declare const RecentReferrals: React.FC<RecentReferralsProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RecentReferrals.d.ts","sourceRoot":"","sources":["../../../src/components/PartnerDashboard/RecentReferrals.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"RecentReferrals.d.ts","sourceRoot":"","sources":["../../../src/components/PartnerDashboard/RecentReferrals.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,EAAE,YAAY,CAAC,iBAAiB,CAAC,CAAA;IAC1C,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAkBD,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAoC1D,CAAA;AAED,eAAe,eAAe,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import type { PartnerDashboardData } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { PartnerDashboardData } from '../../types';
|
|
3
3
|
export type ReferralCodesProps = {
|
|
4
|
-
codes: PartnerDashboardData[
|
|
4
|
+
codes: PartnerDashboardData['referralCodes'];
|
|
5
5
|
currency: string;
|
|
6
6
|
};
|
|
7
7
|
export declare const ReferralCodes: React.FC<ReferralCodesProps>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReferralCodes.d.ts","sourceRoot":"","sources":["../../../src/components/PartnerDashboard/ReferralCodes.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAmB,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"ReferralCodes.d.ts","sourceRoot":"","sources":["../../../src/components/PartnerDashboard/ReferralCodes.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAEvC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAEvD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,oBAAoB,CAAC,eAAe,CAAC,CAAA;IAC5C,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAUD,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CA+DtD,CAAA;AAED,eAAe,aAAa,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReferralPerformance.d.ts","sourceRoot":"","sources":["../../../src/components/PartnerDashboard/ReferralPerformance.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"ReferralPerformance.d.ts","sourceRoot":"","sources":["../../../src/components/PartnerDashboard/ReferralPerformance.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,EAAE,YAAY,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,CA6ClE,CAAA;AAED,eAAe,mBAAmB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PartnerDashboard/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA8B,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PartnerDashboard/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA8B,MAAM,OAAO,CAAA;AAWlD,MAAM,MAAM,qBAAqB,GAAG;IAClC,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,uBAAuB,CAAC,EAAE,OAAO,CAAA;IACjC,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,uBAAuB,CAAC,EAAE,OAAO,CAAA;IACjC,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CA2H5D,CAAA;AAED,eAAe,gBAAgB,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Endpoint, PayloadHandler } from
|
|
2
|
-
import type { SanitizedCouponPluginOptions } from
|
|
1
|
+
import type { Endpoint, PayloadHandler } from 'payload';
|
|
2
|
+
import type { SanitizedCouponPluginOptions } from '../types';
|
|
3
3
|
type Args = {
|
|
4
4
|
pluginConfig: SanitizedCouponPluginOptions;
|
|
5
5
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyCoupon.d.ts","sourceRoot":"","sources":["../../src/endpoints/applyCoupon.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"applyCoupon.d.ts","sourceRoot":"","sources":["../../src/endpoints/applyCoupon.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACvD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAA;AAQ5D,KAAK,IAAI,GAAG;IACV,YAAY,EAAE,4BAA4B,CAAA;CAC3C,CAAA;AA4ED,eAAO,MAAM,kBAAkB,GAC5B,kBAAkB,IAAI,KAAG,cA8GzB,CAAA;AAsQH,eAAO,MAAM,mBAAmB,GAAI,kBAAkB,IAAI,KAAG,QAI3D,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Endpoint, PayloadHandler } from
|
|
2
|
-
import type { SanitizedCouponPluginOptions } from
|
|
1
|
+
import type { Endpoint, PayloadHandler } from 'payload';
|
|
2
|
+
import type { SanitizedCouponPluginOptions } from '../types';
|
|
3
3
|
type Args = {
|
|
4
4
|
pluginConfig: SanitizedCouponPluginOptions;
|
|
5
5
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"partnerStats.d.ts","sourceRoot":"","sources":["../../src/endpoints/partnerStats.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"partnerStats.d.ts","sourceRoot":"","sources":["../../src/endpoints/partnerStats.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAEvD,OAAO,KAAK,EAAsC,4BAA4B,EAAE,MAAM,UAAU,CAAA;AAGhG,KAAK,IAAI,GAAG;IACV,YAAY,EAAE,4BAA4B,CAAA;CAC3C,CAAA;AAgCD,eAAO,MAAM,mBAAmB,GAC7B,kBAAkB,IAAI,KAAG,cA0MzB,CAAA;AAEH,eAAO,MAAM,oBAAoB,GAAI,kBAAkB,IAAI,KAAG,QAI5D,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Endpoint, PayloadHandler } from
|
|
2
|
-
import type { SanitizedCouponPluginOptions } from
|
|
1
|
+
import type { Endpoint, PayloadHandler } from 'payload';
|
|
2
|
+
import type { SanitizedCouponPluginOptions } from '../types';
|
|
3
3
|
type Args = {
|
|
4
4
|
pluginConfig: SanitizedCouponPluginOptions;
|
|
5
5
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateCoupon.d.ts","sourceRoot":"","sources":["../../src/endpoints/validateCoupon.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"validateCoupon.d.ts","sourceRoot":"","sources":["../../src/endpoints/validateCoupon.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAEvD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAA;AAO5D,KAAK,IAAI,GAAG;IACV,YAAY,EAAE,4BAA4B,CAAA;CAC3C,CAAA;AAmED,eAAO,MAAM,qBAAqB,GAC/B,kBAAkB,IAAI,KAAG,cA0DzB,CAAA;AAwOH,eAAO,MAAM,sBAAsB,GAAI,kBAAkB,IAAI,KAAG,QAI9D,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CollectionBeforeChangeHook } from
|
|
2
|
-
import type { SanitizedCouponPluginOptions } from
|
|
1
|
+
import type { CollectionBeforeChangeHook } from 'payload';
|
|
2
|
+
import type { SanitizedCouponPluginOptions } from '../types';
|
|
3
3
|
export declare const recalculateCartHook: (pluginConfig: SanitizedCouponPluginOptions) => CollectionBeforeChangeHook;
|
|
4
4
|
//# sourceMappingURL=recalculateCart.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recalculateCart.d.ts","sourceRoot":"","sources":["../../src/hooks/recalculateCart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,
|
|
1
|
+
{"version":3,"file":"recalculateCart.d.ts","sourceRoot":"","sources":["../../src/hooks/recalculateCart.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AACzD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAA;AA6C5D,eAAO,MAAM,mBAAmB,GAC7B,cAAc,4BAA4B,KAAG,0BA4Q7C,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { createCouponsCollection } from
|
|
2
|
-
import { createReferralCodesCollection } from
|
|
3
|
-
import { createReferralProgramsCollection } from
|
|
4
|
-
import { payloadEcommerceCouponPlugin } from
|
|
5
|
-
export { useCouponCode, usePartnerStats, validateCouponCode } from
|
|
6
|
-
export { PartnerDashboard } from
|
|
7
|
-
export { EarningsSummary } from
|
|
8
|
-
export { RecentReferrals } from
|
|
9
|
-
export { ReferralCodes } from
|
|
10
|
-
export { ReferralPerformance } from
|
|
11
|
-
export { ProgramOverview } from
|
|
12
|
-
export { CommissionBreakdown } from
|
|
13
|
-
export { calculateCommissionAndDiscount, getProgramMinimumOrderAmount, } from
|
|
14
|
-
export { getCartTotalWithDiscounts } from
|
|
15
|
-
export { recordCouponUsageForOrder } from
|
|
1
|
+
import { createCouponsCollection } from './collections/createCouponsCollection';
|
|
2
|
+
import { createReferralCodesCollection } from './collections/createReferralCodesCollection';
|
|
3
|
+
import { createReferralProgramsCollection } from './collections/createReferralProgramsCollection';
|
|
4
|
+
import { payloadEcommerceCouponPlugin } from './plugin';
|
|
5
|
+
export { useCouponCode, usePartnerStats, validateCouponCode } from './client/hooks';
|
|
6
|
+
export { PartnerDashboard } from './components/PartnerDashboard';
|
|
7
|
+
export { EarningsSummary } from './components/PartnerDashboard/EarningsSummary';
|
|
8
|
+
export { RecentReferrals } from './components/PartnerDashboard/RecentReferrals';
|
|
9
|
+
export { ReferralCodes } from './components/PartnerDashboard/ReferralCodes';
|
|
10
|
+
export { ReferralPerformance } from './components/PartnerDashboard/ReferralPerformance';
|
|
11
|
+
export { ProgramOverview } from './components/PartnerDashboard/ProgramOverview';
|
|
12
|
+
export { CommissionBreakdown } from './components/PartnerDashboard/CommissionBreakdown';
|
|
13
|
+
export { calculateCommissionAndDiscount, getProgramMinimumOrderAmount, } from './utilities/calculateValues';
|
|
14
|
+
export { getCartTotalWithDiscounts } from './utilities/getCartTotalWithDiscounts';
|
|
15
|
+
export { recordCouponUsageForOrder } from './utilities/recordCouponUsageForOrder';
|
|
16
16
|
export { createCouponsCollection, createReferralCodesCollection, createReferralProgramsCollection, payloadEcommerceCouponPlugin as payloadEcommerceCoupon, };
|
|
17
|
-
export type { AdminGroupConfig, ApplyCouponHook, ApplyCouponResponse, CouponPluginAccess, CouponPluginCollections, CouponPluginOptions, CouponPluginPolicies, OrderIntegrationConfig, PartnerDashboardConfig, PartnerDashboardData, PartnerStats, PartnerStatsPolicyContext, PluginIntegrationCollections, PluginIntegrationConfig, PluginIntegrationFields, PluginIntegrationResolvers, PolicyContext, RecordOrderUsagePolicyContext, ReferralProgramConfig, RoleConfig, } from
|
|
18
|
-
export type { CartLike } from
|
|
17
|
+
export type { AdminGroupConfig, ApplyCouponHook, ApplyCouponResponse, CouponPluginAccess, CouponPluginCollections, CouponPluginOptions, CouponPluginPolicies, OrderIntegrationConfig, PartnerDashboardConfig, PartnerDashboardData, PartnerStats, PartnerStatsPolicyContext, PluginIntegrationCollections, PluginIntegrationConfig, PluginIntegrationFields, PluginIntegrationResolvers, PolicyContext, RecordOrderUsagePolicyContext, ReferralProgramConfig, RoleConfig, } from './types';
|
|
18
|
+
export type { CartLike } from './utilities/getCartTotalWithDiscounts';
|
|
19
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAA;AAC/E,OAAO,EAAE,6BAA6B,EAAE,MAAM,6CAA6C,CAAA;AAC3F,OAAO,EAAE,gCAAgC,EAAE,MAAM,gDAAgD,CAAA;AACjG,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAA;AAEvD,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnF,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAA;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAA;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAA;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAA;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,mDAAmD,CAAA;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,+CAA+C,CAAA;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,mDAAmD,CAAA;AAEvF,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,GAC7B,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAA;AACjF,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAA;AACjF,OAAO,EACL,uBAAuB,EACvB,6BAA6B,EAC7B,gCAAgC,EAChC,4BAA4B,IAAI,sBAAsB,GACvD,CAAA;AAED,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,EACtB,oBAAoB,EACpB,YAAY,EACZ,yBAAyB,EACzB,4BAA4B,EAC5B,uBAAuB,EACvB,uBAAuB,EACvB,0BAA0B,EAC1B,aAAa,EACb,6BAA6B,EAC7B,qBAAqB,EACrB,UAAU,GACX,MAAM,SAAS,CAAA;AAChB,YAAY,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
enumerable: true
|
|
23
23
|
}) : target, mod));
|
|
24
24
|
//#endregion
|
|
25
|
+
let payload = require("payload");
|
|
25
26
|
//#region src/collections/createCouponsCollection.ts
|
|
26
27
|
const createCouponsCollection = (pluginConfig) => {
|
|
27
28
|
const { collections, access, defaultCurrency, adminGroups, integration } = pluginConfig;
|
|
@@ -452,26 +453,24 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
452
453
|
delete: access.isAdmin || (() => false)
|
|
453
454
|
},
|
|
454
455
|
hooks: { beforeChange: [({ data }) => {
|
|
455
|
-
if (!data.commissionRules || !Array.isArray(data.commissionRules) || data.commissionRules.length === 0) throw new
|
|
456
|
-
const
|
|
457
|
-
if (
|
|
456
|
+
if (!data.commissionRules || !Array.isArray(data.commissionRules) || data.commissionRules.length === 0) throw new payload.APIError("At least one commission rule is required", 400);
|
|
457
|
+
const maxPartnerCommissionPerOrder = toNumber(data.maxPartnerCommissionPerOrder);
|
|
458
|
+
if (maxPartnerCommissionPerOrder != null && maxPartnerCommissionPerOrder < 0) throw new payload.APIError("Maximum commission per order for partner must be a non-negative number", 400);
|
|
459
|
+
const maxCustomerDiscountPerOrder = toNumber(data.maxCustomerDiscountPerOrder);
|
|
460
|
+
if (maxCustomerDiscountPerOrder != null && maxCustomerDiscountPerOrder < 0) throw new payload.APIError("Maximum discount for customer per order must be a non-negative number", 400);
|
|
458
461
|
const minOrderAmount = toNumber(data.minOrderAmount);
|
|
459
|
-
if (minOrderAmount != null && minOrderAmount < 0) throw new
|
|
460
|
-
data.
|
|
462
|
+
if (minOrderAmount != null && minOrderAmount < 0) throw new payload.APIError("Minimum Order Amount must be a non-negative number", 400);
|
|
463
|
+
data.maxPartnerCommissionPerOrder = maxPartnerCommissionPerOrder != null ? toCents(maxPartnerCommissionPerOrder) : null;
|
|
464
|
+
data.maxCustomerDiscountPerOrder = maxCustomerDiscountPerOrder != null ? toCents(maxCustomerDiscountPerOrder) : null;
|
|
461
465
|
data.minOrderAmount = minOrderAmount ?? null;
|
|
462
466
|
data.commissionRules = data.commissionRules.map((rule, index) => {
|
|
463
467
|
const r = rule;
|
|
464
|
-
if (!r.totalCommission) throw new
|
|
465
|
-
if (!r.totalCommission.type || !allowedTotalCommissionTypes.includes(r.totalCommission.type)) throw new
|
|
468
|
+
if (!r.totalCommission) throw new payload.APIError(`Commission rule ${index + 1}: Total Commission is required`, 400);
|
|
469
|
+
if (!r.totalCommission.type || !allowedTotalCommissionTypes.includes(r.totalCommission.type)) throw new payload.APIError(`Commission rule ${index + 1}: Total Commission type must be one of ${allowedTotalCommissionTypes.join(", ")}`, 400);
|
|
466
470
|
const type = r.totalCommission.type;
|
|
467
|
-
const totalValue = toNumber(r.totalCommission.value);
|
|
468
|
-
if (type === "percentage") {
|
|
469
|
-
if (totalValue == null || totalValue < 0) throw new Error(`Commission rule ${index + 1}: Total Commission value must be a non-negative number`);
|
|
470
|
-
if (totalValue > 100) throw new Error(`Commission rule ${index + 1}: Percentage Total Commission cannot exceed 100`);
|
|
471
|
-
}
|
|
472
471
|
const appliesTo = r.appliesTo ?? "all";
|
|
473
|
-
if (appliesTo === "products" && (!r.products || r.products.length === 0)) throw new
|
|
474
|
-
if ((appliesTo === "segments" || appliesTo === "categories") && (!r.categories || r.categories.length === 0) && (!r.tags || r.tags.length === 0)) throw new
|
|
472
|
+
if (appliesTo === "products" && (!r.products || r.products.length === 0)) throw new payload.APIError(`Commission rule ${index + 1}: At least one product is required`, 400);
|
|
473
|
+
if ((appliesTo === "segments" || appliesTo === "categories") && (!r.categories || r.categories.length === 0) && (!r.tags || r.tags.length === 0)) throw new payload.APIError(`Commission rule ${index + 1}: At least one category or tag is required`, 400);
|
|
475
474
|
let partnerSplit;
|
|
476
475
|
let customerSplit;
|
|
477
476
|
let partnerPercent = null;
|
|
@@ -482,11 +481,11 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
482
481
|
if (type === "percentage") {
|
|
483
482
|
const partnerPctInput = toNumber(r.partnerPercent) ?? toNumber(r.partnerSplit);
|
|
484
483
|
const customerPctInput = toNumber(r.customerPercent) ?? toNumber(r.customerSplit);
|
|
485
|
-
if (partnerPctInput == null || partnerPctInput < 0 || partnerPctInput > 100) throw new
|
|
486
|
-
if (customerPctInput != null && (customerPctInput < 0 || customerPctInput > 100)) throw new
|
|
484
|
+
if (partnerPctInput == null || partnerPctInput < 0 || partnerPctInput > 100) throw new payload.APIError(`Commission rule ${index + 1}: Partner Split must be between 0 and 100`, 400);
|
|
485
|
+
if (customerPctInput != null && (customerPctInput < 0 || customerPctInput > 100)) throw new payload.APIError(`Commission rule ${index + 1}: Customer percentage must be between 0 and 100`, 400);
|
|
487
486
|
const customerPctComputed = customerPctInput != null ? customerPctInput : 100 - partnerPctInput;
|
|
488
487
|
const percentTotal = partnerPctInput + customerPctComputed;
|
|
489
|
-
if (percentTotal > 100) throw new
|
|
488
|
+
if (percentTotal > 100) throw new payload.APIError(`Commission rule ${index + 1}: Partner percentage + Customer percentage cannot exceed 100`, 400);
|
|
490
489
|
if (percentTotal > 50) splitWarning = `High total split configured: ${percentTotal}% (partner + customer).`;
|
|
491
490
|
partnerPercent = partnerPctInput;
|
|
492
491
|
customerPercent = customerPctComputed;
|
|
@@ -500,30 +499,26 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
500
499
|
const hasNewFixedInputs = partnerAmountInput != null || customerAmountInput != null;
|
|
501
500
|
const hasLegacyFixedInputs = legacyPartnerSplitInput != null || legacyCustomerSplitInput != null;
|
|
502
501
|
if (hasNewFixedInputs) {
|
|
503
|
-
if (partnerAmountInput == null || partnerAmountInput < 0) throw new
|
|
504
|
-
if (customerAmountInput == null || customerAmountInput < 0) throw new
|
|
502
|
+
if (partnerAmountInput == null || partnerAmountInput < 0) throw new payload.APIError(`Commission rule ${index + 1}: Partner fixed amount must be a non-negative number`, 400);
|
|
503
|
+
if (customerAmountInput == null || customerAmountInput < 0) throw new payload.APIError(`Commission rule ${index + 1}: Customer fixed amount must be a non-negative number`, 400);
|
|
505
504
|
partnerAmount = partnerAmountInput;
|
|
506
505
|
customerAmount = customerAmountInput;
|
|
507
506
|
partnerSplit = toCents(partnerAmountInput);
|
|
508
507
|
customerSplit = toCents(customerAmountInput);
|
|
509
508
|
} else if (hasLegacyFixedInputs) {
|
|
510
|
-
if (legacyPartnerSplitInput == null || legacyPartnerSplitInput < 0) throw new
|
|
511
|
-
const
|
|
512
|
-
|
|
513
|
-
if (resolvedLegacyCustomerSplit == null || resolvedLegacyCustomerSplit < 0) throw new Error(`Commission rule ${index + 1}: For fixed commissions, both partner and customer values must be non-negative numbers`);
|
|
509
|
+
if (legacyPartnerSplitInput == null || legacyPartnerSplitInput < 0) throw new payload.APIError(`Commission rule ${index + 1}: For fixed commissions, both partner and customer values must be non-negative numbers`, 400);
|
|
510
|
+
const resolvedLegacyCustomerSplit = legacyCustomerSplitInput ?? 100 - legacyPartnerSplitInput;
|
|
511
|
+
if (resolvedLegacyCustomerSplit == null || resolvedLegacyCustomerSplit < 0) throw new payload.APIError(`Commission rule ${index + 1}: For fixed commissions, both partner and customer values must be non-negative numbers`, 400);
|
|
514
512
|
partnerSplit = legacyPartnerSplitInput;
|
|
515
513
|
customerSplit = resolvedLegacyCustomerSplit;
|
|
516
514
|
partnerAmount = null;
|
|
517
515
|
customerAmount = null;
|
|
518
|
-
} else throw new
|
|
516
|
+
} else throw new payload.APIError(`Commission rule ${index + 1}: For fixed commissions, both partner and customer values must be provided`, 400);
|
|
519
517
|
}
|
|
520
518
|
return {
|
|
521
519
|
...rule,
|
|
522
520
|
appliesTo: appliesTo === "categories" ? "segments" : appliesTo,
|
|
523
|
-
totalCommission: {
|
|
524
|
-
type,
|
|
525
|
-
value: type === "percentage" ? totalValue : null
|
|
526
|
-
},
|
|
521
|
+
totalCommission: { type },
|
|
527
522
|
partnerPercent,
|
|
528
523
|
customerPercent,
|
|
529
524
|
partnerAmount,
|
|
@@ -549,10 +544,16 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
549
544
|
admin: { description: "Whether this referral program is currently active" }
|
|
550
545
|
},
|
|
551
546
|
{
|
|
552
|
-
name: "
|
|
547
|
+
name: "maxPartnerCommissionPerOrder",
|
|
548
|
+
type: "number",
|
|
549
|
+
min: 0,
|
|
550
|
+
admin: { description: "Maximum commission per order for partner. Leave empty for no cap. Enter value in currency units (will be converted to cents)." }
|
|
551
|
+
},
|
|
552
|
+
{
|
|
553
|
+
name: "maxCustomerDiscountPerOrder",
|
|
553
554
|
type: "number",
|
|
554
555
|
min: 0,
|
|
555
|
-
admin: { description: "Maximum
|
|
556
|
+
admin: { description: "Maximum customer discount per order. Leave empty for no cap. Enter value in currency units (will be converted to cents)." }
|
|
556
557
|
},
|
|
557
558
|
{
|
|
558
559
|
name: "minOrderAmount",
|
|
@@ -687,16 +688,6 @@ const createReferralProgramsCollection = (pluginConfig) => {
|
|
|
687
688
|
hidden: true,
|
|
688
689
|
description: "Canonical storage field. Percentage mode: percent. Fixed mode: amount in cents."
|
|
689
690
|
}
|
|
690
|
-
},
|
|
691
|
-
{
|
|
692
|
-
name: "splitWarning",
|
|
693
|
-
type: "text",
|
|
694
|
-
virtual: true,
|
|
695
|
-
admin: {
|
|
696
|
-
readOnly: true,
|
|
697
|
-
condition: (_, siblingData) => siblingData?.totalCommission?.type === "percentage",
|
|
698
|
-
description: "Non-blocking warning shown when partnerPercent + customerPercent is greater than 50%."
|
|
699
|
-
}
|
|
700
691
|
}
|
|
701
692
|
]
|
|
702
693
|
}
|
|
@@ -777,11 +768,11 @@ function getRuleSplits(rule) {
|
|
|
777
768
|
customerSplit: typeof rule.customerSplit === "number" ? rule.customerSplit : typeof rule.refereeSplit === "number" ? rule.refereeSplit : 100 - partnerRaw
|
|
778
769
|
};
|
|
779
770
|
}
|
|
780
|
-
function calculateItemRewardByRule({ rule, itemTotal, quantity,
|
|
771
|
+
function calculateItemRewardByRule({ rule, itemTotal, quantity, allowedTotalCommissionTypes }) {
|
|
781
772
|
const allowedTypes = allowedCommissionTypesSet(allowedTotalCommissionTypes);
|
|
782
773
|
if (rule.totalCommission) {
|
|
783
774
|
if (!allowedTypes.has(rule.totalCommission.type)) return null;
|
|
784
|
-
const resolvedMaxAmount = typeof
|
|
775
|
+
const resolvedMaxAmount = typeof rule.totalCommission.maxAmount === "number" && Number.isFinite(rule.totalCommission.maxAmount) ? rule.totalCommission.maxAmount : null;
|
|
785
776
|
if (rule.totalCommission.type === "fixed" && rule.totalCommission.value == null) {
|
|
786
777
|
const partnerAmtPerUnit = typeof rule.partnerSplit === "number" ? rule.partnerSplit : null;
|
|
787
778
|
const customerAmtPerUnit = typeof rule.customerSplit === "number" ? rule.customerSplit : null;
|
|
@@ -840,7 +831,7 @@ function getItemCategoryIds(item) {
|
|
|
840
831
|
function getItemTagIds(item) {
|
|
841
832
|
return Array.isArray(item?.product?.tags) ? normalizeIds(item.product.tags) : [];
|
|
842
833
|
}
|
|
843
|
-
function selectBestRuleForItem({ rules, item, itemTotal, quantity, cartTotal, minOrderAmount,
|
|
834
|
+
function selectBestRuleForItem({ rules, item, itemTotal, quantity, cartTotal, minOrderAmount, allowedTotalCommissionTypes }) {
|
|
844
835
|
const allowedTypes = allowedCommissionTypesSet(allowedTotalCommissionTypes);
|
|
845
836
|
const eligibleRules = rules.filter((rule) => {
|
|
846
837
|
if (!(rule?.totalCommission?.type ? allowedTypes.has(rule.totalCommission.type) : true)) return false;
|
|
@@ -870,7 +861,6 @@ function selectBestRuleForItem({ rules, item, itemTotal, quantity, cartTotal, mi
|
|
|
870
861
|
rule,
|
|
871
862
|
itemTotal,
|
|
872
863
|
quantity,
|
|
873
|
-
maxAmount,
|
|
874
864
|
allowedTotalCommissionTypes
|
|
875
865
|
});
|
|
876
866
|
if (!reward) continue;
|
|
@@ -935,13 +925,16 @@ function calculateCommissionAndDiscount({ cartItems, program, currencyCode = "AE
|
|
|
935
925
|
quantity,
|
|
936
926
|
cartTotal,
|
|
937
927
|
minOrderAmount: typeof program?.minOrderAmount === "number" && Number.isFinite(program.minOrderAmount) ? program.minOrderAmount : null,
|
|
938
|
-
maxAmount: typeof program?.maxAmount === "number" && Number.isFinite(program.maxAmount) ? program.maxAmount : null,
|
|
939
928
|
allowedTotalCommissionTypes
|
|
940
929
|
});
|
|
941
930
|
if (!bestMatch) continue;
|
|
942
931
|
totalPartnerCommission += bestMatch.reward.partner;
|
|
943
932
|
totalCustomerDiscount += bestMatch.reward.customer;
|
|
944
933
|
}
|
|
934
|
+
const maxPartnerCommissionPerOrder = typeof program?.maxPartnerCommissionPerOrder === "number" && Number.isFinite(program.maxPartnerCommissionPerOrder) ? program.maxPartnerCommissionPerOrder : null;
|
|
935
|
+
const maxCustomerDiscountPerOrder = typeof program?.maxCustomerDiscountPerOrder === "number" && Number.isFinite(program.maxCustomerDiscountPerOrder) ? program.maxCustomerDiscountPerOrder : null;
|
|
936
|
+
if (maxPartnerCommissionPerOrder != null) totalPartnerCommission = Math.min(totalPartnerCommission, maxPartnerCommissionPerOrder);
|
|
937
|
+
if (maxCustomerDiscountPerOrder != null) totalCustomerDiscount = Math.min(totalCustomerDiscount, maxCustomerDiscountPerOrder);
|
|
945
938
|
return {
|
|
946
939
|
partnerCommission: totalPartnerCommission,
|
|
947
940
|
customerDiscount: totalCustomerDiscount
|