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