fix: make last license date input only applicable to one-time purchases and ensure multiplier only affects one_time products
All checks were successful
Staging Build / build (push) Successful in 2m22s

This commit is contained in:
DanielS
2026-06-25 23:07:14 +02:00
parent 1a2ace937c
commit 71c6ad3721
2 changed files with 29 additions and 23 deletions

View File

@@ -138,7 +138,8 @@ export function buildOrderSnapshot(
: 'monthly')
let multiplier = 1
if (lastLicenseDate && billingCycle === 'one_time') {
const hasOneTime = items.some(item => item.billing_interval === 'one_time')
if (lastLicenseDate && hasOneTime) {
const lastDate = new Date(lastLicenseDate)
const today = new Date()
const yearsDiff = today.getFullYear() - lastDate.getFullYear()
@@ -159,11 +160,13 @@ export function buildOrderSnapshot(
multiplier = 0.90
}
// Multiply item_total in items by multiplier
// Multiply only one_time item totals by multiplier
items.forEach(item => {
item.item_total = item.item_total * multiplier
if (item.billing_interval === 'one_time') {
item.item_total = item.item_total * multiplier
}
})
subtotal = subtotal * multiplier
subtotal = items.reduce((acc, item) => acc + item.item_total, 0)
}
const taxAmount = Math.round(subtotal * (dominantTaxRate / 100) * 100) / 100
@@ -178,7 +181,7 @@ export function buildOrderSnapshot(
tax_amount: taxAmount,
total,
last_license_date: lastLicenseDate || null,
price_multiplier: lastLicenseDate && billingCycle === 'one_time' ? multiplier : null,
price_multiplier: lastLicenseDate && hasOneTime ? multiplier : null,
}
}