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