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