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