@dodopayments/nextjs 0.2.1 → 0.2.2

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
@@ -11510,532 +11510,432 @@ DodoPayments.Webhooks = Webhooks$1;
11510
11510
  DodoPayments.UsageEvents = UsageEvents;
11511
11511
  DodoPayments.Meters = Meters;
11512
11512
 
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
- };
11513
+ // src/checkout/checkout.ts
11560
11514
  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
11515
+ productId: stringType(),
11516
+ quantity: stringType().optional(),
11517
+ // Customer fields
11518
+ fullName: stringType().optional(),
11519
+ firstName: stringType().optional(),
11520
+ lastName: stringType().optional(),
11521
+ email: stringType().optional(),
11522
+ country: stringType().optional(),
11523
+ addressLine: stringType().optional(),
11524
+ city: stringType().optional(),
11525
+ state: stringType().optional(),
11526
+ zipCode: stringType().optional(),
11527
+ // Disable flags
11528
+ disableFullName: stringType().optional(),
11529
+ disableFirstName: stringType().optional(),
11530
+ disableLastName: stringType().optional(),
11531
+ disableEmail: stringType().optional(),
11532
+ disableCountry: stringType().optional(),
11533
+ disableAddressLine: stringType().optional(),
11534
+ disableCity: stringType().optional(),
11535
+ disableState: stringType().optional(),
11536
+ disableZipCode: stringType().optional(),
11537
+ // Advanced controls
11538
+ paymentCurrency: stringType().optional(),
11539
+ showCurrencySelector: stringType().optional(),
11540
+ paymentAmount: stringType().optional(),
11541
+ showDiscounts: stringType().optional()
11542
+ // Metadata (allow any key starting with metadata_)
11543
+ // We'll handle metadata separately in the handler
11544
+ }).catchall(unknownType());
11593
11545
  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
11546
+ // For subscription
11547
+ product_id: stringType().optional(),
11548
+ quantity: numberType().optional(),
11549
+ // For one-time payment
11550
+ product_cart: arrayType(
11551
+ objectType({
11552
+ product_id: stringType(),
11553
+ quantity: numberType()
11554
+ })
11555
+ ).optional(),
11556
+ // Common fields
11557
+ billing: objectType({
11558
+ city: stringType(),
11559
+ country: stringType(),
11560
+ state: stringType(),
11561
+ street: stringType(),
11562
+ zipcode: stringType()
11563
+ }),
11564
+ customer: objectType({
11565
+ customer_id: stringType().optional(),
11566
+ email: stringType().optional(),
11567
+ name: stringType().optional()
11568
+ }),
11569
+ discount_id: stringType().optional(),
11570
+ addons: arrayType(
11571
+ objectType({
11572
+ addon_id: stringType(),
11573
+ quantity: numberType()
11574
+ })
11575
+ ).optional(),
11576
+ metadata: recordType(stringType(), stringType()).optional(),
11577
+ currency: stringType().optional()
11578
+ // Allow any additional fields (for future compatibility)
11579
+ }).catchall(unknownType());
11631
11580
  var checkoutSessionProductCartItemSchema = objectType({
11632
- product_id: stringType().min(1, "Product ID is required"),
11633
- quantity: numberType().int().positive("Quantity must be a positive integer"),
11581
+ product_id: stringType().min(1, "Product ID is required"),
11582
+ quantity: numberType().int().positive("Quantity must be a positive integer")
11634
11583
  });
11635
- // Customer information schema for checkout sessions
11636
11584
  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
11585
+ email: stringType().email().optional(),
11586
+ name: stringType().min(1).optional(),
11587
+ phone_number: stringType().optional()
11588
+ }).optional();
11643
11589
  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
11590
+ street: stringType().optional(),
11591
+ city: stringType().optional(),
11592
+ state: stringType().optional(),
11593
+ country: stringType().length(2, "Country must be a 2-letter ISO code"),
11594
+ zipcode: stringType().optional()
11595
+ }).optional();
11652
11596
  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",
11597
+ "credit",
11598
+ "debit",
11599
+ "upi_collect",
11600
+ "upi_intent",
11601
+ "apple_pay",
11602
+ "google_pay",
11603
+ "amazon_pay",
11604
+ "klarna",
11605
+ "affirm",
11606
+ "afterpay_clearpay",
11607
+ "sepa",
11608
+ "ach"
11665
11609
  ]);
11666
- // Customization options schema
11667
11610
  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
11611
+ theme: enumType(["light", "dark", "system"]).optional(),
11612
+ show_order_details: booleanType().optional(),
11613
+ show_on_demand_tag: booleanType().optional()
11614
+ }).optional();
11674
11615
  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
11616
+ allow_currency_selection: booleanType().optional(),
11617
+ allow_discount_code: booleanType().optional(),
11618
+ allow_phone_number_collection: booleanType().optional(),
11619
+ allow_tax_id: booleanType().optional(),
11620
+ always_create_new_customer: booleanType().optional()
11621
+ }).optional();
11683
11622
  var checkoutSessionSubscriptionDataSchema = objectType({
11684
- trial_period_days: numberType().int().nonnegative().optional(),
11685
- })
11686
- .optional();
11687
- // Main checkout session payload schema
11623
+ trial_period_days: numberType().int().nonnegative().optional()
11624
+ }).optional();
11688
11625
  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,
11626
+ // Required fields
11627
+ product_cart: arrayType(checkoutSessionProductCartItemSchema).min(1, "At least one product is required"),
11628
+ // Optional fields
11629
+ customer: checkoutSessionCustomerSchema,
11630
+ billing_address: checkoutSessionBillingAddressSchema,
11631
+ return_url: stringType().url().optional(),
11632
+ allowed_payment_method_types: arrayType(paymentMethodTypeSchema).optional(),
11633
+ billing_currency: stringType().length(3, "Currency must be a 3-letter ISO code").optional(),
11634
+ show_saved_payment_methods: booleanType().optional(),
11635
+ confirm: booleanType().optional(),
11636
+ discount_code: stringType().optional(),
11637
+ metadata: recordType(stringType(), stringType()).optional(),
11638
+ customization: checkoutSessionCustomizationSchema,
11639
+ feature_flags: checkoutSessionFeatureFlagsSchema,
11640
+ subscription_data: checkoutSessionSubscriptionDataSchema
11707
11641
  });
11708
- // Checkout session response schema
11709
11642
  var checkoutSessionResponseSchema = objectType({
11710
- session_id: stringType().min(1, "Session ID is required"),
11711
- checkout_url: stringType().url("Invalid checkout URL"),
11643
+ session_id: stringType().min(1, "Session ID is required"),
11644
+ checkout_url: stringType().url("Invalid checkout URL")
11712
11645
  });
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*/];
11646
+ var createCheckoutSession = async (payload, config) => {
11647
+ const validation = checkoutSessionPayloadSchema.safeParse(payload);
11648
+ if (!validation.success) {
11649
+ throw new Error(
11650
+ `Invalid checkout session payload: ${validation.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join(", ")}`
11651
+ );
11652
+ }
11653
+ const dodopayments = new DodoPayments({
11654
+ bearerToken: config.bearerToken,
11655
+ environment: config.environment
11656
+ });
11657
+ try {
11658
+ const sdkPayload = {
11659
+ ...validation.data,
11660
+ ...validation.data.billing_address && {
11661
+ billing_address: {
11662
+ ...validation.data.billing_address,
11663
+ country: validation.data.billing_address.country
11785
11664
  }
11665
+ }
11666
+ };
11667
+ const session = await dodopayments.checkoutSessions.create(
11668
+ sdkPayload
11669
+ );
11670
+ const responseValidation = checkoutSessionResponseSchema.safeParse(session);
11671
+ if (!responseValidation.success) {
11672
+ throw new Error(
11673
+ `Invalid checkout session response from API: ${responseValidation.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join(", ")}`
11674
+ );
11675
+ }
11676
+ return responseValidation.data;
11677
+ } catch (error) {
11678
+ if (error instanceof Error) {
11679
+ console.error("Dodo Payments Checkout Session API Error:", {
11680
+ message: error.message,
11681
+ payload: validation.data,
11682
+ config: {
11683
+ environment: config.environment,
11684
+ hasBearerToken: !!config.bearerToken
11685
+ }
11686
+ });
11687
+ throw new Error(`Failed to create checkout session: ${error.message}`);
11688
+ }
11689
+ console.error("Unknown error creating checkout session:", error);
11690
+ throw new Error(
11691
+ "Failed to create checkout session due to an unknown error"
11692
+ );
11693
+ }
11694
+ };
11695
+ var buildCheckoutUrl = async ({
11696
+ queryParams,
11697
+ body,
11698
+ sessionPayload,
11699
+ returnUrl,
11700
+ bearerToken,
11701
+ environment,
11702
+ type = "static"
11703
+ }) => {
11704
+ if (type === "session") {
11705
+ if (!sessionPayload) {
11706
+ throw new Error("sessionPayload is required when type is 'session'");
11707
+ }
11708
+ const session = await createCheckoutSession(sessionPayload, {
11709
+ bearerToken,
11710
+ environment
11786
11711
  });
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
- }
11712
+ return session.checkout_url;
11713
+ }
11714
+ const inputData = type === "dynamic" ? body : queryParams;
11715
+ let parseResult;
11716
+ if (type === "dynamic") {
11717
+ parseResult = dynamicCheckoutBodySchema.safeParse(inputData);
11718
+ } else {
11719
+ parseResult = checkoutQuerySchema.safeParse(inputData);
11720
+ }
11721
+ const { success, data, error } = parseResult;
11722
+ if (!success) {
11723
+ throw new Error(
11724
+ `Invalid ${type === "dynamic" ? "body" : "query parameters"}.
11725
+ ${error.message}`
11726
+ );
11727
+ }
11728
+ if (type !== "dynamic") {
11729
+ const {
11730
+ productId,
11731
+ quantity: quantity2,
11732
+ fullName,
11733
+ firstName,
11734
+ lastName,
11735
+ email,
11736
+ country,
11737
+ addressLine,
11738
+ city,
11739
+ state,
11740
+ zipCode,
11741
+ disableFullName,
11742
+ disableFirstName,
11743
+ disableLastName,
11744
+ disableEmail,
11745
+ disableCountry,
11746
+ disableAddressLine,
11747
+ disableCity,
11748
+ disableState,
11749
+ disableZipCode,
11750
+ paymentCurrency,
11751
+ showCurrencySelector,
11752
+ paymentAmount,
11753
+ showDiscounts
11754
+ // metadata handled below
11755
+ } = data;
11756
+ const dodopayments2 = new DodoPayments({
11757
+ bearerToken,
11758
+ environment
12037
11759
  });
12038
- }); };
11760
+ if (!productId) throw new Error("Missing required field: productId");
11761
+ try {
11762
+ await dodopayments2.products.retrieve(productId);
11763
+ } catch (err) {
11764
+ console.error(err);
11765
+ throw new Error("Product not found");
11766
+ }
11767
+ const url = new URL(
11768
+ `${environment === "test_mode" ? "https://test.checkout.dodopayments.com" : "https://checkout.dodopayments.com"}/buy/${productId}`
11769
+ );
11770
+ url.searchParams.set("quantity", quantity2 ? String(quantity2) : "1");
11771
+ if (returnUrl) url.searchParams.set("redirect_url", returnUrl);
11772
+ if (fullName) url.searchParams.set("fullName", String(fullName));
11773
+ if (firstName) url.searchParams.set("firstName", String(firstName));
11774
+ if (lastName) url.searchParams.set("lastName", String(lastName));
11775
+ if (email) url.searchParams.set("email", String(email));
11776
+ if (country) url.searchParams.set("country", String(country));
11777
+ if (addressLine) url.searchParams.set("addressLine", String(addressLine));
11778
+ if (city) url.searchParams.set("city", String(city));
11779
+ if (state) url.searchParams.set("state", String(state));
11780
+ if (zipCode) url.searchParams.set("zipCode", String(zipCode));
11781
+ if (disableFullName === "true")
11782
+ url.searchParams.set("disableFullName", "true");
11783
+ if (disableFirstName === "true")
11784
+ url.searchParams.set("disableFirstName", "true");
11785
+ if (disableLastName === "true")
11786
+ url.searchParams.set("disableLastName", "true");
11787
+ if (disableEmail === "true") url.searchParams.set("disableEmail", "true");
11788
+ if (disableCountry === "true")
11789
+ url.searchParams.set("disableCountry", "true");
11790
+ if (disableAddressLine === "true")
11791
+ url.searchParams.set("disableAddressLine", "true");
11792
+ if (disableCity === "true") url.searchParams.set("disableCity", "true");
11793
+ if (disableState === "true") url.searchParams.set("disableState", "true");
11794
+ if (disableZipCode === "true")
11795
+ url.searchParams.set("disableZipCode", "true");
11796
+ if (paymentCurrency)
11797
+ url.searchParams.set("paymentCurrency", String(paymentCurrency));
11798
+ if (showCurrencySelector)
11799
+ url.searchParams.set(
11800
+ "showCurrencySelector",
11801
+ String(showCurrencySelector)
11802
+ );
11803
+ if (paymentAmount)
11804
+ url.searchParams.set("paymentAmount", String(paymentAmount));
11805
+ if (showDiscounts)
11806
+ url.searchParams.set("showDiscounts", String(showDiscounts));
11807
+ for (const [key, value] of Object.entries(queryParams || {})) {
11808
+ if (key.startsWith("metadata_") && value && typeof value !== "object") {
11809
+ url.searchParams.set(key, String(value));
11810
+ }
11811
+ }
11812
+ return url.toString();
11813
+ }
11814
+ const dyn = data;
11815
+ const {
11816
+ product_id,
11817
+ product_cart,
11818
+ quantity,
11819
+ billing,
11820
+ customer,
11821
+ addons,
11822
+ metadata,
11823
+ allowed_payment_method_types,
11824
+ billing_currency,
11825
+ discount_code,
11826
+ on_demand,
11827
+ return_url: bodyReturnUrl,
11828
+ show_saved_payment_methods,
11829
+ tax_id,
11830
+ trial_period_days
11831
+ } = dyn;
11832
+ const dodopayments = new DodoPayments({
11833
+ bearerToken,
11834
+ environment
11835
+ });
11836
+ let isSubscription = false;
11837
+ let productIdToFetch = product_id;
11838
+ if (!product_id && product_cart && product_cart.length > 0) {
11839
+ productIdToFetch = product_cart[0].product_id;
11840
+ }
11841
+ if (!productIdToFetch)
11842
+ throw new Error(
11843
+ "Missing required field: product_id or product_cart[0].product_id"
11844
+ );
11845
+ let product;
11846
+ try {
11847
+ product = await dodopayments.products.retrieve(productIdToFetch);
11848
+ } catch (err) {
11849
+ console.error(err);
11850
+ throw new Error("Product not found");
11851
+ }
11852
+ isSubscription = Boolean(product.is_recurring);
11853
+ if (isSubscription && !product_id)
11854
+ throw new Error("Missing required field: product_id for subscription");
11855
+ if (!billing) throw new Error("Missing required field: billing");
11856
+ if (!customer) throw new Error("Missing required field: customer");
11857
+ if (isSubscription) {
11858
+ const subscriptionPayload = {
11859
+ billing,
11860
+ customer,
11861
+ product_id,
11862
+ quantity: quantity ? Number(quantity) : 1
11863
+ };
11864
+ if (metadata) subscriptionPayload.metadata = metadata;
11865
+ if (discount_code) subscriptionPayload.discount_code = discount_code;
11866
+ if (addons) subscriptionPayload.addons = addons;
11867
+ if (allowed_payment_method_types)
11868
+ subscriptionPayload.allowed_payment_method_types = allowed_payment_method_types;
11869
+ if (billing_currency)
11870
+ subscriptionPayload.billing_currency = billing_currency;
11871
+ if (on_demand) subscriptionPayload.on_demand = on_demand;
11872
+ subscriptionPayload.payment_link = true;
11873
+ if (bodyReturnUrl) {
11874
+ subscriptionPayload.return_url = bodyReturnUrl;
11875
+ } else if (returnUrl) {
11876
+ subscriptionPayload.return_url = returnUrl;
11877
+ }
11878
+ if (show_saved_payment_methods)
11879
+ subscriptionPayload.show_saved_payment_methods = show_saved_payment_methods;
11880
+ if (tax_id) subscriptionPayload.tax_id = tax_id;
11881
+ if (trial_period_days)
11882
+ subscriptionPayload.trial_period_days = trial_period_days;
11883
+ let subscription;
11884
+ try {
11885
+ subscription = await dodopayments.subscriptions.create(subscriptionPayload);
11886
+ } catch (err) {
11887
+ console.error("Error when creating subscription", err);
11888
+ throw new Error(err instanceof Error ? err.message : String(err));
11889
+ }
11890
+ if (!subscription || !subscription.payment_link) {
11891
+ throw new Error(
11892
+ "No payment link returned from Dodo Payments API (subscription). Make sure to set payment_link as true in payload"
11893
+ );
11894
+ }
11895
+ return subscription.payment_link;
11896
+ } else {
11897
+ let cart = product_cart;
11898
+ if (!cart && product_id) {
11899
+ cart = [
11900
+ { product_id, quantity: quantity ? Number(quantity) : 1 }
11901
+ ];
11902
+ }
11903
+ if (!cart || cart.length === 0)
11904
+ throw new Error("Missing required field: product_cart or product_id");
11905
+ const paymentPayload = {
11906
+ billing,
11907
+ customer,
11908
+ product_cart: cart
11909
+ };
11910
+ if (metadata) paymentPayload.metadata = metadata;
11911
+ paymentPayload.payment_link = true;
11912
+ if (allowed_payment_method_types)
11913
+ paymentPayload.allowed_payment_method_types = allowed_payment_method_types;
11914
+ if (billing_currency) paymentPayload.billing_currency = billing_currency;
11915
+ if (discount_code) paymentPayload.discount_code = discount_code;
11916
+ if (bodyReturnUrl) {
11917
+ paymentPayload.return_url = bodyReturnUrl;
11918
+ } else if (returnUrl) {
11919
+ paymentPayload.return_url = returnUrl;
11920
+ }
11921
+ if (show_saved_payment_methods)
11922
+ paymentPayload.show_saved_payment_methods = show_saved_payment_methods;
11923
+ if (tax_id) paymentPayload.tax_id = tax_id;
11924
+ let payment;
11925
+ try {
11926
+ payment = await dodopayments.payments.create(paymentPayload);
11927
+ } catch (err) {
11928
+ console.error("Error when creating payment link", err);
11929
+ throw new Error(err instanceof Error ? err.message : String(err));
11930
+ }
11931
+ if (!payment || !payment.payment_link) {
11932
+ throw new Error(
11933
+ "No payment link returned from Dodo Payments API. Make sure to set payment_link as true in payload."
11934
+ );
11935
+ }
11936
+ return payment.payment_link;
11937
+ }
11938
+ };
12039
11939
 
12040
11940
  const Checkout = (config) => {
12041
11941
  const getHandler = async (req) => {
@@ -12974,542 +12874,422 @@ class Webhook {
12974
12874
  Webhook_1 = dist.Webhook = Webhook;
12975
12875
  Webhook.prefix = "whsec_";
12976
12876
 
12877
+ // src/schemas/webhook.ts
12977
12878
  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([
12879
+ payload_type: literalType("Payment"),
12880
+ billing: objectType({
12881
+ city: stringType().nullable(),
12882
+ country: stringType().nullable(),
12883
+ state: stringType().nullable(),
12884
+ street: stringType().nullable(),
12885
+ zipcode: stringType().nullable()
12886
+ }),
12887
+ brand_id: stringType(),
12888
+ business_id: stringType(),
12889
+ card_issuing_country: stringType().nullable(),
12890
+ card_last_four: stringType().nullable(),
12891
+ card_network: stringType().nullable(),
12892
+ card_type: stringType().nullable(),
12893
+ created_at: stringType().transform((d) => new Date(d)),
12894
+ currency: stringType(),
12895
+ customer: objectType({
12896
+ customer_id: stringType(),
12897
+ email: stringType(),
12898
+ name: stringType().nullable()
12899
+ }),
12900
+ digital_products_delivered: booleanType(),
12901
+ discount_id: stringType().nullable(),
12902
+ disputes: arrayType(
12903
+ objectType({
12904
+ amount: stringType(),
12905
+ business_id: stringType(),
12906
+ created_at: stringType().transform((d) => new Date(d)),
12907
+ currency: stringType(),
12908
+ dispute_id: stringType(),
12909
+ dispute_stage: enumType([
13134
12910
  "pre_dispute",
13135
12911
  "dispute_opened",
13136
12912
  "dispute_won",
13137
- "dispute_lost",
13138
- ]),
13139
- dispute_status: enumType([
12913
+ "dispute_lost"
12914
+ ]),
12915
+ dispute_status: enumType([
13140
12916
  "dispute_opened",
13141
12917
  "dispute_won",
13142
12918
  "dispute_lost",
13143
12919
  "dispute_accepted",
13144
12920
  "dispute_cancelled",
13145
- "dispute_challenged",
13146
- ]),
13147
- payment_id: stringType(),
13148
- remarks: stringType().nullable(),
12921
+ "dispute_challenged"
12922
+ ]),
12923
+ payment_id: stringType(),
12924
+ remarks: stringType().nullable()
12925
+ })
12926
+ ).nullable(),
12927
+ error_code: stringType().nullable(),
12928
+ error_message: stringType().nullable(),
12929
+ metadata: recordType(anyType()).nullable(),
12930
+ payment_id: stringType(),
12931
+ payment_link: stringType().nullable(),
12932
+ payment_method: stringType().nullable(),
12933
+ payment_method_type: stringType().nullable(),
12934
+ product_cart: arrayType(
12935
+ objectType({
12936
+ product_id: stringType(),
12937
+ quantity: numberType()
12938
+ })
12939
+ ).nullable(),
12940
+ refunds: arrayType(
12941
+ objectType({
12942
+ amount: numberType(),
12943
+ business_id: stringType(),
12944
+ created_at: stringType().transform((d) => new Date(d)),
12945
+ currency: stringType(),
12946
+ is_partial: booleanType(),
12947
+ payment_id: stringType(),
12948
+ reason: stringType().nullable(),
12949
+ refund_id: stringType(),
12950
+ status: enumType(["succeeded", "failed", "pending"])
12951
+ })
12952
+ ).nullable(),
12953
+ settlement_amount: numberType(),
12954
+ settlement_currency: stringType(),
12955
+ settlement_tax: numberType().nullable(),
12956
+ status: enumType(["succeeded", "failed", "pending", "processing", "cancelled"]),
12957
+ subscription_id: stringType().nullable(),
12958
+ tax: numberType().nullable(),
12959
+ total_amount: numberType(),
12960
+ updated_at: stringType().transform((d) => new Date(d)).nullable()
13149
12961
  });
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); }),
12962
+ var SubscriptionSchema = objectType({
12963
+ payload_type: literalType("Subscription"),
12964
+ addons: arrayType(
12965
+ objectType({
12966
+ addon_id: stringType(),
12967
+ quantity: numberType()
12968
+ })
12969
+ ).nullable(),
12970
+ billing: objectType({
12971
+ city: stringType().nullable(),
12972
+ country: stringType().nullable(),
12973
+ state: stringType().nullable(),
12974
+ street: stringType().nullable(),
12975
+ zipcode: stringType().nullable()
12976
+ }),
12977
+ cancel_at_next_billing_date: booleanType(),
12978
+ cancelled_at: stringType().transform((d) => new Date(d)).nullable(),
12979
+ created_at: stringType().transform((d) => new Date(d)),
12980
+ currency: stringType(),
12981
+ customer: objectType({
13155
12982
  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(),
12983
+ email: stringType(),
12984
+ name: stringType().nullable()
12985
+ }),
12986
+ discount_id: stringType().nullable(),
12987
+ metadata: recordType(anyType()).nullable(),
12988
+ next_billing_date: stringType().transform((d) => new Date(d)).nullable(),
12989
+ on_demand: booleanType(),
12990
+ payment_frequency_count: numberType(),
12991
+ payment_frequency_interval: enumType(["Day", "Week", "Month", "Year"]),
12992
+ previous_billing_date: stringType().transform((d) => new Date(d)).nullable(),
12993
+ product_id: stringType(),
12994
+ quantity: numberType(),
12995
+ recurring_pre_tax_amount: numberType(),
12996
+ status: enumType([
12997
+ "pending",
12998
+ "active",
12999
+ "on_hold",
13000
+ "paused",
13001
+ "cancelled",
13002
+ "expired",
13003
+ "failed"
13004
+ ]),
13005
+ subscription_id: stringType(),
13006
+ subscription_period_count: numberType(),
13007
+ subscription_period_interval: enumType(["Day", "Week", "Month", "Year"]),
13008
+ tax_inclusive: booleanType(),
13009
+ trial_period_days: numberType()
13010
+ });
13011
+ var RefundSchema = objectType({
13012
+ payload_type: literalType("Refund"),
13013
+ amount: numberType(),
13014
+ business_id: stringType(),
13015
+ created_at: stringType().transform((d) => new Date(d)),
13016
+ currency: stringType(),
13017
+ is_partial: booleanType(),
13018
+ payment_id: stringType(),
13019
+ reason: stringType().nullable(),
13020
+ refund_id: stringType(),
13021
+ status: enumType(["succeeded", "failed", "pending"])
13022
+ });
13023
+ var DisputeSchema = objectType({
13024
+ payload_type: literalType("Dispute"),
13025
+ amount: stringType(),
13026
+ business_id: stringType(),
13027
+ created_at: stringType().transform((d) => new Date(d)),
13028
+ currency: stringType(),
13029
+ dispute_id: stringType(),
13030
+ dispute_stage: enumType([
13031
+ "pre_dispute",
13032
+ "dispute_opened",
13033
+ "dispute_won",
13034
+ "dispute_lost"
13035
+ ]),
13036
+ dispute_status: enumType([
13037
+ "dispute_opened",
13038
+ "dispute_won",
13039
+ "dispute_lost",
13040
+ "dispute_accepted",
13041
+ "dispute_cancelled",
13042
+ "dispute_challenged"
13043
+ ]),
13044
+ payment_id: stringType(),
13045
+ remarks: stringType().nullable()
13046
+ });
13047
+ var LicenseKeySchema = objectType({
13048
+ payload_type: literalType("LicenseKey"),
13049
+ activations_limit: numberType(),
13050
+ business_id: stringType(),
13051
+ created_at: stringType().transform((d) => new Date(d)),
13052
+ customer_id: stringType(),
13053
+ expires_at: stringType().transform((d) => new Date(d)).nullable(),
13054
+ id: stringType(),
13055
+ instances_count: numberType(),
13056
+ key: stringType(),
13057
+ payment_id: stringType(),
13058
+ product_id: stringType(),
13059
+ status: enumType(["active", "inactive", "expired"]),
13060
+ subscription_id: stringType().nullable()
13166
13061
  });
13167
13062
  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,
13063
+ business_id: stringType(),
13064
+ type: literalType("payment.succeeded"),
13065
+ timestamp: stringType().transform((d) => new Date(d)),
13066
+ data: PaymentSchema
13172
13067
  });
13173
13068
  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,
13069
+ business_id: stringType(),
13070
+ type: literalType("payment.failed"),
13071
+ timestamp: stringType().transform((d) => new Date(d)),
13072
+ data: PaymentSchema
13178
13073
  });
13179
13074
  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,
13075
+ business_id: stringType(),
13076
+ type: literalType("payment.processing"),
13077
+ timestamp: stringType().transform((d) => new Date(d)),
13078
+ data: PaymentSchema
13184
13079
  });
13185
13080
  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,
13081
+ business_id: stringType(),
13082
+ type: literalType("payment.cancelled"),
13083
+ timestamp: stringType().transform((d) => new Date(d)),
13084
+ data: PaymentSchema
13190
13085
  });
13191
13086
  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,
13087
+ business_id: stringType(),
13088
+ type: literalType("refund.succeeded"),
13089
+ timestamp: stringType().transform((d) => new Date(d)),
13090
+ data: RefundSchema
13196
13091
  });
13197
13092
  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,
13093
+ business_id: stringType(),
13094
+ type: literalType("refund.failed"),
13095
+ timestamp: stringType().transform((d) => new Date(d)),
13096
+ data: RefundSchema
13202
13097
  });
13203
13098
  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,
13099
+ business_id: stringType(),
13100
+ type: literalType("dispute.opened"),
13101
+ timestamp: stringType().transform((d) => new Date(d)),
13102
+ data: DisputeSchema
13208
13103
  });
13209
13104
  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,
13105
+ business_id: stringType(),
13106
+ type: literalType("dispute.expired"),
13107
+ timestamp: stringType().transform((d) => new Date(d)),
13108
+ data: DisputeSchema
13214
13109
  });
13215
13110
  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,
13111
+ business_id: stringType(),
13112
+ type: literalType("dispute.accepted"),
13113
+ timestamp: stringType().transform((d) => new Date(d)),
13114
+ data: DisputeSchema
13220
13115
  });
13221
13116
  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,
13117
+ business_id: stringType(),
13118
+ type: literalType("dispute.cancelled"),
13119
+ timestamp: stringType().transform((d) => new Date(d)),
13120
+ data: DisputeSchema
13226
13121
  });
13227
13122
  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,
13123
+ business_id: stringType(),
13124
+ type: literalType("dispute.challenged"),
13125
+ timestamp: stringType().transform((d) => new Date(d)),
13126
+ data: DisputeSchema
13232
13127
  });
13233
13128
  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,
13129
+ business_id: stringType(),
13130
+ type: literalType("dispute.won"),
13131
+ timestamp: stringType().transform((d) => new Date(d)),
13132
+ data: DisputeSchema
13238
13133
  });
13239
13134
  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,
13135
+ business_id: stringType(),
13136
+ type: literalType("dispute.lost"),
13137
+ timestamp: stringType().transform((d) => new Date(d)),
13138
+ data: DisputeSchema
13244
13139
  });
13245
13140
  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,
13141
+ business_id: stringType(),
13142
+ type: literalType("subscription.active"),
13143
+ timestamp: stringType().transform((d) => new Date(d)),
13144
+ data: SubscriptionSchema
13250
13145
  });
13251
13146
  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,
13147
+ business_id: stringType(),
13148
+ type: literalType("subscription.on_hold"),
13149
+ timestamp: stringType().transform((d) => new Date(d)),
13150
+ data: SubscriptionSchema
13256
13151
  });
13257
13152
  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,
13153
+ business_id: stringType(),
13154
+ type: literalType("subscription.renewed"),
13155
+ timestamp: stringType().transform((d) => new Date(d)),
13156
+ data: SubscriptionSchema
13262
13157
  });
13263
13158
  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,
13159
+ business_id: stringType(),
13160
+ type: literalType("subscription.paused"),
13161
+ timestamp: stringType().transform((d) => new Date(d)),
13162
+ data: SubscriptionSchema
13268
13163
  });
13269
13164
  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,
13165
+ business_id: stringType(),
13166
+ type: literalType("subscription.plan_changed"),
13167
+ timestamp: stringType().transform((d) => new Date(d)),
13168
+ data: SubscriptionSchema
13274
13169
  });
13275
13170
  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,
13171
+ business_id: stringType(),
13172
+ type: literalType("subscription.cancelled"),
13173
+ timestamp: stringType().transform((d) => new Date(d)),
13174
+ data: SubscriptionSchema
13280
13175
  });
13281
13176
  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,
13177
+ business_id: stringType(),
13178
+ type: literalType("subscription.failed"),
13179
+ timestamp: stringType().transform((d) => new Date(d)),
13180
+ data: SubscriptionSchema
13286
13181
  });
13287
13182
  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,
13183
+ business_id: stringType(),
13184
+ type: literalType("subscription.expired"),
13185
+ timestamp: stringType().transform((d) => new Date(d)),
13186
+ data: SubscriptionSchema
13292
13187
  });
13293
13188
  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,
13189
+ business_id: stringType(),
13190
+ type: literalType("license_key.created"),
13191
+ timestamp: stringType().transform((d) => new Date(d)),
13192
+ data: LicenseKeySchema
13298
13193
  });
13299
13194
  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,
13195
+ PaymentSucceededPayloadSchema,
13196
+ PaymentFailedPayloadSchema,
13197
+ PaymentProcessingPayloadSchema,
13198
+ PaymentCancelledPayloadSchema,
13199
+ RefundSucceededPayloadSchema,
13200
+ RefundFailedPayloadSchema,
13201
+ DisputeOpenedPayloadSchema,
13202
+ DisputeExpiredPayloadSchema,
13203
+ DisputeAcceptedPayloadSchema,
13204
+ DisputeCancelledPayloadSchema,
13205
+ DisputeChallengedPayloadSchema,
13206
+ DisputeWonPayloadSchema,
13207
+ DisputeLostPayloadSchema,
13208
+ SubscriptionActivePayloadSchema,
13209
+ SubscriptionOnHoldPayloadSchema,
13210
+ SubscriptionRenewedPayloadSchema,
13211
+ SubscriptionPausedPayloadSchema,
13212
+ SubscriptionPlanChangedPayloadSchema,
13213
+ SubscriptionCancelledPayloadSchema,
13214
+ SubscriptionFailedPayloadSchema,
13215
+ SubscriptionExpiredPayloadSchema,
13216
+ LicenseKeyCreatedPayloadSchema
13322
13217
  ]);
13323
13218
 
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
- });
13219
+ async function handleWebhookPayload(payload, config, context) {
13220
+ const callHandler = (handler, payload2) => {
13221
+ if (!handler) return;
13222
+ return handler(payload2);
13223
+ };
13224
+ if (config.onPayload) {
13225
+ await callHandler(config.onPayload, payload);
13226
+ }
13227
+ if (payload.type === "payment.succeeded") {
13228
+ await callHandler(config.onPaymentSucceeded, payload);
13229
+ }
13230
+ if (payload.type === "payment.failed") {
13231
+ await callHandler(config.onPaymentFailed, payload);
13232
+ }
13233
+ if (payload.type === "payment.processing") {
13234
+ await callHandler(config.onPaymentProcessing, payload);
13235
+ }
13236
+ if (payload.type === "payment.cancelled") {
13237
+ await callHandler(config.onPaymentCancelled, payload);
13238
+ }
13239
+ if (payload.type === "refund.succeeded") {
13240
+ await callHandler(config.onRefundSucceeded, payload);
13241
+ }
13242
+ if (payload.type === "refund.failed") {
13243
+ await callHandler(config.onRefundFailed, payload);
13244
+ }
13245
+ if (payload.type === "dispute.opened") {
13246
+ await callHandler(config.onDisputeOpened, payload);
13247
+ }
13248
+ if (payload.type === "dispute.expired") {
13249
+ await callHandler(config.onDisputeExpired, payload);
13250
+ }
13251
+ if (payload.type === "dispute.accepted") {
13252
+ await callHandler(config.onDisputeAccepted, payload);
13253
+ }
13254
+ if (payload.type === "dispute.cancelled") {
13255
+ await callHandler(config.onDisputeCancelled, payload);
13256
+ }
13257
+ if (payload.type === "dispute.challenged") {
13258
+ await callHandler(config.onDisputeChallenged, payload);
13259
+ }
13260
+ if (payload.type === "dispute.won") {
13261
+ await callHandler(config.onDisputeWon, payload);
13262
+ }
13263
+ if (payload.type === "dispute.lost") {
13264
+ await callHandler(config.onDisputeLost, payload);
13265
+ }
13266
+ if (payload.type === "subscription.active") {
13267
+ await callHandler(config.onSubscriptionActive, payload);
13268
+ }
13269
+ if (payload.type === "subscription.on_hold") {
13270
+ await callHandler(config.onSubscriptionOnHold, payload);
13271
+ }
13272
+ if (payload.type === "subscription.renewed") {
13273
+ await callHandler(config.onSubscriptionRenewed, payload);
13274
+ }
13275
+ if (payload.type === "subscription.paused") {
13276
+ await callHandler(config.onSubscriptionPaused, payload);
13277
+ }
13278
+ if (payload.type === "subscription.plan_changed") {
13279
+ await callHandler(config.onSubscriptionPlanChanged, payload);
13280
+ }
13281
+ if (payload.type === "subscription.cancelled") {
13282
+ await callHandler(config.onSubscriptionCancelled, payload);
13283
+ }
13284
+ if (payload.type === "subscription.failed") {
13285
+ await callHandler(config.onSubscriptionFailed, payload);
13286
+ }
13287
+ if (payload.type === "subscription.expired") {
13288
+ await callHandler(config.onSubscriptionExpired, payload);
13289
+ }
13290
+ if (payload.type === "license_key.created") {
13291
+ await callHandler(config.onLicenseKeyCreated, payload);
13292
+ }
13513
13293
  }
13514
13294
 
13515
13295
  const Webhooks = ({ webhookKey, ...eventHandlers }) => {