@dodopayments/sveltekit 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
@@ -6260,532 +6260,432 @@ DodoPayments.Webhooks = Webhooks$1;
6260
6260
  DodoPayments.UsageEvents = UsageEvents;
6261
6261
  DodoPayments.Meters = Meters;
6262
6262
 
6263
- var __assign = (undefined && undefined.__assign) || function () {
6264
- __assign = Object.assign || function(t) {
6265
- for (var s, i = 1, n = arguments.length; i < n; i++) {
6266
- s = arguments[i];
6267
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6268
- t[p] = s[p];
6269
- }
6270
- return t;
6271
- };
6272
- return __assign.apply(this, arguments);
6273
- };
6274
- var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
6275
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6276
- return new (P || (P = Promise))(function (resolve, reject) {
6277
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6278
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6279
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
6280
- step((generator = generator.apply(thisArg, _arguments || [])).next());
6281
- });
6282
- };
6283
- var __generator$1 = (undefined && undefined.__generator) || function (thisArg, body) {
6284
- 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);
6285
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
6286
- function verb(n) { return function (v) { return step([n, v]); }; }
6287
- function step(op) {
6288
- if (f) throw new TypeError("Generator is already executing.");
6289
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
6290
- 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;
6291
- if (y = 0, t) op = [op[0] & 2, t.value];
6292
- switch (op[0]) {
6293
- case 0: case 1: t = op; break;
6294
- case 4: _.label++; return { value: op[1], done: false };
6295
- case 5: _.label++; y = op[1]; op = [0]; continue;
6296
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
6297
- default:
6298
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
6299
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
6300
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
6301
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
6302
- if (t[2]) _.ops.pop();
6303
- _.trys.pop(); continue;
6304
- }
6305
- op = body.call(thisArg, _);
6306
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
6307
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
6308
- }
6309
- };
6263
+ // src/checkout/checkout.ts
6310
6264
  var checkoutQuerySchema = objectType({
6311
- productId: stringType(),
6312
- quantity: stringType().optional(),
6313
- // Customer fields
6314
- fullName: stringType().optional(),
6315
- firstName: stringType().optional(),
6316
- lastName: stringType().optional(),
6317
- email: stringType().optional(),
6318
- country: stringType().optional(),
6319
- addressLine: stringType().optional(),
6320
- city: stringType().optional(),
6321
- state: stringType().optional(),
6322
- zipCode: stringType().optional(),
6323
- // Disable flags
6324
- disableFullName: stringType().optional(),
6325
- disableFirstName: stringType().optional(),
6326
- disableLastName: stringType().optional(),
6327
- disableEmail: stringType().optional(),
6328
- disableCountry: stringType().optional(),
6329
- disableAddressLine: stringType().optional(),
6330
- disableCity: stringType().optional(),
6331
- disableState: stringType().optional(),
6332
- disableZipCode: stringType().optional(),
6333
- // Advanced controls
6334
- paymentCurrency: stringType().optional(),
6335
- showCurrencySelector: stringType().optional(),
6336
- paymentAmount: stringType().optional(),
6337
- showDiscounts: stringType().optional(),
6338
- // Metadata (allow any key starting with metadata_)
6339
- // We'll handle metadata separately in the handler
6340
- })
6341
- .catchall(unknownType());
6342
- // Add Zod schema for dynamic checkout body
6265
+ productId: stringType(),
6266
+ quantity: stringType().optional(),
6267
+ // Customer fields
6268
+ fullName: stringType().optional(),
6269
+ firstName: stringType().optional(),
6270
+ lastName: stringType().optional(),
6271
+ email: stringType().optional(),
6272
+ country: stringType().optional(),
6273
+ addressLine: stringType().optional(),
6274
+ city: stringType().optional(),
6275
+ state: stringType().optional(),
6276
+ zipCode: stringType().optional(),
6277
+ // Disable flags
6278
+ disableFullName: stringType().optional(),
6279
+ disableFirstName: stringType().optional(),
6280
+ disableLastName: stringType().optional(),
6281
+ disableEmail: stringType().optional(),
6282
+ disableCountry: stringType().optional(),
6283
+ disableAddressLine: stringType().optional(),
6284
+ disableCity: stringType().optional(),
6285
+ disableState: stringType().optional(),
6286
+ disableZipCode: stringType().optional(),
6287
+ // Advanced controls
6288
+ paymentCurrency: stringType().optional(),
6289
+ showCurrencySelector: stringType().optional(),
6290
+ paymentAmount: stringType().optional(),
6291
+ showDiscounts: stringType().optional()
6292
+ // Metadata (allow any key starting with metadata_)
6293
+ // We'll handle metadata separately in the handler
6294
+ }).catchall(unknownType());
6343
6295
  var dynamicCheckoutBodySchema = objectType({
6344
- // For subscription
6345
- product_id: stringType().optional(),
6346
- quantity: numberType().optional(),
6347
- // For one-time payment
6348
- product_cart: arrayType(objectType({
6349
- product_id: stringType(),
6350
- quantity: numberType(),
6351
- }))
6352
- .optional(),
6353
- // Common fields
6354
- billing: objectType({
6355
- city: stringType(),
6356
- country: stringType(),
6357
- state: stringType(),
6358
- street: stringType(),
6359
- zipcode: stringType(),
6360
- }),
6361
- customer: objectType({
6362
- customer_id: stringType().optional(),
6363
- email: stringType().optional(),
6364
- name: stringType().optional(),
6365
- }),
6366
- discount_id: stringType().optional(),
6367
- addons: arrayType(objectType({
6368
- addon_id: stringType(),
6369
- quantity: numberType(),
6370
- }))
6371
- .optional(),
6372
- metadata: recordType(stringType(), stringType()).optional(),
6373
- currency: stringType().optional(),
6374
- // Allow any additional fields (for future compatibility)
6375
- })
6376
- .catchall(unknownType());
6377
- // ========================================
6378
- // CHECKOUT SESSIONS SCHEMAS & TYPES
6379
- // ========================================
6380
- // Product cart item schema for checkout sessions
6296
+ // For subscription
6297
+ product_id: stringType().optional(),
6298
+ quantity: numberType().optional(),
6299
+ // For one-time payment
6300
+ product_cart: arrayType(
6301
+ objectType({
6302
+ product_id: stringType(),
6303
+ quantity: numberType()
6304
+ })
6305
+ ).optional(),
6306
+ // Common fields
6307
+ billing: objectType({
6308
+ city: stringType(),
6309
+ country: stringType(),
6310
+ state: stringType(),
6311
+ street: stringType(),
6312
+ zipcode: stringType()
6313
+ }),
6314
+ customer: objectType({
6315
+ customer_id: stringType().optional(),
6316
+ email: stringType().optional(),
6317
+ name: stringType().optional()
6318
+ }),
6319
+ discount_id: stringType().optional(),
6320
+ addons: arrayType(
6321
+ objectType({
6322
+ addon_id: stringType(),
6323
+ quantity: numberType()
6324
+ })
6325
+ ).optional(),
6326
+ metadata: recordType(stringType(), stringType()).optional(),
6327
+ currency: stringType().optional()
6328
+ // Allow any additional fields (for future compatibility)
6329
+ }).catchall(unknownType());
6381
6330
  var checkoutSessionProductCartItemSchema = objectType({
6382
- product_id: stringType().min(1, "Product ID is required"),
6383
- quantity: numberType().int().positive("Quantity must be a positive integer"),
6331
+ product_id: stringType().min(1, "Product ID is required"),
6332
+ quantity: numberType().int().positive("Quantity must be a positive integer")
6384
6333
  });
6385
- // Customer information schema for checkout sessions
6386
6334
  var checkoutSessionCustomerSchema = objectType({
6387
- email: stringType().email().optional(),
6388
- name: stringType().min(1).optional(),
6389
- phone_number: stringType().optional(),
6390
- })
6391
- .optional();
6392
- // Billing address schema for checkout sessions
6335
+ email: stringType().email().optional(),
6336
+ name: stringType().min(1).optional(),
6337
+ phone_number: stringType().optional()
6338
+ }).optional();
6393
6339
  var checkoutSessionBillingAddressSchema = objectType({
6394
- street: stringType().optional(),
6395
- city: stringType().optional(),
6396
- state: stringType().optional(),
6397
- country: stringType().length(2, "Country must be a 2-letter ISO code"),
6398
- zipcode: stringType().optional(),
6399
- })
6400
- .optional();
6401
- // Payment method types enum based on Dodo Payments documentation
6340
+ street: stringType().optional(),
6341
+ city: stringType().optional(),
6342
+ state: stringType().optional(),
6343
+ country: stringType().length(2, "Country must be a 2-letter ISO code"),
6344
+ zipcode: stringType().optional()
6345
+ }).optional();
6402
6346
  var paymentMethodTypeSchema = enumType([
6403
- "credit",
6404
- "debit",
6405
- "upi_collect",
6406
- "upi_intent",
6407
- "apple_pay",
6408
- "google_pay",
6409
- "amazon_pay",
6410
- "klarna",
6411
- "affirm",
6412
- "afterpay_clearpay",
6413
- "sepa",
6414
- "ach",
6347
+ "credit",
6348
+ "debit",
6349
+ "upi_collect",
6350
+ "upi_intent",
6351
+ "apple_pay",
6352
+ "google_pay",
6353
+ "amazon_pay",
6354
+ "klarna",
6355
+ "affirm",
6356
+ "afterpay_clearpay",
6357
+ "sepa",
6358
+ "ach"
6415
6359
  ]);
6416
- // Customization options schema
6417
6360
  var checkoutSessionCustomizationSchema = objectType({
6418
- theme: enumType(["light", "dark", "system"]).optional(),
6419
- show_order_details: booleanType().optional(),
6420
- show_on_demand_tag: booleanType().optional(),
6421
- })
6422
- .optional();
6423
- // Feature flags schema
6361
+ theme: enumType(["light", "dark", "system"]).optional(),
6362
+ show_order_details: booleanType().optional(),
6363
+ show_on_demand_tag: booleanType().optional()
6364
+ }).optional();
6424
6365
  var checkoutSessionFeatureFlagsSchema = objectType({
6425
- allow_currency_selection: booleanType().optional(),
6426
- allow_discount_code: booleanType().optional(),
6427
- allow_phone_number_collection: booleanType().optional(),
6428
- allow_tax_id: booleanType().optional(),
6429
- always_create_new_customer: booleanType().optional(),
6430
- })
6431
- .optional();
6432
- // Subscription data schema
6366
+ allow_currency_selection: booleanType().optional(),
6367
+ allow_discount_code: booleanType().optional(),
6368
+ allow_phone_number_collection: booleanType().optional(),
6369
+ allow_tax_id: booleanType().optional(),
6370
+ always_create_new_customer: booleanType().optional()
6371
+ }).optional();
6433
6372
  var checkoutSessionSubscriptionDataSchema = objectType({
6434
- trial_period_days: numberType().int().nonnegative().optional(),
6435
- })
6436
- .optional();
6437
- // Main checkout session payload schema
6373
+ trial_period_days: numberType().int().nonnegative().optional()
6374
+ }).optional();
6438
6375
  var checkoutSessionPayloadSchema = objectType({
6439
- // Required fields
6440
- product_cart: arrayType(checkoutSessionProductCartItemSchema)
6441
- .min(1, "At least one product is required"),
6442
- // Optional fields
6443
- customer: checkoutSessionCustomerSchema,
6444
- billing_address: checkoutSessionBillingAddressSchema,
6445
- return_url: stringType().url().optional(),
6446
- allowed_payment_method_types: arrayType(paymentMethodTypeSchema).optional(),
6447
- billing_currency: stringType()
6448
- .length(3, "Currency must be a 3-letter ISO code")
6449
- .optional(),
6450
- show_saved_payment_methods: booleanType().optional(),
6451
- confirm: booleanType().optional(),
6452
- discount_code: stringType().optional(),
6453
- metadata: recordType(stringType(), stringType()).optional(),
6454
- customization: checkoutSessionCustomizationSchema,
6455
- feature_flags: checkoutSessionFeatureFlagsSchema,
6456
- subscription_data: checkoutSessionSubscriptionDataSchema,
6376
+ // Required fields
6377
+ product_cart: arrayType(checkoutSessionProductCartItemSchema).min(1, "At least one product is required"),
6378
+ // Optional fields
6379
+ customer: checkoutSessionCustomerSchema,
6380
+ billing_address: checkoutSessionBillingAddressSchema,
6381
+ return_url: stringType().url().optional(),
6382
+ allowed_payment_method_types: arrayType(paymentMethodTypeSchema).optional(),
6383
+ billing_currency: stringType().length(3, "Currency must be a 3-letter ISO code").optional(),
6384
+ show_saved_payment_methods: booleanType().optional(),
6385
+ confirm: booleanType().optional(),
6386
+ discount_code: stringType().optional(),
6387
+ metadata: recordType(stringType(), stringType()).optional(),
6388
+ customization: checkoutSessionCustomizationSchema,
6389
+ feature_flags: checkoutSessionFeatureFlagsSchema,
6390
+ subscription_data: checkoutSessionSubscriptionDataSchema
6457
6391
  });
6458
- // Checkout session response schema
6459
6392
  var checkoutSessionResponseSchema = objectType({
6460
- session_id: stringType().min(1, "Session ID is required"),
6461
- checkout_url: stringType().url("Invalid checkout URL"),
6393
+ session_id: stringType().min(1, "Session ID is required"),
6394
+ checkout_url: stringType().url("Invalid checkout URL")
6462
6395
  });
6463
- /**
6464
- * Creates a new Dodo Payments Checkout Session using the modern /checkouts endpoint.
6465
- * This function provides a clean, type-safe interface to the Checkout Sessions API.
6466
- *
6467
- * @param payload - The checkout session data, validated against CheckoutSessionPayloadSchema
6468
- * @param config - Dodo Payments client configuration (bearerToken, environment)
6469
- * @returns Promise<CheckoutSessionResponse> - The checkout session with session_id and checkout_url
6470
- *
6471
- * @throws {Error} When payload validation fails or API request fails
6472
- *
6473
- * @example
6474
- * ```typescript
6475
- * const session = await createCheckoutSession({
6476
- * product_cart: [{ product_id: 'prod_123', quantity: 1 }],
6477
- * customer: { email: 'customer@example.com' },
6478
- * return_url: 'https://yoursite.com/success'
6479
- * }, {
6480
- * bearerToken: process.env.DODO_PAYMENTS_API_KEY,
6481
- * environment: 'test_mode'
6482
- * });
6483
- *
6484
- * ```
6485
- */
6486
- var createCheckoutSession = function (payload, config) { return __awaiter$1(void 0, void 0, void 0, function () {
6487
- var validation, dodopayments, sdkPayload, session, responseValidation, error_1;
6488
- return __generator$1(this, function (_a) {
6489
- switch (_a.label) {
6490
- case 0:
6491
- validation = checkoutSessionPayloadSchema.safeParse(payload);
6492
- if (!validation.success) {
6493
- throw new Error("Invalid checkout session payload: ".concat(validation.error.issues
6494
- .map(function (issue) { return "".concat(issue.path.join("."), ": ").concat(issue.message); })
6495
- .join(", ")));
6496
- }
6497
- dodopayments = new DodoPayments({
6498
- bearerToken: config.bearerToken,
6499
- environment: config.environment,
6500
- });
6501
- _a.label = 1;
6502
- case 1:
6503
- _a.trys.push([1, 3, , 4]);
6504
- sdkPayload = __assign(__assign({}, validation.data), (validation.data.billing_address && {
6505
- billing_address: __assign(__assign({}, validation.data.billing_address), { country: validation.data.billing_address.country }),
6506
- }));
6507
- return [4 /*yield*/, dodopayments.checkoutSessions.create(sdkPayload)];
6508
- case 2:
6509
- session = _a.sent();
6510
- responseValidation = checkoutSessionResponseSchema.safeParse(session);
6511
- if (!responseValidation.success) {
6512
- throw new Error("Invalid checkout session response from API: ".concat(responseValidation.error.issues
6513
- .map(function (issue) { return "".concat(issue.path.join("."), ": ").concat(issue.message); })
6514
- .join(", ")));
6515
- }
6516
- return [2 /*return*/, responseValidation.data];
6517
- case 3:
6518
- error_1 = _a.sent();
6519
- if (error_1 instanceof Error) {
6520
- console.error("Dodo Payments Checkout Session API Error:", {
6521
- message: error_1.message,
6522
- payload: validation.data,
6523
- config: {
6524
- environment: config.environment,
6525
- hasBearerToken: !!config.bearerToken,
6526
- },
6527
- });
6528
- // Re-throw with a more user-friendly message
6529
- throw new Error("Failed to create checkout session: ".concat(error_1.message));
6530
- }
6531
- // Handle non-Error objects
6532
- console.error("Unknown error creating checkout session:", error_1);
6533
- throw new Error("Failed to create checkout session due to an unknown error");
6534
- case 4: return [2 /*return*/];
6535
- }
6396
+ var createCheckoutSession = async (payload, config) => {
6397
+ const validation = checkoutSessionPayloadSchema.safeParse(payload);
6398
+ if (!validation.success) {
6399
+ throw new Error(
6400
+ `Invalid checkout session payload: ${validation.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join(", ")}`
6401
+ );
6402
+ }
6403
+ const dodopayments = new DodoPayments({
6404
+ bearerToken: config.bearerToken,
6405
+ environment: config.environment
6406
+ });
6407
+ try {
6408
+ const sdkPayload = {
6409
+ ...validation.data,
6410
+ ...validation.data.billing_address && {
6411
+ billing_address: {
6412
+ ...validation.data.billing_address,
6413
+ country: validation.data.billing_address.country
6414
+ }
6415
+ }
6416
+ };
6417
+ const session = await dodopayments.checkoutSessions.create(
6418
+ sdkPayload
6419
+ );
6420
+ const responseValidation = checkoutSessionResponseSchema.safeParse(session);
6421
+ if (!responseValidation.success) {
6422
+ throw new Error(
6423
+ `Invalid checkout session response from API: ${responseValidation.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join(", ")}`
6424
+ );
6425
+ }
6426
+ return responseValidation.data;
6427
+ } catch (error) {
6428
+ if (error instanceof Error) {
6429
+ console.error("Dodo Payments Checkout Session API Error:", {
6430
+ message: error.message,
6431
+ payload: validation.data,
6432
+ config: {
6433
+ environment: config.environment,
6434
+ hasBearerToken: !!config.bearerToken
6435
+ }
6436
+ });
6437
+ throw new Error(`Failed to create checkout session: ${error.message}`);
6438
+ }
6439
+ console.error("Unknown error creating checkout session:", error);
6440
+ throw new Error(
6441
+ "Failed to create checkout session due to an unknown error"
6442
+ );
6443
+ }
6444
+ };
6445
+ var buildCheckoutUrl = async ({
6446
+ queryParams,
6447
+ body,
6448
+ sessionPayload,
6449
+ returnUrl,
6450
+ bearerToken,
6451
+ environment,
6452
+ type = "static"
6453
+ }) => {
6454
+ if (type === "session") {
6455
+ if (!sessionPayload) {
6456
+ throw new Error("sessionPayload is required when type is 'session'");
6457
+ }
6458
+ const session = await createCheckoutSession(sessionPayload, {
6459
+ bearerToken,
6460
+ environment
6536
6461
  });
6537
- }); };
6538
- var buildCheckoutUrl = function (_a) { return __awaiter$1(void 0, [_a], void 0, function (_b) {
6539
- 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;
6540
- 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;
6541
- return __generator$1(this, function (_g) {
6542
- switch (_g.label) {
6543
- case 0:
6544
- if (!(type === "session")) return [3 /*break*/, 2];
6545
- if (!sessionPayload) {
6546
- throw new Error("sessionPayload is required when type is 'session'");
6547
- }
6548
- return [4 /*yield*/, createCheckoutSession(sessionPayload, {
6549
- bearerToken: bearerToken,
6550
- environment: environment,
6551
- })];
6552
- case 1:
6553
- session = _g.sent();
6554
- return [2 /*return*/, session.checkout_url];
6555
- case 2:
6556
- inputData = type === "dynamic" ? body : queryParams;
6557
- if (type === "dynamic") {
6558
- parseResult = dynamicCheckoutBodySchema.safeParse(inputData);
6559
- }
6560
- else {
6561
- parseResult = checkoutQuerySchema.safeParse(inputData);
6562
- }
6563
- success = parseResult.success, data = parseResult.data, error = parseResult.error;
6564
- if (!success) {
6565
- throw new Error("Invalid ".concat(type === "dynamic" ? "body" : "query parameters", ".\n ").concat(error.message));
6566
- }
6567
- if (!(type !== "dynamic")) return [3 /*break*/, 7];
6568
- _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;
6569
- dodopayments_1 = new DodoPayments({
6570
- bearerToken: bearerToken,
6571
- environment: environment,
6572
- });
6573
- // Check that the product exists for this merchant
6574
- if (!productId)
6575
- throw new Error("Missing required field: productId");
6576
- _g.label = 3;
6577
- case 3:
6578
- _g.trys.push([3, 5, , 6]);
6579
- return [4 /*yield*/, dodopayments_1.products.retrieve(productId)];
6580
- case 4:
6581
- _g.sent();
6582
- return [3 /*break*/, 6];
6583
- case 5:
6584
- err_1 = _g.sent();
6585
- console.error(err_1);
6586
- throw new Error("Product not found");
6587
- case 6:
6588
- url = new URL("".concat(environment === "test_mode" ? "https://test.checkout.dodopayments.com" : "https://checkout.dodopayments.com", "/buy/").concat(productId));
6589
- url.searchParams.set("quantity", quantity_1 ? String(quantity_1) : "1");
6590
- if (returnUrl)
6591
- url.searchParams.set("redirect_url", returnUrl);
6592
- // Customer/billing fields
6593
- if (fullName)
6594
- url.searchParams.set("fullName", String(fullName));
6595
- if (firstName)
6596
- url.searchParams.set("firstName", String(firstName));
6597
- if (lastName)
6598
- url.searchParams.set("lastName", String(lastName));
6599
- if (email)
6600
- url.searchParams.set("email", String(email));
6601
- if (country)
6602
- url.searchParams.set("country", String(country));
6603
- if (addressLine)
6604
- url.searchParams.set("addressLine", String(addressLine));
6605
- if (city)
6606
- url.searchParams.set("city", String(city));
6607
- if (state)
6608
- url.searchParams.set("state", String(state));
6609
- if (zipCode)
6610
- url.searchParams.set("zipCode", String(zipCode));
6611
- // Disable flags (must be set to 'true' to disable)
6612
- if (disableFullName === "true")
6613
- url.searchParams.set("disableFullName", "true");
6614
- if (disableFirstName === "true")
6615
- url.searchParams.set("disableFirstName", "true");
6616
- if (disableLastName === "true")
6617
- url.searchParams.set("disableLastName", "true");
6618
- if (disableEmail === "true")
6619
- url.searchParams.set("disableEmail", "true");
6620
- if (disableCountry === "true")
6621
- url.searchParams.set("disableCountry", "true");
6622
- if (disableAddressLine === "true")
6623
- url.searchParams.set("disableAddressLine", "true");
6624
- if (disableCity === "true")
6625
- url.searchParams.set("disableCity", "true");
6626
- if (disableState === "true")
6627
- url.searchParams.set("disableState", "true");
6628
- if (disableZipCode === "true")
6629
- url.searchParams.set("disableZipCode", "true");
6630
- // Advanced controls
6631
- if (paymentCurrency)
6632
- url.searchParams.set("paymentCurrency", String(paymentCurrency));
6633
- if (showCurrencySelector)
6634
- url.searchParams.set("showCurrencySelector", String(showCurrencySelector));
6635
- if (paymentAmount)
6636
- url.searchParams.set("paymentAmount", String(paymentAmount));
6637
- if (showDiscounts)
6638
- url.searchParams.set("showDiscounts", String(showDiscounts));
6639
- // Metadata: add all query params starting with metadata_
6640
- for (_i = 0, _d = Object.entries(queryParams || {}); _i < _d.length; _i++) {
6641
- _e = _d[_i], key = _e[0], value = _e[1];
6642
- if (key.startsWith("metadata_") && value && typeof value !== "object") {
6643
- url.searchParams.set(key, String(value));
6644
- }
6645
- }
6646
- return [2 /*return*/, url.toString()];
6647
- case 7:
6648
- dyn = data;
6649
- 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;
6650
- dodopayments = new DodoPayments({
6651
- bearerToken: bearerToken,
6652
- environment: environment,
6653
- });
6654
- isSubscription = false;
6655
- productIdToFetch = product_id;
6656
- if (!product_id && product_cart && product_cart.length > 0) {
6657
- productIdToFetch = product_cart[0].product_id;
6658
- }
6659
- if (!productIdToFetch)
6660
- throw new Error("Missing required field: product_id or product_cart[0].product_id");
6661
- _g.label = 8;
6662
- case 8:
6663
- _g.trys.push([8, 10, , 11]);
6664
- return [4 /*yield*/, dodopayments.products.retrieve(productIdToFetch)];
6665
- case 9:
6666
- product = _g.sent();
6667
- return [3 /*break*/, 11];
6668
- case 10:
6669
- err_2 = _g.sent();
6670
- console.error(err_2);
6671
- throw new Error("Product not found");
6672
- case 11:
6673
- isSubscription = Boolean(product.is_recurring);
6674
- // Required field validation
6675
- if (isSubscription && !product_id)
6676
- throw new Error("Missing required field: product_id for subscription");
6677
- if (!billing)
6678
- throw new Error("Missing required field: billing");
6679
- if (!customer)
6680
- throw new Error("Missing required field: customer");
6681
- if (!isSubscription) return [3 /*break*/, 16];
6682
- subscriptionPayload = {
6683
- billing: billing,
6684
- customer: customer,
6685
- product_id: product_id,
6686
- quantity: quantity ? Number(quantity) : 1,
6687
- };
6688
- if (metadata)
6689
- subscriptionPayload.metadata = metadata;
6690
- if (discount_code)
6691
- subscriptionPayload.discount_code = discount_code;
6692
- if (addons)
6693
- subscriptionPayload.addons = addons;
6694
- if (allowed_payment_method_types)
6695
- subscriptionPayload.allowed_payment_method_types =
6696
- allowed_payment_method_types;
6697
- if (billing_currency)
6698
- subscriptionPayload.billing_currency = billing_currency;
6699
- if (on_demand)
6700
- subscriptionPayload.on_demand = on_demand;
6701
- subscriptionPayload.payment_link = true;
6702
- // Use bodyReturnUrl if present, otherwise use top-level returnUrl
6703
- if (bodyReturnUrl) {
6704
- subscriptionPayload.return_url = bodyReturnUrl;
6705
- }
6706
- else if (returnUrl) {
6707
- subscriptionPayload.return_url = returnUrl;
6708
- }
6709
- if (show_saved_payment_methods)
6710
- subscriptionPayload.show_saved_payment_methods =
6711
- show_saved_payment_methods;
6712
- if (tax_id)
6713
- subscriptionPayload.tax_id = tax_id;
6714
- if (trial_period_days)
6715
- subscriptionPayload.trial_period_days = trial_period_days;
6716
- subscription = void 0;
6717
- _g.label = 12;
6718
- case 12:
6719
- _g.trys.push([12, 14, , 15]);
6720
- return [4 /*yield*/, dodopayments.subscriptions.create(subscriptionPayload)];
6721
- case 13:
6722
- subscription =
6723
- _g.sent();
6724
- return [3 /*break*/, 15];
6725
- case 14:
6726
- err_3 = _g.sent();
6727
- console.error("Error when creating subscription", err_3);
6728
- throw new Error(err_3 instanceof Error ? err_3.message : String(err_3));
6729
- case 15:
6730
- if (!subscription || !subscription.payment_link) {
6731
- throw new Error("No payment link returned from Dodo Payments API (subscription). Make sure to set payment_link as true in payload");
6732
- }
6733
- return [2 /*return*/, subscription.payment_link];
6734
- case 16:
6735
- cart = product_cart;
6736
- if (!cart && product_id) {
6737
- cart = [
6738
- { product_id: product_id, quantity: quantity ? Number(quantity) : 1 },
6739
- ];
6740
- }
6741
- if (!cart || cart.length === 0)
6742
- throw new Error("Missing required field: product_cart or product_id");
6743
- paymentPayload = {
6744
- billing: billing,
6745
- customer: customer,
6746
- product_cart: cart,
6747
- };
6748
- if (metadata)
6749
- paymentPayload.metadata = metadata;
6750
- paymentPayload.payment_link = true;
6751
- if (allowed_payment_method_types)
6752
- paymentPayload.allowed_payment_method_types =
6753
- allowed_payment_method_types;
6754
- if (billing_currency)
6755
- paymentPayload.billing_currency = billing_currency;
6756
- if (discount_code)
6757
- paymentPayload.discount_code = discount_code;
6758
- // Use bodyReturnUrl if present, otherwise use top-level returnUrl
6759
- if (bodyReturnUrl) {
6760
- paymentPayload.return_url = bodyReturnUrl;
6761
- }
6762
- else if (returnUrl) {
6763
- paymentPayload.return_url = returnUrl;
6764
- }
6765
- if (show_saved_payment_methods)
6766
- paymentPayload.show_saved_payment_methods = show_saved_payment_methods;
6767
- if (tax_id)
6768
- paymentPayload.tax_id = tax_id;
6769
- payment = void 0;
6770
- _g.label = 17;
6771
- case 17:
6772
- _g.trys.push([17, 19, , 20]);
6773
- return [4 /*yield*/, dodopayments.payments.create(paymentPayload)];
6774
- case 18:
6775
- payment = _g.sent();
6776
- return [3 /*break*/, 20];
6777
- case 19:
6778
- err_4 = _g.sent();
6779
- console.error("Error when creating payment link", err_4);
6780
- throw new Error(err_4 instanceof Error ? err_4.message : String(err_4));
6781
- case 20:
6782
- if (!payment || !payment.payment_link) {
6783
- throw new Error("No payment link returned from Dodo Payments API. Make sure to set payment_link as true in payload.");
6784
- }
6785
- return [2 /*return*/, payment.payment_link];
6786
- }
6462
+ return session.checkout_url;
6463
+ }
6464
+ const inputData = type === "dynamic" ? body : queryParams;
6465
+ let parseResult;
6466
+ if (type === "dynamic") {
6467
+ parseResult = dynamicCheckoutBodySchema.safeParse(inputData);
6468
+ } else {
6469
+ parseResult = checkoutQuerySchema.safeParse(inputData);
6470
+ }
6471
+ const { success, data, error } = parseResult;
6472
+ if (!success) {
6473
+ throw new Error(
6474
+ `Invalid ${type === "dynamic" ? "body" : "query parameters"}.
6475
+ ${error.message}`
6476
+ );
6477
+ }
6478
+ if (type !== "dynamic") {
6479
+ const {
6480
+ productId,
6481
+ quantity: quantity2,
6482
+ fullName,
6483
+ firstName,
6484
+ lastName,
6485
+ email,
6486
+ country,
6487
+ addressLine,
6488
+ city,
6489
+ state,
6490
+ zipCode,
6491
+ disableFullName,
6492
+ disableFirstName,
6493
+ disableLastName,
6494
+ disableEmail,
6495
+ disableCountry,
6496
+ disableAddressLine,
6497
+ disableCity,
6498
+ disableState,
6499
+ disableZipCode,
6500
+ paymentCurrency,
6501
+ showCurrencySelector,
6502
+ paymentAmount,
6503
+ showDiscounts
6504
+ // metadata handled below
6505
+ } = data;
6506
+ const dodopayments2 = new DodoPayments({
6507
+ bearerToken,
6508
+ environment
6787
6509
  });
6788
- }); };
6510
+ if (!productId) throw new Error("Missing required field: productId");
6511
+ try {
6512
+ await dodopayments2.products.retrieve(productId);
6513
+ } catch (err) {
6514
+ console.error(err);
6515
+ throw new Error("Product not found");
6516
+ }
6517
+ const url = new URL(
6518
+ `${environment === "test_mode" ? "https://test.checkout.dodopayments.com" : "https://checkout.dodopayments.com"}/buy/${productId}`
6519
+ );
6520
+ url.searchParams.set("quantity", quantity2 ? String(quantity2) : "1");
6521
+ if (returnUrl) url.searchParams.set("redirect_url", returnUrl);
6522
+ if (fullName) url.searchParams.set("fullName", String(fullName));
6523
+ if (firstName) url.searchParams.set("firstName", String(firstName));
6524
+ if (lastName) url.searchParams.set("lastName", String(lastName));
6525
+ if (email) url.searchParams.set("email", String(email));
6526
+ if (country) url.searchParams.set("country", String(country));
6527
+ if (addressLine) url.searchParams.set("addressLine", String(addressLine));
6528
+ if (city) url.searchParams.set("city", String(city));
6529
+ if (state) url.searchParams.set("state", String(state));
6530
+ if (zipCode) url.searchParams.set("zipCode", String(zipCode));
6531
+ if (disableFullName === "true")
6532
+ url.searchParams.set("disableFullName", "true");
6533
+ if (disableFirstName === "true")
6534
+ url.searchParams.set("disableFirstName", "true");
6535
+ if (disableLastName === "true")
6536
+ url.searchParams.set("disableLastName", "true");
6537
+ if (disableEmail === "true") url.searchParams.set("disableEmail", "true");
6538
+ if (disableCountry === "true")
6539
+ url.searchParams.set("disableCountry", "true");
6540
+ if (disableAddressLine === "true")
6541
+ url.searchParams.set("disableAddressLine", "true");
6542
+ if (disableCity === "true") url.searchParams.set("disableCity", "true");
6543
+ if (disableState === "true") url.searchParams.set("disableState", "true");
6544
+ if (disableZipCode === "true")
6545
+ url.searchParams.set("disableZipCode", "true");
6546
+ if (paymentCurrency)
6547
+ url.searchParams.set("paymentCurrency", String(paymentCurrency));
6548
+ if (showCurrencySelector)
6549
+ url.searchParams.set(
6550
+ "showCurrencySelector",
6551
+ String(showCurrencySelector)
6552
+ );
6553
+ if (paymentAmount)
6554
+ url.searchParams.set("paymentAmount", String(paymentAmount));
6555
+ if (showDiscounts)
6556
+ url.searchParams.set("showDiscounts", String(showDiscounts));
6557
+ for (const [key, value] of Object.entries(queryParams || {})) {
6558
+ if (key.startsWith("metadata_") && value && typeof value !== "object") {
6559
+ url.searchParams.set(key, String(value));
6560
+ }
6561
+ }
6562
+ return url.toString();
6563
+ }
6564
+ const dyn = data;
6565
+ const {
6566
+ product_id,
6567
+ product_cart,
6568
+ quantity,
6569
+ billing,
6570
+ customer,
6571
+ addons,
6572
+ metadata,
6573
+ allowed_payment_method_types,
6574
+ billing_currency,
6575
+ discount_code,
6576
+ on_demand,
6577
+ return_url: bodyReturnUrl,
6578
+ show_saved_payment_methods,
6579
+ tax_id,
6580
+ trial_period_days
6581
+ } = dyn;
6582
+ const dodopayments = new DodoPayments({
6583
+ bearerToken,
6584
+ environment
6585
+ });
6586
+ let isSubscription = false;
6587
+ let productIdToFetch = product_id;
6588
+ if (!product_id && product_cart && product_cart.length > 0) {
6589
+ productIdToFetch = product_cart[0].product_id;
6590
+ }
6591
+ if (!productIdToFetch)
6592
+ throw new Error(
6593
+ "Missing required field: product_id or product_cart[0].product_id"
6594
+ );
6595
+ let product;
6596
+ try {
6597
+ product = await dodopayments.products.retrieve(productIdToFetch);
6598
+ } catch (err) {
6599
+ console.error(err);
6600
+ throw new Error("Product not found");
6601
+ }
6602
+ isSubscription = Boolean(product.is_recurring);
6603
+ if (isSubscription && !product_id)
6604
+ throw new Error("Missing required field: product_id for subscription");
6605
+ if (!billing) throw new Error("Missing required field: billing");
6606
+ if (!customer) throw new Error("Missing required field: customer");
6607
+ if (isSubscription) {
6608
+ const subscriptionPayload = {
6609
+ billing,
6610
+ customer,
6611
+ product_id,
6612
+ quantity: quantity ? Number(quantity) : 1
6613
+ };
6614
+ if (metadata) subscriptionPayload.metadata = metadata;
6615
+ if (discount_code) subscriptionPayload.discount_code = discount_code;
6616
+ if (addons) subscriptionPayload.addons = addons;
6617
+ if (allowed_payment_method_types)
6618
+ subscriptionPayload.allowed_payment_method_types = allowed_payment_method_types;
6619
+ if (billing_currency)
6620
+ subscriptionPayload.billing_currency = billing_currency;
6621
+ if (on_demand) subscriptionPayload.on_demand = on_demand;
6622
+ subscriptionPayload.payment_link = true;
6623
+ if (bodyReturnUrl) {
6624
+ subscriptionPayload.return_url = bodyReturnUrl;
6625
+ } else if (returnUrl) {
6626
+ subscriptionPayload.return_url = returnUrl;
6627
+ }
6628
+ if (show_saved_payment_methods)
6629
+ subscriptionPayload.show_saved_payment_methods = show_saved_payment_methods;
6630
+ if (tax_id) subscriptionPayload.tax_id = tax_id;
6631
+ if (trial_period_days)
6632
+ subscriptionPayload.trial_period_days = trial_period_days;
6633
+ let subscription;
6634
+ try {
6635
+ subscription = await dodopayments.subscriptions.create(subscriptionPayload);
6636
+ } catch (err) {
6637
+ console.error("Error when creating subscription", err);
6638
+ throw new Error(err instanceof Error ? err.message : String(err));
6639
+ }
6640
+ if (!subscription || !subscription.payment_link) {
6641
+ throw new Error(
6642
+ "No payment link returned from Dodo Payments API (subscription). Make sure to set payment_link as true in payload"
6643
+ );
6644
+ }
6645
+ return subscription.payment_link;
6646
+ } else {
6647
+ let cart = product_cart;
6648
+ if (!cart && product_id) {
6649
+ cart = [
6650
+ { product_id, quantity: quantity ? Number(quantity) : 1 }
6651
+ ];
6652
+ }
6653
+ if (!cart || cart.length === 0)
6654
+ throw new Error("Missing required field: product_cart or product_id");
6655
+ const paymentPayload = {
6656
+ billing,
6657
+ customer,
6658
+ product_cart: cart
6659
+ };
6660
+ if (metadata) paymentPayload.metadata = metadata;
6661
+ paymentPayload.payment_link = true;
6662
+ if (allowed_payment_method_types)
6663
+ paymentPayload.allowed_payment_method_types = allowed_payment_method_types;
6664
+ if (billing_currency) paymentPayload.billing_currency = billing_currency;
6665
+ if (discount_code) paymentPayload.discount_code = discount_code;
6666
+ if (bodyReturnUrl) {
6667
+ paymentPayload.return_url = bodyReturnUrl;
6668
+ } else if (returnUrl) {
6669
+ paymentPayload.return_url = returnUrl;
6670
+ }
6671
+ if (show_saved_payment_methods)
6672
+ paymentPayload.show_saved_payment_methods = show_saved_payment_methods;
6673
+ if (tax_id) paymentPayload.tax_id = tax_id;
6674
+ let payment;
6675
+ try {
6676
+ payment = await dodopayments.payments.create(paymentPayload);
6677
+ } catch (err) {
6678
+ console.error("Error when creating payment link", err);
6679
+ throw new Error(err instanceof Error ? err.message : String(err));
6680
+ }
6681
+ if (!payment || !payment.payment_link) {
6682
+ throw new Error(
6683
+ "No payment link returned from Dodo Payments API. Make sure to set payment_link as true in payload."
6684
+ );
6685
+ }
6686
+ return payment.payment_link;
6687
+ }
6688
+ };
6789
6689
 
6790
6690
  const Checkout = (config) => {
6791
6691
  const getHandler = async (event) => {
@@ -7715,542 +7615,422 @@ class Webhook {
7715
7615
  Webhook_1 = dist.Webhook = Webhook;
7716
7616
  Webhook.prefix = "whsec_";
7717
7617
 
7618
+ // src/schemas/webhook.ts
7718
7619
  var PaymentSchema = objectType({
7719
- payload_type: literalType("Payment"),
7720
- billing: objectType({
7721
- city: stringType().nullable(),
7722
- country: stringType().nullable(),
7723
- state: stringType().nullable(),
7724
- street: stringType().nullable(),
7725
- zipcode: stringType().nullable(),
7726
- }),
7727
- brand_id: stringType(),
7728
- business_id: stringType(),
7729
- card_issuing_country: stringType().nullable(),
7730
- card_last_four: stringType().nullable(),
7731
- card_network: stringType().nullable(),
7732
- card_type: stringType().nullable(),
7733
- created_at: stringType().transform(function (d) { return new Date(d); }),
7734
- currency: stringType(),
7735
- customer: objectType({
7736
- customer_id: stringType(),
7737
- email: stringType(),
7738
- name: stringType().nullable(),
7739
- }),
7740
- digital_products_delivered: booleanType(),
7741
- discount_id: stringType().nullable(),
7742
- disputes: arrayType(objectType({
7743
- amount: stringType(),
7744
- business_id: stringType(),
7745
- created_at: stringType().transform(function (d) { return new Date(d); }),
7746
- currency: stringType(),
7747
- dispute_id: stringType(),
7748
- dispute_stage: enumType([
7749
- "pre_dispute",
7750
- "dispute_opened",
7751
- "dispute_won",
7752
- "dispute_lost",
7753
- ]),
7754
- dispute_status: enumType([
7755
- "dispute_opened",
7756
- "dispute_won",
7757
- "dispute_lost",
7758
- "dispute_accepted",
7759
- "dispute_cancelled",
7760
- "dispute_challenged",
7761
- ]),
7762
- payment_id: stringType(),
7763
- remarks: stringType().nullable(),
7764
- }))
7765
- .nullable(),
7766
- error_code: stringType().nullable(),
7767
- error_message: stringType().nullable(),
7768
- metadata: recordType(anyType()).nullable(),
7769
- payment_id: stringType(),
7770
- payment_link: stringType().nullable(),
7771
- payment_method: stringType().nullable(),
7772
- payment_method_type: stringType().nullable(),
7773
- product_cart: arrayType(objectType({
7774
- product_id: stringType(),
7775
- quantity: numberType(),
7776
- }))
7777
- .nullable(),
7778
- refunds: arrayType(objectType({
7779
- amount: numberType(),
7780
- business_id: stringType(),
7781
- created_at: stringType().transform(function (d) { return new Date(d); }),
7782
- currency: stringType(),
7783
- is_partial: booleanType(),
7784
- payment_id: stringType(),
7785
- reason: stringType().nullable(),
7786
- refund_id: stringType(),
7787
- status: enumType(["succeeded", "failed", "pending"]),
7788
- }))
7789
- .nullable(),
7790
- settlement_amount: numberType(),
7791
- settlement_currency: stringType(),
7792
- settlement_tax: numberType().nullable(),
7793
- status: enumType(["succeeded", "failed", "pending", "processing", "cancelled"]),
7794
- subscription_id: stringType().nullable(),
7795
- tax: numberType().nullable(),
7796
- total_amount: numberType(),
7797
- updated_at: stringType()
7798
- .transform(function (d) { return new Date(d); })
7799
- .nullable(),
7800
- });
7801
- var SubscriptionSchema = objectType({
7802
- payload_type: literalType("Subscription"),
7803
- addons: arrayType(objectType({
7804
- addon_id: stringType(),
7805
- quantity: numberType(),
7806
- }))
7807
- .nullable(),
7808
- billing: objectType({
7809
- city: stringType().nullable(),
7810
- country: stringType().nullable(),
7811
- state: stringType().nullable(),
7812
- street: stringType().nullable(),
7813
- zipcode: stringType().nullable(),
7814
- }),
7815
- cancel_at_next_billing_date: booleanType(),
7816
- cancelled_at: stringType()
7817
- .transform(function (d) { return new Date(d); })
7818
- .nullable(),
7819
- created_at: stringType().transform(function (d) { return new Date(d); }),
7820
- currency: stringType(),
7821
- customer: objectType({
7822
- customer_id: stringType(),
7823
- email: stringType(),
7824
- name: stringType().nullable(),
7825
- }),
7826
- discount_id: stringType().nullable(),
7827
- metadata: recordType(anyType()).nullable(),
7828
- next_billing_date: stringType()
7829
- .transform(function (d) { return new Date(d); })
7830
- .nullable(),
7831
- on_demand: booleanType(),
7832
- payment_frequency_count: numberType(),
7833
- payment_frequency_interval: enumType(["Day", "Week", "Month", "Year"]),
7834
- previous_billing_date: stringType()
7835
- .transform(function (d) { return new Date(d); })
7836
- .nullable(),
7837
- product_id: stringType(),
7838
- quantity: numberType(),
7839
- recurring_pre_tax_amount: numberType(),
7840
- status: enumType([
7841
- "pending",
7842
- "active",
7843
- "on_hold",
7844
- "paused",
7845
- "cancelled",
7846
- "expired",
7847
- "failed",
7848
- ]),
7849
- subscription_id: stringType(),
7850
- subscription_period_count: numberType(),
7851
- subscription_period_interval: enumType(["Day", "Week", "Month", "Year"]),
7852
- tax_inclusive: booleanType(),
7853
- trial_period_days: numberType(),
7854
- });
7855
- var RefundSchema = objectType({
7856
- payload_type: literalType("Refund"),
7857
- amount: numberType(),
7858
- business_id: stringType(),
7859
- created_at: stringType().transform(function (d) { return new Date(d); }),
7860
- currency: stringType(),
7861
- is_partial: booleanType(),
7862
- payment_id: stringType(),
7863
- reason: stringType().nullable(),
7864
- refund_id: stringType(),
7865
- status: enumType(["succeeded", "failed", "pending"]),
7866
- });
7867
- var DisputeSchema = objectType({
7868
- payload_type: literalType("Dispute"),
7869
- amount: stringType(),
7870
- business_id: stringType(),
7871
- created_at: stringType().transform(function (d) { return new Date(d); }),
7872
- currency: stringType(),
7873
- dispute_id: stringType(),
7874
- dispute_stage: enumType([
7620
+ payload_type: literalType("Payment"),
7621
+ billing: objectType({
7622
+ city: stringType().nullable(),
7623
+ country: stringType().nullable(),
7624
+ state: stringType().nullable(),
7625
+ street: stringType().nullable(),
7626
+ zipcode: stringType().nullable()
7627
+ }),
7628
+ brand_id: stringType(),
7629
+ business_id: stringType(),
7630
+ card_issuing_country: stringType().nullable(),
7631
+ card_last_four: stringType().nullable(),
7632
+ card_network: stringType().nullable(),
7633
+ card_type: stringType().nullable(),
7634
+ created_at: stringType().transform((d) => new Date(d)),
7635
+ currency: stringType(),
7636
+ customer: objectType({
7637
+ customer_id: stringType(),
7638
+ email: stringType(),
7639
+ name: stringType().nullable()
7640
+ }),
7641
+ digital_products_delivered: booleanType(),
7642
+ discount_id: stringType().nullable(),
7643
+ disputes: arrayType(
7644
+ objectType({
7645
+ amount: stringType(),
7646
+ business_id: stringType(),
7647
+ created_at: stringType().transform((d) => new Date(d)),
7648
+ currency: stringType(),
7649
+ dispute_id: stringType(),
7650
+ dispute_stage: enumType([
7875
7651
  "pre_dispute",
7876
7652
  "dispute_opened",
7877
7653
  "dispute_won",
7878
- "dispute_lost",
7879
- ]),
7880
- dispute_status: enumType([
7654
+ "dispute_lost"
7655
+ ]),
7656
+ dispute_status: enumType([
7881
7657
  "dispute_opened",
7882
7658
  "dispute_won",
7883
7659
  "dispute_lost",
7884
7660
  "dispute_accepted",
7885
7661
  "dispute_cancelled",
7886
- "dispute_challenged",
7887
- ]),
7888
- payment_id: stringType(),
7889
- remarks: stringType().nullable(),
7662
+ "dispute_challenged"
7663
+ ]),
7664
+ payment_id: stringType(),
7665
+ remarks: stringType().nullable()
7666
+ })
7667
+ ).nullable(),
7668
+ error_code: stringType().nullable(),
7669
+ error_message: stringType().nullable(),
7670
+ metadata: recordType(anyType()).nullable(),
7671
+ payment_id: stringType(),
7672
+ payment_link: stringType().nullable(),
7673
+ payment_method: stringType().nullable(),
7674
+ payment_method_type: stringType().nullable(),
7675
+ product_cart: arrayType(
7676
+ objectType({
7677
+ product_id: stringType(),
7678
+ quantity: numberType()
7679
+ })
7680
+ ).nullable(),
7681
+ refunds: arrayType(
7682
+ objectType({
7683
+ amount: numberType(),
7684
+ business_id: stringType(),
7685
+ created_at: stringType().transform((d) => new Date(d)),
7686
+ currency: stringType(),
7687
+ is_partial: booleanType(),
7688
+ payment_id: stringType(),
7689
+ reason: stringType().nullable(),
7690
+ refund_id: stringType(),
7691
+ status: enumType(["succeeded", "failed", "pending"])
7692
+ })
7693
+ ).nullable(),
7694
+ settlement_amount: numberType(),
7695
+ settlement_currency: stringType(),
7696
+ settlement_tax: numberType().nullable(),
7697
+ status: enumType(["succeeded", "failed", "pending", "processing", "cancelled"]),
7698
+ subscription_id: stringType().nullable(),
7699
+ tax: numberType().nullable(),
7700
+ total_amount: numberType(),
7701
+ updated_at: stringType().transform((d) => new Date(d)).nullable()
7890
7702
  });
7891
- var LicenseKeySchema = objectType({
7892
- payload_type: literalType("LicenseKey"),
7893
- activations_limit: numberType(),
7894
- business_id: stringType(),
7895
- created_at: stringType().transform(function (d) { return new Date(d); }),
7703
+ var SubscriptionSchema = objectType({
7704
+ payload_type: literalType("Subscription"),
7705
+ addons: arrayType(
7706
+ objectType({
7707
+ addon_id: stringType(),
7708
+ quantity: numberType()
7709
+ })
7710
+ ).nullable(),
7711
+ billing: objectType({
7712
+ city: stringType().nullable(),
7713
+ country: stringType().nullable(),
7714
+ state: stringType().nullable(),
7715
+ street: stringType().nullable(),
7716
+ zipcode: stringType().nullable()
7717
+ }),
7718
+ cancel_at_next_billing_date: booleanType(),
7719
+ cancelled_at: stringType().transform((d) => new Date(d)).nullable(),
7720
+ created_at: stringType().transform((d) => new Date(d)),
7721
+ currency: stringType(),
7722
+ customer: objectType({
7896
7723
  customer_id: stringType(),
7897
- expires_at: stringType()
7898
- .transform(function (d) { return new Date(d); })
7899
- .nullable(),
7900
- id: stringType(),
7901
- instances_count: numberType(),
7902
- key: stringType(),
7903
- payment_id: stringType(),
7904
- product_id: stringType(),
7905
- status: enumType(["active", "inactive", "expired"]),
7906
- subscription_id: stringType().nullable(),
7724
+ email: stringType(),
7725
+ name: stringType().nullable()
7726
+ }),
7727
+ discount_id: stringType().nullable(),
7728
+ metadata: recordType(anyType()).nullable(),
7729
+ next_billing_date: stringType().transform((d) => new Date(d)).nullable(),
7730
+ on_demand: booleanType(),
7731
+ payment_frequency_count: numberType(),
7732
+ payment_frequency_interval: enumType(["Day", "Week", "Month", "Year"]),
7733
+ previous_billing_date: stringType().transform((d) => new Date(d)).nullable(),
7734
+ product_id: stringType(),
7735
+ quantity: numberType(),
7736
+ recurring_pre_tax_amount: numberType(),
7737
+ status: enumType([
7738
+ "pending",
7739
+ "active",
7740
+ "on_hold",
7741
+ "paused",
7742
+ "cancelled",
7743
+ "expired",
7744
+ "failed"
7745
+ ]),
7746
+ subscription_id: stringType(),
7747
+ subscription_period_count: numberType(),
7748
+ subscription_period_interval: enumType(["Day", "Week", "Month", "Year"]),
7749
+ tax_inclusive: booleanType(),
7750
+ trial_period_days: numberType()
7751
+ });
7752
+ var RefundSchema = objectType({
7753
+ payload_type: literalType("Refund"),
7754
+ amount: numberType(),
7755
+ business_id: stringType(),
7756
+ created_at: stringType().transform((d) => new Date(d)),
7757
+ currency: stringType(),
7758
+ is_partial: booleanType(),
7759
+ payment_id: stringType(),
7760
+ reason: stringType().nullable(),
7761
+ refund_id: stringType(),
7762
+ status: enumType(["succeeded", "failed", "pending"])
7763
+ });
7764
+ var DisputeSchema = objectType({
7765
+ payload_type: literalType("Dispute"),
7766
+ amount: stringType(),
7767
+ business_id: stringType(),
7768
+ created_at: stringType().transform((d) => new Date(d)),
7769
+ currency: stringType(),
7770
+ dispute_id: stringType(),
7771
+ dispute_stage: enumType([
7772
+ "pre_dispute",
7773
+ "dispute_opened",
7774
+ "dispute_won",
7775
+ "dispute_lost"
7776
+ ]),
7777
+ dispute_status: enumType([
7778
+ "dispute_opened",
7779
+ "dispute_won",
7780
+ "dispute_lost",
7781
+ "dispute_accepted",
7782
+ "dispute_cancelled",
7783
+ "dispute_challenged"
7784
+ ]),
7785
+ payment_id: stringType(),
7786
+ remarks: stringType().nullable()
7787
+ });
7788
+ var LicenseKeySchema = objectType({
7789
+ payload_type: literalType("LicenseKey"),
7790
+ activations_limit: numberType(),
7791
+ business_id: stringType(),
7792
+ created_at: stringType().transform((d) => new Date(d)),
7793
+ customer_id: stringType(),
7794
+ expires_at: stringType().transform((d) => new Date(d)).nullable(),
7795
+ id: stringType(),
7796
+ instances_count: numberType(),
7797
+ key: stringType(),
7798
+ payment_id: stringType(),
7799
+ product_id: stringType(),
7800
+ status: enumType(["active", "inactive", "expired"]),
7801
+ subscription_id: stringType().nullable()
7907
7802
  });
7908
7803
  var PaymentSucceededPayloadSchema = objectType({
7909
- business_id: stringType(),
7910
- type: literalType("payment.succeeded"),
7911
- timestamp: stringType().transform(function (d) { return new Date(d); }),
7912
- data: PaymentSchema,
7804
+ business_id: stringType(),
7805
+ type: literalType("payment.succeeded"),
7806
+ timestamp: stringType().transform((d) => new Date(d)),
7807
+ data: PaymentSchema
7913
7808
  });
7914
7809
  var PaymentFailedPayloadSchema = objectType({
7915
- business_id: stringType(),
7916
- type: literalType("payment.failed"),
7917
- timestamp: stringType().transform(function (d) { return new Date(d); }),
7918
- data: PaymentSchema,
7810
+ business_id: stringType(),
7811
+ type: literalType("payment.failed"),
7812
+ timestamp: stringType().transform((d) => new Date(d)),
7813
+ data: PaymentSchema
7919
7814
  });
7920
7815
  var PaymentProcessingPayloadSchema = objectType({
7921
- business_id: stringType(),
7922
- type: literalType("payment.processing"),
7923
- timestamp: stringType().transform(function (d) { return new Date(d); }),
7924
- data: PaymentSchema,
7816
+ business_id: stringType(),
7817
+ type: literalType("payment.processing"),
7818
+ timestamp: stringType().transform((d) => new Date(d)),
7819
+ data: PaymentSchema
7925
7820
  });
7926
7821
  var PaymentCancelledPayloadSchema = objectType({
7927
- business_id: stringType(),
7928
- type: literalType("payment.cancelled"),
7929
- timestamp: stringType().transform(function (d) { return new Date(d); }),
7930
- data: PaymentSchema,
7822
+ business_id: stringType(),
7823
+ type: literalType("payment.cancelled"),
7824
+ timestamp: stringType().transform((d) => new Date(d)),
7825
+ data: PaymentSchema
7931
7826
  });
7932
7827
  var RefundSucceededPayloadSchema = objectType({
7933
- business_id: stringType(),
7934
- type: literalType("refund.succeeded"),
7935
- timestamp: stringType().transform(function (d) { return new Date(d); }),
7936
- data: RefundSchema,
7828
+ business_id: stringType(),
7829
+ type: literalType("refund.succeeded"),
7830
+ timestamp: stringType().transform((d) => new Date(d)),
7831
+ data: RefundSchema
7937
7832
  });
7938
7833
  var RefundFailedPayloadSchema = objectType({
7939
- business_id: stringType(),
7940
- type: literalType("refund.failed"),
7941
- timestamp: stringType().transform(function (d) { return new Date(d); }),
7942
- data: RefundSchema,
7834
+ business_id: stringType(),
7835
+ type: literalType("refund.failed"),
7836
+ timestamp: stringType().transform((d) => new Date(d)),
7837
+ data: RefundSchema
7943
7838
  });
7944
7839
  var DisputeOpenedPayloadSchema = objectType({
7945
- business_id: stringType(),
7946
- type: literalType("dispute.opened"),
7947
- timestamp: stringType().transform(function (d) { return new Date(d); }),
7948
- data: DisputeSchema,
7840
+ business_id: stringType(),
7841
+ type: literalType("dispute.opened"),
7842
+ timestamp: stringType().transform((d) => new Date(d)),
7843
+ data: DisputeSchema
7949
7844
  });
7950
7845
  var DisputeExpiredPayloadSchema = objectType({
7951
- business_id: stringType(),
7952
- type: literalType("dispute.expired"),
7953
- timestamp: stringType().transform(function (d) { return new Date(d); }),
7954
- data: DisputeSchema,
7846
+ business_id: stringType(),
7847
+ type: literalType("dispute.expired"),
7848
+ timestamp: stringType().transform((d) => new Date(d)),
7849
+ data: DisputeSchema
7955
7850
  });
7956
7851
  var DisputeAcceptedPayloadSchema = objectType({
7957
- business_id: stringType(),
7958
- type: literalType("dispute.accepted"),
7959
- timestamp: stringType().transform(function (d) { return new Date(d); }),
7960
- data: DisputeSchema,
7852
+ business_id: stringType(),
7853
+ type: literalType("dispute.accepted"),
7854
+ timestamp: stringType().transform((d) => new Date(d)),
7855
+ data: DisputeSchema
7961
7856
  });
7962
7857
  var DisputeCancelledPayloadSchema = objectType({
7963
- business_id: stringType(),
7964
- type: literalType("dispute.cancelled"),
7965
- timestamp: stringType().transform(function (d) { return new Date(d); }),
7966
- data: DisputeSchema,
7858
+ business_id: stringType(),
7859
+ type: literalType("dispute.cancelled"),
7860
+ timestamp: stringType().transform((d) => new Date(d)),
7861
+ data: DisputeSchema
7967
7862
  });
7968
7863
  var DisputeChallengedPayloadSchema = objectType({
7969
- business_id: stringType(),
7970
- type: literalType("dispute.challenged"),
7971
- timestamp: stringType().transform(function (d) { return new Date(d); }),
7972
- data: DisputeSchema,
7864
+ business_id: stringType(),
7865
+ type: literalType("dispute.challenged"),
7866
+ timestamp: stringType().transform((d) => new Date(d)),
7867
+ data: DisputeSchema
7973
7868
  });
7974
7869
  var DisputeWonPayloadSchema = objectType({
7975
- business_id: stringType(),
7976
- type: literalType("dispute.won"),
7977
- timestamp: stringType().transform(function (d) { return new Date(d); }),
7978
- data: DisputeSchema,
7870
+ business_id: stringType(),
7871
+ type: literalType("dispute.won"),
7872
+ timestamp: stringType().transform((d) => new Date(d)),
7873
+ data: DisputeSchema
7979
7874
  });
7980
7875
  var DisputeLostPayloadSchema = objectType({
7981
- business_id: stringType(),
7982
- type: literalType("dispute.lost"),
7983
- timestamp: stringType().transform(function (d) { return new Date(d); }),
7984
- data: DisputeSchema,
7876
+ business_id: stringType(),
7877
+ type: literalType("dispute.lost"),
7878
+ timestamp: stringType().transform((d) => new Date(d)),
7879
+ data: DisputeSchema
7985
7880
  });
7986
7881
  var SubscriptionActivePayloadSchema = objectType({
7987
- business_id: stringType(),
7988
- type: literalType("subscription.active"),
7989
- timestamp: stringType().transform(function (d) { return new Date(d); }),
7990
- data: SubscriptionSchema,
7882
+ business_id: stringType(),
7883
+ type: literalType("subscription.active"),
7884
+ timestamp: stringType().transform((d) => new Date(d)),
7885
+ data: SubscriptionSchema
7991
7886
  });
7992
7887
  var SubscriptionOnHoldPayloadSchema = objectType({
7993
- business_id: stringType(),
7994
- type: literalType("subscription.on_hold"),
7995
- timestamp: stringType().transform(function (d) { return new Date(d); }),
7996
- data: SubscriptionSchema,
7888
+ business_id: stringType(),
7889
+ type: literalType("subscription.on_hold"),
7890
+ timestamp: stringType().transform((d) => new Date(d)),
7891
+ data: SubscriptionSchema
7997
7892
  });
7998
7893
  var SubscriptionRenewedPayloadSchema = objectType({
7999
- business_id: stringType(),
8000
- type: literalType("subscription.renewed"),
8001
- timestamp: stringType().transform(function (d) { return new Date(d); }),
8002
- data: SubscriptionSchema,
7894
+ business_id: stringType(),
7895
+ type: literalType("subscription.renewed"),
7896
+ timestamp: stringType().transform((d) => new Date(d)),
7897
+ data: SubscriptionSchema
8003
7898
  });
8004
7899
  var SubscriptionPausedPayloadSchema = objectType({
8005
- business_id: stringType(),
8006
- type: literalType("subscription.paused"),
8007
- timestamp: stringType().transform(function (d) { return new Date(d); }),
8008
- data: SubscriptionSchema,
7900
+ business_id: stringType(),
7901
+ type: literalType("subscription.paused"),
7902
+ timestamp: stringType().transform((d) => new Date(d)),
7903
+ data: SubscriptionSchema
8009
7904
  });
8010
7905
  var SubscriptionPlanChangedPayloadSchema = objectType({
8011
- business_id: stringType(),
8012
- type: literalType("subscription.plan_changed"),
8013
- timestamp: stringType().transform(function (d) { return new Date(d); }),
8014
- data: SubscriptionSchema,
7906
+ business_id: stringType(),
7907
+ type: literalType("subscription.plan_changed"),
7908
+ timestamp: stringType().transform((d) => new Date(d)),
7909
+ data: SubscriptionSchema
8015
7910
  });
8016
7911
  var SubscriptionCancelledPayloadSchema = objectType({
8017
- business_id: stringType(),
8018
- type: literalType("subscription.cancelled"),
8019
- timestamp: stringType().transform(function (d) { return new Date(d); }),
8020
- data: SubscriptionSchema,
7912
+ business_id: stringType(),
7913
+ type: literalType("subscription.cancelled"),
7914
+ timestamp: stringType().transform((d) => new Date(d)),
7915
+ data: SubscriptionSchema
8021
7916
  });
8022
7917
  var SubscriptionFailedPayloadSchema = objectType({
8023
- business_id: stringType(),
8024
- type: literalType("subscription.failed"),
8025
- timestamp: stringType().transform(function (d) { return new Date(d); }),
8026
- data: SubscriptionSchema,
7918
+ business_id: stringType(),
7919
+ type: literalType("subscription.failed"),
7920
+ timestamp: stringType().transform((d) => new Date(d)),
7921
+ data: SubscriptionSchema
8027
7922
  });
8028
7923
  var SubscriptionExpiredPayloadSchema = objectType({
8029
- business_id: stringType(),
8030
- type: literalType("subscription.expired"),
8031
- timestamp: stringType().transform(function (d) { return new Date(d); }),
8032
- data: SubscriptionSchema,
7924
+ business_id: stringType(),
7925
+ type: literalType("subscription.expired"),
7926
+ timestamp: stringType().transform((d) => new Date(d)),
7927
+ data: SubscriptionSchema
8033
7928
  });
8034
7929
  var LicenseKeyCreatedPayloadSchema = objectType({
8035
- business_id: stringType(),
8036
- type: literalType("license_key.created"),
8037
- timestamp: stringType().transform(function (d) { return new Date(d); }),
8038
- data: LicenseKeySchema,
7930
+ business_id: stringType(),
7931
+ type: literalType("license_key.created"),
7932
+ timestamp: stringType().transform((d) => new Date(d)),
7933
+ data: LicenseKeySchema
8039
7934
  });
8040
7935
  var WebhookPayloadSchema = discriminatedUnionType("type", [
8041
- PaymentSucceededPayloadSchema,
8042
- PaymentFailedPayloadSchema,
8043
- PaymentProcessingPayloadSchema,
8044
- PaymentCancelledPayloadSchema,
8045
- RefundSucceededPayloadSchema,
8046
- RefundFailedPayloadSchema,
8047
- DisputeOpenedPayloadSchema,
8048
- DisputeExpiredPayloadSchema,
8049
- DisputeAcceptedPayloadSchema,
8050
- DisputeCancelledPayloadSchema,
8051
- DisputeChallengedPayloadSchema,
8052
- DisputeWonPayloadSchema,
8053
- DisputeLostPayloadSchema,
8054
- SubscriptionActivePayloadSchema,
8055
- SubscriptionOnHoldPayloadSchema,
8056
- SubscriptionRenewedPayloadSchema,
8057
- SubscriptionPausedPayloadSchema,
8058
- SubscriptionPlanChangedPayloadSchema,
8059
- SubscriptionCancelledPayloadSchema,
8060
- SubscriptionFailedPayloadSchema,
8061
- SubscriptionExpiredPayloadSchema,
8062
- LicenseKeyCreatedPayloadSchema,
7936
+ PaymentSucceededPayloadSchema,
7937
+ PaymentFailedPayloadSchema,
7938
+ PaymentProcessingPayloadSchema,
7939
+ PaymentCancelledPayloadSchema,
7940
+ RefundSucceededPayloadSchema,
7941
+ RefundFailedPayloadSchema,
7942
+ DisputeOpenedPayloadSchema,
7943
+ DisputeExpiredPayloadSchema,
7944
+ DisputeAcceptedPayloadSchema,
7945
+ DisputeCancelledPayloadSchema,
7946
+ DisputeChallengedPayloadSchema,
7947
+ DisputeWonPayloadSchema,
7948
+ DisputeLostPayloadSchema,
7949
+ SubscriptionActivePayloadSchema,
7950
+ SubscriptionOnHoldPayloadSchema,
7951
+ SubscriptionRenewedPayloadSchema,
7952
+ SubscriptionPausedPayloadSchema,
7953
+ SubscriptionPlanChangedPayloadSchema,
7954
+ SubscriptionCancelledPayloadSchema,
7955
+ SubscriptionFailedPayloadSchema,
7956
+ SubscriptionExpiredPayloadSchema,
7957
+ LicenseKeyCreatedPayloadSchema
8063
7958
  ]);
8064
7959
 
8065
- var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
8066
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
8067
- return new (P || (P = Promise))(function (resolve, reject) {
8068
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8069
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8070
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8071
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8072
- });
8073
- };
8074
- var __generator = (undefined && undefined.__generator) || function (thisArg, body) {
8075
- 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);
8076
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
8077
- function verb(n) { return function (v) { return step([n, v]); }; }
8078
- function step(op) {
8079
- if (f) throw new TypeError("Generator is already executing.");
8080
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
8081
- 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;
8082
- if (y = 0, t) op = [op[0] & 2, t.value];
8083
- switch (op[0]) {
8084
- case 0: case 1: t = op; break;
8085
- case 4: _.label++; return { value: op[1], done: false };
8086
- case 5: _.label++; y = op[1]; op = [0]; continue;
8087
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
8088
- default:
8089
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
8090
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
8091
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
8092
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
8093
- if (t[2]) _.ops.pop();
8094
- _.trys.pop(); continue;
8095
- }
8096
- op = body.call(thisArg, _);
8097
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
8098
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
8099
- }
8100
- };
8101
- // Implementation
8102
- function handleWebhookPayload(payload, config, context) {
8103
- return __awaiter(this, void 0, void 0, function () {
8104
- var callHandler;
8105
- return __generator(this, function (_a) {
8106
- switch (_a.label) {
8107
- case 0:
8108
- callHandler = function (handler, payload) {
8109
- if (!handler)
8110
- return;
8111
- return handler(payload);
8112
- };
8113
- if (!config.onPayload) return [3 /*break*/, 2];
8114
- return [4 /*yield*/, callHandler(config.onPayload, payload)];
8115
- case 1:
8116
- _a.sent();
8117
- _a.label = 2;
8118
- case 2:
8119
- if (!(payload.type === "payment.succeeded")) return [3 /*break*/, 4];
8120
- return [4 /*yield*/, callHandler(config.onPaymentSucceeded, payload)];
8121
- case 3:
8122
- _a.sent();
8123
- _a.label = 4;
8124
- case 4:
8125
- if (!(payload.type === "payment.failed")) return [3 /*break*/, 6];
8126
- return [4 /*yield*/, callHandler(config.onPaymentFailed, payload)];
8127
- case 5:
8128
- _a.sent();
8129
- _a.label = 6;
8130
- case 6:
8131
- if (!(payload.type === "payment.processing")) return [3 /*break*/, 8];
8132
- return [4 /*yield*/, callHandler(config.onPaymentProcessing, payload)];
8133
- case 7:
8134
- _a.sent();
8135
- _a.label = 8;
8136
- case 8:
8137
- if (!(payload.type === "payment.cancelled")) return [3 /*break*/, 10];
8138
- return [4 /*yield*/, callHandler(config.onPaymentCancelled, payload)];
8139
- case 9:
8140
- _a.sent();
8141
- _a.label = 10;
8142
- case 10:
8143
- if (!(payload.type === "refund.succeeded")) return [3 /*break*/, 12];
8144
- return [4 /*yield*/, callHandler(config.onRefundSucceeded, payload)];
8145
- case 11:
8146
- _a.sent();
8147
- _a.label = 12;
8148
- case 12:
8149
- if (!(payload.type === "refund.failed")) return [3 /*break*/, 14];
8150
- return [4 /*yield*/, callHandler(config.onRefundFailed, payload)];
8151
- case 13:
8152
- _a.sent();
8153
- _a.label = 14;
8154
- case 14:
8155
- if (!(payload.type === "dispute.opened")) return [3 /*break*/, 16];
8156
- return [4 /*yield*/, callHandler(config.onDisputeOpened, payload)];
8157
- case 15:
8158
- _a.sent();
8159
- _a.label = 16;
8160
- case 16:
8161
- if (!(payload.type === "dispute.expired")) return [3 /*break*/, 18];
8162
- return [4 /*yield*/, callHandler(config.onDisputeExpired, payload)];
8163
- case 17:
8164
- _a.sent();
8165
- _a.label = 18;
8166
- case 18:
8167
- if (!(payload.type === "dispute.accepted")) return [3 /*break*/, 20];
8168
- return [4 /*yield*/, callHandler(config.onDisputeAccepted, payload)];
8169
- case 19:
8170
- _a.sent();
8171
- _a.label = 20;
8172
- case 20:
8173
- if (!(payload.type === "dispute.cancelled")) return [3 /*break*/, 22];
8174
- return [4 /*yield*/, callHandler(config.onDisputeCancelled, payload)];
8175
- case 21:
8176
- _a.sent();
8177
- _a.label = 22;
8178
- case 22:
8179
- if (!(payload.type === "dispute.challenged")) return [3 /*break*/, 24];
8180
- return [4 /*yield*/, callHandler(config.onDisputeChallenged, payload)];
8181
- case 23:
8182
- _a.sent();
8183
- _a.label = 24;
8184
- case 24:
8185
- if (!(payload.type === "dispute.won")) return [3 /*break*/, 26];
8186
- return [4 /*yield*/, callHandler(config.onDisputeWon, payload)];
8187
- case 25:
8188
- _a.sent();
8189
- _a.label = 26;
8190
- case 26:
8191
- if (!(payload.type === "dispute.lost")) return [3 /*break*/, 28];
8192
- return [4 /*yield*/, callHandler(config.onDisputeLost, payload)];
8193
- case 27:
8194
- _a.sent();
8195
- _a.label = 28;
8196
- case 28:
8197
- if (!(payload.type === "subscription.active")) return [3 /*break*/, 30];
8198
- return [4 /*yield*/, callHandler(config.onSubscriptionActive, payload)];
8199
- case 29:
8200
- _a.sent();
8201
- _a.label = 30;
8202
- case 30:
8203
- if (!(payload.type === "subscription.on_hold")) return [3 /*break*/, 32];
8204
- return [4 /*yield*/, callHandler(config.onSubscriptionOnHold, payload)];
8205
- case 31:
8206
- _a.sent();
8207
- _a.label = 32;
8208
- case 32:
8209
- if (!(payload.type === "subscription.renewed")) return [3 /*break*/, 34];
8210
- return [4 /*yield*/, callHandler(config.onSubscriptionRenewed, payload)];
8211
- case 33:
8212
- _a.sent();
8213
- _a.label = 34;
8214
- case 34:
8215
- if (!(payload.type === "subscription.paused")) return [3 /*break*/, 36];
8216
- return [4 /*yield*/, callHandler(config.onSubscriptionPaused, payload)];
8217
- case 35:
8218
- _a.sent();
8219
- _a.label = 36;
8220
- case 36:
8221
- if (!(payload.type === "subscription.plan_changed")) return [3 /*break*/, 38];
8222
- return [4 /*yield*/, callHandler(config.onSubscriptionPlanChanged, payload)];
8223
- case 37:
8224
- _a.sent();
8225
- _a.label = 38;
8226
- case 38:
8227
- if (!(payload.type === "subscription.cancelled")) return [3 /*break*/, 40];
8228
- return [4 /*yield*/, callHandler(config.onSubscriptionCancelled, payload)];
8229
- case 39:
8230
- _a.sent();
8231
- _a.label = 40;
8232
- case 40:
8233
- if (!(payload.type === "subscription.failed")) return [3 /*break*/, 42];
8234
- return [4 /*yield*/, callHandler(config.onSubscriptionFailed, payload)];
8235
- case 41:
8236
- _a.sent();
8237
- _a.label = 42;
8238
- case 42:
8239
- if (!(payload.type === "subscription.expired")) return [3 /*break*/, 44];
8240
- return [4 /*yield*/, callHandler(config.onSubscriptionExpired, payload)];
8241
- case 43:
8242
- _a.sent();
8243
- _a.label = 44;
8244
- case 44:
8245
- if (!(payload.type === "license_key.created")) return [3 /*break*/, 46];
8246
- return [4 /*yield*/, callHandler(config.onLicenseKeyCreated, payload)];
8247
- case 45:
8248
- _a.sent();
8249
- _a.label = 46;
8250
- case 46: return [2 /*return*/];
8251
- }
8252
- });
8253
- });
7960
+ async function handleWebhookPayload(payload, config, context) {
7961
+ const callHandler = (handler, payload2) => {
7962
+ if (!handler) return;
7963
+ return handler(payload2);
7964
+ };
7965
+ if (config.onPayload) {
7966
+ await callHandler(config.onPayload, payload);
7967
+ }
7968
+ if (payload.type === "payment.succeeded") {
7969
+ await callHandler(config.onPaymentSucceeded, payload);
7970
+ }
7971
+ if (payload.type === "payment.failed") {
7972
+ await callHandler(config.onPaymentFailed, payload);
7973
+ }
7974
+ if (payload.type === "payment.processing") {
7975
+ await callHandler(config.onPaymentProcessing, payload);
7976
+ }
7977
+ if (payload.type === "payment.cancelled") {
7978
+ await callHandler(config.onPaymentCancelled, payload);
7979
+ }
7980
+ if (payload.type === "refund.succeeded") {
7981
+ await callHandler(config.onRefundSucceeded, payload);
7982
+ }
7983
+ if (payload.type === "refund.failed") {
7984
+ await callHandler(config.onRefundFailed, payload);
7985
+ }
7986
+ if (payload.type === "dispute.opened") {
7987
+ await callHandler(config.onDisputeOpened, payload);
7988
+ }
7989
+ if (payload.type === "dispute.expired") {
7990
+ await callHandler(config.onDisputeExpired, payload);
7991
+ }
7992
+ if (payload.type === "dispute.accepted") {
7993
+ await callHandler(config.onDisputeAccepted, payload);
7994
+ }
7995
+ if (payload.type === "dispute.cancelled") {
7996
+ await callHandler(config.onDisputeCancelled, payload);
7997
+ }
7998
+ if (payload.type === "dispute.challenged") {
7999
+ await callHandler(config.onDisputeChallenged, payload);
8000
+ }
8001
+ if (payload.type === "dispute.won") {
8002
+ await callHandler(config.onDisputeWon, payload);
8003
+ }
8004
+ if (payload.type === "dispute.lost") {
8005
+ await callHandler(config.onDisputeLost, payload);
8006
+ }
8007
+ if (payload.type === "subscription.active") {
8008
+ await callHandler(config.onSubscriptionActive, payload);
8009
+ }
8010
+ if (payload.type === "subscription.on_hold") {
8011
+ await callHandler(config.onSubscriptionOnHold, payload);
8012
+ }
8013
+ if (payload.type === "subscription.renewed") {
8014
+ await callHandler(config.onSubscriptionRenewed, payload);
8015
+ }
8016
+ if (payload.type === "subscription.paused") {
8017
+ await callHandler(config.onSubscriptionPaused, payload);
8018
+ }
8019
+ if (payload.type === "subscription.plan_changed") {
8020
+ await callHandler(config.onSubscriptionPlanChanged, payload);
8021
+ }
8022
+ if (payload.type === "subscription.cancelled") {
8023
+ await callHandler(config.onSubscriptionCancelled, payload);
8024
+ }
8025
+ if (payload.type === "subscription.failed") {
8026
+ await callHandler(config.onSubscriptionFailed, payload);
8027
+ }
8028
+ if (payload.type === "subscription.expired") {
8029
+ await callHandler(config.onSubscriptionExpired, payload);
8030
+ }
8031
+ if (payload.type === "license_key.created") {
8032
+ await callHandler(config.onLicenseKeyCreated, payload);
8033
+ }
8254
8034
  }
8255
8035
 
8256
8036
  const Webhooks = ({ webhookKey, ...eventHandlers }) => {