From 4181d575b11936cbe6e96f2196d1d11e8fb198ee Mon Sep 17 00:00:00 2001 From: Rishi Gupta Date: Mon, 13 Aug 2018 20:19:18 -0700 Subject: [PATCH] billing: Move Stripe call to end in do_subscribe_customer_to_plan. In general, everything that could throw an error and that could come before the Stripe call should do so. --- zilencer/lib/stripe.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zilencer/lib/stripe.py b/zilencer/lib/stripe.py index 2ca45e798e..ce356582d9 100644 --- a/zilencer/lib/stripe.py +++ b/zilencer/lib/stripe.py @@ -181,7 +181,8 @@ def do_subscribe_customer_to_plan(stripe_customer: stripe.Customer, stripe_plan_ billing_logger.error("Stripe customer %s trying to subscribe to %s, " "but has an active subscription" % (stripe_customer.id, stripe_plan_id)) raise BillingError('subscribing with existing subscription', BillingError.TRY_RELOADING) - # Success implies the customer was charged: https://stripe.com/docs/billing/lifecycle#active + customer = Customer.objects.get(stripe_customer_id=stripe_customer.id) + # Success implies the stripe_customer was charged: https://stripe.com/docs/billing/lifecycle#active stripe_subscription = stripe.Subscription.create( customer=stripe_customer.id, billing='charge_automatically', @@ -193,7 +194,6 @@ def do_subscribe_customer_to_plan(stripe_customer: stripe.Customer, stripe_plan_ tax_percent=tax_percent) if PRINT_STRIPE_FIXTURE_DATA: print(''.join(['"create_subscription": ', str(stripe_subscription), ','])) # nocoverage - customer = Customer.objects.get(stripe_customer_id=stripe_customer.id) with transaction.atomic(): customer.has_billing_relationship = True customer.save(update_fields=['has_billing_relationship'])