updated attach

This commit is contained in:
John Yeo
2026-02-06 14:40:39 -08:00
parent 3f1be17034
commit 0a28944996
12 changed files with 166 additions and 32 deletions

View File

@@ -1,18 +1,25 @@
import type { AttachBillingContext, AutumnBillingPlan } from "@autumn/shared";
import type {
AttachBillingContext,
AttachParamsV0,
AutumnBillingPlan,
} from "@autumn/shared";
import type { AutumnContext } from "@/honoUtils/HonoEnv";
import { finalizeLineItems } from "@/internal/billing/v2/compute/finalize/finalizeLineItems";
/**
* Finalizes the attach billing plan by processing line items.
* Finalizes the attach billing plan by processing line items
* and applying attach-specific guards.
*/
export const finalizeAttachPlan = ({
ctx,
plan,
attachBillingContext,
params,
}: {
ctx: AutumnContext;
plan: AutumnBillingPlan;
attachBillingContext: AttachBillingContext;
params: AttachParamsV0;
}): AutumnBillingPlan => {
plan.lineItems = finalizeLineItems({
ctx,
@@ -21,5 +28,10 @@ export const finalizeAttachPlan = ({
autumnBillingPlan: plan,
});
// Guard: if billing_behavior is 'next_cycle_only', clear line items (skip proration charges)
if (params.billing_behavior === "next_cycle_only") {
plan.lineItems = [];
}
return plan;
};