diff --git a/hc/payments/models.py b/hc/payments/models.py index c8972582..7ab352a3 100644 --- a/hc/payments/models.py +++ b/hc/payments/models.py @@ -65,6 +65,9 @@ class Subscription(models.Model): @property def payment_method(self): + if not self.subscription_id: + return None + if not hasattr(self, "_pm"): o = self._get_braintree_subscription() self._pm = braintree.PaymentMethod.find(o.payment_method_token) @@ -152,7 +155,8 @@ class Subscription(models.Model): self.save() - return result + if not result.is_success: + return result def cancel(self): if self.subscription_id: diff --git a/hc/payments/tests/test_payment_method.py b/hc/payments/tests/test_payment_method.py index 71bb4f71..920af9da 100644 --- a/hc/payments/tests/test_payment_method.py +++ b/hc/payments/tests/test_payment_method.py @@ -11,7 +11,7 @@ class UpdatePaymentMethodTestCase(BaseTestCase): mock.credit_card.CreditCard = list mock.PaymentMethod.find.return_value = {"email": "foo@example.org"} - Subscription.objects.create(user=self.alice) + Subscription.objects.create(user=self.alice, subscription_id="fake-id") self.client.login(username="alice@example.org", password="password") r = self.client.get("/accounts/profile/billing/payment_method/") @@ -23,7 +23,7 @@ class UpdatePaymentMethodTestCase(BaseTestCase): mock.credit_card.CreditCard = dict mock.PaymentMethod.find.return_value = {"masked_number": "1***2"} - Subscription.objects.create(user=self.alice) + Subscription.objects.create(user=self.alice, subscription_id="fake-id") self.client.login(username="alice@example.org", password="password") r = self.client.get("/accounts/profile/billing/payment_method/") diff --git a/hc/payments/views.py b/hc/payments/views.py index 9d9e5224..7ceb2545 100644 --- a/hc/payments/views.py +++ b/hc/payments/views.py @@ -95,7 +95,11 @@ def update(request): sub = Subscription.objects.for_user(request.user) # If plan_id has not changed then just update the payment method: if plan_id == sub.plan_id: - error = sub.update_payment_method(nonce) + if not sub.subscription_id: + error = sub.setup(plan_id, nonce) + else: + error = sub.update_payment_method(nonce) + if error: return log_and_bail(request, error) @@ -119,9 +123,9 @@ def update(request): request.session["set_plan_status"] = "success" return redirect("hc-billing") - result = sub.setup(plan_id, nonce) - if not result.is_success: - return log_and_bail(request, result) + error = sub.setup(plan_id, nonce) + if error: + return log_and_bail(request, error) # Update user's profile profile = request.user.profile diff --git a/static/css/billing.css b/static/css/billing.css index 0a96ea4b..390f7e54 100644 --- a/static/css/billing.css +++ b/static/css/billing.css @@ -37,6 +37,19 @@ border-color: #0091EA; } +#payment-method-modal .modal-header { + border-bottom: 0; + padding: 30px 30px 0 30px; +} + +#payment-method-modal .modal-body { + padding: 15px 30px; +} + +#payment-method-modal .modal-footer { + border-top: 0; +} + .plan .marker { display: none; } diff --git a/static/css/pricing.css b/static/css/pricing.css index 1576294c..8d105b5d 100644 --- a/static/css/pricing.css +++ b/static/css/pricing.css @@ -67,14 +67,6 @@ } -#payment-method-modal .modal-header { - border-bottom: 0; -} - -#payment-method-modal .modal-footer { - border-top: 0; -} - .error-message { font-family: monospace; } diff --git a/templates/accounts/billing.html b/templates/accounts/billing.html index f665bb44..564b0e2f 100644 --- a/templates/accounts/billing.html +++ b/templates/accounts/billing.html @@ -46,7 +46,7 @@ Current Plan {{ sub.plan_name|default:"Hobbyist" }} - {% if sub.plan_id %} + {% if sub.subscription_id %} Next Payment @@ -78,7 +78,7 @@ {% endif %} - {% if sub.subscription_id %} + {% if sub.plan_id %}

Payment Method

@@ -288,24 +288,19 @@