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