@dodopayments/nextjs 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 +765 -985
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +765 -985
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -11512,532 +11512,432 @@ DodoPayments.Webhooks = Webhooks$1;
|
|
|
11512
11512
|
DodoPayments.UsageEvents = UsageEvents;
|
|
11513
11513
|
DodoPayments.Meters = Meters;
|
|
11514
11514
|
|
|
11515
|
-
|
|
11516
|
-
__assign = Object.assign || function(t) {
|
|
11517
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
11518
|
-
s = arguments[i];
|
|
11519
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
11520
|
-
t[p] = s[p];
|
|
11521
|
-
}
|
|
11522
|
-
return t;
|
|
11523
|
-
};
|
|
11524
|
-
return __assign.apply(this, arguments);
|
|
11525
|
-
};
|
|
11526
|
-
var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
11527
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
11528
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11529
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11530
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11531
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
11532
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11533
|
-
});
|
|
11534
|
-
};
|
|
11535
|
-
var __generator$1 = (undefined && undefined.__generator) || function (thisArg, body) {
|
|
11536
|
-
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);
|
|
11537
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
11538
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
11539
|
-
function step(op) {
|
|
11540
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
11541
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
11542
|
-
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;
|
|
11543
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
11544
|
-
switch (op[0]) {
|
|
11545
|
-
case 0: case 1: t = op; break;
|
|
11546
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
11547
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
11548
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
11549
|
-
default:
|
|
11550
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
11551
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
11552
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
11553
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
11554
|
-
if (t[2]) _.ops.pop();
|
|
11555
|
-
_.trys.pop(); continue;
|
|
11556
|
-
}
|
|
11557
|
-
op = body.call(thisArg, _);
|
|
11558
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
11559
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
11560
|
-
}
|
|
11561
|
-
};
|
|
11515
|
+
// src/checkout/checkout.ts
|
|
11562
11516
|
var checkoutQuerySchema = objectType({
|
|
11563
|
-
|
|
11564
|
-
|
|
11565
|
-
|
|
11566
|
-
|
|
11567
|
-
|
|
11568
|
-
|
|
11569
|
-
|
|
11570
|
-
|
|
11571
|
-
|
|
11572
|
-
|
|
11573
|
-
|
|
11574
|
-
|
|
11575
|
-
|
|
11576
|
-
|
|
11577
|
-
|
|
11578
|
-
|
|
11579
|
-
|
|
11580
|
-
|
|
11581
|
-
|
|
11582
|
-
|
|
11583
|
-
|
|
11584
|
-
|
|
11585
|
-
|
|
11586
|
-
|
|
11587
|
-
|
|
11588
|
-
|
|
11589
|
-
|
|
11590
|
-
|
|
11591
|
-
|
|
11592
|
-
})
|
|
11593
|
-
.catchall(unknownType());
|
|
11594
|
-
// Add Zod schema for dynamic checkout body
|
|
11517
|
+
productId: stringType(),
|
|
11518
|
+
quantity: stringType().optional(),
|
|
11519
|
+
// Customer fields
|
|
11520
|
+
fullName: stringType().optional(),
|
|
11521
|
+
firstName: stringType().optional(),
|
|
11522
|
+
lastName: stringType().optional(),
|
|
11523
|
+
email: stringType().optional(),
|
|
11524
|
+
country: stringType().optional(),
|
|
11525
|
+
addressLine: stringType().optional(),
|
|
11526
|
+
city: stringType().optional(),
|
|
11527
|
+
state: stringType().optional(),
|
|
11528
|
+
zipCode: stringType().optional(),
|
|
11529
|
+
// Disable flags
|
|
11530
|
+
disableFullName: stringType().optional(),
|
|
11531
|
+
disableFirstName: stringType().optional(),
|
|
11532
|
+
disableLastName: stringType().optional(),
|
|
11533
|
+
disableEmail: stringType().optional(),
|
|
11534
|
+
disableCountry: stringType().optional(),
|
|
11535
|
+
disableAddressLine: stringType().optional(),
|
|
11536
|
+
disableCity: stringType().optional(),
|
|
11537
|
+
disableState: stringType().optional(),
|
|
11538
|
+
disableZipCode: stringType().optional(),
|
|
11539
|
+
// Advanced controls
|
|
11540
|
+
paymentCurrency: stringType().optional(),
|
|
11541
|
+
showCurrencySelector: stringType().optional(),
|
|
11542
|
+
paymentAmount: stringType().optional(),
|
|
11543
|
+
showDiscounts: stringType().optional()
|
|
11544
|
+
// Metadata (allow any key starting with metadata_)
|
|
11545
|
+
// We'll handle metadata separately in the handler
|
|
11546
|
+
}).catchall(unknownType());
|
|
11595
11547
|
var dynamicCheckoutBodySchema = objectType({
|
|
11596
|
-
|
|
11597
|
-
|
|
11598
|
-
|
|
11599
|
-
|
|
11600
|
-
|
|
11601
|
-
|
|
11602
|
-
|
|
11603
|
-
|
|
11604
|
-
|
|
11605
|
-
|
|
11606
|
-
|
|
11607
|
-
|
|
11608
|
-
|
|
11609
|
-
|
|
11610
|
-
|
|
11611
|
-
|
|
11612
|
-
|
|
11613
|
-
|
|
11614
|
-
|
|
11615
|
-
|
|
11616
|
-
|
|
11617
|
-
|
|
11618
|
-
|
|
11619
|
-
|
|
11620
|
-
|
|
11621
|
-
|
|
11622
|
-
|
|
11623
|
-
|
|
11624
|
-
|
|
11625
|
-
|
|
11626
|
-
|
|
11627
|
-
|
|
11628
|
-
|
|
11629
|
-
|
|
11630
|
-
// CHECKOUT SESSIONS SCHEMAS & TYPES
|
|
11631
|
-
// ========================================
|
|
11632
|
-
// Product cart item schema for checkout sessions
|
|
11548
|
+
// For subscription
|
|
11549
|
+
product_id: stringType().optional(),
|
|
11550
|
+
quantity: numberType().optional(),
|
|
11551
|
+
// For one-time payment
|
|
11552
|
+
product_cart: arrayType(
|
|
11553
|
+
objectType({
|
|
11554
|
+
product_id: stringType(),
|
|
11555
|
+
quantity: numberType()
|
|
11556
|
+
})
|
|
11557
|
+
).optional(),
|
|
11558
|
+
// Common fields
|
|
11559
|
+
billing: objectType({
|
|
11560
|
+
city: stringType(),
|
|
11561
|
+
country: stringType(),
|
|
11562
|
+
state: stringType(),
|
|
11563
|
+
street: stringType(),
|
|
11564
|
+
zipcode: stringType()
|
|
11565
|
+
}),
|
|
11566
|
+
customer: objectType({
|
|
11567
|
+
customer_id: stringType().optional(),
|
|
11568
|
+
email: stringType().optional(),
|
|
11569
|
+
name: stringType().optional()
|
|
11570
|
+
}),
|
|
11571
|
+
discount_id: stringType().optional(),
|
|
11572
|
+
addons: arrayType(
|
|
11573
|
+
objectType({
|
|
11574
|
+
addon_id: stringType(),
|
|
11575
|
+
quantity: numberType()
|
|
11576
|
+
})
|
|
11577
|
+
).optional(),
|
|
11578
|
+
metadata: recordType(stringType(), stringType()).optional(),
|
|
11579
|
+
currency: stringType().optional()
|
|
11580
|
+
// Allow any additional fields (for future compatibility)
|
|
11581
|
+
}).catchall(unknownType());
|
|
11633
11582
|
var checkoutSessionProductCartItemSchema = objectType({
|
|
11634
|
-
|
|
11635
|
-
|
|
11583
|
+
product_id: stringType().min(1, "Product ID is required"),
|
|
11584
|
+
quantity: numberType().int().positive("Quantity must be a positive integer")
|
|
11636
11585
|
});
|
|
11637
|
-
// Customer information schema for checkout sessions
|
|
11638
11586
|
var checkoutSessionCustomerSchema = objectType({
|
|
11639
|
-
|
|
11640
|
-
|
|
11641
|
-
|
|
11642
|
-
})
|
|
11643
|
-
.optional();
|
|
11644
|
-
// Billing address schema for checkout sessions
|
|
11587
|
+
email: stringType().email().optional(),
|
|
11588
|
+
name: stringType().min(1).optional(),
|
|
11589
|
+
phone_number: stringType().optional()
|
|
11590
|
+
}).optional();
|
|
11645
11591
|
var checkoutSessionBillingAddressSchema = objectType({
|
|
11646
|
-
|
|
11647
|
-
|
|
11648
|
-
|
|
11649
|
-
|
|
11650
|
-
|
|
11651
|
-
})
|
|
11652
|
-
.optional();
|
|
11653
|
-
// Payment method types enum based on Dodo Payments documentation
|
|
11592
|
+
street: stringType().optional(),
|
|
11593
|
+
city: stringType().optional(),
|
|
11594
|
+
state: stringType().optional(),
|
|
11595
|
+
country: stringType().length(2, "Country must be a 2-letter ISO code"),
|
|
11596
|
+
zipcode: stringType().optional()
|
|
11597
|
+
}).optional();
|
|
11654
11598
|
var paymentMethodTypeSchema = enumType([
|
|
11655
|
-
|
|
11656
|
-
|
|
11657
|
-
|
|
11658
|
-
|
|
11659
|
-
|
|
11660
|
-
|
|
11661
|
-
|
|
11662
|
-
|
|
11663
|
-
|
|
11664
|
-
|
|
11665
|
-
|
|
11666
|
-
|
|
11599
|
+
"credit",
|
|
11600
|
+
"debit",
|
|
11601
|
+
"upi_collect",
|
|
11602
|
+
"upi_intent",
|
|
11603
|
+
"apple_pay",
|
|
11604
|
+
"google_pay",
|
|
11605
|
+
"amazon_pay",
|
|
11606
|
+
"klarna",
|
|
11607
|
+
"affirm",
|
|
11608
|
+
"afterpay_clearpay",
|
|
11609
|
+
"sepa",
|
|
11610
|
+
"ach"
|
|
11667
11611
|
]);
|
|
11668
|
-
// Customization options schema
|
|
11669
11612
|
var checkoutSessionCustomizationSchema = objectType({
|
|
11670
|
-
|
|
11671
|
-
|
|
11672
|
-
|
|
11673
|
-
})
|
|
11674
|
-
.optional();
|
|
11675
|
-
// Feature flags schema
|
|
11613
|
+
theme: enumType(["light", "dark", "system"]).optional(),
|
|
11614
|
+
show_order_details: booleanType().optional(),
|
|
11615
|
+
show_on_demand_tag: booleanType().optional()
|
|
11616
|
+
}).optional();
|
|
11676
11617
|
var checkoutSessionFeatureFlagsSchema = objectType({
|
|
11677
|
-
|
|
11678
|
-
|
|
11679
|
-
|
|
11680
|
-
|
|
11681
|
-
|
|
11682
|
-
})
|
|
11683
|
-
.optional();
|
|
11684
|
-
// Subscription data schema
|
|
11618
|
+
allow_currency_selection: booleanType().optional(),
|
|
11619
|
+
allow_discount_code: booleanType().optional(),
|
|
11620
|
+
allow_phone_number_collection: booleanType().optional(),
|
|
11621
|
+
allow_tax_id: booleanType().optional(),
|
|
11622
|
+
always_create_new_customer: booleanType().optional()
|
|
11623
|
+
}).optional();
|
|
11685
11624
|
var checkoutSessionSubscriptionDataSchema = objectType({
|
|
11686
|
-
|
|
11687
|
-
})
|
|
11688
|
-
.optional();
|
|
11689
|
-
// Main checkout session payload schema
|
|
11625
|
+
trial_period_days: numberType().int().nonnegative().optional()
|
|
11626
|
+
}).optional();
|
|
11690
11627
|
var checkoutSessionPayloadSchema = objectType({
|
|
11691
|
-
|
|
11692
|
-
|
|
11693
|
-
|
|
11694
|
-
|
|
11695
|
-
|
|
11696
|
-
|
|
11697
|
-
|
|
11698
|
-
|
|
11699
|
-
|
|
11700
|
-
|
|
11701
|
-
|
|
11702
|
-
|
|
11703
|
-
|
|
11704
|
-
|
|
11705
|
-
|
|
11706
|
-
customization: checkoutSessionCustomizationSchema,
|
|
11707
|
-
feature_flags: checkoutSessionFeatureFlagsSchema,
|
|
11708
|
-
subscription_data: checkoutSessionSubscriptionDataSchema,
|
|
11628
|
+
// Required fields
|
|
11629
|
+
product_cart: arrayType(checkoutSessionProductCartItemSchema).min(1, "At least one product is required"),
|
|
11630
|
+
// Optional fields
|
|
11631
|
+
customer: checkoutSessionCustomerSchema,
|
|
11632
|
+
billing_address: checkoutSessionBillingAddressSchema,
|
|
11633
|
+
return_url: stringType().url().optional(),
|
|
11634
|
+
allowed_payment_method_types: arrayType(paymentMethodTypeSchema).optional(),
|
|
11635
|
+
billing_currency: stringType().length(3, "Currency must be a 3-letter ISO code").optional(),
|
|
11636
|
+
show_saved_payment_methods: booleanType().optional(),
|
|
11637
|
+
confirm: booleanType().optional(),
|
|
11638
|
+
discount_code: stringType().optional(),
|
|
11639
|
+
metadata: recordType(stringType(), stringType()).optional(),
|
|
11640
|
+
customization: checkoutSessionCustomizationSchema,
|
|
11641
|
+
feature_flags: checkoutSessionFeatureFlagsSchema,
|
|
11642
|
+
subscription_data: checkoutSessionSubscriptionDataSchema
|
|
11709
11643
|
});
|
|
11710
|
-
// Checkout session response schema
|
|
11711
11644
|
var checkoutSessionResponseSchema = objectType({
|
|
11712
|
-
|
|
11713
|
-
|
|
11645
|
+
session_id: stringType().min(1, "Session ID is required"),
|
|
11646
|
+
checkout_url: stringType().url("Invalid checkout URL")
|
|
11714
11647
|
});
|
|
11715
|
-
|
|
11716
|
-
|
|
11717
|
-
|
|
11718
|
-
|
|
11719
|
-
|
|
11720
|
-
|
|
11721
|
-
|
|
11722
|
-
|
|
11723
|
-
|
|
11724
|
-
|
|
11725
|
-
|
|
11726
|
-
|
|
11727
|
-
|
|
11728
|
-
|
|
11729
|
-
|
|
11730
|
-
|
|
11731
|
-
|
|
11732
|
-
|
|
11733
|
-
* environment: 'test_mode'
|
|
11734
|
-
* });
|
|
11735
|
-
*
|
|
11736
|
-
* ```
|
|
11737
|
-
*/
|
|
11738
|
-
var createCheckoutSession = function (payload, config) { return __awaiter$1(void 0, void 0, void 0, function () {
|
|
11739
|
-
var validation, dodopayments, sdkPayload, session, responseValidation, error_1;
|
|
11740
|
-
return __generator$1(this, function (_a) {
|
|
11741
|
-
switch (_a.label) {
|
|
11742
|
-
case 0:
|
|
11743
|
-
validation = checkoutSessionPayloadSchema.safeParse(payload);
|
|
11744
|
-
if (!validation.success) {
|
|
11745
|
-
throw new Error("Invalid checkout session payload: ".concat(validation.error.issues
|
|
11746
|
-
.map(function (issue) { return "".concat(issue.path.join("."), ": ").concat(issue.message); })
|
|
11747
|
-
.join(", ")));
|
|
11748
|
-
}
|
|
11749
|
-
dodopayments = new DodoPayments({
|
|
11750
|
-
bearerToken: config.bearerToken,
|
|
11751
|
-
environment: config.environment,
|
|
11752
|
-
});
|
|
11753
|
-
_a.label = 1;
|
|
11754
|
-
case 1:
|
|
11755
|
-
_a.trys.push([1, 3, , 4]);
|
|
11756
|
-
sdkPayload = __assign(__assign({}, validation.data), (validation.data.billing_address && {
|
|
11757
|
-
billing_address: __assign(__assign({}, validation.data.billing_address), { country: validation.data.billing_address.country }),
|
|
11758
|
-
}));
|
|
11759
|
-
return [4 /*yield*/, dodopayments.checkoutSessions.create(sdkPayload)];
|
|
11760
|
-
case 2:
|
|
11761
|
-
session = _a.sent();
|
|
11762
|
-
responseValidation = checkoutSessionResponseSchema.safeParse(session);
|
|
11763
|
-
if (!responseValidation.success) {
|
|
11764
|
-
throw new Error("Invalid checkout session response from API: ".concat(responseValidation.error.issues
|
|
11765
|
-
.map(function (issue) { return "".concat(issue.path.join("."), ": ").concat(issue.message); })
|
|
11766
|
-
.join(", ")));
|
|
11767
|
-
}
|
|
11768
|
-
return [2 /*return*/, responseValidation.data];
|
|
11769
|
-
case 3:
|
|
11770
|
-
error_1 = _a.sent();
|
|
11771
|
-
if (error_1 instanceof Error) {
|
|
11772
|
-
console.error("Dodo Payments Checkout Session API Error:", {
|
|
11773
|
-
message: error_1.message,
|
|
11774
|
-
payload: validation.data,
|
|
11775
|
-
config: {
|
|
11776
|
-
environment: config.environment,
|
|
11777
|
-
hasBearerToken: !!config.bearerToken,
|
|
11778
|
-
},
|
|
11779
|
-
});
|
|
11780
|
-
// Re-throw with a more user-friendly message
|
|
11781
|
-
throw new Error("Failed to create checkout session: ".concat(error_1.message));
|
|
11782
|
-
}
|
|
11783
|
-
// Handle non-Error objects
|
|
11784
|
-
console.error("Unknown error creating checkout session:", error_1);
|
|
11785
|
-
throw new Error("Failed to create checkout session due to an unknown error");
|
|
11786
|
-
case 4: return [2 /*return*/];
|
|
11648
|
+
var createCheckoutSession = async (payload, config) => {
|
|
11649
|
+
const validation = checkoutSessionPayloadSchema.safeParse(payload);
|
|
11650
|
+
if (!validation.success) {
|
|
11651
|
+
throw new Error(
|
|
11652
|
+
`Invalid checkout session payload: ${validation.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join(", ")}`
|
|
11653
|
+
);
|
|
11654
|
+
}
|
|
11655
|
+
const dodopayments = new DodoPayments({
|
|
11656
|
+
bearerToken: config.bearerToken,
|
|
11657
|
+
environment: config.environment
|
|
11658
|
+
});
|
|
11659
|
+
try {
|
|
11660
|
+
const sdkPayload = {
|
|
11661
|
+
...validation.data,
|
|
11662
|
+
...validation.data.billing_address && {
|
|
11663
|
+
billing_address: {
|
|
11664
|
+
...validation.data.billing_address,
|
|
11665
|
+
country: validation.data.billing_address.country
|
|
11787
11666
|
}
|
|
11667
|
+
}
|
|
11668
|
+
};
|
|
11669
|
+
const session = await dodopayments.checkoutSessions.create(
|
|
11670
|
+
sdkPayload
|
|
11671
|
+
);
|
|
11672
|
+
const responseValidation = checkoutSessionResponseSchema.safeParse(session);
|
|
11673
|
+
if (!responseValidation.success) {
|
|
11674
|
+
throw new Error(
|
|
11675
|
+
`Invalid checkout session response from API: ${responseValidation.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join(", ")}`
|
|
11676
|
+
);
|
|
11677
|
+
}
|
|
11678
|
+
return responseValidation.data;
|
|
11679
|
+
} catch (error) {
|
|
11680
|
+
if (error instanceof Error) {
|
|
11681
|
+
console.error("Dodo Payments Checkout Session API Error:", {
|
|
11682
|
+
message: error.message,
|
|
11683
|
+
payload: validation.data,
|
|
11684
|
+
config: {
|
|
11685
|
+
environment: config.environment,
|
|
11686
|
+
hasBearerToken: !!config.bearerToken
|
|
11687
|
+
}
|
|
11688
|
+
});
|
|
11689
|
+
throw new Error(`Failed to create checkout session: ${error.message}`);
|
|
11690
|
+
}
|
|
11691
|
+
console.error("Unknown error creating checkout session:", error);
|
|
11692
|
+
throw new Error(
|
|
11693
|
+
"Failed to create checkout session due to an unknown error"
|
|
11694
|
+
);
|
|
11695
|
+
}
|
|
11696
|
+
};
|
|
11697
|
+
var buildCheckoutUrl = async ({
|
|
11698
|
+
queryParams,
|
|
11699
|
+
body,
|
|
11700
|
+
sessionPayload,
|
|
11701
|
+
returnUrl,
|
|
11702
|
+
bearerToken,
|
|
11703
|
+
environment,
|
|
11704
|
+
type = "static"
|
|
11705
|
+
}) => {
|
|
11706
|
+
if (type === "session") {
|
|
11707
|
+
if (!sessionPayload) {
|
|
11708
|
+
throw new Error("sessionPayload is required when type is 'session'");
|
|
11709
|
+
}
|
|
11710
|
+
const session = await createCheckoutSession(sessionPayload, {
|
|
11711
|
+
bearerToken,
|
|
11712
|
+
environment
|
|
11788
11713
|
});
|
|
11789
|
-
|
|
11790
|
-
|
|
11791
|
-
|
|
11792
|
-
|
|
11793
|
-
|
|
11794
|
-
|
|
11795
|
-
|
|
11796
|
-
|
|
11797
|
-
|
|
11798
|
-
|
|
11799
|
-
|
|
11800
|
-
|
|
11801
|
-
|
|
11802
|
-
|
|
11803
|
-
|
|
11804
|
-
|
|
11805
|
-
|
|
11806
|
-
|
|
11807
|
-
|
|
11808
|
-
|
|
11809
|
-
|
|
11810
|
-
|
|
11811
|
-
|
|
11812
|
-
|
|
11813
|
-
|
|
11814
|
-
|
|
11815
|
-
|
|
11816
|
-
|
|
11817
|
-
|
|
11818
|
-
|
|
11819
|
-
|
|
11820
|
-
|
|
11821
|
-
|
|
11822
|
-
|
|
11823
|
-
|
|
11824
|
-
|
|
11825
|
-
|
|
11826
|
-
|
|
11827
|
-
|
|
11828
|
-
|
|
11829
|
-
|
|
11830
|
-
|
|
11831
|
-
|
|
11832
|
-
|
|
11833
|
-
|
|
11834
|
-
|
|
11835
|
-
|
|
11836
|
-
err_1 = _g.sent();
|
|
11837
|
-
console.error(err_1);
|
|
11838
|
-
throw new Error("Product not found");
|
|
11839
|
-
case 6:
|
|
11840
|
-
url = new URL("".concat(environment === "test_mode" ? "https://test.checkout.dodopayments.com" : "https://checkout.dodopayments.com", "/buy/").concat(productId));
|
|
11841
|
-
url.searchParams.set("quantity", quantity_1 ? String(quantity_1) : "1");
|
|
11842
|
-
if (returnUrl)
|
|
11843
|
-
url.searchParams.set("redirect_url", returnUrl);
|
|
11844
|
-
// Customer/billing fields
|
|
11845
|
-
if (fullName)
|
|
11846
|
-
url.searchParams.set("fullName", String(fullName));
|
|
11847
|
-
if (firstName)
|
|
11848
|
-
url.searchParams.set("firstName", String(firstName));
|
|
11849
|
-
if (lastName)
|
|
11850
|
-
url.searchParams.set("lastName", String(lastName));
|
|
11851
|
-
if (email)
|
|
11852
|
-
url.searchParams.set("email", String(email));
|
|
11853
|
-
if (country)
|
|
11854
|
-
url.searchParams.set("country", String(country));
|
|
11855
|
-
if (addressLine)
|
|
11856
|
-
url.searchParams.set("addressLine", String(addressLine));
|
|
11857
|
-
if (city)
|
|
11858
|
-
url.searchParams.set("city", String(city));
|
|
11859
|
-
if (state)
|
|
11860
|
-
url.searchParams.set("state", String(state));
|
|
11861
|
-
if (zipCode)
|
|
11862
|
-
url.searchParams.set("zipCode", String(zipCode));
|
|
11863
|
-
// Disable flags (must be set to 'true' to disable)
|
|
11864
|
-
if (disableFullName === "true")
|
|
11865
|
-
url.searchParams.set("disableFullName", "true");
|
|
11866
|
-
if (disableFirstName === "true")
|
|
11867
|
-
url.searchParams.set("disableFirstName", "true");
|
|
11868
|
-
if (disableLastName === "true")
|
|
11869
|
-
url.searchParams.set("disableLastName", "true");
|
|
11870
|
-
if (disableEmail === "true")
|
|
11871
|
-
url.searchParams.set("disableEmail", "true");
|
|
11872
|
-
if (disableCountry === "true")
|
|
11873
|
-
url.searchParams.set("disableCountry", "true");
|
|
11874
|
-
if (disableAddressLine === "true")
|
|
11875
|
-
url.searchParams.set("disableAddressLine", "true");
|
|
11876
|
-
if (disableCity === "true")
|
|
11877
|
-
url.searchParams.set("disableCity", "true");
|
|
11878
|
-
if (disableState === "true")
|
|
11879
|
-
url.searchParams.set("disableState", "true");
|
|
11880
|
-
if (disableZipCode === "true")
|
|
11881
|
-
url.searchParams.set("disableZipCode", "true");
|
|
11882
|
-
// Advanced controls
|
|
11883
|
-
if (paymentCurrency)
|
|
11884
|
-
url.searchParams.set("paymentCurrency", String(paymentCurrency));
|
|
11885
|
-
if (showCurrencySelector)
|
|
11886
|
-
url.searchParams.set("showCurrencySelector", String(showCurrencySelector));
|
|
11887
|
-
if (paymentAmount)
|
|
11888
|
-
url.searchParams.set("paymentAmount", String(paymentAmount));
|
|
11889
|
-
if (showDiscounts)
|
|
11890
|
-
url.searchParams.set("showDiscounts", String(showDiscounts));
|
|
11891
|
-
// Metadata: add all query params starting with metadata_
|
|
11892
|
-
for (_i = 0, _d = Object.entries(queryParams || {}); _i < _d.length; _i++) {
|
|
11893
|
-
_e = _d[_i], key = _e[0], value = _e[1];
|
|
11894
|
-
if (key.startsWith("metadata_") && value && typeof value !== "object") {
|
|
11895
|
-
url.searchParams.set(key, String(value));
|
|
11896
|
-
}
|
|
11897
|
-
}
|
|
11898
|
-
return [2 /*return*/, url.toString()];
|
|
11899
|
-
case 7:
|
|
11900
|
-
dyn = data;
|
|
11901
|
-
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;
|
|
11902
|
-
dodopayments = new DodoPayments({
|
|
11903
|
-
bearerToken: bearerToken,
|
|
11904
|
-
environment: environment,
|
|
11905
|
-
});
|
|
11906
|
-
isSubscription = false;
|
|
11907
|
-
productIdToFetch = product_id;
|
|
11908
|
-
if (!product_id && product_cart && product_cart.length > 0) {
|
|
11909
|
-
productIdToFetch = product_cart[0].product_id;
|
|
11910
|
-
}
|
|
11911
|
-
if (!productIdToFetch)
|
|
11912
|
-
throw new Error("Missing required field: product_id or product_cart[0].product_id");
|
|
11913
|
-
_g.label = 8;
|
|
11914
|
-
case 8:
|
|
11915
|
-
_g.trys.push([8, 10, , 11]);
|
|
11916
|
-
return [4 /*yield*/, dodopayments.products.retrieve(productIdToFetch)];
|
|
11917
|
-
case 9:
|
|
11918
|
-
product = _g.sent();
|
|
11919
|
-
return [3 /*break*/, 11];
|
|
11920
|
-
case 10:
|
|
11921
|
-
err_2 = _g.sent();
|
|
11922
|
-
console.error(err_2);
|
|
11923
|
-
throw new Error("Product not found");
|
|
11924
|
-
case 11:
|
|
11925
|
-
isSubscription = Boolean(product.is_recurring);
|
|
11926
|
-
// Required field validation
|
|
11927
|
-
if (isSubscription && !product_id)
|
|
11928
|
-
throw new Error("Missing required field: product_id for subscription");
|
|
11929
|
-
if (!billing)
|
|
11930
|
-
throw new Error("Missing required field: billing");
|
|
11931
|
-
if (!customer)
|
|
11932
|
-
throw new Error("Missing required field: customer");
|
|
11933
|
-
if (!isSubscription) return [3 /*break*/, 16];
|
|
11934
|
-
subscriptionPayload = {
|
|
11935
|
-
billing: billing,
|
|
11936
|
-
customer: customer,
|
|
11937
|
-
product_id: product_id,
|
|
11938
|
-
quantity: quantity ? Number(quantity) : 1,
|
|
11939
|
-
};
|
|
11940
|
-
if (metadata)
|
|
11941
|
-
subscriptionPayload.metadata = metadata;
|
|
11942
|
-
if (discount_code)
|
|
11943
|
-
subscriptionPayload.discount_code = discount_code;
|
|
11944
|
-
if (addons)
|
|
11945
|
-
subscriptionPayload.addons = addons;
|
|
11946
|
-
if (allowed_payment_method_types)
|
|
11947
|
-
subscriptionPayload.allowed_payment_method_types =
|
|
11948
|
-
allowed_payment_method_types;
|
|
11949
|
-
if (billing_currency)
|
|
11950
|
-
subscriptionPayload.billing_currency = billing_currency;
|
|
11951
|
-
if (on_demand)
|
|
11952
|
-
subscriptionPayload.on_demand = on_demand;
|
|
11953
|
-
subscriptionPayload.payment_link = true;
|
|
11954
|
-
// Use bodyReturnUrl if present, otherwise use top-level returnUrl
|
|
11955
|
-
if (bodyReturnUrl) {
|
|
11956
|
-
subscriptionPayload.return_url = bodyReturnUrl;
|
|
11957
|
-
}
|
|
11958
|
-
else if (returnUrl) {
|
|
11959
|
-
subscriptionPayload.return_url = returnUrl;
|
|
11960
|
-
}
|
|
11961
|
-
if (show_saved_payment_methods)
|
|
11962
|
-
subscriptionPayload.show_saved_payment_methods =
|
|
11963
|
-
show_saved_payment_methods;
|
|
11964
|
-
if (tax_id)
|
|
11965
|
-
subscriptionPayload.tax_id = tax_id;
|
|
11966
|
-
if (trial_period_days)
|
|
11967
|
-
subscriptionPayload.trial_period_days = trial_period_days;
|
|
11968
|
-
subscription = void 0;
|
|
11969
|
-
_g.label = 12;
|
|
11970
|
-
case 12:
|
|
11971
|
-
_g.trys.push([12, 14, , 15]);
|
|
11972
|
-
return [4 /*yield*/, dodopayments.subscriptions.create(subscriptionPayload)];
|
|
11973
|
-
case 13:
|
|
11974
|
-
subscription =
|
|
11975
|
-
_g.sent();
|
|
11976
|
-
return [3 /*break*/, 15];
|
|
11977
|
-
case 14:
|
|
11978
|
-
err_3 = _g.sent();
|
|
11979
|
-
console.error("Error when creating subscription", err_3);
|
|
11980
|
-
throw new Error(err_3 instanceof Error ? err_3.message : String(err_3));
|
|
11981
|
-
case 15:
|
|
11982
|
-
if (!subscription || !subscription.payment_link) {
|
|
11983
|
-
throw new Error("No payment link returned from Dodo Payments API (subscription). Make sure to set payment_link as true in payload");
|
|
11984
|
-
}
|
|
11985
|
-
return [2 /*return*/, subscription.payment_link];
|
|
11986
|
-
case 16:
|
|
11987
|
-
cart = product_cart;
|
|
11988
|
-
if (!cart && product_id) {
|
|
11989
|
-
cart = [
|
|
11990
|
-
{ product_id: product_id, quantity: quantity ? Number(quantity) : 1 },
|
|
11991
|
-
];
|
|
11992
|
-
}
|
|
11993
|
-
if (!cart || cart.length === 0)
|
|
11994
|
-
throw new Error("Missing required field: product_cart or product_id");
|
|
11995
|
-
paymentPayload = {
|
|
11996
|
-
billing: billing,
|
|
11997
|
-
customer: customer,
|
|
11998
|
-
product_cart: cart,
|
|
11999
|
-
};
|
|
12000
|
-
if (metadata)
|
|
12001
|
-
paymentPayload.metadata = metadata;
|
|
12002
|
-
paymentPayload.payment_link = true;
|
|
12003
|
-
if (allowed_payment_method_types)
|
|
12004
|
-
paymentPayload.allowed_payment_method_types =
|
|
12005
|
-
allowed_payment_method_types;
|
|
12006
|
-
if (billing_currency)
|
|
12007
|
-
paymentPayload.billing_currency = billing_currency;
|
|
12008
|
-
if (discount_code)
|
|
12009
|
-
paymentPayload.discount_code = discount_code;
|
|
12010
|
-
// Use bodyReturnUrl if present, otherwise use top-level returnUrl
|
|
12011
|
-
if (bodyReturnUrl) {
|
|
12012
|
-
paymentPayload.return_url = bodyReturnUrl;
|
|
12013
|
-
}
|
|
12014
|
-
else if (returnUrl) {
|
|
12015
|
-
paymentPayload.return_url = returnUrl;
|
|
12016
|
-
}
|
|
12017
|
-
if (show_saved_payment_methods)
|
|
12018
|
-
paymentPayload.show_saved_payment_methods = show_saved_payment_methods;
|
|
12019
|
-
if (tax_id)
|
|
12020
|
-
paymentPayload.tax_id = tax_id;
|
|
12021
|
-
payment = void 0;
|
|
12022
|
-
_g.label = 17;
|
|
12023
|
-
case 17:
|
|
12024
|
-
_g.trys.push([17, 19, , 20]);
|
|
12025
|
-
return [4 /*yield*/, dodopayments.payments.create(paymentPayload)];
|
|
12026
|
-
case 18:
|
|
12027
|
-
payment = _g.sent();
|
|
12028
|
-
return [3 /*break*/, 20];
|
|
12029
|
-
case 19:
|
|
12030
|
-
err_4 = _g.sent();
|
|
12031
|
-
console.error("Error when creating payment link", err_4);
|
|
12032
|
-
throw new Error(err_4 instanceof Error ? err_4.message : String(err_4));
|
|
12033
|
-
case 20:
|
|
12034
|
-
if (!payment || !payment.payment_link) {
|
|
12035
|
-
throw new Error("No payment link returned from Dodo Payments API. Make sure to set payment_link as true in payload.");
|
|
12036
|
-
}
|
|
12037
|
-
return [2 /*return*/, payment.payment_link];
|
|
12038
|
-
}
|
|
11714
|
+
return session.checkout_url;
|
|
11715
|
+
}
|
|
11716
|
+
const inputData = type === "dynamic" ? body : queryParams;
|
|
11717
|
+
let parseResult;
|
|
11718
|
+
if (type === "dynamic") {
|
|
11719
|
+
parseResult = dynamicCheckoutBodySchema.safeParse(inputData);
|
|
11720
|
+
} else {
|
|
11721
|
+
parseResult = checkoutQuerySchema.safeParse(inputData);
|
|
11722
|
+
}
|
|
11723
|
+
const { success, data, error } = parseResult;
|
|
11724
|
+
if (!success) {
|
|
11725
|
+
throw new Error(
|
|
11726
|
+
`Invalid ${type === "dynamic" ? "body" : "query parameters"}.
|
|
11727
|
+
${error.message}`
|
|
11728
|
+
);
|
|
11729
|
+
}
|
|
11730
|
+
if (type !== "dynamic") {
|
|
11731
|
+
const {
|
|
11732
|
+
productId,
|
|
11733
|
+
quantity: quantity2,
|
|
11734
|
+
fullName,
|
|
11735
|
+
firstName,
|
|
11736
|
+
lastName,
|
|
11737
|
+
email,
|
|
11738
|
+
country,
|
|
11739
|
+
addressLine,
|
|
11740
|
+
city,
|
|
11741
|
+
state,
|
|
11742
|
+
zipCode,
|
|
11743
|
+
disableFullName,
|
|
11744
|
+
disableFirstName,
|
|
11745
|
+
disableLastName,
|
|
11746
|
+
disableEmail,
|
|
11747
|
+
disableCountry,
|
|
11748
|
+
disableAddressLine,
|
|
11749
|
+
disableCity,
|
|
11750
|
+
disableState,
|
|
11751
|
+
disableZipCode,
|
|
11752
|
+
paymentCurrency,
|
|
11753
|
+
showCurrencySelector,
|
|
11754
|
+
paymentAmount,
|
|
11755
|
+
showDiscounts
|
|
11756
|
+
// metadata handled below
|
|
11757
|
+
} = data;
|
|
11758
|
+
const dodopayments2 = new DodoPayments({
|
|
11759
|
+
bearerToken,
|
|
11760
|
+
environment
|
|
12039
11761
|
});
|
|
12040
|
-
|
|
11762
|
+
if (!productId) throw new Error("Missing required field: productId");
|
|
11763
|
+
try {
|
|
11764
|
+
await dodopayments2.products.retrieve(productId);
|
|
11765
|
+
} catch (err) {
|
|
11766
|
+
console.error(err);
|
|
11767
|
+
throw new Error("Product not found");
|
|
11768
|
+
}
|
|
11769
|
+
const url = new URL(
|
|
11770
|
+
`${environment === "test_mode" ? "https://test.checkout.dodopayments.com" : "https://checkout.dodopayments.com"}/buy/${productId}`
|
|
11771
|
+
);
|
|
11772
|
+
url.searchParams.set("quantity", quantity2 ? String(quantity2) : "1");
|
|
11773
|
+
if (returnUrl) url.searchParams.set("redirect_url", returnUrl);
|
|
11774
|
+
if (fullName) url.searchParams.set("fullName", String(fullName));
|
|
11775
|
+
if (firstName) url.searchParams.set("firstName", String(firstName));
|
|
11776
|
+
if (lastName) url.searchParams.set("lastName", String(lastName));
|
|
11777
|
+
if (email) url.searchParams.set("email", String(email));
|
|
11778
|
+
if (country) url.searchParams.set("country", String(country));
|
|
11779
|
+
if (addressLine) url.searchParams.set("addressLine", String(addressLine));
|
|
11780
|
+
if (city) url.searchParams.set("city", String(city));
|
|
11781
|
+
if (state) url.searchParams.set("state", String(state));
|
|
11782
|
+
if (zipCode) url.searchParams.set("zipCode", String(zipCode));
|
|
11783
|
+
if (disableFullName === "true")
|
|
11784
|
+
url.searchParams.set("disableFullName", "true");
|
|
11785
|
+
if (disableFirstName === "true")
|
|
11786
|
+
url.searchParams.set("disableFirstName", "true");
|
|
11787
|
+
if (disableLastName === "true")
|
|
11788
|
+
url.searchParams.set("disableLastName", "true");
|
|
11789
|
+
if (disableEmail === "true") url.searchParams.set("disableEmail", "true");
|
|
11790
|
+
if (disableCountry === "true")
|
|
11791
|
+
url.searchParams.set("disableCountry", "true");
|
|
11792
|
+
if (disableAddressLine === "true")
|
|
11793
|
+
url.searchParams.set("disableAddressLine", "true");
|
|
11794
|
+
if (disableCity === "true") url.searchParams.set("disableCity", "true");
|
|
11795
|
+
if (disableState === "true") url.searchParams.set("disableState", "true");
|
|
11796
|
+
if (disableZipCode === "true")
|
|
11797
|
+
url.searchParams.set("disableZipCode", "true");
|
|
11798
|
+
if (paymentCurrency)
|
|
11799
|
+
url.searchParams.set("paymentCurrency", String(paymentCurrency));
|
|
11800
|
+
if (showCurrencySelector)
|
|
11801
|
+
url.searchParams.set(
|
|
11802
|
+
"showCurrencySelector",
|
|
11803
|
+
String(showCurrencySelector)
|
|
11804
|
+
);
|
|
11805
|
+
if (paymentAmount)
|
|
11806
|
+
url.searchParams.set("paymentAmount", String(paymentAmount));
|
|
11807
|
+
if (showDiscounts)
|
|
11808
|
+
url.searchParams.set("showDiscounts", String(showDiscounts));
|
|
11809
|
+
for (const [key, value] of Object.entries(queryParams || {})) {
|
|
11810
|
+
if (key.startsWith("metadata_") && value && typeof value !== "object") {
|
|
11811
|
+
url.searchParams.set(key, String(value));
|
|
11812
|
+
}
|
|
11813
|
+
}
|
|
11814
|
+
return url.toString();
|
|
11815
|
+
}
|
|
11816
|
+
const dyn = data;
|
|
11817
|
+
const {
|
|
11818
|
+
product_id,
|
|
11819
|
+
product_cart,
|
|
11820
|
+
quantity,
|
|
11821
|
+
billing,
|
|
11822
|
+
customer,
|
|
11823
|
+
addons,
|
|
11824
|
+
metadata,
|
|
11825
|
+
allowed_payment_method_types,
|
|
11826
|
+
billing_currency,
|
|
11827
|
+
discount_code,
|
|
11828
|
+
on_demand,
|
|
11829
|
+
return_url: bodyReturnUrl,
|
|
11830
|
+
show_saved_payment_methods,
|
|
11831
|
+
tax_id,
|
|
11832
|
+
trial_period_days
|
|
11833
|
+
} = dyn;
|
|
11834
|
+
const dodopayments = new DodoPayments({
|
|
11835
|
+
bearerToken,
|
|
11836
|
+
environment
|
|
11837
|
+
});
|
|
11838
|
+
let isSubscription = false;
|
|
11839
|
+
let productIdToFetch = product_id;
|
|
11840
|
+
if (!product_id && product_cart && product_cart.length > 0) {
|
|
11841
|
+
productIdToFetch = product_cart[0].product_id;
|
|
11842
|
+
}
|
|
11843
|
+
if (!productIdToFetch)
|
|
11844
|
+
throw new Error(
|
|
11845
|
+
"Missing required field: product_id or product_cart[0].product_id"
|
|
11846
|
+
);
|
|
11847
|
+
let product;
|
|
11848
|
+
try {
|
|
11849
|
+
product = await dodopayments.products.retrieve(productIdToFetch);
|
|
11850
|
+
} catch (err) {
|
|
11851
|
+
console.error(err);
|
|
11852
|
+
throw new Error("Product not found");
|
|
11853
|
+
}
|
|
11854
|
+
isSubscription = Boolean(product.is_recurring);
|
|
11855
|
+
if (isSubscription && !product_id)
|
|
11856
|
+
throw new Error("Missing required field: product_id for subscription");
|
|
11857
|
+
if (!billing) throw new Error("Missing required field: billing");
|
|
11858
|
+
if (!customer) throw new Error("Missing required field: customer");
|
|
11859
|
+
if (isSubscription) {
|
|
11860
|
+
const subscriptionPayload = {
|
|
11861
|
+
billing,
|
|
11862
|
+
customer,
|
|
11863
|
+
product_id,
|
|
11864
|
+
quantity: quantity ? Number(quantity) : 1
|
|
11865
|
+
};
|
|
11866
|
+
if (metadata) subscriptionPayload.metadata = metadata;
|
|
11867
|
+
if (discount_code) subscriptionPayload.discount_code = discount_code;
|
|
11868
|
+
if (addons) subscriptionPayload.addons = addons;
|
|
11869
|
+
if (allowed_payment_method_types)
|
|
11870
|
+
subscriptionPayload.allowed_payment_method_types = allowed_payment_method_types;
|
|
11871
|
+
if (billing_currency)
|
|
11872
|
+
subscriptionPayload.billing_currency = billing_currency;
|
|
11873
|
+
if (on_demand) subscriptionPayload.on_demand = on_demand;
|
|
11874
|
+
subscriptionPayload.payment_link = true;
|
|
11875
|
+
if (bodyReturnUrl) {
|
|
11876
|
+
subscriptionPayload.return_url = bodyReturnUrl;
|
|
11877
|
+
} else if (returnUrl) {
|
|
11878
|
+
subscriptionPayload.return_url = returnUrl;
|
|
11879
|
+
}
|
|
11880
|
+
if (show_saved_payment_methods)
|
|
11881
|
+
subscriptionPayload.show_saved_payment_methods = show_saved_payment_methods;
|
|
11882
|
+
if (tax_id) subscriptionPayload.tax_id = tax_id;
|
|
11883
|
+
if (trial_period_days)
|
|
11884
|
+
subscriptionPayload.trial_period_days = trial_period_days;
|
|
11885
|
+
let subscription;
|
|
11886
|
+
try {
|
|
11887
|
+
subscription = await dodopayments.subscriptions.create(subscriptionPayload);
|
|
11888
|
+
} catch (err) {
|
|
11889
|
+
console.error("Error when creating subscription", err);
|
|
11890
|
+
throw new Error(err instanceof Error ? err.message : String(err));
|
|
11891
|
+
}
|
|
11892
|
+
if (!subscription || !subscription.payment_link) {
|
|
11893
|
+
throw new Error(
|
|
11894
|
+
"No payment link returned from Dodo Payments API (subscription). Make sure to set payment_link as true in payload"
|
|
11895
|
+
);
|
|
11896
|
+
}
|
|
11897
|
+
return subscription.payment_link;
|
|
11898
|
+
} else {
|
|
11899
|
+
let cart = product_cart;
|
|
11900
|
+
if (!cart && product_id) {
|
|
11901
|
+
cart = [
|
|
11902
|
+
{ product_id, quantity: quantity ? Number(quantity) : 1 }
|
|
11903
|
+
];
|
|
11904
|
+
}
|
|
11905
|
+
if (!cart || cart.length === 0)
|
|
11906
|
+
throw new Error("Missing required field: product_cart or product_id");
|
|
11907
|
+
const paymentPayload = {
|
|
11908
|
+
billing,
|
|
11909
|
+
customer,
|
|
11910
|
+
product_cart: cart
|
|
11911
|
+
};
|
|
11912
|
+
if (metadata) paymentPayload.metadata = metadata;
|
|
11913
|
+
paymentPayload.payment_link = true;
|
|
11914
|
+
if (allowed_payment_method_types)
|
|
11915
|
+
paymentPayload.allowed_payment_method_types = allowed_payment_method_types;
|
|
11916
|
+
if (billing_currency) paymentPayload.billing_currency = billing_currency;
|
|
11917
|
+
if (discount_code) paymentPayload.discount_code = discount_code;
|
|
11918
|
+
if (bodyReturnUrl) {
|
|
11919
|
+
paymentPayload.return_url = bodyReturnUrl;
|
|
11920
|
+
} else if (returnUrl) {
|
|
11921
|
+
paymentPayload.return_url = returnUrl;
|
|
11922
|
+
}
|
|
11923
|
+
if (show_saved_payment_methods)
|
|
11924
|
+
paymentPayload.show_saved_payment_methods = show_saved_payment_methods;
|
|
11925
|
+
if (tax_id) paymentPayload.tax_id = tax_id;
|
|
11926
|
+
let payment;
|
|
11927
|
+
try {
|
|
11928
|
+
payment = await dodopayments.payments.create(paymentPayload);
|
|
11929
|
+
} catch (err) {
|
|
11930
|
+
console.error("Error when creating payment link", err);
|
|
11931
|
+
throw new Error(err instanceof Error ? err.message : String(err));
|
|
11932
|
+
}
|
|
11933
|
+
if (!payment || !payment.payment_link) {
|
|
11934
|
+
throw new Error(
|
|
11935
|
+
"No payment link returned from Dodo Payments API. Make sure to set payment_link as true in payload."
|
|
11936
|
+
);
|
|
11937
|
+
}
|
|
11938
|
+
return payment.payment_link;
|
|
11939
|
+
}
|
|
11940
|
+
};
|
|
12041
11941
|
|
|
12042
11942
|
const Checkout = (config) => {
|
|
12043
11943
|
const getHandler = async (req) => {
|
|
@@ -12976,542 +12876,422 @@ class Webhook {
|
|
|
12976
12876
|
Webhook_1 = dist.Webhook = Webhook;
|
|
12977
12877
|
Webhook.prefix = "whsec_";
|
|
12978
12878
|
|
|
12879
|
+
// src/schemas/webhook.ts
|
|
12979
12880
|
var PaymentSchema = objectType({
|
|
12980
|
-
|
|
12981
|
-
|
|
12982
|
-
|
|
12983
|
-
|
|
12984
|
-
|
|
12985
|
-
|
|
12986
|
-
|
|
12987
|
-
|
|
12988
|
-
|
|
12989
|
-
|
|
12990
|
-
|
|
12991
|
-
|
|
12992
|
-
|
|
12993
|
-
|
|
12994
|
-
|
|
12995
|
-
|
|
12996
|
-
|
|
12997
|
-
|
|
12998
|
-
|
|
12999
|
-
|
|
13000
|
-
|
|
13001
|
-
|
|
13002
|
-
|
|
13003
|
-
|
|
13004
|
-
|
|
13005
|
-
|
|
13006
|
-
|
|
13007
|
-
|
|
13008
|
-
|
|
13009
|
-
|
|
13010
|
-
|
|
13011
|
-
"dispute_opened",
|
|
13012
|
-
"dispute_won",
|
|
13013
|
-
"dispute_lost",
|
|
13014
|
-
]),
|
|
13015
|
-
dispute_status: enumType([
|
|
13016
|
-
"dispute_opened",
|
|
13017
|
-
"dispute_won",
|
|
13018
|
-
"dispute_lost",
|
|
13019
|
-
"dispute_accepted",
|
|
13020
|
-
"dispute_cancelled",
|
|
13021
|
-
"dispute_challenged",
|
|
13022
|
-
]),
|
|
13023
|
-
payment_id: stringType(),
|
|
13024
|
-
remarks: stringType().nullable(),
|
|
13025
|
-
}))
|
|
13026
|
-
.nullable(),
|
|
13027
|
-
error_code: stringType().nullable(),
|
|
13028
|
-
error_message: stringType().nullable(),
|
|
13029
|
-
metadata: recordType(anyType()).nullable(),
|
|
13030
|
-
payment_id: stringType(),
|
|
13031
|
-
payment_link: stringType().nullable(),
|
|
13032
|
-
payment_method: stringType().nullable(),
|
|
13033
|
-
payment_method_type: stringType().nullable(),
|
|
13034
|
-
product_cart: arrayType(objectType({
|
|
13035
|
-
product_id: stringType(),
|
|
13036
|
-
quantity: numberType(),
|
|
13037
|
-
}))
|
|
13038
|
-
.nullable(),
|
|
13039
|
-
refunds: arrayType(objectType({
|
|
13040
|
-
amount: numberType(),
|
|
13041
|
-
business_id: stringType(),
|
|
13042
|
-
created_at: stringType().transform(function (d) { return new Date(d); }),
|
|
13043
|
-
currency: stringType(),
|
|
13044
|
-
is_partial: booleanType(),
|
|
13045
|
-
payment_id: stringType(),
|
|
13046
|
-
reason: stringType().nullable(),
|
|
13047
|
-
refund_id: stringType(),
|
|
13048
|
-
status: enumType(["succeeded", "failed", "pending"]),
|
|
13049
|
-
}))
|
|
13050
|
-
.nullable(),
|
|
13051
|
-
settlement_amount: numberType(),
|
|
13052
|
-
settlement_currency: stringType(),
|
|
13053
|
-
settlement_tax: numberType().nullable(),
|
|
13054
|
-
status: enumType(["succeeded", "failed", "pending", "processing", "cancelled"]),
|
|
13055
|
-
subscription_id: stringType().nullable(),
|
|
13056
|
-
tax: numberType().nullable(),
|
|
13057
|
-
total_amount: numberType(),
|
|
13058
|
-
updated_at: stringType()
|
|
13059
|
-
.transform(function (d) { return new Date(d); })
|
|
13060
|
-
.nullable(),
|
|
13061
|
-
});
|
|
13062
|
-
var SubscriptionSchema = objectType({
|
|
13063
|
-
payload_type: literalType("Subscription"),
|
|
13064
|
-
addons: arrayType(objectType({
|
|
13065
|
-
addon_id: stringType(),
|
|
13066
|
-
quantity: numberType(),
|
|
13067
|
-
}))
|
|
13068
|
-
.nullable(),
|
|
13069
|
-
billing: objectType({
|
|
13070
|
-
city: stringType().nullable(),
|
|
13071
|
-
country: stringType().nullable(),
|
|
13072
|
-
state: stringType().nullable(),
|
|
13073
|
-
street: stringType().nullable(),
|
|
13074
|
-
zipcode: stringType().nullable(),
|
|
13075
|
-
}),
|
|
13076
|
-
cancel_at_next_billing_date: booleanType(),
|
|
13077
|
-
cancelled_at: stringType()
|
|
13078
|
-
.transform(function (d) { return new Date(d); })
|
|
13079
|
-
.nullable(),
|
|
13080
|
-
created_at: stringType().transform(function (d) { return new Date(d); }),
|
|
13081
|
-
currency: stringType(),
|
|
13082
|
-
customer: objectType({
|
|
13083
|
-
customer_id: stringType(),
|
|
13084
|
-
email: stringType(),
|
|
13085
|
-
name: stringType().nullable(),
|
|
13086
|
-
}),
|
|
13087
|
-
discount_id: stringType().nullable(),
|
|
13088
|
-
metadata: recordType(anyType()).nullable(),
|
|
13089
|
-
next_billing_date: stringType()
|
|
13090
|
-
.transform(function (d) { return new Date(d); })
|
|
13091
|
-
.nullable(),
|
|
13092
|
-
on_demand: booleanType(),
|
|
13093
|
-
payment_frequency_count: numberType(),
|
|
13094
|
-
payment_frequency_interval: enumType(["Day", "Week", "Month", "Year"]),
|
|
13095
|
-
previous_billing_date: stringType()
|
|
13096
|
-
.transform(function (d) { return new Date(d); })
|
|
13097
|
-
.nullable(),
|
|
13098
|
-
product_id: stringType(),
|
|
13099
|
-
quantity: numberType(),
|
|
13100
|
-
recurring_pre_tax_amount: numberType(),
|
|
13101
|
-
status: enumType([
|
|
13102
|
-
"pending",
|
|
13103
|
-
"active",
|
|
13104
|
-
"on_hold",
|
|
13105
|
-
"paused",
|
|
13106
|
-
"cancelled",
|
|
13107
|
-
"expired",
|
|
13108
|
-
"failed",
|
|
13109
|
-
]),
|
|
13110
|
-
subscription_id: stringType(),
|
|
13111
|
-
subscription_period_count: numberType(),
|
|
13112
|
-
subscription_period_interval: enumType(["Day", "Week", "Month", "Year"]),
|
|
13113
|
-
tax_inclusive: booleanType(),
|
|
13114
|
-
trial_period_days: numberType(),
|
|
13115
|
-
});
|
|
13116
|
-
var RefundSchema = objectType({
|
|
13117
|
-
payload_type: literalType("Refund"),
|
|
13118
|
-
amount: numberType(),
|
|
13119
|
-
business_id: stringType(),
|
|
13120
|
-
created_at: stringType().transform(function (d) { return new Date(d); }),
|
|
13121
|
-
currency: stringType(),
|
|
13122
|
-
is_partial: booleanType(),
|
|
13123
|
-
payment_id: stringType(),
|
|
13124
|
-
reason: stringType().nullable(),
|
|
13125
|
-
refund_id: stringType(),
|
|
13126
|
-
status: enumType(["succeeded", "failed", "pending"]),
|
|
13127
|
-
});
|
|
13128
|
-
var DisputeSchema = objectType({
|
|
13129
|
-
payload_type: literalType("Dispute"),
|
|
13130
|
-
amount: stringType(),
|
|
13131
|
-
business_id: stringType(),
|
|
13132
|
-
created_at: stringType().transform(function (d) { return new Date(d); }),
|
|
13133
|
-
currency: stringType(),
|
|
13134
|
-
dispute_id: stringType(),
|
|
13135
|
-
dispute_stage: enumType([
|
|
12881
|
+
payload_type: literalType("Payment"),
|
|
12882
|
+
billing: objectType({
|
|
12883
|
+
city: stringType().nullable(),
|
|
12884
|
+
country: stringType().nullable(),
|
|
12885
|
+
state: stringType().nullable(),
|
|
12886
|
+
street: stringType().nullable(),
|
|
12887
|
+
zipcode: stringType().nullable()
|
|
12888
|
+
}),
|
|
12889
|
+
brand_id: stringType(),
|
|
12890
|
+
business_id: stringType(),
|
|
12891
|
+
card_issuing_country: stringType().nullable(),
|
|
12892
|
+
card_last_four: stringType().nullable(),
|
|
12893
|
+
card_network: stringType().nullable(),
|
|
12894
|
+
card_type: stringType().nullable(),
|
|
12895
|
+
created_at: stringType().transform((d) => new Date(d)),
|
|
12896
|
+
currency: stringType(),
|
|
12897
|
+
customer: objectType({
|
|
12898
|
+
customer_id: stringType(),
|
|
12899
|
+
email: stringType(),
|
|
12900
|
+
name: stringType().nullable()
|
|
12901
|
+
}),
|
|
12902
|
+
digital_products_delivered: booleanType(),
|
|
12903
|
+
discount_id: stringType().nullable(),
|
|
12904
|
+
disputes: arrayType(
|
|
12905
|
+
objectType({
|
|
12906
|
+
amount: stringType(),
|
|
12907
|
+
business_id: stringType(),
|
|
12908
|
+
created_at: stringType().transform((d) => new Date(d)),
|
|
12909
|
+
currency: stringType(),
|
|
12910
|
+
dispute_id: stringType(),
|
|
12911
|
+
dispute_stage: enumType([
|
|
13136
12912
|
"pre_dispute",
|
|
13137
12913
|
"dispute_opened",
|
|
13138
12914
|
"dispute_won",
|
|
13139
|
-
"dispute_lost"
|
|
13140
|
-
|
|
13141
|
-
|
|
12915
|
+
"dispute_lost"
|
|
12916
|
+
]),
|
|
12917
|
+
dispute_status: enumType([
|
|
13142
12918
|
"dispute_opened",
|
|
13143
12919
|
"dispute_won",
|
|
13144
12920
|
"dispute_lost",
|
|
13145
12921
|
"dispute_accepted",
|
|
13146
12922
|
"dispute_cancelled",
|
|
13147
|
-
"dispute_challenged"
|
|
13148
|
-
|
|
13149
|
-
|
|
13150
|
-
|
|
12923
|
+
"dispute_challenged"
|
|
12924
|
+
]),
|
|
12925
|
+
payment_id: stringType(),
|
|
12926
|
+
remarks: stringType().nullable()
|
|
12927
|
+
})
|
|
12928
|
+
).nullable(),
|
|
12929
|
+
error_code: stringType().nullable(),
|
|
12930
|
+
error_message: stringType().nullable(),
|
|
12931
|
+
metadata: recordType(anyType()).nullable(),
|
|
12932
|
+
payment_id: stringType(),
|
|
12933
|
+
payment_link: stringType().nullable(),
|
|
12934
|
+
payment_method: stringType().nullable(),
|
|
12935
|
+
payment_method_type: stringType().nullable(),
|
|
12936
|
+
product_cart: arrayType(
|
|
12937
|
+
objectType({
|
|
12938
|
+
product_id: stringType(),
|
|
12939
|
+
quantity: numberType()
|
|
12940
|
+
})
|
|
12941
|
+
).nullable(),
|
|
12942
|
+
refunds: arrayType(
|
|
12943
|
+
objectType({
|
|
12944
|
+
amount: numberType(),
|
|
12945
|
+
business_id: stringType(),
|
|
12946
|
+
created_at: stringType().transform((d) => new Date(d)),
|
|
12947
|
+
currency: stringType(),
|
|
12948
|
+
is_partial: booleanType(),
|
|
12949
|
+
payment_id: stringType(),
|
|
12950
|
+
reason: stringType().nullable(),
|
|
12951
|
+
refund_id: stringType(),
|
|
12952
|
+
status: enumType(["succeeded", "failed", "pending"])
|
|
12953
|
+
})
|
|
12954
|
+
).nullable(),
|
|
12955
|
+
settlement_amount: numberType(),
|
|
12956
|
+
settlement_currency: stringType(),
|
|
12957
|
+
settlement_tax: numberType().nullable(),
|
|
12958
|
+
status: enumType(["succeeded", "failed", "pending", "processing", "cancelled"]),
|
|
12959
|
+
subscription_id: stringType().nullable(),
|
|
12960
|
+
tax: numberType().nullable(),
|
|
12961
|
+
total_amount: numberType(),
|
|
12962
|
+
updated_at: stringType().transform((d) => new Date(d)).nullable()
|
|
13151
12963
|
});
|
|
13152
|
-
var
|
|
13153
|
-
|
|
13154
|
-
|
|
13155
|
-
|
|
13156
|
-
|
|
12964
|
+
var SubscriptionSchema = objectType({
|
|
12965
|
+
payload_type: literalType("Subscription"),
|
|
12966
|
+
addons: arrayType(
|
|
12967
|
+
objectType({
|
|
12968
|
+
addon_id: stringType(),
|
|
12969
|
+
quantity: numberType()
|
|
12970
|
+
})
|
|
12971
|
+
).nullable(),
|
|
12972
|
+
billing: objectType({
|
|
12973
|
+
city: stringType().nullable(),
|
|
12974
|
+
country: stringType().nullable(),
|
|
12975
|
+
state: stringType().nullable(),
|
|
12976
|
+
street: stringType().nullable(),
|
|
12977
|
+
zipcode: stringType().nullable()
|
|
12978
|
+
}),
|
|
12979
|
+
cancel_at_next_billing_date: booleanType(),
|
|
12980
|
+
cancelled_at: stringType().transform((d) => new Date(d)).nullable(),
|
|
12981
|
+
created_at: stringType().transform((d) => new Date(d)),
|
|
12982
|
+
currency: stringType(),
|
|
12983
|
+
customer: objectType({
|
|
13157
12984
|
customer_id: stringType(),
|
|
13158
|
-
|
|
13159
|
-
|
|
13160
|
-
|
|
13161
|
-
|
|
13162
|
-
|
|
13163
|
-
|
|
13164
|
-
|
|
13165
|
-
|
|
13166
|
-
|
|
13167
|
-
|
|
12985
|
+
email: stringType(),
|
|
12986
|
+
name: stringType().nullable()
|
|
12987
|
+
}),
|
|
12988
|
+
discount_id: stringType().nullable(),
|
|
12989
|
+
metadata: recordType(anyType()).nullable(),
|
|
12990
|
+
next_billing_date: stringType().transform((d) => new Date(d)).nullable(),
|
|
12991
|
+
on_demand: booleanType(),
|
|
12992
|
+
payment_frequency_count: numberType(),
|
|
12993
|
+
payment_frequency_interval: enumType(["Day", "Week", "Month", "Year"]),
|
|
12994
|
+
previous_billing_date: stringType().transform((d) => new Date(d)).nullable(),
|
|
12995
|
+
product_id: stringType(),
|
|
12996
|
+
quantity: numberType(),
|
|
12997
|
+
recurring_pre_tax_amount: numberType(),
|
|
12998
|
+
status: enumType([
|
|
12999
|
+
"pending",
|
|
13000
|
+
"active",
|
|
13001
|
+
"on_hold",
|
|
13002
|
+
"paused",
|
|
13003
|
+
"cancelled",
|
|
13004
|
+
"expired",
|
|
13005
|
+
"failed"
|
|
13006
|
+
]),
|
|
13007
|
+
subscription_id: stringType(),
|
|
13008
|
+
subscription_period_count: numberType(),
|
|
13009
|
+
subscription_period_interval: enumType(["Day", "Week", "Month", "Year"]),
|
|
13010
|
+
tax_inclusive: booleanType(),
|
|
13011
|
+
trial_period_days: numberType()
|
|
13012
|
+
});
|
|
13013
|
+
var RefundSchema = objectType({
|
|
13014
|
+
payload_type: literalType("Refund"),
|
|
13015
|
+
amount: numberType(),
|
|
13016
|
+
business_id: stringType(),
|
|
13017
|
+
created_at: stringType().transform((d) => new Date(d)),
|
|
13018
|
+
currency: stringType(),
|
|
13019
|
+
is_partial: booleanType(),
|
|
13020
|
+
payment_id: stringType(),
|
|
13021
|
+
reason: stringType().nullable(),
|
|
13022
|
+
refund_id: stringType(),
|
|
13023
|
+
status: enumType(["succeeded", "failed", "pending"])
|
|
13024
|
+
});
|
|
13025
|
+
var DisputeSchema = objectType({
|
|
13026
|
+
payload_type: literalType("Dispute"),
|
|
13027
|
+
amount: stringType(),
|
|
13028
|
+
business_id: stringType(),
|
|
13029
|
+
created_at: stringType().transform((d) => new Date(d)),
|
|
13030
|
+
currency: stringType(),
|
|
13031
|
+
dispute_id: stringType(),
|
|
13032
|
+
dispute_stage: enumType([
|
|
13033
|
+
"pre_dispute",
|
|
13034
|
+
"dispute_opened",
|
|
13035
|
+
"dispute_won",
|
|
13036
|
+
"dispute_lost"
|
|
13037
|
+
]),
|
|
13038
|
+
dispute_status: enumType([
|
|
13039
|
+
"dispute_opened",
|
|
13040
|
+
"dispute_won",
|
|
13041
|
+
"dispute_lost",
|
|
13042
|
+
"dispute_accepted",
|
|
13043
|
+
"dispute_cancelled",
|
|
13044
|
+
"dispute_challenged"
|
|
13045
|
+
]),
|
|
13046
|
+
payment_id: stringType(),
|
|
13047
|
+
remarks: stringType().nullable()
|
|
13048
|
+
});
|
|
13049
|
+
var LicenseKeySchema = objectType({
|
|
13050
|
+
payload_type: literalType("LicenseKey"),
|
|
13051
|
+
activations_limit: numberType(),
|
|
13052
|
+
business_id: stringType(),
|
|
13053
|
+
created_at: stringType().transform((d) => new Date(d)),
|
|
13054
|
+
customer_id: stringType(),
|
|
13055
|
+
expires_at: stringType().transform((d) => new Date(d)).nullable(),
|
|
13056
|
+
id: stringType(),
|
|
13057
|
+
instances_count: numberType(),
|
|
13058
|
+
key: stringType(),
|
|
13059
|
+
payment_id: stringType(),
|
|
13060
|
+
product_id: stringType(),
|
|
13061
|
+
status: enumType(["active", "inactive", "expired"]),
|
|
13062
|
+
subscription_id: stringType().nullable()
|
|
13168
13063
|
});
|
|
13169
13064
|
var PaymentSucceededPayloadSchema = objectType({
|
|
13170
|
-
|
|
13171
|
-
|
|
13172
|
-
|
|
13173
|
-
|
|
13065
|
+
business_id: stringType(),
|
|
13066
|
+
type: literalType("payment.succeeded"),
|
|
13067
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13068
|
+
data: PaymentSchema
|
|
13174
13069
|
});
|
|
13175
13070
|
var PaymentFailedPayloadSchema = objectType({
|
|
13176
|
-
|
|
13177
|
-
|
|
13178
|
-
|
|
13179
|
-
|
|
13071
|
+
business_id: stringType(),
|
|
13072
|
+
type: literalType("payment.failed"),
|
|
13073
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13074
|
+
data: PaymentSchema
|
|
13180
13075
|
});
|
|
13181
13076
|
var PaymentProcessingPayloadSchema = objectType({
|
|
13182
|
-
|
|
13183
|
-
|
|
13184
|
-
|
|
13185
|
-
|
|
13077
|
+
business_id: stringType(),
|
|
13078
|
+
type: literalType("payment.processing"),
|
|
13079
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13080
|
+
data: PaymentSchema
|
|
13186
13081
|
});
|
|
13187
13082
|
var PaymentCancelledPayloadSchema = objectType({
|
|
13188
|
-
|
|
13189
|
-
|
|
13190
|
-
|
|
13191
|
-
|
|
13083
|
+
business_id: stringType(),
|
|
13084
|
+
type: literalType("payment.cancelled"),
|
|
13085
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13086
|
+
data: PaymentSchema
|
|
13192
13087
|
});
|
|
13193
13088
|
var RefundSucceededPayloadSchema = objectType({
|
|
13194
|
-
|
|
13195
|
-
|
|
13196
|
-
|
|
13197
|
-
|
|
13089
|
+
business_id: stringType(),
|
|
13090
|
+
type: literalType("refund.succeeded"),
|
|
13091
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13092
|
+
data: RefundSchema
|
|
13198
13093
|
});
|
|
13199
13094
|
var RefundFailedPayloadSchema = objectType({
|
|
13200
|
-
|
|
13201
|
-
|
|
13202
|
-
|
|
13203
|
-
|
|
13095
|
+
business_id: stringType(),
|
|
13096
|
+
type: literalType("refund.failed"),
|
|
13097
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13098
|
+
data: RefundSchema
|
|
13204
13099
|
});
|
|
13205
13100
|
var DisputeOpenedPayloadSchema = objectType({
|
|
13206
|
-
|
|
13207
|
-
|
|
13208
|
-
|
|
13209
|
-
|
|
13101
|
+
business_id: stringType(),
|
|
13102
|
+
type: literalType("dispute.opened"),
|
|
13103
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13104
|
+
data: DisputeSchema
|
|
13210
13105
|
});
|
|
13211
13106
|
var DisputeExpiredPayloadSchema = objectType({
|
|
13212
|
-
|
|
13213
|
-
|
|
13214
|
-
|
|
13215
|
-
|
|
13107
|
+
business_id: stringType(),
|
|
13108
|
+
type: literalType("dispute.expired"),
|
|
13109
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13110
|
+
data: DisputeSchema
|
|
13216
13111
|
});
|
|
13217
13112
|
var DisputeAcceptedPayloadSchema = objectType({
|
|
13218
|
-
|
|
13219
|
-
|
|
13220
|
-
|
|
13221
|
-
|
|
13113
|
+
business_id: stringType(),
|
|
13114
|
+
type: literalType("dispute.accepted"),
|
|
13115
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13116
|
+
data: DisputeSchema
|
|
13222
13117
|
});
|
|
13223
13118
|
var DisputeCancelledPayloadSchema = objectType({
|
|
13224
|
-
|
|
13225
|
-
|
|
13226
|
-
|
|
13227
|
-
|
|
13119
|
+
business_id: stringType(),
|
|
13120
|
+
type: literalType("dispute.cancelled"),
|
|
13121
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13122
|
+
data: DisputeSchema
|
|
13228
13123
|
});
|
|
13229
13124
|
var DisputeChallengedPayloadSchema = objectType({
|
|
13230
|
-
|
|
13231
|
-
|
|
13232
|
-
|
|
13233
|
-
|
|
13125
|
+
business_id: stringType(),
|
|
13126
|
+
type: literalType("dispute.challenged"),
|
|
13127
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13128
|
+
data: DisputeSchema
|
|
13234
13129
|
});
|
|
13235
13130
|
var DisputeWonPayloadSchema = objectType({
|
|
13236
|
-
|
|
13237
|
-
|
|
13238
|
-
|
|
13239
|
-
|
|
13131
|
+
business_id: stringType(),
|
|
13132
|
+
type: literalType("dispute.won"),
|
|
13133
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13134
|
+
data: DisputeSchema
|
|
13240
13135
|
});
|
|
13241
13136
|
var DisputeLostPayloadSchema = objectType({
|
|
13242
|
-
|
|
13243
|
-
|
|
13244
|
-
|
|
13245
|
-
|
|
13137
|
+
business_id: stringType(),
|
|
13138
|
+
type: literalType("dispute.lost"),
|
|
13139
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13140
|
+
data: DisputeSchema
|
|
13246
13141
|
});
|
|
13247
13142
|
var SubscriptionActivePayloadSchema = objectType({
|
|
13248
|
-
|
|
13249
|
-
|
|
13250
|
-
|
|
13251
|
-
|
|
13143
|
+
business_id: stringType(),
|
|
13144
|
+
type: literalType("subscription.active"),
|
|
13145
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13146
|
+
data: SubscriptionSchema
|
|
13252
13147
|
});
|
|
13253
13148
|
var SubscriptionOnHoldPayloadSchema = objectType({
|
|
13254
|
-
|
|
13255
|
-
|
|
13256
|
-
|
|
13257
|
-
|
|
13149
|
+
business_id: stringType(),
|
|
13150
|
+
type: literalType("subscription.on_hold"),
|
|
13151
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13152
|
+
data: SubscriptionSchema
|
|
13258
13153
|
});
|
|
13259
13154
|
var SubscriptionRenewedPayloadSchema = objectType({
|
|
13260
|
-
|
|
13261
|
-
|
|
13262
|
-
|
|
13263
|
-
|
|
13155
|
+
business_id: stringType(),
|
|
13156
|
+
type: literalType("subscription.renewed"),
|
|
13157
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13158
|
+
data: SubscriptionSchema
|
|
13264
13159
|
});
|
|
13265
13160
|
var SubscriptionPausedPayloadSchema = objectType({
|
|
13266
|
-
|
|
13267
|
-
|
|
13268
|
-
|
|
13269
|
-
|
|
13161
|
+
business_id: stringType(),
|
|
13162
|
+
type: literalType("subscription.paused"),
|
|
13163
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13164
|
+
data: SubscriptionSchema
|
|
13270
13165
|
});
|
|
13271
13166
|
var SubscriptionPlanChangedPayloadSchema = objectType({
|
|
13272
|
-
|
|
13273
|
-
|
|
13274
|
-
|
|
13275
|
-
|
|
13167
|
+
business_id: stringType(),
|
|
13168
|
+
type: literalType("subscription.plan_changed"),
|
|
13169
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13170
|
+
data: SubscriptionSchema
|
|
13276
13171
|
});
|
|
13277
13172
|
var SubscriptionCancelledPayloadSchema = objectType({
|
|
13278
|
-
|
|
13279
|
-
|
|
13280
|
-
|
|
13281
|
-
|
|
13173
|
+
business_id: stringType(),
|
|
13174
|
+
type: literalType("subscription.cancelled"),
|
|
13175
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13176
|
+
data: SubscriptionSchema
|
|
13282
13177
|
});
|
|
13283
13178
|
var SubscriptionFailedPayloadSchema = objectType({
|
|
13284
|
-
|
|
13285
|
-
|
|
13286
|
-
|
|
13287
|
-
|
|
13179
|
+
business_id: stringType(),
|
|
13180
|
+
type: literalType("subscription.failed"),
|
|
13181
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13182
|
+
data: SubscriptionSchema
|
|
13288
13183
|
});
|
|
13289
13184
|
var SubscriptionExpiredPayloadSchema = objectType({
|
|
13290
|
-
|
|
13291
|
-
|
|
13292
|
-
|
|
13293
|
-
|
|
13185
|
+
business_id: stringType(),
|
|
13186
|
+
type: literalType("subscription.expired"),
|
|
13187
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13188
|
+
data: SubscriptionSchema
|
|
13294
13189
|
});
|
|
13295
13190
|
var LicenseKeyCreatedPayloadSchema = objectType({
|
|
13296
|
-
|
|
13297
|
-
|
|
13298
|
-
|
|
13299
|
-
|
|
13191
|
+
business_id: stringType(),
|
|
13192
|
+
type: literalType("license_key.created"),
|
|
13193
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
13194
|
+
data: LicenseKeySchema
|
|
13300
13195
|
});
|
|
13301
13196
|
var WebhookPayloadSchema = discriminatedUnionType("type", [
|
|
13302
|
-
|
|
13303
|
-
|
|
13304
|
-
|
|
13305
|
-
|
|
13306
|
-
|
|
13307
|
-
|
|
13308
|
-
|
|
13309
|
-
|
|
13310
|
-
|
|
13311
|
-
|
|
13312
|
-
|
|
13313
|
-
|
|
13314
|
-
|
|
13315
|
-
|
|
13316
|
-
|
|
13317
|
-
|
|
13318
|
-
|
|
13319
|
-
|
|
13320
|
-
|
|
13321
|
-
|
|
13322
|
-
|
|
13323
|
-
|
|
13197
|
+
PaymentSucceededPayloadSchema,
|
|
13198
|
+
PaymentFailedPayloadSchema,
|
|
13199
|
+
PaymentProcessingPayloadSchema,
|
|
13200
|
+
PaymentCancelledPayloadSchema,
|
|
13201
|
+
RefundSucceededPayloadSchema,
|
|
13202
|
+
RefundFailedPayloadSchema,
|
|
13203
|
+
DisputeOpenedPayloadSchema,
|
|
13204
|
+
DisputeExpiredPayloadSchema,
|
|
13205
|
+
DisputeAcceptedPayloadSchema,
|
|
13206
|
+
DisputeCancelledPayloadSchema,
|
|
13207
|
+
DisputeChallengedPayloadSchema,
|
|
13208
|
+
DisputeWonPayloadSchema,
|
|
13209
|
+
DisputeLostPayloadSchema,
|
|
13210
|
+
SubscriptionActivePayloadSchema,
|
|
13211
|
+
SubscriptionOnHoldPayloadSchema,
|
|
13212
|
+
SubscriptionRenewedPayloadSchema,
|
|
13213
|
+
SubscriptionPausedPayloadSchema,
|
|
13214
|
+
SubscriptionPlanChangedPayloadSchema,
|
|
13215
|
+
SubscriptionCancelledPayloadSchema,
|
|
13216
|
+
SubscriptionFailedPayloadSchema,
|
|
13217
|
+
SubscriptionExpiredPayloadSchema,
|
|
13218
|
+
LicenseKeyCreatedPayloadSchema
|
|
13324
13219
|
]);
|
|
13325
13220
|
|
|
13326
|
-
|
|
13327
|
-
|
|
13328
|
-
|
|
13329
|
-
|
|
13330
|
-
|
|
13331
|
-
|
|
13332
|
-
|
|
13333
|
-
|
|
13334
|
-
|
|
13335
|
-
|
|
13336
|
-
|
|
13337
|
-
|
|
13338
|
-
|
|
13339
|
-
|
|
13340
|
-
|
|
13341
|
-
|
|
13342
|
-
|
|
13343
|
-
|
|
13344
|
-
|
|
13345
|
-
|
|
13346
|
-
|
|
13347
|
-
|
|
13348
|
-
|
|
13349
|
-
|
|
13350
|
-
|
|
13351
|
-
|
|
13352
|
-
|
|
13353
|
-
|
|
13354
|
-
|
|
13355
|
-
|
|
13356
|
-
|
|
13357
|
-
|
|
13358
|
-
|
|
13359
|
-
|
|
13360
|
-
|
|
13361
|
-
|
|
13362
|
-
|
|
13363
|
-
|
|
13364
|
-
|
|
13365
|
-
|
|
13366
|
-
|
|
13367
|
-
|
|
13368
|
-
|
|
13369
|
-
|
|
13370
|
-
|
|
13371
|
-
|
|
13372
|
-
|
|
13373
|
-
|
|
13374
|
-
|
|
13375
|
-
|
|
13376
|
-
|
|
13377
|
-
|
|
13378
|
-
|
|
13379
|
-
|
|
13380
|
-
|
|
13381
|
-
|
|
13382
|
-
|
|
13383
|
-
|
|
13384
|
-
|
|
13385
|
-
|
|
13386
|
-
|
|
13387
|
-
|
|
13388
|
-
|
|
13389
|
-
|
|
13390
|
-
|
|
13391
|
-
|
|
13392
|
-
|
|
13393
|
-
|
|
13394
|
-
|
|
13395
|
-
|
|
13396
|
-
|
|
13397
|
-
|
|
13398
|
-
|
|
13399
|
-
|
|
13400
|
-
case 9:
|
|
13401
|
-
_a.sent();
|
|
13402
|
-
_a.label = 10;
|
|
13403
|
-
case 10:
|
|
13404
|
-
if (!(payload.type === "refund.succeeded")) return [3 /*break*/, 12];
|
|
13405
|
-
return [4 /*yield*/, callHandler(config.onRefundSucceeded, payload)];
|
|
13406
|
-
case 11:
|
|
13407
|
-
_a.sent();
|
|
13408
|
-
_a.label = 12;
|
|
13409
|
-
case 12:
|
|
13410
|
-
if (!(payload.type === "refund.failed")) return [3 /*break*/, 14];
|
|
13411
|
-
return [4 /*yield*/, callHandler(config.onRefundFailed, payload)];
|
|
13412
|
-
case 13:
|
|
13413
|
-
_a.sent();
|
|
13414
|
-
_a.label = 14;
|
|
13415
|
-
case 14:
|
|
13416
|
-
if (!(payload.type === "dispute.opened")) return [3 /*break*/, 16];
|
|
13417
|
-
return [4 /*yield*/, callHandler(config.onDisputeOpened, payload)];
|
|
13418
|
-
case 15:
|
|
13419
|
-
_a.sent();
|
|
13420
|
-
_a.label = 16;
|
|
13421
|
-
case 16:
|
|
13422
|
-
if (!(payload.type === "dispute.expired")) return [3 /*break*/, 18];
|
|
13423
|
-
return [4 /*yield*/, callHandler(config.onDisputeExpired, payload)];
|
|
13424
|
-
case 17:
|
|
13425
|
-
_a.sent();
|
|
13426
|
-
_a.label = 18;
|
|
13427
|
-
case 18:
|
|
13428
|
-
if (!(payload.type === "dispute.accepted")) return [3 /*break*/, 20];
|
|
13429
|
-
return [4 /*yield*/, callHandler(config.onDisputeAccepted, payload)];
|
|
13430
|
-
case 19:
|
|
13431
|
-
_a.sent();
|
|
13432
|
-
_a.label = 20;
|
|
13433
|
-
case 20:
|
|
13434
|
-
if (!(payload.type === "dispute.cancelled")) return [3 /*break*/, 22];
|
|
13435
|
-
return [4 /*yield*/, callHandler(config.onDisputeCancelled, payload)];
|
|
13436
|
-
case 21:
|
|
13437
|
-
_a.sent();
|
|
13438
|
-
_a.label = 22;
|
|
13439
|
-
case 22:
|
|
13440
|
-
if (!(payload.type === "dispute.challenged")) return [3 /*break*/, 24];
|
|
13441
|
-
return [4 /*yield*/, callHandler(config.onDisputeChallenged, payload)];
|
|
13442
|
-
case 23:
|
|
13443
|
-
_a.sent();
|
|
13444
|
-
_a.label = 24;
|
|
13445
|
-
case 24:
|
|
13446
|
-
if (!(payload.type === "dispute.won")) return [3 /*break*/, 26];
|
|
13447
|
-
return [4 /*yield*/, callHandler(config.onDisputeWon, payload)];
|
|
13448
|
-
case 25:
|
|
13449
|
-
_a.sent();
|
|
13450
|
-
_a.label = 26;
|
|
13451
|
-
case 26:
|
|
13452
|
-
if (!(payload.type === "dispute.lost")) return [3 /*break*/, 28];
|
|
13453
|
-
return [4 /*yield*/, callHandler(config.onDisputeLost, payload)];
|
|
13454
|
-
case 27:
|
|
13455
|
-
_a.sent();
|
|
13456
|
-
_a.label = 28;
|
|
13457
|
-
case 28:
|
|
13458
|
-
if (!(payload.type === "subscription.active")) return [3 /*break*/, 30];
|
|
13459
|
-
return [4 /*yield*/, callHandler(config.onSubscriptionActive, payload)];
|
|
13460
|
-
case 29:
|
|
13461
|
-
_a.sent();
|
|
13462
|
-
_a.label = 30;
|
|
13463
|
-
case 30:
|
|
13464
|
-
if (!(payload.type === "subscription.on_hold")) return [3 /*break*/, 32];
|
|
13465
|
-
return [4 /*yield*/, callHandler(config.onSubscriptionOnHold, payload)];
|
|
13466
|
-
case 31:
|
|
13467
|
-
_a.sent();
|
|
13468
|
-
_a.label = 32;
|
|
13469
|
-
case 32:
|
|
13470
|
-
if (!(payload.type === "subscription.renewed")) return [3 /*break*/, 34];
|
|
13471
|
-
return [4 /*yield*/, callHandler(config.onSubscriptionRenewed, payload)];
|
|
13472
|
-
case 33:
|
|
13473
|
-
_a.sent();
|
|
13474
|
-
_a.label = 34;
|
|
13475
|
-
case 34:
|
|
13476
|
-
if (!(payload.type === "subscription.paused")) return [3 /*break*/, 36];
|
|
13477
|
-
return [4 /*yield*/, callHandler(config.onSubscriptionPaused, payload)];
|
|
13478
|
-
case 35:
|
|
13479
|
-
_a.sent();
|
|
13480
|
-
_a.label = 36;
|
|
13481
|
-
case 36:
|
|
13482
|
-
if (!(payload.type === "subscription.plan_changed")) return [3 /*break*/, 38];
|
|
13483
|
-
return [4 /*yield*/, callHandler(config.onSubscriptionPlanChanged, payload)];
|
|
13484
|
-
case 37:
|
|
13485
|
-
_a.sent();
|
|
13486
|
-
_a.label = 38;
|
|
13487
|
-
case 38:
|
|
13488
|
-
if (!(payload.type === "subscription.cancelled")) return [3 /*break*/, 40];
|
|
13489
|
-
return [4 /*yield*/, callHandler(config.onSubscriptionCancelled, payload)];
|
|
13490
|
-
case 39:
|
|
13491
|
-
_a.sent();
|
|
13492
|
-
_a.label = 40;
|
|
13493
|
-
case 40:
|
|
13494
|
-
if (!(payload.type === "subscription.failed")) return [3 /*break*/, 42];
|
|
13495
|
-
return [4 /*yield*/, callHandler(config.onSubscriptionFailed, payload)];
|
|
13496
|
-
case 41:
|
|
13497
|
-
_a.sent();
|
|
13498
|
-
_a.label = 42;
|
|
13499
|
-
case 42:
|
|
13500
|
-
if (!(payload.type === "subscription.expired")) return [3 /*break*/, 44];
|
|
13501
|
-
return [4 /*yield*/, callHandler(config.onSubscriptionExpired, payload)];
|
|
13502
|
-
case 43:
|
|
13503
|
-
_a.sent();
|
|
13504
|
-
_a.label = 44;
|
|
13505
|
-
case 44:
|
|
13506
|
-
if (!(payload.type === "license_key.created")) return [3 /*break*/, 46];
|
|
13507
|
-
return [4 /*yield*/, callHandler(config.onLicenseKeyCreated, payload)];
|
|
13508
|
-
case 45:
|
|
13509
|
-
_a.sent();
|
|
13510
|
-
_a.label = 46;
|
|
13511
|
-
case 46: return [2 /*return*/];
|
|
13512
|
-
}
|
|
13513
|
-
});
|
|
13514
|
-
});
|
|
13221
|
+
async function handleWebhookPayload(payload, config, context) {
|
|
13222
|
+
const callHandler = (handler, payload2) => {
|
|
13223
|
+
if (!handler) return;
|
|
13224
|
+
return handler(payload2);
|
|
13225
|
+
};
|
|
13226
|
+
if (config.onPayload) {
|
|
13227
|
+
await callHandler(config.onPayload, payload);
|
|
13228
|
+
}
|
|
13229
|
+
if (payload.type === "payment.succeeded") {
|
|
13230
|
+
await callHandler(config.onPaymentSucceeded, payload);
|
|
13231
|
+
}
|
|
13232
|
+
if (payload.type === "payment.failed") {
|
|
13233
|
+
await callHandler(config.onPaymentFailed, payload);
|
|
13234
|
+
}
|
|
13235
|
+
if (payload.type === "payment.processing") {
|
|
13236
|
+
await callHandler(config.onPaymentProcessing, payload);
|
|
13237
|
+
}
|
|
13238
|
+
if (payload.type === "payment.cancelled") {
|
|
13239
|
+
await callHandler(config.onPaymentCancelled, payload);
|
|
13240
|
+
}
|
|
13241
|
+
if (payload.type === "refund.succeeded") {
|
|
13242
|
+
await callHandler(config.onRefundSucceeded, payload);
|
|
13243
|
+
}
|
|
13244
|
+
if (payload.type === "refund.failed") {
|
|
13245
|
+
await callHandler(config.onRefundFailed, payload);
|
|
13246
|
+
}
|
|
13247
|
+
if (payload.type === "dispute.opened") {
|
|
13248
|
+
await callHandler(config.onDisputeOpened, payload);
|
|
13249
|
+
}
|
|
13250
|
+
if (payload.type === "dispute.expired") {
|
|
13251
|
+
await callHandler(config.onDisputeExpired, payload);
|
|
13252
|
+
}
|
|
13253
|
+
if (payload.type === "dispute.accepted") {
|
|
13254
|
+
await callHandler(config.onDisputeAccepted, payload);
|
|
13255
|
+
}
|
|
13256
|
+
if (payload.type === "dispute.cancelled") {
|
|
13257
|
+
await callHandler(config.onDisputeCancelled, payload);
|
|
13258
|
+
}
|
|
13259
|
+
if (payload.type === "dispute.challenged") {
|
|
13260
|
+
await callHandler(config.onDisputeChallenged, payload);
|
|
13261
|
+
}
|
|
13262
|
+
if (payload.type === "dispute.won") {
|
|
13263
|
+
await callHandler(config.onDisputeWon, payload);
|
|
13264
|
+
}
|
|
13265
|
+
if (payload.type === "dispute.lost") {
|
|
13266
|
+
await callHandler(config.onDisputeLost, payload);
|
|
13267
|
+
}
|
|
13268
|
+
if (payload.type === "subscription.active") {
|
|
13269
|
+
await callHandler(config.onSubscriptionActive, payload);
|
|
13270
|
+
}
|
|
13271
|
+
if (payload.type === "subscription.on_hold") {
|
|
13272
|
+
await callHandler(config.onSubscriptionOnHold, payload);
|
|
13273
|
+
}
|
|
13274
|
+
if (payload.type === "subscription.renewed") {
|
|
13275
|
+
await callHandler(config.onSubscriptionRenewed, payload);
|
|
13276
|
+
}
|
|
13277
|
+
if (payload.type === "subscription.paused") {
|
|
13278
|
+
await callHandler(config.onSubscriptionPaused, payload);
|
|
13279
|
+
}
|
|
13280
|
+
if (payload.type === "subscription.plan_changed") {
|
|
13281
|
+
await callHandler(config.onSubscriptionPlanChanged, payload);
|
|
13282
|
+
}
|
|
13283
|
+
if (payload.type === "subscription.cancelled") {
|
|
13284
|
+
await callHandler(config.onSubscriptionCancelled, payload);
|
|
13285
|
+
}
|
|
13286
|
+
if (payload.type === "subscription.failed") {
|
|
13287
|
+
await callHandler(config.onSubscriptionFailed, payload);
|
|
13288
|
+
}
|
|
13289
|
+
if (payload.type === "subscription.expired") {
|
|
13290
|
+
await callHandler(config.onSubscriptionExpired, payload);
|
|
13291
|
+
}
|
|
13292
|
+
if (payload.type === "license_key.created") {
|
|
13293
|
+
await callHandler(config.onLicenseKeyCreated, payload);
|
|
13294
|
+
}
|
|
13515
13295
|
}
|
|
13516
13296
|
|
|
13517
13297
|
const Webhooks = ({ webhookKey, ...eventHandlers }) => {
|