Fix account paid status between subscription payments

master
Alice 8 years ago
parent 381eab7943
commit 1db8f98ebe

@ -44,6 +44,8 @@ class VPNUser(models.Model):
@property
def is_paid(self):
if self.get_subscription():
return True
if not self.expiration:
return False
return self.expiration > timezone.now()

@ -62,6 +62,19 @@ class UserModelTest(TestCase, UserTestMixin):
vu.add_paid_time(p)
self.assertTrue(vu.is_paid)
def test_paid_between_subscr_payments(self):
u = User.objects.get(username='aaa')
vu = u.vpnuser
s = Subscription(user=u, backend_id='paypal', status='new')
s.save()
self.assertFalse(vu.is_paid)
s.status = 'active'
s.save()
self.assertTrue(vu.is_paid)
def test_grant_trial(self):
p = timedelta(days=1)
u = User.objects.get(username='aaa')

@ -175,15 +175,12 @@ class StripeBackend(BackendBase):
subscr.backend_data['stripe_error'] = e.json_body['error']['message']
return
try:
if subscr.status == 'new':
subscr.status = 'unconfirmed'
subscr.backend_extid = cust['id']
subscr.save()
except (self.stripe.error.InvalidRequestError, self.stripe.error.CardError) as e:
subscr.status = 'error'
subscr.backend_data['stripe_error'] = e.json_body['error']['message']
subscr.save()
# We don't know much about the new Payment, but we know it
# succeeded. Wekhooks aren't very reliable, so let's mark it as active
# anyway.
subscr.status = 'active'
subscr.backend_extid = cust['id']
subscr.save()
def webhook_payment_succeeded(self, event):
from payments.models import Subscription, Payment

Loading…
Cancel
Save