@dodopayments/nextjs 0.2.1 → 0.3.0

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.cjs CHANGED
@@ -2324,6 +2324,7 @@ function requireReact_production () {
2324
2324
  REACT_SUSPENSE_TYPE = Symbol.for("react.suspense"),
2325
2325
  REACT_MEMO_TYPE = Symbol.for("react.memo"),
2326
2326
  REACT_LAZY_TYPE = Symbol.for("react.lazy"),
2327
+ REACT_ACTIVITY_TYPE = Symbol.for("react.activity"),
2327
2328
  MAYBE_ITERATOR_SYMBOL = Symbol.iterator;
2328
2329
  function getIteratorFn(maybeIterable) {
2329
2330
  if (null === maybeIterable || "object" !== typeof maybeIterable) return null;
@@ -2375,28 +2376,22 @@ function requireReact_production () {
2375
2376
  pureComponentPrototype.constructor = PureComponent;
2376
2377
  assign(pureComponentPrototype, Component.prototype);
2377
2378
  pureComponentPrototype.isPureReactComponent = true;
2378
- var isArrayImpl = Array.isArray,
2379
- ReactSharedInternals = { H: null, A: null, T: null, S: null, V: null },
2379
+ var isArrayImpl = Array.isArray;
2380
+ function noop() {}
2381
+ var ReactSharedInternals = { H: null, A: null, T: null, S: null },
2380
2382
  hasOwnProperty = Object.prototype.hasOwnProperty;
2381
- function ReactElement(type, key, self, source, owner, props) {
2382
- self = props.ref;
2383
+ function ReactElement(type, key, props) {
2384
+ var refProp = props.ref;
2383
2385
  return {
2384
2386
  $$typeof: REACT_ELEMENT_TYPE,
2385
2387
  type: type,
2386
2388
  key: key,
2387
- ref: void 0 !== self ? self : null,
2389
+ ref: void 0 !== refProp ? refProp : null,
2388
2390
  props: props
2389
2391
  };
2390
2392
  }
2391
2393
  function cloneAndReplaceKey(oldElement, newKey) {
2392
- return ReactElement(
2393
- oldElement.type,
2394
- newKey,
2395
- void 0,
2396
- void 0,
2397
- void 0,
2398
- oldElement.props
2399
- );
2394
+ return ReactElement(oldElement.type, newKey, oldElement.props);
2400
2395
  }
2401
2396
  function isValidElement(object) {
2402
2397
  return (
@@ -2420,7 +2415,6 @@ function requireReact_production () {
2420
2415
  ? escape("" + element.key)
2421
2416
  : index.toString(36);
2422
2417
  }
2423
- function noop$1() {}
2424
2418
  function resolveThenable(thenable) {
2425
2419
  switch (thenable.status) {
2426
2420
  case "fulfilled":
@@ -2430,7 +2424,7 @@ function requireReact_production () {
2430
2424
  default:
2431
2425
  switch (
2432
2426
  ("string" === typeof thenable.status
2433
- ? thenable.then(noop$1, noop$1)
2427
+ ? thenable.then(noop, noop)
2434
2428
  : ((thenable.status = "pending"),
2435
2429
  thenable.then(
2436
2430
  function (fulfilledValue) {
@@ -2591,68 +2585,69 @@ function requireReact_production () {
2591
2585
  throw payload._result;
2592
2586
  }
2593
2587
  var reportGlobalError =
2594
- "function" === typeof reportError
2595
- ? reportError
2596
- : function (error) {
2597
- if (
2598
- "object" === typeof window &&
2599
- "function" === typeof window.ErrorEvent
2600
- ) {
2601
- var event = new window.ErrorEvent("error", {
2602
- bubbles: true,
2603
- cancelable: true,
2604
- message:
2605
- "object" === typeof error &&
2606
- null !== error &&
2607
- "string" === typeof error.message
2608
- ? String(error.message)
2609
- : String(error),
2610
- error: error
2611
- });
2612
- if (!window.dispatchEvent(event)) return;
2613
- } else if (
2614
- "object" === typeof process &&
2615
- "function" === typeof process.emit
2616
- ) {
2617
- process.emit("uncaughtException", error);
2618
- return;
2619
- }
2620
- console.error(error);
2621
- };
2622
- function noop() {}
2623
- react_production.Children = {
2624
- map: mapChildren,
2625
- forEach: function (children, forEachFunc, forEachContext) {
2626
- mapChildren(
2627
- children,
2628
- function () {
2629
- forEachFunc.apply(this, arguments);
2630
- },
2631
- forEachContext
2632
- );
2633
- },
2634
- count: function (children) {
2635
- var n = 0;
2636
- mapChildren(children, function () {
2637
- n++;
2638
- });
2639
- return n;
2640
- },
2641
- toArray: function (children) {
2642
- return (
2643
- mapChildren(children, function (child) {
2644
- return child;
2645
- }) || []
2646
- );
2647
- },
2648
- only: function (children) {
2649
- if (!isValidElement(children))
2650
- throw Error(
2651
- "React.Children.only expected to receive a single React element child."
2588
+ "function" === typeof reportError
2589
+ ? reportError
2590
+ : function (error) {
2591
+ if (
2592
+ "object" === typeof window &&
2593
+ "function" === typeof window.ErrorEvent
2594
+ ) {
2595
+ var event = new window.ErrorEvent("error", {
2596
+ bubbles: true,
2597
+ cancelable: true,
2598
+ message:
2599
+ "object" === typeof error &&
2600
+ null !== error &&
2601
+ "string" === typeof error.message
2602
+ ? String(error.message)
2603
+ : String(error),
2604
+ error: error
2605
+ });
2606
+ if (!window.dispatchEvent(event)) return;
2607
+ } else if (
2608
+ "object" === typeof process &&
2609
+ "function" === typeof process.emit
2610
+ ) {
2611
+ process.emit("uncaughtException", error);
2612
+ return;
2613
+ }
2614
+ console.error(error);
2615
+ },
2616
+ Children = {
2617
+ map: mapChildren,
2618
+ forEach: function (children, forEachFunc, forEachContext) {
2619
+ mapChildren(
2620
+ children,
2621
+ function () {
2622
+ forEachFunc.apply(this, arguments);
2623
+ },
2624
+ forEachContext
2652
2625
  );
2653
- return children;
2654
- }
2655
- };
2626
+ },
2627
+ count: function (children) {
2628
+ var n = 0;
2629
+ mapChildren(children, function () {
2630
+ n++;
2631
+ });
2632
+ return n;
2633
+ },
2634
+ toArray: function (children) {
2635
+ return (
2636
+ mapChildren(children, function (child) {
2637
+ return child;
2638
+ }) || []
2639
+ );
2640
+ },
2641
+ only: function (children) {
2642
+ if (!isValidElement(children))
2643
+ throw Error(
2644
+ "React.Children.only expected to receive a single React element child."
2645
+ );
2646
+ return children;
2647
+ }
2648
+ };
2649
+ react_production.Activity = REACT_ACTIVITY_TYPE;
2650
+ react_production.Children = Children;
2656
2651
  react_production.Component = Component;
2657
2652
  react_production.Fragment = REACT_FRAGMENT_TYPE;
2658
2653
  react_production.Profiler = REACT_PROFILER_TYPE;
@@ -2672,18 +2667,18 @@ function requireReact_production () {
2672
2667
  return fn.apply(null, arguments);
2673
2668
  };
2674
2669
  };
2670
+ react_production.cacheSignal = function () {
2671
+ return null;
2672
+ };
2675
2673
  react_production.cloneElement = function (element, config, children) {
2676
2674
  if (null === element || void 0 === element)
2677
2675
  throw Error(
2678
2676
  "The argument must be a React element, but you passed " + element + "."
2679
2677
  );
2680
2678
  var props = assign({}, element.props),
2681
- key = element.key,
2682
- owner = void 0;
2679
+ key = element.key;
2683
2680
  if (null != config)
2684
- for (propName in (void 0 !== config.ref && (owner = void 0),
2685
- void 0 !== config.key && (key = "" + config.key),
2686
- config))
2681
+ for (propName in (void 0 !== config.key && (key = "" + config.key), config))
2687
2682
  !hasOwnProperty.call(config, propName) ||
2688
2683
  "key" === propName ||
2689
2684
  "__self" === propName ||
@@ -2697,7 +2692,7 @@ function requireReact_production () {
2697
2692
  childArray[i] = arguments[i + 2];
2698
2693
  props.children = childArray;
2699
2694
  }
2700
- return ReactElement(element.type, key, void 0, void 0, owner, props);
2695
+ return ReactElement(element.type, key, props);
2701
2696
  };
2702
2697
  react_production.createContext = function (defaultValue) {
2703
2698
  defaultValue = {
@@ -2737,7 +2732,7 @@ function requireReact_production () {
2737
2732
  for (propName in ((childrenLength = type.defaultProps), childrenLength))
2738
2733
  void 0 === props[propName] &&
2739
2734
  (props[propName] = childrenLength[propName]);
2740
- return ReactElement(type, key, void 0, void 0, null, props);
2735
+ return ReactElement(type, key, props);
2741
2736
  };
2742
2737
  react_production.createRef = function () {
2743
2738
  return { current: null };
@@ -2776,7 +2771,10 @@ function requireReact_production () {
2776
2771
  } catch (error) {
2777
2772
  reportGlobalError(error);
2778
2773
  } finally {
2779
- ReactSharedInternals.T = prevTransition;
2774
+ null !== prevTransition &&
2775
+ null !== currentTransition.types &&
2776
+ (prevTransition.types = currentTransition.types),
2777
+ (ReactSharedInternals.T = prevTransition);
2780
2778
  }
2781
2779
  };
2782
2780
  react_production.unstable_useCacheRefresh = function () {
@@ -2798,13 +2796,11 @@ function requireReact_production () {
2798
2796
  react_production.useDeferredValue = function (value, initialValue) {
2799
2797
  return ReactSharedInternals.H.useDeferredValue(value, initialValue);
2800
2798
  };
2801
- react_production.useEffect = function (create, createDeps, update) {
2802
- var dispatcher = ReactSharedInternals.H;
2803
- if ("function" === typeof update)
2804
- throw Error(
2805
- "useEffect CRUD overload is not enabled in this build of React."
2806
- );
2807
- return dispatcher.useEffect(create, createDeps);
2799
+ react_production.useEffect = function (create, deps) {
2800
+ return ReactSharedInternals.H.useEffect(create, deps);
2801
+ };
2802
+ react_production.useEffectEvent = function (callback) {
2803
+ return ReactSharedInternals.H.useEffectEvent(callback);
2808
2804
  };
2809
2805
  react_production.useId = function () {
2810
2806
  return ReactSharedInternals.H.useId();
@@ -2847,7 +2843,7 @@ function requireReact_production () {
2847
2843
  react_production.useTransition = function () {
2848
2844
  return ReactSharedInternals.H.useTransition();
2849
2845
  };
2850
- react_production.version = "19.1.0";
2846
+ react_production.version = "19.2.0";
2851
2847
  return react_production;
2852
2848
  }
2853
2849
 
@@ -2918,6 +2914,7 @@ function requireReact_development () {
2918
2914
  this.refs = emptyObject;
2919
2915
  this.updater = updater || ReactNoopUpdateQueue;
2920
2916
  }
2917
+ function noop() {}
2921
2918
  function testStringCoercion(value) {
2922
2919
  return "" + value;
2923
2920
  }
@@ -2977,7 +2974,7 @@ function requireReact_development () {
2977
2974
  case REACT_PORTAL_TYPE:
2978
2975
  return "Portal";
2979
2976
  case REACT_CONTEXT_TYPE:
2980
- return (type.displayName || "Context") + ".Provider";
2977
+ return type.displayName || "Context";
2981
2978
  case REACT_CONSUMER_TYPE:
2982
2979
  return (type._context.displayName || "Context") + ".Consumer";
2983
2980
  case REACT_FORWARD_REF_TYPE:
@@ -3057,17 +3054,8 @@ function requireReact_development () {
3057
3054
  componentName = this.props.ref;
3058
3055
  return void 0 !== componentName ? componentName : null;
3059
3056
  }
3060
- function ReactElement(
3061
- type,
3062
- key,
3063
- self,
3064
- source,
3065
- owner,
3066
- props,
3067
- debugStack,
3068
- debugTask
3069
- ) {
3070
- self = props.ref;
3057
+ function ReactElement(type, key, props, owner, debugStack, debugTask) {
3058
+ var refProp = props.ref;
3071
3059
  type = {
3072
3060
  $$typeof: REACT_ELEMENT_TYPE,
3073
3061
  type: type,
@@ -3075,7 +3063,7 @@ function requireReact_development () {
3075
3063
  props: props,
3076
3064
  _owner: owner
3077
3065
  };
3078
- null !== (void 0 !== self ? self : null)
3066
+ null !== (void 0 !== refProp ? refProp : null)
3079
3067
  ? Object.defineProperty(type, "ref", {
3080
3068
  enumerable: false,
3081
3069
  get: elementRefGetterWithDeprecationWarning
@@ -3113,10 +3101,8 @@ function requireReact_development () {
3113
3101
  newKey = ReactElement(
3114
3102
  oldElement.type,
3115
3103
  newKey,
3116
- void 0,
3117
- void 0,
3118
- oldElement._owner,
3119
3104
  oldElement.props,
3105
+ oldElement._owner,
3120
3106
  oldElement._debugStack,
3121
3107
  oldElement._debugTask
3122
3108
  );
@@ -3124,6 +3110,18 @@ function requireReact_development () {
3124
3110
  (newKey._store.validated = oldElement._store.validated);
3125
3111
  return newKey;
3126
3112
  }
3113
+ function validateChildKeys(node) {
3114
+ isValidElement(node)
3115
+ ? node._store && (node._store.validated = 1)
3116
+ : "object" === typeof node &&
3117
+ null !== node &&
3118
+ node.$$typeof === REACT_LAZY_TYPE &&
3119
+ ("fulfilled" === node._payload.status
3120
+ ? isValidElement(node._payload.value) &&
3121
+ node._payload.value._store &&
3122
+ (node._payload.value._store.validated = 1)
3123
+ : node._store && (node._store.validated = 1));
3124
+ }
3127
3125
  function isValidElement(object) {
3128
3126
  return (
3129
3127
  "object" === typeof object &&
@@ -3147,7 +3145,6 @@ function requireReact_development () {
3147
3145
  ? (checkKeyStringCoercion(element.key), escape("" + element.key))
3148
3146
  : index.toString(36);
3149
3147
  }
3150
- function noop$1() {}
3151
3148
  function resolveThenable(thenable) {
3152
3149
  switch (thenable.status) {
3153
3150
  case "fulfilled":
@@ -3157,7 +3154,7 @@ function requireReact_development () {
3157
3154
  default:
3158
3155
  switch (
3159
3156
  ("string" === typeof thenable.status
3160
- ? thenable.then(noop$1, noop$1)
3157
+ ? thenable.then(noop, noop)
3161
3158
  : ((thenable.status = "pending"),
3162
3159
  thenable.then(
3163
3160
  function (fulfilledValue) {
@@ -3319,35 +3316,56 @@ function requireReact_development () {
3319
3316
  }
3320
3317
  function lazyInitializer(payload) {
3321
3318
  if (-1 === payload._status) {
3322
- var ctor = payload._result;
3323
- ctor = ctor();
3324
- ctor.then(
3319
+ var ioInfo = payload._ioInfo;
3320
+ null != ioInfo && (ioInfo.start = ioInfo.end = performance.now());
3321
+ ioInfo = payload._result;
3322
+ var thenable = ioInfo();
3323
+ thenable.then(
3325
3324
  function (moduleObject) {
3326
- if (0 === payload._status || -1 === payload._status)
3327
- (payload._status = 1), (payload._result = moduleObject);
3325
+ if (0 === payload._status || -1 === payload._status) {
3326
+ payload._status = 1;
3327
+ payload._result = moduleObject;
3328
+ var _ioInfo = payload._ioInfo;
3329
+ null != _ioInfo && (_ioInfo.end = performance.now());
3330
+ void 0 === thenable.status &&
3331
+ ((thenable.status = "fulfilled"),
3332
+ (thenable.value = moduleObject));
3333
+ }
3328
3334
  },
3329
3335
  function (error) {
3330
- if (0 === payload._status || -1 === payload._status)
3331
- (payload._status = 2), (payload._result = error);
3336
+ if (0 === payload._status || -1 === payload._status) {
3337
+ payload._status = 2;
3338
+ payload._result = error;
3339
+ var _ioInfo2 = payload._ioInfo;
3340
+ null != _ioInfo2 && (_ioInfo2.end = performance.now());
3341
+ void 0 === thenable.status &&
3342
+ ((thenable.status = "rejected"), (thenable.reason = error));
3343
+ }
3332
3344
  }
3333
3345
  );
3346
+ ioInfo = payload._ioInfo;
3347
+ if (null != ioInfo) {
3348
+ ioInfo.value = thenable;
3349
+ var displayName = thenable.displayName;
3350
+ "string" === typeof displayName && (ioInfo.name = displayName);
3351
+ }
3334
3352
  -1 === payload._status &&
3335
- ((payload._status = 0), (payload._result = ctor));
3353
+ ((payload._status = 0), (payload._result = thenable));
3336
3354
  }
3337
3355
  if (1 === payload._status)
3338
3356
  return (
3339
- (ctor = payload._result),
3340
- void 0 === ctor &&
3357
+ (ioInfo = payload._result),
3358
+ void 0 === ioInfo &&
3341
3359
  console.error(
3342
3360
  "lazy: Expected the result of a dynamic import() call. Instead received: %s\n\nYour code should look like: \n const MyComponent = lazy(() => import('./MyComponent'))\n\nDid you accidentally put curly braces around the import?",
3343
- ctor
3361
+ ioInfo
3344
3362
  ),
3345
- "default" in ctor ||
3363
+ "default" in ioInfo ||
3346
3364
  console.error(
3347
3365
  "lazy: Expected the result of a dynamic import() call. Instead received: %s\n\nYour code should look like: \n const MyComponent = lazy(() => import('./MyComponent'))",
3348
- ctor
3366
+ ioInfo
3349
3367
  ),
3350
- ctor.default
3368
+ ioInfo.default
3351
3369
  );
3352
3370
  throw payload._result;
3353
3371
  }
@@ -3359,7 +3377,9 @@ function requireReact_development () {
3359
3377
  );
3360
3378
  return dispatcher;
3361
3379
  }
3362
- function noop() {}
3380
+ function releaseAsyncTransition() {
3381
+ ReactSharedInternals.asyncTransitions--;
3382
+ }
3363
3383
  function enqueueTask(task) {
3364
3384
  if (null === enqueueTaskImpl)
3365
3385
  try {
@@ -3451,8 +3471,8 @@ function requireReact_development () {
3451
3471
  REACT_PORTAL_TYPE = Symbol.for("react.portal"),
3452
3472
  REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
3453
3473
  REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"),
3454
- REACT_PROFILER_TYPE = Symbol.for("react.profiler");
3455
- var REACT_CONSUMER_TYPE = Symbol.for("react.consumer"),
3474
+ REACT_PROFILER_TYPE = Symbol.for("react.profiler"),
3475
+ REACT_CONSUMER_TYPE = Symbol.for("react.consumer"),
3456
3476
  REACT_CONTEXT_TYPE = Symbol.for("react.context"),
3457
3477
  REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"),
3458
3478
  REACT_SUSPENSE_TYPE = Symbol.for("react.suspense"),
@@ -3495,16 +3515,15 @@ function requireReact_development () {
3495
3515
  this.updater.enqueueForceUpdate(this, callback, "forceUpdate");
3496
3516
  };
3497
3517
  var deprecatedAPIs = {
3498
- isMounted: [
3499
- "isMounted",
3500
- "Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks."
3501
- ],
3502
- replaceState: [
3503
- "replaceState",
3504
- "Refactor your code to use setState instead (see https://github.com/facebook/react/issues/3236)."
3505
- ]
3506
- },
3507
- fnName;
3518
+ isMounted: [
3519
+ "isMounted",
3520
+ "Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks."
3521
+ ],
3522
+ replaceState: [
3523
+ "replaceState",
3524
+ "Refactor your code to use setState instead (see https://github.com/facebook/react/issues/3236)."
3525
+ ]
3526
+ };
3508
3527
  for (fnName in deprecatedAPIs)
3509
3528
  deprecatedAPIs.hasOwnProperty(fnName) &&
3510
3529
  defineDeprecationWarning(fnName, deprecatedAPIs[fnName]);
@@ -3520,8 +3539,8 @@ function requireReact_development () {
3520
3539
  A: null,
3521
3540
  T: null,
3522
3541
  S: null,
3523
- V: null,
3524
3542
  actQueue: null,
3543
+ asyncTransitions: 0,
3525
3544
  isBatchingLegacy: false,
3526
3545
  didScheduleLegacyUpdate: false,
3527
3546
  didUsePromise: false,
@@ -3536,15 +3555,16 @@ function requireReact_development () {
3536
3555
  return null;
3537
3556
  };
3538
3557
  deprecatedAPIs = {
3539
- "react-stack-bottom-frame": function (callStackForError) {
3558
+ react_stack_bottom_frame: function (callStackForError) {
3540
3559
  return callStackForError();
3541
3560
  }
3542
3561
  };
3543
3562
  var specialPropKeyWarningShown, didWarnAboutOldJSXRuntime;
3544
3563
  var didWarnAboutElementRef = {};
3545
- var unknownOwnerDebugStack = deprecatedAPIs[
3546
- "react-stack-bottom-frame"
3547
- ].bind(deprecatedAPIs, UnknownOwner)();
3564
+ var unknownOwnerDebugStack = deprecatedAPIs.react_stack_bottom_frame.bind(
3565
+ deprecatedAPIs,
3566
+ UnknownOwner
3567
+ )();
3548
3568
  var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
3549
3569
  var didWarnAboutMaps = false,
3550
3570
  userProvidedKeyEscapeRegex = /\/+/g,
@@ -3596,7 +3616,7 @@ function requireReact_development () {
3596
3616
  return resolveDispatcher().useMemoCache(size);
3597
3617
  }
3598
3618
  });
3599
- exports.Children = {
3619
+ var fnName = {
3600
3620
  map: mapChildren,
3601
3621
  forEach: function (children, forEachFunc, forEachContext) {
3602
3622
  mapChildren(
@@ -3629,6 +3649,8 @@ function requireReact_development () {
3629
3649
  return children;
3630
3650
  }
3631
3651
  };
3652
+ exports.Activity = REACT_ACTIVITY_TYPE;
3653
+ exports.Children = fnName;
3632
3654
  exports.Component = Component;
3633
3655
  exports.Fragment = REACT_FRAGMENT_TYPE;
3634
3656
  exports.Profiler = REACT_PROFILER_TYPE;
@@ -3754,6 +3776,9 @@ function requireReact_development () {
3754
3776
  return fn.apply(null, arguments);
3755
3777
  };
3756
3778
  };
3779
+ exports.cacheSignal = function () {
3780
+ return null;
3781
+ };
3757
3782
  exports.captureOwnerStack = function () {
3758
3783
  var getCurrentStack = ReactSharedInternals.getCurrentStack;
3759
3784
  return null === getCurrentStack ? null : getCurrentStack();
@@ -3806,16 +3831,13 @@ function requireReact_development () {
3806
3831
  props = ReactElement(
3807
3832
  element.type,
3808
3833
  key,
3809
- void 0,
3810
- void 0,
3811
- owner,
3812
3834
  props,
3835
+ owner,
3813
3836
  element._debugStack,
3814
3837
  element._debugTask
3815
3838
  );
3816
3839
  for (key = 2; key < arguments.length; key++)
3817
- (owner = arguments[key]),
3818
- isValidElement(owner) && owner._store && (owner._store.validated = 1);
3840
+ validateChildKeys(arguments[key]);
3819
3841
  return props;
3820
3842
  };
3821
3843
  exports.createContext = function (defaultValue) {
@@ -3837,12 +3859,10 @@ function requireReact_development () {
3837
3859
  return defaultValue;
3838
3860
  };
3839
3861
  exports.createElement = function (type, config, children) {
3840
- for (var i = 2; i < arguments.length; i++) {
3841
- var node = arguments[i];
3842
- isValidElement(node) && node._store && (node._store.validated = 1);
3843
- }
3862
+ for (var i = 2; i < arguments.length; i++)
3863
+ validateChildKeys(arguments[i]);
3844
3864
  i = {};
3845
- node = null;
3865
+ var key = null;
3846
3866
  if (null != config)
3847
3867
  for (propName in (didWarnAboutOldJSXRuntime ||
3848
3868
  !("__self" in config) ||
@@ -3852,7 +3872,7 @@ function requireReact_development () {
3852
3872
  "Your app (or one of its dependencies) is using an outdated JSX transform. Update to the modern JSX transform for faster performance: https://react.dev/link/new-jsx-transform"
3853
3873
  )),
3854
3874
  hasValidKey(config) &&
3855
- (checkKeyStringCoercion(config.key), (node = "" + config.key)),
3875
+ (checkKeyStringCoercion(config.key), (key = "" + config.key)),
3856
3876
  config))
3857
3877
  hasOwnProperty.call(config, propName) &&
3858
3878
  "key" !== propName &&
@@ -3874,7 +3894,7 @@ function requireReact_development () {
3874
3894
  if (type && type.defaultProps)
3875
3895
  for (propName in ((childrenLength = type.defaultProps), childrenLength))
3876
3896
  void 0 === i[propName] && (i[propName] = childrenLength[propName]);
3877
- node &&
3897
+ key &&
3878
3898
  defineKeyPropWarningGetter(
3879
3899
  i,
3880
3900
  "function" === typeof type
@@ -3884,11 +3904,9 @@ function requireReact_development () {
3884
3904
  var propName = 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
3885
3905
  return ReactElement(
3886
3906
  type,
3887
- node,
3888
- void 0,
3889
- void 0,
3890
- getOwner(),
3907
+ key,
3891
3908
  i,
3909
+ getOwner(),
3892
3910
  propName ? Error("react-stack-top-frame") : unknownOwnerDebugStack,
3893
3911
  propName ? createTask(getTaskName(type)) : unknownOwnerDebugTask
3894
3912
  );
@@ -3941,11 +3959,24 @@ function requireReact_development () {
3941
3959
  };
3942
3960
  exports.isValidElement = isValidElement;
3943
3961
  exports.lazy = function (ctor) {
3944
- return {
3945
- $$typeof: REACT_LAZY_TYPE,
3946
- _payload: { _status: -1, _result: ctor },
3947
- _init: lazyInitializer
3948
- };
3962
+ ctor = { _status: -1, _result: ctor };
3963
+ var lazyType = {
3964
+ $$typeof: REACT_LAZY_TYPE,
3965
+ _payload: ctor,
3966
+ _init: lazyInitializer
3967
+ },
3968
+ ioInfo = {
3969
+ name: "lazy",
3970
+ start: -1,
3971
+ end: -1,
3972
+ value: null,
3973
+ owner: null,
3974
+ debugStack: Error("react-stack-top-frame"),
3975
+ debugTask: console.createTask ? console.createTask("lazy()") : null
3976
+ };
3977
+ ctor._ioInfo = ioInfo;
3978
+ lazyType._debugInfo = [{ awaited: ioInfo }];
3979
+ return lazyType;
3949
3980
  };
3950
3981
  exports.memo = function (type, compare) {
3951
3982
  null == type &&
@@ -3978,8 +4009,8 @@ function requireReact_development () {
3978
4009
  exports.startTransition = function (scope) {
3979
4010
  var prevTransition = ReactSharedInternals.T,
3980
4011
  currentTransition = {};
3981
- ReactSharedInternals.T = currentTransition;
3982
4012
  currentTransition._updatedFibers = new Set();
4013
+ ReactSharedInternals.T = currentTransition;
3983
4014
  try {
3984
4015
  var returnValue = scope(),
3985
4016
  onStartTransitionFinish = ReactSharedInternals.S;
@@ -3988,7 +4019,9 @@ function requireReact_development () {
3988
4019
  "object" === typeof returnValue &&
3989
4020
  null !== returnValue &&
3990
4021
  "function" === typeof returnValue.then &&
3991
- returnValue.then(noop, reportGlobalError);
4022
+ (ReactSharedInternals.asyncTransitions++,
4023
+ returnValue.then(releaseAsyncTransition, releaseAsyncTransition),
4024
+ returnValue.then(noop, reportGlobalError));
3992
4025
  } catch (error) {
3993
4026
  reportGlobalError(error);
3994
4027
  } finally {
@@ -4000,6 +4033,14 @@ function requireReact_development () {
4000
4033
  console.warn(
4001
4034
  "Detected a large number of updates inside startTransition. If this is due to a subscription please re-write it to use React provided hooks. Otherwise concurrent mode guarantees are off the table."
4002
4035
  )),
4036
+ null !== prevTransition &&
4037
+ null !== currentTransition.types &&
4038
+ (null !== prevTransition.types &&
4039
+ prevTransition.types !== currentTransition.types &&
4040
+ console.error(
4041
+ "We expected inner Transitions to have transferred the outer types set and that you cannot add to the outer Transition while inside the inner.This is a bug in React."
4042
+ ),
4043
+ (prevTransition.types = currentTransition.types)),
4003
4044
  (ReactSharedInternals.T = prevTransition);
4004
4045
  }
4005
4046
  };
@@ -4033,17 +4074,15 @@ function requireReact_development () {
4033
4074
  exports.useDeferredValue = function (value, initialValue) {
4034
4075
  return resolveDispatcher().useDeferredValue(value, initialValue);
4035
4076
  };
4036
- exports.useEffect = function (create, createDeps, update) {
4077
+ exports.useEffect = function (create, deps) {
4037
4078
  null == create &&
4038
4079
  console.warn(
4039
4080
  "React Hook useEffect requires an effect callback. Did you forget to pass a callback to the hook?"
4040
4081
  );
4041
- var dispatcher = resolveDispatcher();
4042
- if ("function" === typeof update)
4043
- throw Error(
4044
- "useEffect CRUD overload is not enabled in this build of React."
4045
- );
4046
- return dispatcher.useEffect(create, createDeps);
4082
+ return resolveDispatcher().useEffect(create, deps);
4083
+ };
4084
+ exports.useEffectEvent = function (callback) {
4085
+ return resolveDispatcher().useEffectEvent(callback);
4047
4086
  };
4048
4087
  exports.useId = function () {
4049
4088
  return resolveDispatcher().useId();
@@ -4094,7 +4133,7 @@ function requireReact_development () {
4094
4133
  exports.useTransition = function () {
4095
4134
  return resolveDispatcher().useTransition();
4096
4135
  };
4097
- exports.version = "19.1.0";
4136
+ exports.version = "19.2.0";
4098
4137
  "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
4099
4138
  "function" ===
4100
4139
  typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
@@ -11512,532 +11551,432 @@ DodoPayments.Webhooks = Webhooks$1;
11512
11551
  DodoPayments.UsageEvents = UsageEvents;
11513
11552
  DodoPayments.Meters = Meters;
11514
11553
 
11515
- var __assign = (undefined && undefined.__assign) || function () {
11516
- __assign = Object.assign || function(t) {
11517
- for (var s, i = 1, n = arguments.length; i < n; i++) {
11518
- s = arguments[i];
11519
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
11520
- t[p] = s[p];
11521
- }
11522
- return t;
11523
- };
11524
- return __assign.apply(this, arguments);
11525
- };
11526
- var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
11527
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
11528
- return new (P || (P = Promise))(function (resolve, reject) {
11529
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11530
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
11531
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11532
- step((generator = generator.apply(thisArg, _arguments || [])).next());
11533
- });
11534
- };
11535
- var __generator$1 = (undefined && undefined.__generator) || function (thisArg, body) {
11536
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
11537
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
11538
- function verb(n) { return function (v) { return step([n, v]); }; }
11539
- function step(op) {
11540
- if (f) throw new TypeError("Generator is already executing.");
11541
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
11542
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
11543
- if (y = 0, t) op = [op[0] & 2, t.value];
11544
- switch (op[0]) {
11545
- case 0: case 1: t = op; break;
11546
- case 4: _.label++; return { value: op[1], done: false };
11547
- case 5: _.label++; y = op[1]; op = [0]; continue;
11548
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
11549
- default:
11550
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
11551
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
11552
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
11553
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
11554
- if (t[2]) _.ops.pop();
11555
- _.trys.pop(); continue;
11556
- }
11557
- op = body.call(thisArg, _);
11558
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
11559
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
11560
- }
11561
- };
11554
+ // src/checkout/checkout.ts
11562
11555
  var checkoutQuerySchema = objectType({
11563
- productId: stringType(),
11564
- quantity: stringType().optional(),
11565
- // Customer fields
11566
- fullName: stringType().optional(),
11567
- firstName: stringType().optional(),
11568
- lastName: stringType().optional(),
11569
- email: stringType().optional(),
11570
- country: stringType().optional(),
11571
- addressLine: stringType().optional(),
11572
- city: stringType().optional(),
11573
- state: stringType().optional(),
11574
- zipCode: stringType().optional(),
11575
- // Disable flags
11576
- disableFullName: stringType().optional(),
11577
- disableFirstName: stringType().optional(),
11578
- disableLastName: stringType().optional(),
11579
- disableEmail: stringType().optional(),
11580
- disableCountry: stringType().optional(),
11581
- disableAddressLine: stringType().optional(),
11582
- disableCity: stringType().optional(),
11583
- disableState: stringType().optional(),
11584
- disableZipCode: stringType().optional(),
11585
- // Advanced controls
11586
- paymentCurrency: stringType().optional(),
11587
- showCurrencySelector: stringType().optional(),
11588
- paymentAmount: stringType().optional(),
11589
- showDiscounts: stringType().optional(),
11590
- // Metadata (allow any key starting with metadata_)
11591
- // We'll handle metadata separately in the handler
11592
- })
11593
- .catchall(unknownType());
11594
- // Add Zod schema for dynamic checkout body
11556
+ productId: stringType(),
11557
+ quantity: stringType().optional(),
11558
+ // Customer fields
11559
+ fullName: stringType().optional(),
11560
+ firstName: stringType().optional(),
11561
+ lastName: stringType().optional(),
11562
+ email: stringType().optional(),
11563
+ country: stringType().optional(),
11564
+ addressLine: stringType().optional(),
11565
+ city: stringType().optional(),
11566
+ state: stringType().optional(),
11567
+ zipCode: stringType().optional(),
11568
+ // Disable flags
11569
+ disableFullName: stringType().optional(),
11570
+ disableFirstName: stringType().optional(),
11571
+ disableLastName: stringType().optional(),
11572
+ disableEmail: stringType().optional(),
11573
+ disableCountry: stringType().optional(),
11574
+ disableAddressLine: stringType().optional(),
11575
+ disableCity: stringType().optional(),
11576
+ disableState: stringType().optional(),
11577
+ disableZipCode: stringType().optional(),
11578
+ // Advanced controls
11579
+ paymentCurrency: stringType().optional(),
11580
+ showCurrencySelector: stringType().optional(),
11581
+ paymentAmount: stringType().optional(),
11582
+ showDiscounts: stringType().optional()
11583
+ // Metadata (allow any key starting with metadata_)
11584
+ // We'll handle metadata separately in the handler
11585
+ }).catchall(unknownType());
11595
11586
  var dynamicCheckoutBodySchema = objectType({
11596
- // For subscription
11597
- product_id: stringType().optional(),
11598
- quantity: numberType().optional(),
11599
- // For one-time payment
11600
- product_cart: arrayType(objectType({
11601
- product_id: stringType(),
11602
- quantity: numberType(),
11603
- }))
11604
- .optional(),
11605
- // Common fields
11606
- billing: objectType({
11607
- city: stringType(),
11608
- country: stringType(),
11609
- state: stringType(),
11610
- street: stringType(),
11611
- zipcode: stringType(),
11612
- }),
11613
- customer: objectType({
11614
- customer_id: stringType().optional(),
11615
- email: stringType().optional(),
11616
- name: stringType().optional(),
11617
- }),
11618
- discount_id: stringType().optional(),
11619
- addons: arrayType(objectType({
11620
- addon_id: stringType(),
11621
- quantity: numberType(),
11622
- }))
11623
- .optional(),
11624
- metadata: recordType(stringType(), stringType()).optional(),
11625
- currency: stringType().optional(),
11626
- // Allow any additional fields (for future compatibility)
11627
- })
11628
- .catchall(unknownType());
11629
- // ========================================
11630
- // CHECKOUT SESSIONS SCHEMAS & TYPES
11631
- // ========================================
11632
- // Product cart item schema for checkout sessions
11587
+ // For subscription
11588
+ product_id: stringType().optional(),
11589
+ quantity: numberType().optional(),
11590
+ // For one-time payment
11591
+ product_cart: arrayType(
11592
+ objectType({
11593
+ product_id: stringType(),
11594
+ quantity: numberType()
11595
+ })
11596
+ ).optional(),
11597
+ // Common fields
11598
+ billing: objectType({
11599
+ city: stringType(),
11600
+ country: stringType(),
11601
+ state: stringType(),
11602
+ street: stringType(),
11603
+ zipcode: stringType()
11604
+ }),
11605
+ customer: objectType({
11606
+ customer_id: stringType().optional(),
11607
+ email: stringType().optional(),
11608
+ name: stringType().optional()
11609
+ }),
11610
+ discount_id: stringType().optional(),
11611
+ addons: arrayType(
11612
+ objectType({
11613
+ addon_id: stringType(),
11614
+ quantity: numberType()
11615
+ })
11616
+ ).optional(),
11617
+ metadata: recordType(stringType(), stringType()).optional(),
11618
+ currency: stringType().optional()
11619
+ // Allow any additional fields (for future compatibility)
11620
+ }).catchall(unknownType());
11633
11621
  var checkoutSessionProductCartItemSchema = objectType({
11634
- product_id: stringType().min(1, "Product ID is required"),
11635
- quantity: numberType().int().positive("Quantity must be a positive integer"),
11622
+ product_id: stringType().min(1, "Product ID is required"),
11623
+ quantity: numberType().int().positive("Quantity must be a positive integer")
11636
11624
  });
11637
- // Customer information schema for checkout sessions
11638
11625
  var checkoutSessionCustomerSchema = objectType({
11639
- email: stringType().email().optional(),
11640
- name: stringType().min(1).optional(),
11641
- phone_number: stringType().optional(),
11642
- })
11643
- .optional();
11644
- // Billing address schema for checkout sessions
11626
+ email: stringType().email().optional(),
11627
+ name: stringType().min(1).optional(),
11628
+ phone_number: stringType().optional()
11629
+ }).optional();
11645
11630
  var checkoutSessionBillingAddressSchema = objectType({
11646
- street: stringType().optional(),
11647
- city: stringType().optional(),
11648
- state: stringType().optional(),
11649
- country: stringType().length(2, "Country must be a 2-letter ISO code"),
11650
- zipcode: stringType().optional(),
11651
- })
11652
- .optional();
11653
- // Payment method types enum based on Dodo Payments documentation
11631
+ street: stringType().optional(),
11632
+ city: stringType().optional(),
11633
+ state: stringType().optional(),
11634
+ country: stringType().length(2, "Country must be a 2-letter ISO code"),
11635
+ zipcode: stringType().optional()
11636
+ }).optional();
11654
11637
  var paymentMethodTypeSchema = enumType([
11655
- "credit",
11656
- "debit",
11657
- "upi_collect",
11658
- "upi_intent",
11659
- "apple_pay",
11660
- "google_pay",
11661
- "amazon_pay",
11662
- "klarna",
11663
- "affirm",
11664
- "afterpay_clearpay",
11665
- "sepa",
11666
- "ach",
11638
+ "credit",
11639
+ "debit",
11640
+ "upi_collect",
11641
+ "upi_intent",
11642
+ "apple_pay",
11643
+ "google_pay",
11644
+ "amazon_pay",
11645
+ "klarna",
11646
+ "affirm",
11647
+ "afterpay_clearpay",
11648
+ "sepa",
11649
+ "ach"
11667
11650
  ]);
11668
- // Customization options schema
11669
11651
  var checkoutSessionCustomizationSchema = objectType({
11670
- theme: enumType(["light", "dark", "system"]).optional(),
11671
- show_order_details: booleanType().optional(),
11672
- show_on_demand_tag: booleanType().optional(),
11673
- })
11674
- .optional();
11675
- // Feature flags schema
11652
+ theme: enumType(["light", "dark", "system"]).optional(),
11653
+ show_order_details: booleanType().optional(),
11654
+ show_on_demand_tag: booleanType().optional()
11655
+ }).optional();
11676
11656
  var checkoutSessionFeatureFlagsSchema = objectType({
11677
- allow_currency_selection: booleanType().optional(),
11678
- allow_discount_code: booleanType().optional(),
11679
- allow_phone_number_collection: booleanType().optional(),
11680
- allow_tax_id: booleanType().optional(),
11681
- always_create_new_customer: booleanType().optional(),
11682
- })
11683
- .optional();
11684
- // Subscription data schema
11657
+ allow_currency_selection: booleanType().optional(),
11658
+ allow_discount_code: booleanType().optional(),
11659
+ allow_phone_number_collection: booleanType().optional(),
11660
+ allow_tax_id: booleanType().optional(),
11661
+ always_create_new_customer: booleanType().optional()
11662
+ }).optional();
11685
11663
  var checkoutSessionSubscriptionDataSchema = objectType({
11686
- trial_period_days: numberType().int().nonnegative().optional(),
11687
- })
11688
- .optional();
11689
- // Main checkout session payload schema
11664
+ trial_period_days: numberType().int().nonnegative().optional()
11665
+ }).optional();
11690
11666
  var checkoutSessionPayloadSchema = objectType({
11691
- // Required fields
11692
- product_cart: arrayType(checkoutSessionProductCartItemSchema)
11693
- .min(1, "At least one product is required"),
11694
- // Optional fields
11695
- customer: checkoutSessionCustomerSchema,
11696
- billing_address: checkoutSessionBillingAddressSchema,
11697
- return_url: stringType().url().optional(),
11698
- allowed_payment_method_types: arrayType(paymentMethodTypeSchema).optional(),
11699
- billing_currency: stringType()
11700
- .length(3, "Currency must be a 3-letter ISO code")
11701
- .optional(),
11702
- show_saved_payment_methods: booleanType().optional(),
11703
- confirm: booleanType().optional(),
11704
- discount_code: stringType().optional(),
11705
- metadata: recordType(stringType(), stringType()).optional(),
11706
- customization: checkoutSessionCustomizationSchema,
11707
- feature_flags: checkoutSessionFeatureFlagsSchema,
11708
- subscription_data: checkoutSessionSubscriptionDataSchema,
11667
+ // Required fields
11668
+ product_cart: arrayType(checkoutSessionProductCartItemSchema).min(1, "At least one product is required"),
11669
+ // Optional fields
11670
+ customer: checkoutSessionCustomerSchema,
11671
+ billing_address: checkoutSessionBillingAddressSchema,
11672
+ return_url: stringType().url().optional(),
11673
+ allowed_payment_method_types: arrayType(paymentMethodTypeSchema).optional(),
11674
+ billing_currency: stringType().length(3, "Currency must be a 3-letter ISO code").optional(),
11675
+ show_saved_payment_methods: booleanType().optional(),
11676
+ confirm: booleanType().optional(),
11677
+ discount_code: stringType().optional(),
11678
+ metadata: recordType(stringType(), stringType()).optional(),
11679
+ customization: checkoutSessionCustomizationSchema,
11680
+ feature_flags: checkoutSessionFeatureFlagsSchema,
11681
+ subscription_data: checkoutSessionSubscriptionDataSchema
11709
11682
  });
11710
- // Checkout session response schema
11711
11683
  var checkoutSessionResponseSchema = objectType({
11712
- session_id: stringType().min(1, "Session ID is required"),
11713
- checkout_url: stringType().url("Invalid checkout URL"),
11684
+ session_id: stringType().min(1, "Session ID is required"),
11685
+ checkout_url: stringType().url("Invalid checkout URL")
11714
11686
  });
11715
- /**
11716
- * Creates a new Dodo Payments Checkout Session using the modern /checkouts endpoint.
11717
- * This function provides a clean, type-safe interface to the Checkout Sessions API.
11718
- *
11719
- * @param payload - The checkout session data, validated against CheckoutSessionPayloadSchema
11720
- * @param config - Dodo Payments client configuration (bearerToken, environment)
11721
- * @returns Promise<CheckoutSessionResponse> - The checkout session with session_id and checkout_url
11722
- *
11723
- * @throws {Error} When payload validation fails or API request fails
11724
- *
11725
- * @example
11726
- * ```typescript
11727
- * const session = await createCheckoutSession({
11728
- * product_cart: [{ product_id: 'prod_123', quantity: 1 }],
11729
- * customer: { email: 'customer@example.com' },
11730
- * return_url: 'https://yoursite.com/success'
11731
- * }, {
11732
- * bearerToken: process.env.DODO_PAYMENTS_API_KEY,
11733
- * environment: 'test_mode'
11734
- * });
11735
- *
11736
- * ```
11737
- */
11738
- var createCheckoutSession = function (payload, config) { return __awaiter$1(void 0, void 0, void 0, function () {
11739
- var validation, dodopayments, sdkPayload, session, responseValidation, error_1;
11740
- return __generator$1(this, function (_a) {
11741
- switch (_a.label) {
11742
- case 0:
11743
- validation = checkoutSessionPayloadSchema.safeParse(payload);
11744
- if (!validation.success) {
11745
- throw new Error("Invalid checkout session payload: ".concat(validation.error.issues
11746
- .map(function (issue) { return "".concat(issue.path.join("."), ": ").concat(issue.message); })
11747
- .join(", ")));
11748
- }
11749
- dodopayments = new DodoPayments({
11750
- bearerToken: config.bearerToken,
11751
- environment: config.environment,
11752
- });
11753
- _a.label = 1;
11754
- case 1:
11755
- _a.trys.push([1, 3, , 4]);
11756
- sdkPayload = __assign(__assign({}, validation.data), (validation.data.billing_address && {
11757
- billing_address: __assign(__assign({}, validation.data.billing_address), { country: validation.data.billing_address.country }),
11758
- }));
11759
- return [4 /*yield*/, dodopayments.checkoutSessions.create(sdkPayload)];
11760
- case 2:
11761
- session = _a.sent();
11762
- responseValidation = checkoutSessionResponseSchema.safeParse(session);
11763
- if (!responseValidation.success) {
11764
- throw new Error("Invalid checkout session response from API: ".concat(responseValidation.error.issues
11765
- .map(function (issue) { return "".concat(issue.path.join("."), ": ").concat(issue.message); })
11766
- .join(", ")));
11767
- }
11768
- return [2 /*return*/, responseValidation.data];
11769
- case 3:
11770
- error_1 = _a.sent();
11771
- if (error_1 instanceof Error) {
11772
- console.error("Dodo Payments Checkout Session API Error:", {
11773
- message: error_1.message,
11774
- payload: validation.data,
11775
- config: {
11776
- environment: config.environment,
11777
- hasBearerToken: !!config.bearerToken,
11778
- },
11779
- });
11780
- // Re-throw with a more user-friendly message
11781
- throw new Error("Failed to create checkout session: ".concat(error_1.message));
11782
- }
11783
- // Handle non-Error objects
11784
- console.error("Unknown error creating checkout session:", error_1);
11785
- throw new Error("Failed to create checkout session due to an unknown error");
11786
- case 4: return [2 /*return*/];
11687
+ var createCheckoutSession = async (payload, config) => {
11688
+ const validation = checkoutSessionPayloadSchema.safeParse(payload);
11689
+ if (!validation.success) {
11690
+ throw new Error(
11691
+ `Invalid checkout session payload: ${validation.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join(", ")}`
11692
+ );
11693
+ }
11694
+ const dodopayments = new DodoPayments({
11695
+ bearerToken: config.bearerToken,
11696
+ environment: config.environment
11697
+ });
11698
+ try {
11699
+ const sdkPayload = {
11700
+ ...validation.data,
11701
+ ...validation.data.billing_address && {
11702
+ billing_address: {
11703
+ ...validation.data.billing_address,
11704
+ country: validation.data.billing_address.country
11787
11705
  }
11706
+ }
11707
+ };
11708
+ const session = await dodopayments.checkoutSessions.create(
11709
+ sdkPayload
11710
+ );
11711
+ const responseValidation = checkoutSessionResponseSchema.safeParse(session);
11712
+ if (!responseValidation.success) {
11713
+ throw new Error(
11714
+ `Invalid checkout session response from API: ${responseValidation.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join(", ")}`
11715
+ );
11716
+ }
11717
+ return responseValidation.data;
11718
+ } catch (error) {
11719
+ if (error instanceof Error) {
11720
+ console.error("Dodo Payments Checkout Session API Error:", {
11721
+ message: error.message,
11722
+ payload: validation.data,
11723
+ config: {
11724
+ environment: config.environment,
11725
+ hasBearerToken: !!config.bearerToken
11726
+ }
11727
+ });
11728
+ throw new Error(`Failed to create checkout session: ${error.message}`);
11729
+ }
11730
+ console.error("Unknown error creating checkout session:", error);
11731
+ throw new Error(
11732
+ "Failed to create checkout session due to an unknown error"
11733
+ );
11734
+ }
11735
+ };
11736
+ var buildCheckoutUrl = async ({
11737
+ queryParams,
11738
+ body,
11739
+ sessionPayload,
11740
+ returnUrl,
11741
+ bearerToken,
11742
+ environment,
11743
+ type = "static"
11744
+ }) => {
11745
+ if (type === "session") {
11746
+ if (!sessionPayload) {
11747
+ throw new Error("sessionPayload is required when type is 'session'");
11748
+ }
11749
+ const session = await createCheckoutSession(sessionPayload, {
11750
+ bearerToken,
11751
+ environment
11788
11752
  });
11789
- }); };
11790
- var buildCheckoutUrl = function (_a) { return __awaiter$1(void 0, [_a], void 0, function (_b) {
11791
- var session, inputData, parseResult, success, data, error, _c, productId, quantity_1, fullName, firstName, lastName, email, country, addressLine, city, state, zipCode, disableFullName, disableFirstName, disableLastName, disableEmail, disableCountry, disableAddressLine, disableCity, disableState, disableZipCode, paymentCurrency, showCurrencySelector, paymentAmount, showDiscounts, dodopayments_1, err_1, url, _i, _d, _e, key, value, dyn, product_id, product_cart, quantity, billing, customer, addons, metadata, allowed_payment_method_types, billing_currency, discount_code, on_demand, bodyReturnUrl, show_saved_payment_methods, tax_id, trial_period_days, dodopayments, isSubscription, productIdToFetch, product, err_2, subscriptionPayload, subscription, err_3, cart, paymentPayload, payment, err_4;
11792
- var queryParams = _b.queryParams, body = _b.body, sessionPayload = _b.sessionPayload, returnUrl = _b.returnUrl, bearerToken = _b.bearerToken, environment = _b.environment, _f = _b.type, type = _f === void 0 ? "static" : _f;
11793
- return __generator$1(this, function (_g) {
11794
- switch (_g.label) {
11795
- case 0:
11796
- if (!(type === "session")) return [3 /*break*/, 2];
11797
- if (!sessionPayload) {
11798
- throw new Error("sessionPayload is required when type is 'session'");
11799
- }
11800
- return [4 /*yield*/, createCheckoutSession(sessionPayload, {
11801
- bearerToken: bearerToken,
11802
- environment: environment,
11803
- })];
11804
- case 1:
11805
- session = _g.sent();
11806
- return [2 /*return*/, session.checkout_url];
11807
- case 2:
11808
- inputData = type === "dynamic" ? body : queryParams;
11809
- if (type === "dynamic") {
11810
- parseResult = dynamicCheckoutBodySchema.safeParse(inputData);
11811
- }
11812
- else {
11813
- parseResult = checkoutQuerySchema.safeParse(inputData);
11814
- }
11815
- success = parseResult.success, data = parseResult.data, error = parseResult.error;
11816
- if (!success) {
11817
- throw new Error("Invalid ".concat(type === "dynamic" ? "body" : "query parameters", ".\n ").concat(error.message));
11818
- }
11819
- if (!(type !== "dynamic")) return [3 /*break*/, 7];
11820
- _c = data, productId = _c.productId, quantity_1 = _c.quantity, fullName = _c.fullName, firstName = _c.firstName, lastName = _c.lastName, email = _c.email, country = _c.country, addressLine = _c.addressLine, city = _c.city, state = _c.state, zipCode = _c.zipCode, disableFullName = _c.disableFullName, disableFirstName = _c.disableFirstName, disableLastName = _c.disableLastName, disableEmail = _c.disableEmail, disableCountry = _c.disableCountry, disableAddressLine = _c.disableAddressLine, disableCity = _c.disableCity, disableState = _c.disableState, disableZipCode = _c.disableZipCode, paymentCurrency = _c.paymentCurrency, showCurrencySelector = _c.showCurrencySelector, paymentAmount = _c.paymentAmount, showDiscounts = _c.showDiscounts;
11821
- dodopayments_1 = new DodoPayments({
11822
- bearerToken: bearerToken,
11823
- environment: environment,
11824
- });
11825
- // Check that the product exists for this merchant
11826
- if (!productId)
11827
- throw new Error("Missing required field: productId");
11828
- _g.label = 3;
11829
- case 3:
11830
- _g.trys.push([3, 5, , 6]);
11831
- return [4 /*yield*/, dodopayments_1.products.retrieve(productId)];
11832
- case 4:
11833
- _g.sent();
11834
- return [3 /*break*/, 6];
11835
- case 5:
11836
- err_1 = _g.sent();
11837
- console.error(err_1);
11838
- throw new Error("Product not found");
11839
- case 6:
11840
- url = new URL("".concat(environment === "test_mode" ? "https://test.checkout.dodopayments.com" : "https://checkout.dodopayments.com", "/buy/").concat(productId));
11841
- url.searchParams.set("quantity", quantity_1 ? String(quantity_1) : "1");
11842
- if (returnUrl)
11843
- url.searchParams.set("redirect_url", returnUrl);
11844
- // Customer/billing fields
11845
- if (fullName)
11846
- url.searchParams.set("fullName", String(fullName));
11847
- if (firstName)
11848
- url.searchParams.set("firstName", String(firstName));
11849
- if (lastName)
11850
- url.searchParams.set("lastName", String(lastName));
11851
- if (email)
11852
- url.searchParams.set("email", String(email));
11853
- if (country)
11854
- url.searchParams.set("country", String(country));
11855
- if (addressLine)
11856
- url.searchParams.set("addressLine", String(addressLine));
11857
- if (city)
11858
- url.searchParams.set("city", String(city));
11859
- if (state)
11860
- url.searchParams.set("state", String(state));
11861
- if (zipCode)
11862
- url.searchParams.set("zipCode", String(zipCode));
11863
- // Disable flags (must be set to 'true' to disable)
11864
- if (disableFullName === "true")
11865
- url.searchParams.set("disableFullName", "true");
11866
- if (disableFirstName === "true")
11867
- url.searchParams.set("disableFirstName", "true");
11868
- if (disableLastName === "true")
11869
- url.searchParams.set("disableLastName", "true");
11870
- if (disableEmail === "true")
11871
- url.searchParams.set("disableEmail", "true");
11872
- if (disableCountry === "true")
11873
- url.searchParams.set("disableCountry", "true");
11874
- if (disableAddressLine === "true")
11875
- url.searchParams.set("disableAddressLine", "true");
11876
- if (disableCity === "true")
11877
- url.searchParams.set("disableCity", "true");
11878
- if (disableState === "true")
11879
- url.searchParams.set("disableState", "true");
11880
- if (disableZipCode === "true")
11881
- url.searchParams.set("disableZipCode", "true");
11882
- // Advanced controls
11883
- if (paymentCurrency)
11884
- url.searchParams.set("paymentCurrency", String(paymentCurrency));
11885
- if (showCurrencySelector)
11886
- url.searchParams.set("showCurrencySelector", String(showCurrencySelector));
11887
- if (paymentAmount)
11888
- url.searchParams.set("paymentAmount", String(paymentAmount));
11889
- if (showDiscounts)
11890
- url.searchParams.set("showDiscounts", String(showDiscounts));
11891
- // Metadata: add all query params starting with metadata_
11892
- for (_i = 0, _d = Object.entries(queryParams || {}); _i < _d.length; _i++) {
11893
- _e = _d[_i], key = _e[0], value = _e[1];
11894
- if (key.startsWith("metadata_") && value && typeof value !== "object") {
11895
- url.searchParams.set(key, String(value));
11896
- }
11897
- }
11898
- return [2 /*return*/, url.toString()];
11899
- case 7:
11900
- dyn = data;
11901
- product_id = dyn.product_id, product_cart = dyn.product_cart, quantity = dyn.quantity, billing = dyn.billing, customer = dyn.customer, addons = dyn.addons, metadata = dyn.metadata, allowed_payment_method_types = dyn.allowed_payment_method_types, billing_currency = dyn.billing_currency, discount_code = dyn.discount_code, on_demand = dyn.on_demand, bodyReturnUrl = dyn.return_url, show_saved_payment_methods = dyn.show_saved_payment_methods, tax_id = dyn.tax_id, trial_period_days = dyn.trial_period_days;
11902
- dodopayments = new DodoPayments({
11903
- bearerToken: bearerToken,
11904
- environment: environment,
11905
- });
11906
- isSubscription = false;
11907
- productIdToFetch = product_id;
11908
- if (!product_id && product_cart && product_cart.length > 0) {
11909
- productIdToFetch = product_cart[0].product_id;
11910
- }
11911
- if (!productIdToFetch)
11912
- throw new Error("Missing required field: product_id or product_cart[0].product_id");
11913
- _g.label = 8;
11914
- case 8:
11915
- _g.trys.push([8, 10, , 11]);
11916
- return [4 /*yield*/, dodopayments.products.retrieve(productIdToFetch)];
11917
- case 9:
11918
- product = _g.sent();
11919
- return [3 /*break*/, 11];
11920
- case 10:
11921
- err_2 = _g.sent();
11922
- console.error(err_2);
11923
- throw new Error("Product not found");
11924
- case 11:
11925
- isSubscription = Boolean(product.is_recurring);
11926
- // Required field validation
11927
- if (isSubscription && !product_id)
11928
- throw new Error("Missing required field: product_id for subscription");
11929
- if (!billing)
11930
- throw new Error("Missing required field: billing");
11931
- if (!customer)
11932
- throw new Error("Missing required field: customer");
11933
- if (!isSubscription) return [3 /*break*/, 16];
11934
- subscriptionPayload = {
11935
- billing: billing,
11936
- customer: customer,
11937
- product_id: product_id,
11938
- quantity: quantity ? Number(quantity) : 1,
11939
- };
11940
- if (metadata)
11941
- subscriptionPayload.metadata = metadata;
11942
- if (discount_code)
11943
- subscriptionPayload.discount_code = discount_code;
11944
- if (addons)
11945
- subscriptionPayload.addons = addons;
11946
- if (allowed_payment_method_types)
11947
- subscriptionPayload.allowed_payment_method_types =
11948
- allowed_payment_method_types;
11949
- if (billing_currency)
11950
- subscriptionPayload.billing_currency = billing_currency;
11951
- if (on_demand)
11952
- subscriptionPayload.on_demand = on_demand;
11953
- subscriptionPayload.payment_link = true;
11954
- // Use bodyReturnUrl if present, otherwise use top-level returnUrl
11955
- if (bodyReturnUrl) {
11956
- subscriptionPayload.return_url = bodyReturnUrl;
11957
- }
11958
- else if (returnUrl) {
11959
- subscriptionPayload.return_url = returnUrl;
11960
- }
11961
- if (show_saved_payment_methods)
11962
- subscriptionPayload.show_saved_payment_methods =
11963
- show_saved_payment_methods;
11964
- if (tax_id)
11965
- subscriptionPayload.tax_id = tax_id;
11966
- if (trial_period_days)
11967
- subscriptionPayload.trial_period_days = trial_period_days;
11968
- subscription = void 0;
11969
- _g.label = 12;
11970
- case 12:
11971
- _g.trys.push([12, 14, , 15]);
11972
- return [4 /*yield*/, dodopayments.subscriptions.create(subscriptionPayload)];
11973
- case 13:
11974
- subscription =
11975
- _g.sent();
11976
- return [3 /*break*/, 15];
11977
- case 14:
11978
- err_3 = _g.sent();
11979
- console.error("Error when creating subscription", err_3);
11980
- throw new Error(err_3 instanceof Error ? err_3.message : String(err_3));
11981
- case 15:
11982
- if (!subscription || !subscription.payment_link) {
11983
- throw new Error("No payment link returned from Dodo Payments API (subscription). Make sure to set payment_link as true in payload");
11984
- }
11985
- return [2 /*return*/, subscription.payment_link];
11986
- case 16:
11987
- cart = product_cart;
11988
- if (!cart && product_id) {
11989
- cart = [
11990
- { product_id: product_id, quantity: quantity ? Number(quantity) : 1 },
11991
- ];
11992
- }
11993
- if (!cart || cart.length === 0)
11994
- throw new Error("Missing required field: product_cart or product_id");
11995
- paymentPayload = {
11996
- billing: billing,
11997
- customer: customer,
11998
- product_cart: cart,
11999
- };
12000
- if (metadata)
12001
- paymentPayload.metadata = metadata;
12002
- paymentPayload.payment_link = true;
12003
- if (allowed_payment_method_types)
12004
- paymentPayload.allowed_payment_method_types =
12005
- allowed_payment_method_types;
12006
- if (billing_currency)
12007
- paymentPayload.billing_currency = billing_currency;
12008
- if (discount_code)
12009
- paymentPayload.discount_code = discount_code;
12010
- // Use bodyReturnUrl if present, otherwise use top-level returnUrl
12011
- if (bodyReturnUrl) {
12012
- paymentPayload.return_url = bodyReturnUrl;
12013
- }
12014
- else if (returnUrl) {
12015
- paymentPayload.return_url = returnUrl;
12016
- }
12017
- if (show_saved_payment_methods)
12018
- paymentPayload.show_saved_payment_methods = show_saved_payment_methods;
12019
- if (tax_id)
12020
- paymentPayload.tax_id = tax_id;
12021
- payment = void 0;
12022
- _g.label = 17;
12023
- case 17:
12024
- _g.trys.push([17, 19, , 20]);
12025
- return [4 /*yield*/, dodopayments.payments.create(paymentPayload)];
12026
- case 18:
12027
- payment = _g.sent();
12028
- return [3 /*break*/, 20];
12029
- case 19:
12030
- err_4 = _g.sent();
12031
- console.error("Error when creating payment link", err_4);
12032
- throw new Error(err_4 instanceof Error ? err_4.message : String(err_4));
12033
- case 20:
12034
- if (!payment || !payment.payment_link) {
12035
- throw new Error("No payment link returned from Dodo Payments API. Make sure to set payment_link as true in payload.");
12036
- }
12037
- return [2 /*return*/, payment.payment_link];
12038
- }
11753
+ return session.checkout_url;
11754
+ }
11755
+ const inputData = type === "dynamic" ? body : queryParams;
11756
+ let parseResult;
11757
+ if (type === "dynamic") {
11758
+ parseResult = dynamicCheckoutBodySchema.safeParse(inputData);
11759
+ } else {
11760
+ parseResult = checkoutQuerySchema.safeParse(inputData);
11761
+ }
11762
+ const { success, data, error } = parseResult;
11763
+ if (!success) {
11764
+ throw new Error(
11765
+ `Invalid ${type === "dynamic" ? "body" : "query parameters"}.
11766
+ ${error.message}`
11767
+ );
11768
+ }
11769
+ if (type !== "dynamic") {
11770
+ const {
11771
+ productId,
11772
+ quantity: quantity2,
11773
+ fullName,
11774
+ firstName,
11775
+ lastName,
11776
+ email,
11777
+ country,
11778
+ addressLine,
11779
+ city,
11780
+ state,
11781
+ zipCode,
11782
+ disableFullName,
11783
+ disableFirstName,
11784
+ disableLastName,
11785
+ disableEmail,
11786
+ disableCountry,
11787
+ disableAddressLine,
11788
+ disableCity,
11789
+ disableState,
11790
+ disableZipCode,
11791
+ paymentCurrency,
11792
+ showCurrencySelector,
11793
+ paymentAmount,
11794
+ showDiscounts
11795
+ // metadata handled below
11796
+ } = data;
11797
+ const dodopayments2 = new DodoPayments({
11798
+ bearerToken,
11799
+ environment
12039
11800
  });
12040
- }); };
11801
+ if (!productId) throw new Error("Missing required field: productId");
11802
+ try {
11803
+ await dodopayments2.products.retrieve(productId);
11804
+ } catch (err) {
11805
+ console.error(err);
11806
+ throw new Error("Product not found");
11807
+ }
11808
+ const url = new URL(
11809
+ `${environment === "test_mode" ? "https://test.checkout.dodopayments.com" : "https://checkout.dodopayments.com"}/buy/${productId}`
11810
+ );
11811
+ url.searchParams.set("quantity", quantity2 ? String(quantity2) : "1");
11812
+ if (returnUrl) url.searchParams.set("redirect_url", returnUrl);
11813
+ if (fullName) url.searchParams.set("fullName", String(fullName));
11814
+ if (firstName) url.searchParams.set("firstName", String(firstName));
11815
+ if (lastName) url.searchParams.set("lastName", String(lastName));
11816
+ if (email) url.searchParams.set("email", String(email));
11817
+ if (country) url.searchParams.set("country", String(country));
11818
+ if (addressLine) url.searchParams.set("addressLine", String(addressLine));
11819
+ if (city) url.searchParams.set("city", String(city));
11820
+ if (state) url.searchParams.set("state", String(state));
11821
+ if (zipCode) url.searchParams.set("zipCode", String(zipCode));
11822
+ if (disableFullName === "true")
11823
+ url.searchParams.set("disableFullName", "true");
11824
+ if (disableFirstName === "true")
11825
+ url.searchParams.set("disableFirstName", "true");
11826
+ if (disableLastName === "true")
11827
+ url.searchParams.set("disableLastName", "true");
11828
+ if (disableEmail === "true") url.searchParams.set("disableEmail", "true");
11829
+ if (disableCountry === "true")
11830
+ url.searchParams.set("disableCountry", "true");
11831
+ if (disableAddressLine === "true")
11832
+ url.searchParams.set("disableAddressLine", "true");
11833
+ if (disableCity === "true") url.searchParams.set("disableCity", "true");
11834
+ if (disableState === "true") url.searchParams.set("disableState", "true");
11835
+ if (disableZipCode === "true")
11836
+ url.searchParams.set("disableZipCode", "true");
11837
+ if (paymentCurrency)
11838
+ url.searchParams.set("paymentCurrency", String(paymentCurrency));
11839
+ if (showCurrencySelector)
11840
+ url.searchParams.set(
11841
+ "showCurrencySelector",
11842
+ String(showCurrencySelector)
11843
+ );
11844
+ if (paymentAmount)
11845
+ url.searchParams.set("paymentAmount", String(paymentAmount));
11846
+ if (showDiscounts)
11847
+ url.searchParams.set("showDiscounts", String(showDiscounts));
11848
+ for (const [key, value] of Object.entries(queryParams || {})) {
11849
+ if (key.startsWith("metadata_") && value && typeof value !== "object") {
11850
+ url.searchParams.set(key, String(value));
11851
+ }
11852
+ }
11853
+ return url.toString();
11854
+ }
11855
+ const dyn = data;
11856
+ const {
11857
+ product_id,
11858
+ product_cart,
11859
+ quantity,
11860
+ billing,
11861
+ customer,
11862
+ addons,
11863
+ metadata,
11864
+ allowed_payment_method_types,
11865
+ billing_currency,
11866
+ discount_code,
11867
+ on_demand,
11868
+ return_url: bodyReturnUrl,
11869
+ show_saved_payment_methods,
11870
+ tax_id,
11871
+ trial_period_days
11872
+ } = dyn;
11873
+ const dodopayments = new DodoPayments({
11874
+ bearerToken,
11875
+ environment
11876
+ });
11877
+ let isSubscription = false;
11878
+ let productIdToFetch = product_id;
11879
+ if (!product_id && product_cart && product_cart.length > 0) {
11880
+ productIdToFetch = product_cart[0].product_id;
11881
+ }
11882
+ if (!productIdToFetch)
11883
+ throw new Error(
11884
+ "Missing required field: product_id or product_cart[0].product_id"
11885
+ );
11886
+ let product;
11887
+ try {
11888
+ product = await dodopayments.products.retrieve(productIdToFetch);
11889
+ } catch (err) {
11890
+ console.error(err);
11891
+ throw new Error("Product not found");
11892
+ }
11893
+ isSubscription = Boolean(product.is_recurring);
11894
+ if (isSubscription && !product_id)
11895
+ throw new Error("Missing required field: product_id for subscription");
11896
+ if (!billing) throw new Error("Missing required field: billing");
11897
+ if (!customer) throw new Error("Missing required field: customer");
11898
+ if (isSubscription) {
11899
+ const subscriptionPayload = {
11900
+ billing,
11901
+ customer,
11902
+ product_id,
11903
+ quantity: quantity ? Number(quantity) : 1
11904
+ };
11905
+ if (metadata) subscriptionPayload.metadata = metadata;
11906
+ if (discount_code) subscriptionPayload.discount_code = discount_code;
11907
+ if (addons) subscriptionPayload.addons = addons;
11908
+ if (allowed_payment_method_types)
11909
+ subscriptionPayload.allowed_payment_method_types = allowed_payment_method_types;
11910
+ if (billing_currency)
11911
+ subscriptionPayload.billing_currency = billing_currency;
11912
+ if (on_demand) subscriptionPayload.on_demand = on_demand;
11913
+ subscriptionPayload.payment_link = true;
11914
+ if (bodyReturnUrl) {
11915
+ subscriptionPayload.return_url = bodyReturnUrl;
11916
+ } else if (returnUrl) {
11917
+ subscriptionPayload.return_url = returnUrl;
11918
+ }
11919
+ if (show_saved_payment_methods)
11920
+ subscriptionPayload.show_saved_payment_methods = show_saved_payment_methods;
11921
+ if (tax_id) subscriptionPayload.tax_id = tax_id;
11922
+ if (trial_period_days)
11923
+ subscriptionPayload.trial_period_days = trial_period_days;
11924
+ let subscription;
11925
+ try {
11926
+ subscription = await dodopayments.subscriptions.create(subscriptionPayload);
11927
+ } catch (err) {
11928
+ console.error("Error when creating subscription", err);
11929
+ throw new Error(err instanceof Error ? err.message : String(err));
11930
+ }
11931
+ if (!subscription || !subscription.payment_link) {
11932
+ throw new Error(
11933
+ "No payment link returned from Dodo Payments API (subscription). Make sure to set payment_link as true in payload"
11934
+ );
11935
+ }
11936
+ return subscription.payment_link;
11937
+ } else {
11938
+ let cart = product_cart;
11939
+ if (!cart && product_id) {
11940
+ cart = [
11941
+ { product_id, quantity: quantity ? Number(quantity) : 1 }
11942
+ ];
11943
+ }
11944
+ if (!cart || cart.length === 0)
11945
+ throw new Error("Missing required field: product_cart or product_id");
11946
+ const paymentPayload = {
11947
+ billing,
11948
+ customer,
11949
+ product_cart: cart
11950
+ };
11951
+ if (metadata) paymentPayload.metadata = metadata;
11952
+ paymentPayload.payment_link = true;
11953
+ if (allowed_payment_method_types)
11954
+ paymentPayload.allowed_payment_method_types = allowed_payment_method_types;
11955
+ if (billing_currency) paymentPayload.billing_currency = billing_currency;
11956
+ if (discount_code) paymentPayload.discount_code = discount_code;
11957
+ if (bodyReturnUrl) {
11958
+ paymentPayload.return_url = bodyReturnUrl;
11959
+ } else if (returnUrl) {
11960
+ paymentPayload.return_url = returnUrl;
11961
+ }
11962
+ if (show_saved_payment_methods)
11963
+ paymentPayload.show_saved_payment_methods = show_saved_payment_methods;
11964
+ if (tax_id) paymentPayload.tax_id = tax_id;
11965
+ let payment;
11966
+ try {
11967
+ payment = await dodopayments.payments.create(paymentPayload);
11968
+ } catch (err) {
11969
+ console.error("Error when creating payment link", err);
11970
+ throw new Error(err instanceof Error ? err.message : String(err));
11971
+ }
11972
+ if (!payment || !payment.payment_link) {
11973
+ throw new Error(
11974
+ "No payment link returned from Dodo Payments API. Make sure to set payment_link as true in payload."
11975
+ );
11976
+ }
11977
+ return payment.payment_link;
11978
+ }
11979
+ };
12041
11980
 
12042
11981
  const Checkout = (config) => {
12043
11982
  const getHandler = async (req) => {
@@ -12976,542 +12915,422 @@ class Webhook {
12976
12915
  Webhook_1 = dist.Webhook = Webhook;
12977
12916
  Webhook.prefix = "whsec_";
12978
12917
 
12918
+ // src/schemas/webhook.ts
12979
12919
  var PaymentSchema = objectType({
12980
- payload_type: literalType("Payment"),
12981
- billing: objectType({
12982
- city: stringType().nullable(),
12983
- country: stringType().nullable(),
12984
- state: stringType().nullable(),
12985
- street: stringType().nullable(),
12986
- zipcode: stringType().nullable(),
12987
- }),
12988
- brand_id: stringType(),
12989
- business_id: stringType(),
12990
- card_issuing_country: stringType().nullable(),
12991
- card_last_four: stringType().nullable(),
12992
- card_network: stringType().nullable(),
12993
- card_type: stringType().nullable(),
12994
- created_at: stringType().transform(function (d) { return new Date(d); }),
12995
- currency: stringType(),
12996
- customer: objectType({
12997
- customer_id: stringType(),
12998
- email: stringType(),
12999
- name: stringType().nullable(),
13000
- }),
13001
- digital_products_delivered: booleanType(),
13002
- discount_id: stringType().nullable(),
13003
- disputes: arrayType(objectType({
13004
- amount: stringType(),
13005
- business_id: stringType(),
13006
- created_at: stringType().transform(function (d) { return new Date(d); }),
13007
- currency: stringType(),
13008
- dispute_id: stringType(),
13009
- dispute_stage: enumType([
13010
- "pre_dispute",
13011
- "dispute_opened",
13012
- "dispute_won",
13013
- "dispute_lost",
13014
- ]),
13015
- dispute_status: enumType([
13016
- "dispute_opened",
13017
- "dispute_won",
13018
- "dispute_lost",
13019
- "dispute_accepted",
13020
- "dispute_cancelled",
13021
- "dispute_challenged",
13022
- ]),
13023
- payment_id: stringType(),
13024
- remarks: stringType().nullable(),
13025
- }))
13026
- .nullable(),
13027
- error_code: stringType().nullable(),
13028
- error_message: stringType().nullable(),
13029
- metadata: recordType(anyType()).nullable(),
13030
- payment_id: stringType(),
13031
- payment_link: stringType().nullable(),
13032
- payment_method: stringType().nullable(),
13033
- payment_method_type: stringType().nullable(),
13034
- product_cart: arrayType(objectType({
13035
- product_id: stringType(),
13036
- quantity: numberType(),
13037
- }))
13038
- .nullable(),
13039
- refunds: arrayType(objectType({
13040
- amount: numberType(),
13041
- business_id: stringType(),
13042
- created_at: stringType().transform(function (d) { return new Date(d); }),
13043
- currency: stringType(),
13044
- is_partial: booleanType(),
13045
- payment_id: stringType(),
13046
- reason: stringType().nullable(),
13047
- refund_id: stringType(),
13048
- status: enumType(["succeeded", "failed", "pending"]),
13049
- }))
13050
- .nullable(),
13051
- settlement_amount: numberType(),
13052
- settlement_currency: stringType(),
13053
- settlement_tax: numberType().nullable(),
13054
- status: enumType(["succeeded", "failed", "pending", "processing", "cancelled"]),
13055
- subscription_id: stringType().nullable(),
13056
- tax: numberType().nullable(),
13057
- total_amount: numberType(),
13058
- updated_at: stringType()
13059
- .transform(function (d) { return new Date(d); })
13060
- .nullable(),
13061
- });
13062
- var SubscriptionSchema = objectType({
13063
- payload_type: literalType("Subscription"),
13064
- addons: arrayType(objectType({
13065
- addon_id: stringType(),
13066
- quantity: numberType(),
13067
- }))
13068
- .nullable(),
13069
- billing: objectType({
13070
- city: stringType().nullable(),
13071
- country: stringType().nullable(),
13072
- state: stringType().nullable(),
13073
- street: stringType().nullable(),
13074
- zipcode: stringType().nullable(),
13075
- }),
13076
- cancel_at_next_billing_date: booleanType(),
13077
- cancelled_at: stringType()
13078
- .transform(function (d) { return new Date(d); })
13079
- .nullable(),
13080
- created_at: stringType().transform(function (d) { return new Date(d); }),
13081
- currency: stringType(),
13082
- customer: objectType({
13083
- customer_id: stringType(),
13084
- email: stringType(),
13085
- name: stringType().nullable(),
13086
- }),
13087
- discount_id: stringType().nullable(),
13088
- metadata: recordType(anyType()).nullable(),
13089
- next_billing_date: stringType()
13090
- .transform(function (d) { return new Date(d); })
13091
- .nullable(),
13092
- on_demand: booleanType(),
13093
- payment_frequency_count: numberType(),
13094
- payment_frequency_interval: enumType(["Day", "Week", "Month", "Year"]),
13095
- previous_billing_date: stringType()
13096
- .transform(function (d) { return new Date(d); })
13097
- .nullable(),
13098
- product_id: stringType(),
13099
- quantity: numberType(),
13100
- recurring_pre_tax_amount: numberType(),
13101
- status: enumType([
13102
- "pending",
13103
- "active",
13104
- "on_hold",
13105
- "paused",
13106
- "cancelled",
13107
- "expired",
13108
- "failed",
13109
- ]),
13110
- subscription_id: stringType(),
13111
- subscription_period_count: numberType(),
13112
- subscription_period_interval: enumType(["Day", "Week", "Month", "Year"]),
13113
- tax_inclusive: booleanType(),
13114
- trial_period_days: numberType(),
13115
- });
13116
- var RefundSchema = objectType({
13117
- payload_type: literalType("Refund"),
13118
- amount: numberType(),
13119
- business_id: stringType(),
13120
- created_at: stringType().transform(function (d) { return new Date(d); }),
13121
- currency: stringType(),
13122
- is_partial: booleanType(),
13123
- payment_id: stringType(),
13124
- reason: stringType().nullable(),
13125
- refund_id: stringType(),
13126
- status: enumType(["succeeded", "failed", "pending"]),
13127
- });
13128
- var DisputeSchema = objectType({
13129
- payload_type: literalType("Dispute"),
13130
- amount: stringType(),
13131
- business_id: stringType(),
13132
- created_at: stringType().transform(function (d) { return new Date(d); }),
13133
- currency: stringType(),
13134
- dispute_id: stringType(),
13135
- dispute_stage: enumType([
12920
+ payload_type: literalType("Payment"),
12921
+ billing: objectType({
12922
+ city: stringType().nullable(),
12923
+ country: stringType().nullable(),
12924
+ state: stringType().nullable(),
12925
+ street: stringType().nullable(),
12926
+ zipcode: stringType().nullable()
12927
+ }),
12928
+ brand_id: stringType(),
12929
+ business_id: stringType(),
12930
+ card_issuing_country: stringType().nullable(),
12931
+ card_last_four: stringType().nullable(),
12932
+ card_network: stringType().nullable(),
12933
+ card_type: stringType().nullable(),
12934
+ created_at: stringType().transform((d) => new Date(d)),
12935
+ currency: stringType(),
12936
+ customer: objectType({
12937
+ customer_id: stringType(),
12938
+ email: stringType(),
12939
+ name: stringType().nullable()
12940
+ }),
12941
+ digital_products_delivered: booleanType(),
12942
+ discount_id: stringType().nullable(),
12943
+ disputes: arrayType(
12944
+ objectType({
12945
+ amount: stringType(),
12946
+ business_id: stringType(),
12947
+ created_at: stringType().transform((d) => new Date(d)),
12948
+ currency: stringType(),
12949
+ dispute_id: stringType(),
12950
+ dispute_stage: enumType([
13136
12951
  "pre_dispute",
13137
12952
  "dispute_opened",
13138
12953
  "dispute_won",
13139
- "dispute_lost",
13140
- ]),
13141
- dispute_status: enumType([
12954
+ "dispute_lost"
12955
+ ]),
12956
+ dispute_status: enumType([
13142
12957
  "dispute_opened",
13143
12958
  "dispute_won",
13144
12959
  "dispute_lost",
13145
12960
  "dispute_accepted",
13146
12961
  "dispute_cancelled",
13147
- "dispute_challenged",
13148
- ]),
13149
- payment_id: stringType(),
13150
- remarks: stringType().nullable(),
12962
+ "dispute_challenged"
12963
+ ]),
12964
+ payment_id: stringType(),
12965
+ remarks: stringType().nullable()
12966
+ })
12967
+ ).nullable(),
12968
+ error_code: stringType().nullable(),
12969
+ error_message: stringType().nullable(),
12970
+ metadata: recordType(anyType()).nullable(),
12971
+ payment_id: stringType(),
12972
+ payment_link: stringType().nullable(),
12973
+ payment_method: stringType().nullable(),
12974
+ payment_method_type: stringType().nullable(),
12975
+ product_cart: arrayType(
12976
+ objectType({
12977
+ product_id: stringType(),
12978
+ quantity: numberType()
12979
+ })
12980
+ ).nullable(),
12981
+ refunds: arrayType(
12982
+ objectType({
12983
+ amount: numberType(),
12984
+ business_id: stringType(),
12985
+ created_at: stringType().transform((d) => new Date(d)),
12986
+ currency: stringType(),
12987
+ is_partial: booleanType(),
12988
+ payment_id: stringType(),
12989
+ reason: stringType().nullable(),
12990
+ refund_id: stringType(),
12991
+ status: enumType(["succeeded", "failed", "pending"])
12992
+ })
12993
+ ).nullable(),
12994
+ settlement_amount: numberType(),
12995
+ settlement_currency: stringType(),
12996
+ settlement_tax: numberType().nullable(),
12997
+ status: enumType(["succeeded", "failed", "pending", "processing", "cancelled"]),
12998
+ subscription_id: stringType().nullable(),
12999
+ tax: numberType().nullable(),
13000
+ total_amount: numberType(),
13001
+ updated_at: stringType().transform((d) => new Date(d)).nullable()
13151
13002
  });
13152
- var LicenseKeySchema = objectType({
13153
- payload_type: literalType("LicenseKey"),
13154
- activations_limit: numberType(),
13155
- business_id: stringType(),
13156
- created_at: stringType().transform(function (d) { return new Date(d); }),
13003
+ var SubscriptionSchema = objectType({
13004
+ payload_type: literalType("Subscription"),
13005
+ addons: arrayType(
13006
+ objectType({
13007
+ addon_id: stringType(),
13008
+ quantity: numberType()
13009
+ })
13010
+ ).nullable(),
13011
+ billing: objectType({
13012
+ city: stringType().nullable(),
13013
+ country: stringType().nullable(),
13014
+ state: stringType().nullable(),
13015
+ street: stringType().nullable(),
13016
+ zipcode: stringType().nullable()
13017
+ }),
13018
+ cancel_at_next_billing_date: booleanType(),
13019
+ cancelled_at: stringType().transform((d) => new Date(d)).nullable(),
13020
+ created_at: stringType().transform((d) => new Date(d)),
13021
+ currency: stringType(),
13022
+ customer: objectType({
13157
13023
  customer_id: stringType(),
13158
- expires_at: stringType()
13159
- .transform(function (d) { return new Date(d); })
13160
- .nullable(),
13161
- id: stringType(),
13162
- instances_count: numberType(),
13163
- key: stringType(),
13164
- payment_id: stringType(),
13165
- product_id: stringType(),
13166
- status: enumType(["active", "inactive", "expired"]),
13167
- subscription_id: stringType().nullable(),
13024
+ email: stringType(),
13025
+ name: stringType().nullable()
13026
+ }),
13027
+ discount_id: stringType().nullable(),
13028
+ metadata: recordType(anyType()).nullable(),
13029
+ next_billing_date: stringType().transform((d) => new Date(d)).nullable(),
13030
+ on_demand: booleanType(),
13031
+ payment_frequency_count: numberType(),
13032
+ payment_frequency_interval: enumType(["Day", "Week", "Month", "Year"]),
13033
+ previous_billing_date: stringType().transform((d) => new Date(d)).nullable(),
13034
+ product_id: stringType(),
13035
+ quantity: numberType(),
13036
+ recurring_pre_tax_amount: numberType(),
13037
+ status: enumType([
13038
+ "pending",
13039
+ "active",
13040
+ "on_hold",
13041
+ "paused",
13042
+ "cancelled",
13043
+ "expired",
13044
+ "failed"
13045
+ ]),
13046
+ subscription_id: stringType(),
13047
+ subscription_period_count: numberType(),
13048
+ subscription_period_interval: enumType(["Day", "Week", "Month", "Year"]),
13049
+ tax_inclusive: booleanType(),
13050
+ trial_period_days: numberType()
13051
+ });
13052
+ var RefundSchema = objectType({
13053
+ payload_type: literalType("Refund"),
13054
+ amount: numberType(),
13055
+ business_id: stringType(),
13056
+ created_at: stringType().transform((d) => new Date(d)),
13057
+ currency: stringType(),
13058
+ is_partial: booleanType(),
13059
+ payment_id: stringType(),
13060
+ reason: stringType().nullable(),
13061
+ refund_id: stringType(),
13062
+ status: enumType(["succeeded", "failed", "pending"])
13063
+ });
13064
+ var DisputeSchema = objectType({
13065
+ payload_type: literalType("Dispute"),
13066
+ amount: stringType(),
13067
+ business_id: stringType(),
13068
+ created_at: stringType().transform((d) => new Date(d)),
13069
+ currency: stringType(),
13070
+ dispute_id: stringType(),
13071
+ dispute_stage: enumType([
13072
+ "pre_dispute",
13073
+ "dispute_opened",
13074
+ "dispute_won",
13075
+ "dispute_lost"
13076
+ ]),
13077
+ dispute_status: enumType([
13078
+ "dispute_opened",
13079
+ "dispute_won",
13080
+ "dispute_lost",
13081
+ "dispute_accepted",
13082
+ "dispute_cancelled",
13083
+ "dispute_challenged"
13084
+ ]),
13085
+ payment_id: stringType(),
13086
+ remarks: stringType().nullable()
13087
+ });
13088
+ var LicenseKeySchema = objectType({
13089
+ payload_type: literalType("LicenseKey"),
13090
+ activations_limit: numberType(),
13091
+ business_id: stringType(),
13092
+ created_at: stringType().transform((d) => new Date(d)),
13093
+ customer_id: stringType(),
13094
+ expires_at: stringType().transform((d) => new Date(d)).nullable(),
13095
+ id: stringType(),
13096
+ instances_count: numberType(),
13097
+ key: stringType(),
13098
+ payment_id: stringType(),
13099
+ product_id: stringType(),
13100
+ status: enumType(["active", "inactive", "expired"]),
13101
+ subscription_id: stringType().nullable()
13168
13102
  });
13169
13103
  var PaymentSucceededPayloadSchema = objectType({
13170
- business_id: stringType(),
13171
- type: literalType("payment.succeeded"),
13172
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13173
- data: PaymentSchema,
13104
+ business_id: stringType(),
13105
+ type: literalType("payment.succeeded"),
13106
+ timestamp: stringType().transform((d) => new Date(d)),
13107
+ data: PaymentSchema
13174
13108
  });
13175
13109
  var PaymentFailedPayloadSchema = objectType({
13176
- business_id: stringType(),
13177
- type: literalType("payment.failed"),
13178
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13179
- data: PaymentSchema,
13110
+ business_id: stringType(),
13111
+ type: literalType("payment.failed"),
13112
+ timestamp: stringType().transform((d) => new Date(d)),
13113
+ data: PaymentSchema
13180
13114
  });
13181
13115
  var PaymentProcessingPayloadSchema = objectType({
13182
- business_id: stringType(),
13183
- type: literalType("payment.processing"),
13184
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13185
- data: PaymentSchema,
13116
+ business_id: stringType(),
13117
+ type: literalType("payment.processing"),
13118
+ timestamp: stringType().transform((d) => new Date(d)),
13119
+ data: PaymentSchema
13186
13120
  });
13187
13121
  var PaymentCancelledPayloadSchema = objectType({
13188
- business_id: stringType(),
13189
- type: literalType("payment.cancelled"),
13190
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13191
- data: PaymentSchema,
13122
+ business_id: stringType(),
13123
+ type: literalType("payment.cancelled"),
13124
+ timestamp: stringType().transform((d) => new Date(d)),
13125
+ data: PaymentSchema
13192
13126
  });
13193
13127
  var RefundSucceededPayloadSchema = objectType({
13194
- business_id: stringType(),
13195
- type: literalType("refund.succeeded"),
13196
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13197
- data: RefundSchema,
13128
+ business_id: stringType(),
13129
+ type: literalType("refund.succeeded"),
13130
+ timestamp: stringType().transform((d) => new Date(d)),
13131
+ data: RefundSchema
13198
13132
  });
13199
13133
  var RefundFailedPayloadSchema = objectType({
13200
- business_id: stringType(),
13201
- type: literalType("refund.failed"),
13202
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13203
- data: RefundSchema,
13134
+ business_id: stringType(),
13135
+ type: literalType("refund.failed"),
13136
+ timestamp: stringType().transform((d) => new Date(d)),
13137
+ data: RefundSchema
13204
13138
  });
13205
13139
  var DisputeOpenedPayloadSchema = objectType({
13206
- business_id: stringType(),
13207
- type: literalType("dispute.opened"),
13208
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13209
- data: DisputeSchema,
13140
+ business_id: stringType(),
13141
+ type: literalType("dispute.opened"),
13142
+ timestamp: stringType().transform((d) => new Date(d)),
13143
+ data: DisputeSchema
13210
13144
  });
13211
13145
  var DisputeExpiredPayloadSchema = objectType({
13212
- business_id: stringType(),
13213
- type: literalType("dispute.expired"),
13214
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13215
- data: DisputeSchema,
13146
+ business_id: stringType(),
13147
+ type: literalType("dispute.expired"),
13148
+ timestamp: stringType().transform((d) => new Date(d)),
13149
+ data: DisputeSchema
13216
13150
  });
13217
13151
  var DisputeAcceptedPayloadSchema = objectType({
13218
- business_id: stringType(),
13219
- type: literalType("dispute.accepted"),
13220
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13221
- data: DisputeSchema,
13152
+ business_id: stringType(),
13153
+ type: literalType("dispute.accepted"),
13154
+ timestamp: stringType().transform((d) => new Date(d)),
13155
+ data: DisputeSchema
13222
13156
  });
13223
13157
  var DisputeCancelledPayloadSchema = objectType({
13224
- business_id: stringType(),
13225
- type: literalType("dispute.cancelled"),
13226
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13227
- data: DisputeSchema,
13158
+ business_id: stringType(),
13159
+ type: literalType("dispute.cancelled"),
13160
+ timestamp: stringType().transform((d) => new Date(d)),
13161
+ data: DisputeSchema
13228
13162
  });
13229
13163
  var DisputeChallengedPayloadSchema = objectType({
13230
- business_id: stringType(),
13231
- type: literalType("dispute.challenged"),
13232
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13233
- data: DisputeSchema,
13164
+ business_id: stringType(),
13165
+ type: literalType("dispute.challenged"),
13166
+ timestamp: stringType().transform((d) => new Date(d)),
13167
+ data: DisputeSchema
13234
13168
  });
13235
13169
  var DisputeWonPayloadSchema = objectType({
13236
- business_id: stringType(),
13237
- type: literalType("dispute.won"),
13238
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13239
- data: DisputeSchema,
13170
+ business_id: stringType(),
13171
+ type: literalType("dispute.won"),
13172
+ timestamp: stringType().transform((d) => new Date(d)),
13173
+ data: DisputeSchema
13240
13174
  });
13241
13175
  var DisputeLostPayloadSchema = objectType({
13242
- business_id: stringType(),
13243
- type: literalType("dispute.lost"),
13244
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13245
- data: DisputeSchema,
13176
+ business_id: stringType(),
13177
+ type: literalType("dispute.lost"),
13178
+ timestamp: stringType().transform((d) => new Date(d)),
13179
+ data: DisputeSchema
13246
13180
  });
13247
13181
  var SubscriptionActivePayloadSchema = objectType({
13248
- business_id: stringType(),
13249
- type: literalType("subscription.active"),
13250
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13251
- data: SubscriptionSchema,
13182
+ business_id: stringType(),
13183
+ type: literalType("subscription.active"),
13184
+ timestamp: stringType().transform((d) => new Date(d)),
13185
+ data: SubscriptionSchema
13252
13186
  });
13253
13187
  var SubscriptionOnHoldPayloadSchema = objectType({
13254
- business_id: stringType(),
13255
- type: literalType("subscription.on_hold"),
13256
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13257
- data: SubscriptionSchema,
13188
+ business_id: stringType(),
13189
+ type: literalType("subscription.on_hold"),
13190
+ timestamp: stringType().transform((d) => new Date(d)),
13191
+ data: SubscriptionSchema
13258
13192
  });
13259
13193
  var SubscriptionRenewedPayloadSchema = objectType({
13260
- business_id: stringType(),
13261
- type: literalType("subscription.renewed"),
13262
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13263
- data: SubscriptionSchema,
13194
+ business_id: stringType(),
13195
+ type: literalType("subscription.renewed"),
13196
+ timestamp: stringType().transform((d) => new Date(d)),
13197
+ data: SubscriptionSchema
13264
13198
  });
13265
13199
  var SubscriptionPausedPayloadSchema = objectType({
13266
- business_id: stringType(),
13267
- type: literalType("subscription.paused"),
13268
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13269
- data: SubscriptionSchema,
13200
+ business_id: stringType(),
13201
+ type: literalType("subscription.paused"),
13202
+ timestamp: stringType().transform((d) => new Date(d)),
13203
+ data: SubscriptionSchema
13270
13204
  });
13271
13205
  var SubscriptionPlanChangedPayloadSchema = objectType({
13272
- business_id: stringType(),
13273
- type: literalType("subscription.plan_changed"),
13274
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13275
- data: SubscriptionSchema,
13206
+ business_id: stringType(),
13207
+ type: literalType("subscription.plan_changed"),
13208
+ timestamp: stringType().transform((d) => new Date(d)),
13209
+ data: SubscriptionSchema
13276
13210
  });
13277
13211
  var SubscriptionCancelledPayloadSchema = objectType({
13278
- business_id: stringType(),
13279
- type: literalType("subscription.cancelled"),
13280
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13281
- data: SubscriptionSchema,
13212
+ business_id: stringType(),
13213
+ type: literalType("subscription.cancelled"),
13214
+ timestamp: stringType().transform((d) => new Date(d)),
13215
+ data: SubscriptionSchema
13282
13216
  });
13283
13217
  var SubscriptionFailedPayloadSchema = objectType({
13284
- business_id: stringType(),
13285
- type: literalType("subscription.failed"),
13286
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13287
- data: SubscriptionSchema,
13218
+ business_id: stringType(),
13219
+ type: literalType("subscription.failed"),
13220
+ timestamp: stringType().transform((d) => new Date(d)),
13221
+ data: SubscriptionSchema
13288
13222
  });
13289
13223
  var SubscriptionExpiredPayloadSchema = objectType({
13290
- business_id: stringType(),
13291
- type: literalType("subscription.expired"),
13292
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13293
- data: SubscriptionSchema,
13224
+ business_id: stringType(),
13225
+ type: literalType("subscription.expired"),
13226
+ timestamp: stringType().transform((d) => new Date(d)),
13227
+ data: SubscriptionSchema
13294
13228
  });
13295
13229
  var LicenseKeyCreatedPayloadSchema = objectType({
13296
- business_id: stringType(),
13297
- type: literalType("license_key.created"),
13298
- timestamp: stringType().transform(function (d) { return new Date(d); }),
13299
- data: LicenseKeySchema,
13230
+ business_id: stringType(),
13231
+ type: literalType("license_key.created"),
13232
+ timestamp: stringType().transform((d) => new Date(d)),
13233
+ data: LicenseKeySchema
13300
13234
  });
13301
13235
  var WebhookPayloadSchema = discriminatedUnionType("type", [
13302
- PaymentSucceededPayloadSchema,
13303
- PaymentFailedPayloadSchema,
13304
- PaymentProcessingPayloadSchema,
13305
- PaymentCancelledPayloadSchema,
13306
- RefundSucceededPayloadSchema,
13307
- RefundFailedPayloadSchema,
13308
- DisputeOpenedPayloadSchema,
13309
- DisputeExpiredPayloadSchema,
13310
- DisputeAcceptedPayloadSchema,
13311
- DisputeCancelledPayloadSchema,
13312
- DisputeChallengedPayloadSchema,
13313
- DisputeWonPayloadSchema,
13314
- DisputeLostPayloadSchema,
13315
- SubscriptionActivePayloadSchema,
13316
- SubscriptionOnHoldPayloadSchema,
13317
- SubscriptionRenewedPayloadSchema,
13318
- SubscriptionPausedPayloadSchema,
13319
- SubscriptionPlanChangedPayloadSchema,
13320
- SubscriptionCancelledPayloadSchema,
13321
- SubscriptionFailedPayloadSchema,
13322
- SubscriptionExpiredPayloadSchema,
13323
- LicenseKeyCreatedPayloadSchema,
13236
+ PaymentSucceededPayloadSchema,
13237
+ PaymentFailedPayloadSchema,
13238
+ PaymentProcessingPayloadSchema,
13239
+ PaymentCancelledPayloadSchema,
13240
+ RefundSucceededPayloadSchema,
13241
+ RefundFailedPayloadSchema,
13242
+ DisputeOpenedPayloadSchema,
13243
+ DisputeExpiredPayloadSchema,
13244
+ DisputeAcceptedPayloadSchema,
13245
+ DisputeCancelledPayloadSchema,
13246
+ DisputeChallengedPayloadSchema,
13247
+ DisputeWonPayloadSchema,
13248
+ DisputeLostPayloadSchema,
13249
+ SubscriptionActivePayloadSchema,
13250
+ SubscriptionOnHoldPayloadSchema,
13251
+ SubscriptionRenewedPayloadSchema,
13252
+ SubscriptionPausedPayloadSchema,
13253
+ SubscriptionPlanChangedPayloadSchema,
13254
+ SubscriptionCancelledPayloadSchema,
13255
+ SubscriptionFailedPayloadSchema,
13256
+ SubscriptionExpiredPayloadSchema,
13257
+ LicenseKeyCreatedPayloadSchema
13324
13258
  ]);
13325
13259
 
13326
- var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
13327
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
13328
- return new (P || (P = Promise))(function (resolve, reject) {
13329
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
13330
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13331
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13332
- step((generator = generator.apply(thisArg, _arguments || [])).next());
13333
- });
13334
- };
13335
- var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
13336
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13337
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13338
- function verb(n) { return function (v) { return step([n, v]); }; }
13339
- function step(op) {
13340
- if (f) throw new TypeError("Generator is already executing.");
13341
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
13342
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
13343
- if (y = 0, t) op = [op[0] & 2, t.value];
13344
- switch (op[0]) {
13345
- case 0: case 1: t = op; break;
13346
- case 4: _.label++; return { value: op[1], done: false };
13347
- case 5: _.label++; y = op[1]; op = [0]; continue;
13348
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
13349
- default:
13350
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
13351
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
13352
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
13353
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
13354
- if (t[2]) _.ops.pop();
13355
- _.trys.pop(); continue;
13356
- }
13357
- op = body.call(thisArg, _);
13358
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
13359
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
13360
- }
13361
- };
13362
- // Implementation
13363
- function handleWebhookPayload(payload, config, context) {
13364
- return __awaiter(this, void 0, void 0, function () {
13365
- var callHandler;
13366
- return __generator(this, function (_a) {
13367
- switch (_a.label) {
13368
- case 0:
13369
- callHandler = function (handler, payload) {
13370
- if (!handler)
13371
- return;
13372
- return handler(payload);
13373
- };
13374
- if (!config.onPayload) return [3 /*break*/, 2];
13375
- return [4 /*yield*/, callHandler(config.onPayload, payload)];
13376
- case 1:
13377
- _a.sent();
13378
- _a.label = 2;
13379
- case 2:
13380
- if (!(payload.type === "payment.succeeded")) return [3 /*break*/, 4];
13381
- return [4 /*yield*/, callHandler(config.onPaymentSucceeded, payload)];
13382
- case 3:
13383
- _a.sent();
13384
- _a.label = 4;
13385
- case 4:
13386
- if (!(payload.type === "payment.failed")) return [3 /*break*/, 6];
13387
- return [4 /*yield*/, callHandler(config.onPaymentFailed, payload)];
13388
- case 5:
13389
- _a.sent();
13390
- _a.label = 6;
13391
- case 6:
13392
- if (!(payload.type === "payment.processing")) return [3 /*break*/, 8];
13393
- return [4 /*yield*/, callHandler(config.onPaymentProcessing, payload)];
13394
- case 7:
13395
- _a.sent();
13396
- _a.label = 8;
13397
- case 8:
13398
- if (!(payload.type === "payment.cancelled")) return [3 /*break*/, 10];
13399
- return [4 /*yield*/, callHandler(config.onPaymentCancelled, payload)];
13400
- case 9:
13401
- _a.sent();
13402
- _a.label = 10;
13403
- case 10:
13404
- if (!(payload.type === "refund.succeeded")) return [3 /*break*/, 12];
13405
- return [4 /*yield*/, callHandler(config.onRefundSucceeded, payload)];
13406
- case 11:
13407
- _a.sent();
13408
- _a.label = 12;
13409
- case 12:
13410
- if (!(payload.type === "refund.failed")) return [3 /*break*/, 14];
13411
- return [4 /*yield*/, callHandler(config.onRefundFailed, payload)];
13412
- case 13:
13413
- _a.sent();
13414
- _a.label = 14;
13415
- case 14:
13416
- if (!(payload.type === "dispute.opened")) return [3 /*break*/, 16];
13417
- return [4 /*yield*/, callHandler(config.onDisputeOpened, payload)];
13418
- case 15:
13419
- _a.sent();
13420
- _a.label = 16;
13421
- case 16:
13422
- if (!(payload.type === "dispute.expired")) return [3 /*break*/, 18];
13423
- return [4 /*yield*/, callHandler(config.onDisputeExpired, payload)];
13424
- case 17:
13425
- _a.sent();
13426
- _a.label = 18;
13427
- case 18:
13428
- if (!(payload.type === "dispute.accepted")) return [3 /*break*/, 20];
13429
- return [4 /*yield*/, callHandler(config.onDisputeAccepted, payload)];
13430
- case 19:
13431
- _a.sent();
13432
- _a.label = 20;
13433
- case 20:
13434
- if (!(payload.type === "dispute.cancelled")) return [3 /*break*/, 22];
13435
- return [4 /*yield*/, callHandler(config.onDisputeCancelled, payload)];
13436
- case 21:
13437
- _a.sent();
13438
- _a.label = 22;
13439
- case 22:
13440
- if (!(payload.type === "dispute.challenged")) return [3 /*break*/, 24];
13441
- return [4 /*yield*/, callHandler(config.onDisputeChallenged, payload)];
13442
- case 23:
13443
- _a.sent();
13444
- _a.label = 24;
13445
- case 24:
13446
- if (!(payload.type === "dispute.won")) return [3 /*break*/, 26];
13447
- return [4 /*yield*/, callHandler(config.onDisputeWon, payload)];
13448
- case 25:
13449
- _a.sent();
13450
- _a.label = 26;
13451
- case 26:
13452
- if (!(payload.type === "dispute.lost")) return [3 /*break*/, 28];
13453
- return [4 /*yield*/, callHandler(config.onDisputeLost, payload)];
13454
- case 27:
13455
- _a.sent();
13456
- _a.label = 28;
13457
- case 28:
13458
- if (!(payload.type === "subscription.active")) return [3 /*break*/, 30];
13459
- return [4 /*yield*/, callHandler(config.onSubscriptionActive, payload)];
13460
- case 29:
13461
- _a.sent();
13462
- _a.label = 30;
13463
- case 30:
13464
- if (!(payload.type === "subscription.on_hold")) return [3 /*break*/, 32];
13465
- return [4 /*yield*/, callHandler(config.onSubscriptionOnHold, payload)];
13466
- case 31:
13467
- _a.sent();
13468
- _a.label = 32;
13469
- case 32:
13470
- if (!(payload.type === "subscription.renewed")) return [3 /*break*/, 34];
13471
- return [4 /*yield*/, callHandler(config.onSubscriptionRenewed, payload)];
13472
- case 33:
13473
- _a.sent();
13474
- _a.label = 34;
13475
- case 34:
13476
- if (!(payload.type === "subscription.paused")) return [3 /*break*/, 36];
13477
- return [4 /*yield*/, callHandler(config.onSubscriptionPaused, payload)];
13478
- case 35:
13479
- _a.sent();
13480
- _a.label = 36;
13481
- case 36:
13482
- if (!(payload.type === "subscription.plan_changed")) return [3 /*break*/, 38];
13483
- return [4 /*yield*/, callHandler(config.onSubscriptionPlanChanged, payload)];
13484
- case 37:
13485
- _a.sent();
13486
- _a.label = 38;
13487
- case 38:
13488
- if (!(payload.type === "subscription.cancelled")) return [3 /*break*/, 40];
13489
- return [4 /*yield*/, callHandler(config.onSubscriptionCancelled, payload)];
13490
- case 39:
13491
- _a.sent();
13492
- _a.label = 40;
13493
- case 40:
13494
- if (!(payload.type === "subscription.failed")) return [3 /*break*/, 42];
13495
- return [4 /*yield*/, callHandler(config.onSubscriptionFailed, payload)];
13496
- case 41:
13497
- _a.sent();
13498
- _a.label = 42;
13499
- case 42:
13500
- if (!(payload.type === "subscription.expired")) return [3 /*break*/, 44];
13501
- return [4 /*yield*/, callHandler(config.onSubscriptionExpired, payload)];
13502
- case 43:
13503
- _a.sent();
13504
- _a.label = 44;
13505
- case 44:
13506
- if (!(payload.type === "license_key.created")) return [3 /*break*/, 46];
13507
- return [4 /*yield*/, callHandler(config.onLicenseKeyCreated, payload)];
13508
- case 45:
13509
- _a.sent();
13510
- _a.label = 46;
13511
- case 46: return [2 /*return*/];
13512
- }
13513
- });
13514
- });
13260
+ async function handleWebhookPayload(payload, config, context) {
13261
+ const callHandler = (handler, payload2) => {
13262
+ if (!handler) return;
13263
+ return handler(payload2);
13264
+ };
13265
+ if (config.onPayload) {
13266
+ await callHandler(config.onPayload, payload);
13267
+ }
13268
+ if (payload.type === "payment.succeeded") {
13269
+ await callHandler(config.onPaymentSucceeded, payload);
13270
+ }
13271
+ if (payload.type === "payment.failed") {
13272
+ await callHandler(config.onPaymentFailed, payload);
13273
+ }
13274
+ if (payload.type === "payment.processing") {
13275
+ await callHandler(config.onPaymentProcessing, payload);
13276
+ }
13277
+ if (payload.type === "payment.cancelled") {
13278
+ await callHandler(config.onPaymentCancelled, payload);
13279
+ }
13280
+ if (payload.type === "refund.succeeded") {
13281
+ await callHandler(config.onRefundSucceeded, payload);
13282
+ }
13283
+ if (payload.type === "refund.failed") {
13284
+ await callHandler(config.onRefundFailed, payload);
13285
+ }
13286
+ if (payload.type === "dispute.opened") {
13287
+ await callHandler(config.onDisputeOpened, payload);
13288
+ }
13289
+ if (payload.type === "dispute.expired") {
13290
+ await callHandler(config.onDisputeExpired, payload);
13291
+ }
13292
+ if (payload.type === "dispute.accepted") {
13293
+ await callHandler(config.onDisputeAccepted, payload);
13294
+ }
13295
+ if (payload.type === "dispute.cancelled") {
13296
+ await callHandler(config.onDisputeCancelled, payload);
13297
+ }
13298
+ if (payload.type === "dispute.challenged") {
13299
+ await callHandler(config.onDisputeChallenged, payload);
13300
+ }
13301
+ if (payload.type === "dispute.won") {
13302
+ await callHandler(config.onDisputeWon, payload);
13303
+ }
13304
+ if (payload.type === "dispute.lost") {
13305
+ await callHandler(config.onDisputeLost, payload);
13306
+ }
13307
+ if (payload.type === "subscription.active") {
13308
+ await callHandler(config.onSubscriptionActive, payload);
13309
+ }
13310
+ if (payload.type === "subscription.on_hold") {
13311
+ await callHandler(config.onSubscriptionOnHold, payload);
13312
+ }
13313
+ if (payload.type === "subscription.renewed") {
13314
+ await callHandler(config.onSubscriptionRenewed, payload);
13315
+ }
13316
+ if (payload.type === "subscription.paused") {
13317
+ await callHandler(config.onSubscriptionPaused, payload);
13318
+ }
13319
+ if (payload.type === "subscription.plan_changed") {
13320
+ await callHandler(config.onSubscriptionPlanChanged, payload);
13321
+ }
13322
+ if (payload.type === "subscription.cancelled") {
13323
+ await callHandler(config.onSubscriptionCancelled, payload);
13324
+ }
13325
+ if (payload.type === "subscription.failed") {
13326
+ await callHandler(config.onSubscriptionFailed, payload);
13327
+ }
13328
+ if (payload.type === "subscription.expired") {
13329
+ await callHandler(config.onSubscriptionExpired, payload);
13330
+ }
13331
+ if (payload.type === "license_key.created") {
13332
+ await callHandler(config.onLicenseKeyCreated, payload);
13333
+ }
13515
13334
  }
13516
13335
 
13517
13336
  const Webhooks = ({ webhookKey, ...eventHandlers }) => {