mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
billing: Assume we are charging right away when adding new users.
The actual implementation of the change will be a cron job that runs once a day and generates invoices for anyone with an account_balance > 0. There are currently no tests for that part of the flow, so no tests had to change.
This commit is contained in:
@@ -106,18 +106,19 @@ def billing_home(request: HttpRequest) -> HttpResponse:
|
||||
context = {'admin_access': True}
|
||||
|
||||
stripe_customer = stripe_get_customer(customer.stripe_customer_id)
|
||||
subscription = extract_current_subscription(stripe_customer)
|
||||
if stripe_customer.account_balance > 0:
|
||||
context.update({'account_charges': '{:,.2f}'.format(stripe_customer.account_balance / 100.)})
|
||||
if stripe_customer.account_balance < 0:
|
||||
context.update({'account_credits': '{:,.2f}'.format(-stripe_customer.account_balance / 100.)})
|
||||
|
||||
prorated_charges = stripe_customer.account_balance
|
||||
subscription = extract_current_subscription(stripe_customer)
|
||||
if subscription:
|
||||
plan_name = PLAN_NAMES[Plan.objects.get(stripe_plan_id=subscription.plan.id).nickname]
|
||||
seat_count = subscription.quantity
|
||||
# Need user's timezone to do this properly
|
||||
renewal_date = '{dt:%B} {dt.day}, {dt.year}'.format(
|
||||
dt=timestamp_to_datetime(subscription.current_period_end))
|
||||
upcoming_invoice = stripe_get_upcoming_invoice(customer.stripe_customer_id)
|
||||
renewal_amount = subscription.plan.amount * subscription.quantity
|
||||
prorated_charges += upcoming_invoice.total - renewal_amount
|
||||
renewal_amount = stripe_get_upcoming_invoice(customer.stripe_customer_id).total
|
||||
# Can only get here by subscribing and then downgrading. We don't support downgrading
|
||||
# yet, but keeping this code here since we will soon.
|
||||
else: # nocoverage
|
||||
@@ -126,11 +127,6 @@ def billing_home(request: HttpRequest) -> HttpResponse:
|
||||
renewal_date = ''
|
||||
renewal_amount = 0
|
||||
|
||||
prorated_credits = 0
|
||||
if prorated_charges < 0: # nocoverage
|
||||
prorated_credits = -prorated_charges
|
||||
prorated_charges = 0
|
||||
|
||||
payment_method = None
|
||||
if stripe_customer.default_source is not None:
|
||||
payment_method = "Card ending in %(last4)s" % {'last4': stripe_customer.default_source.last4}
|
||||
@@ -141,8 +137,6 @@ def billing_home(request: HttpRequest) -> HttpResponse:
|
||||
'renewal_date': renewal_date,
|
||||
'renewal_amount': '{:,.2f}'.format(renewal_amount / 100.),
|
||||
'payment_method': payment_method,
|
||||
'prorated_charges': '{:,.2f}'.format(prorated_charges / 100.),
|
||||
'prorated_credits': '{:,.2f}'.format(prorated_credits / 100.),
|
||||
'publishable_key': STRIPE_PUBLISHABLE_KEY,
|
||||
'stripe_email': stripe_customer.email,
|
||||
})
|
||||
|
||||
@@ -32,10 +32,10 @@
|
||||
<p>Your current plan is <strong>{{ plan_name }}</strong></p>
|
||||
<p>You are paying for <strong>{{ seat_count }} users</strong>.</p>
|
||||
<p>Your plan will renew on <strong>{{ renewal_date }}</strong> for <strong>${{ renewal_amount }}</strong>.</p>
|
||||
{% if prorated_charges %}
|
||||
<p>You have <strong>${{ prorated_charges }}</strong> in prorated charges that will be added to your next bill.</p>
|
||||
{% elif prorated_credits %}
|
||||
<p>You have <strong>${{ prorated_credits }}</strong> in prorated credits that will be automatically applied to your next bill.</p>
|
||||
{% if account_charges %}
|
||||
<p>You have <strong>${{ account_charges }}</strong> in charges that will be added to your next bill.</p>
|
||||
{% elif account_credits %}
|
||||
<p>You have <strong>${{ account_credits }}</strong> in credits that will be automatically applied to your next bill.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="tab-pane" id="payment-method" data-email="{{stripe_email}}" data-csrf="{{csrf_token}}" data-key="{{publishable_key}}">
|
||||
|
||||
@@ -51,7 +51,12 @@
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
<p>You’ll initially be charged <b>$<span id="charged_amount">{{ cloud_annual_price * seat_count }}</span></b> for <b>{{ seat_count }}</b> users. You’ll receive prorated charges and credits as users are added, deactivated, or become inactive.</p>
|
||||
<p>
|
||||
You’ll initially be charged
|
||||
<b>$<span id="charged_amount">{{ cloud_annual_price * seat_count }}</span></b>
|
||||
for <b>{{ seat_count }}</b> users. We’ll automatically charge you
|
||||
when new users are added, or give you credit when users are deactivated.
|
||||
</p>
|
||||
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
|
||||
data-key="{{ publishable_key }}"
|
||||
data-image="/static/images/logo/zulip-icon-128x128.png"
|
||||
|
||||
Reference in New Issue
Block a user