Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
stripe: Add flat discount while invoicing self-hosted realm/server.
Prakhar Pratyush608818622382
diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.pyindex c2c876a519f..dd33c70354f 100644--- a/corporate/lib/stripe.py+++ b/corporate/lib/stripe.py@@ -2445,6 +2445,23 @@ class BillingSession(ABC):licenses_base = ledger_entry.licensesif invoice_item_created:+ flat_discount, flat_discounted_months = self.get_flat_discount_info(plan.customer)+ if flat_discounted_months > 0:+ num_months = (+ 12 if plan.billing_schedule == CustomerPlan.BILLING_SCHEDULE_ANNUAL else 1+ )+ flat_discounted_months = min(flat_discounted_months, num_months)+ discount = flat_discount * flat_discounted_months+ plan.customer.flat_discounted_months -= flat_discounted_months+ plan.customer.save(update_fields=["flat_discounted_months"])+ stripe.InvoiceItem.create(+ currency="usd",+ customer=plan.customer.stripe_customer_id,+ description=f"${cents_to_dollar_string(flat_discount)}/month new customer discount",+ # Negative value to apply discount.+ amount=(-1 * discount),+ )+if plan.charge_automatically:collection_method = "charge_automatically"days_until_due = None