chore: cubic nits
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type Stripe from "stripe";
|
||||
import type { StripeWebhookContext } from "../../webhookMiddlewares/stripeWebhookContext.js";
|
||||
import { getFullStripeSub } from "../../stripeSubUtils.js";
|
||||
import type { StripeWebhookContext } from "../../webhookMiddlewares/stripeWebhookContext.js";
|
||||
import { setupStripeSubscriptionCreatedContext } from "./setupStripeSubscriptionCreatedContext.js";
|
||||
import { autoSyncFromSubscription } from "./tasks/autoSyncFromSubscription.js";
|
||||
import { linkScheduledCustomerProductsToSubscription } from "./tasks/linkScheduledCustomerProductsToSubscription.js";
|
||||
@@ -17,7 +17,14 @@ export const handleStripeSubscriptionCreated = async ({
|
||||
stripeId: stripeObject.id,
|
||||
});
|
||||
|
||||
await linkScheduledCustomerProductsToSubscription({ ctx, subscription });
|
||||
try {
|
||||
await linkScheduledCustomerProductsToSubscription({ ctx, subscription });
|
||||
} catch (err) {
|
||||
ctx.logger.error(
|
||||
`[sub.created] failed to link scheduled customer products for subscription ${subscription.id}`,
|
||||
err,
|
||||
);
|
||||
}
|
||||
|
||||
const subscriptionCreatedContext =
|
||||
await setupStripeSubscriptionCreatedContext({
|
||||
|
||||
@@ -65,8 +65,8 @@ export const setupAttachCheckoutMode = ({
|
||||
};
|
||||
|
||||
const checkoutMode = getStripeCheckoutOrDirectBilling();
|
||||
if (hasFutureStartDate && checkoutMode === null) {
|
||||
return null;
|
||||
if (hasFutureStartDate && !hasPaymentMethod) {
|
||||
return "stripe_checkout";
|
||||
}
|
||||
|
||||
if (checkoutMode === null && redirectMode === "always") {
|
||||
|
||||
@@ -29,6 +29,7 @@ export function getConfirmLabel({
|
||||
now?: number;
|
||||
}): string {
|
||||
if (!previewData) return "Attach Plan";
|
||||
if (previewData.redirect_to_checkout) return "Generate Checkout URL";
|
||||
if (isFutureStartDate(startDate, now)) return "Schedule Plan";
|
||||
|
||||
const sixHoursFromNow = addHours(now ?? Date.now(), 6);
|
||||
@@ -39,8 +40,6 @@ export function getConfirmLabel({
|
||||
);
|
||||
if (isScheduled) return "Schedule Change";
|
||||
|
||||
if (previewData.redirect_to_checkout) return "Generate Checkout URL";
|
||||
|
||||
if (previewData.total <= 0) return "Attach Plan";
|
||||
|
||||
return "Charge Customer";
|
||||
@@ -67,9 +66,9 @@ export function AttachFooterV3() {
|
||||
? "Invoices are not available for end of cycle changes as there is no immediate charge to invoice"
|
||||
: hasFutureStartDate
|
||||
? "Invoices are not available for future start dates. Schedule the plan instead."
|
||||
: isZeroAmount
|
||||
? "Cannot send an invoice for $0 amounts. Please confirm the change instead."
|
||||
: null;
|
||||
: isZeroAmount
|
||||
? "Cannot send an invoice for $0 amounts. Please confirm the change instead."
|
||||
: null;
|
||||
|
||||
return (
|
||||
<SheetFooter className="flex flex-col grid-cols-1 mt-0">
|
||||
|
||||
@@ -21,6 +21,19 @@ describe("getConfirmLabel", () => {
|
||||
).toBe("Schedule Plan");
|
||||
});
|
||||
|
||||
test("checkout redirect takes precedence over future startDate", () => {
|
||||
expect(
|
||||
getConfirmLabel({
|
||||
previewData: {
|
||||
...previewData,
|
||||
redirect_to_checkout: true,
|
||||
},
|
||||
startDate: addDays(NOW, 1).getTime(),
|
||||
now: NOW,
|
||||
}),
|
||||
).toBe("Generate Checkout URL");
|
||||
});
|
||||
|
||||
test("immediate paid attach charges customer", () => {
|
||||
expect(
|
||||
getConfirmLabel({
|
||||
|
||||
Reference in New Issue
Block a user