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