From 319ce56e07bd2cd48a510cfd1a20d60831689270 Mon Sep 17 00:00:00 2001 From: Sander Roosendaal Date: Fri, 8 Feb 2019 12:39:31 +0100 Subject: [PATCH] added downgrades & upgrades --- rowers/templates/downgradeconfirm.html | 5 + rowers/templates/upgradeconfirm.html | 5 + rowers/tests/test_payments.py | 136 +++++++++++++++++++++++++ rowers/views/paymentviews.py | 23 ++++- 4 files changed, 167 insertions(+), 2 deletions(-) diff --git a/rowers/templates/downgradeconfirm.html b/rowers/templates/downgradeconfirm.html index 1e027c34..4b76a6d9 100644 --- a/rowers/templates/downgradeconfirm.html +++ b/rowers/templates/downgradeconfirm.html @@ -72,6 +72,11 @@ +

+ I have taken note of the + Refund and Cancellation + Policy and agree with the Terms of Service. +

{% csrf_token %} diff --git a/rowers/templates/upgradeconfirm.html b/rowers/templates/upgradeconfirm.html index 2427117a..e3b0aa98 100644 --- a/rowers/templates/upgradeconfirm.html +++ b/rowers/templates/upgradeconfirm.html @@ -93,6 +93,11 @@ +

+ I have taken note of the + Refund and Cancellation + Policy and agree with the Terms of Service. +

{% csrf_token %} diff --git a/rowers/tests/test_payments.py b/rowers/tests/test_payments.py index 61a9e5c6..794416d5 100644 --- a/rowers/tests/test_payments.py +++ b/rowers/tests/test_payments.py @@ -366,6 +366,7 @@ class PaymentTest(TestCase): 'amount':'15.00', 'plan': plans[1].id, 'payment_method_nonce': 'aap', + 'tac':'tac', } form = BillingForm(form_data) @@ -410,6 +411,7 @@ class PaymentTest(TestCase): 'amount':'15.00', 'plan': plans[1].id, 'payment_method_nonce': 'aap', + 'tac':'tac', } form = BillingForm(form_data) @@ -453,6 +455,7 @@ class PaymentTest(TestCase): 'amount':'15.00', 'plan': plans[1].id, 'payment_method_nonce': 'aap', + 'tac':'tac', } form = BillingForm(form_data) @@ -470,3 +473,136 @@ class PaymentTest(TestCase): expected_url = '/rowers/downgradecompleted/', status_code=302,target_status_code=200) + @patch('rowers.views.braintreestuff.create_subscription', side_effect=mock_create_subscription) + def test_checkouts_view(self,mock_subscription): + u = UserFactory() + r = Rower.objects.create(user=u, + birthdate=faker.profile()['birthdate'], + gdproptin=True, + gdproptindate=timezone.now(), + rowerplan='coach', + paymentprocessor='braintree', + street_address = faker.street_address(), + city = faker.city(), + postal_code = faker.postalcode(), + country = faker.country(), + ) + + r.save() + u.set_password(self.password) + u.save() + + plans = PaidPlan.objects.all().order_by('price') + plan = plans[1] + + form_data = { + 'amount':'15.00', + 'plan': plans[1].id, + 'payment_method_nonce': 'aap', + } + + + login = self.c.login(username=u.username, password=self.password) + self.assertTrue(login) + + url = '/rowers/checkouts/' + + response = self.c.post(url, form_data,follow=True) + self.assertEqual(response.status_code,200) + + self.assertRedirects(response, + expected_url = '/rowers/checkout/{planid}'.format( + planid=plans[1].id), + status_code=302,target_status_code=200) + + + @patch('rowers.views.braintreestuff.update_subscription', side_effect=mock_update_subscription) + def test_upgrade_checkouts_view(self,mock_subscription): + u = UserFactory() + r = Rower.objects.create(user=u, + birthdate=faker.profile()['birthdate'], + gdproptin=True, + gdproptindate=timezone.now(), + rowerplan='coach', + paymentprocessor='braintree', + street_address = faker.street_address(), + city = faker.city(), + postal_code = faker.postalcode(), + country = faker.country(), + ) + + r.save() + u.set_password(self.password) + u.save() + + plans = PaidPlan.objects.all().order_by('price') + plan = plans[1] + + form_data = { + 'amount':'15.00', + 'plan': plans[1].id, + 'payment_method_nonce': 'aap', + # 'tac':'tac', + } + + form = BillingForm(form_data) + self.assertTrue(form.is_valid()) + + login = self.c.login(username=u.username, password=self.password) + self.assertTrue(login) + + url = '/rowers/upgradecheckouts/' + + response = self.c.post(url, form_data,follow=True) + self.assertEqual(response.status_code,200) + + self.assertRedirects(response, + expected_url = '/rowers/upgradecheckout/{planid}'.format( + planid=plans[1].id), + status_code=302,target_status_code=200) + + @patch('rowers.views.braintreestuff.update_subscription', side_effect=mock_update_subscription) + def test_downgrade_checkouts_view(self,mock_subscription): + u = UserFactory() + r = Rower.objects.create(user=u, + birthdate=faker.profile()['birthdate'], + gdproptin=True, + gdproptindate=timezone.now(), + rowerplan='coach', + paymentprocessor='braintree', + street_address = faker.street_address(), + city = faker.city(), + postal_code = faker.postalcode(), + country = faker.country(), + ) + + r.save() + u.set_password(self.password) + u.save() + + plans = PaidPlan.objects.all().order_by('price') + plan = plans[1] + + form_data = { + 'amount':'15.00', + 'plan': plans[1].id, + 'payment_method_nonce': 'aap', + # 'tac':'tac', + } + + form = BillingForm(form_data) + self.assertTrue(form.is_valid()) + + login = self.c.login(username=u.username, password=self.password) + self.assertTrue(login) + + url = '/rowers/downgradecheckouts/' + + response = self.c.post(url, form_data,follow=True) + self.assertEqual(response.status_code,200) + + self.assertRedirects(response, + expected_url = '/rowers/downgradecheckout/{planid}'.format( + planid=plans[1].id), + status_code=302,target_status_code=200) + diff --git a/rowers/views/paymentviews.py b/rowers/views/paymentviews.py index 5183ca27..2f680fe6 100644 --- a/rowers/views/paymentviews.py +++ b/rowers/views/paymentviews.py @@ -316,7 +316,6 @@ def checkouts_view(request): return HttpResponseRedirect(url) form = BillingForm(request.POST) - print request.POST if form.is_valid(): data = form.cleaned_data success,amount = braintreestuff.create_subscription(r,data) @@ -333,7 +332,7 @@ def checkouts_view(request): elif 'tac' not in request.POST: try: planid = int(request.POST['plan']) - url = reverse('payment_confirm_view',kwargs={'planid':planid}) + url = reverse('downgrade_confirm_view',kwargs={'planid':planid}) messages.error(request,"You must review and acknowledge the terms and conditions") return HttpResponseRedirect(url) except IndexError: @@ -376,6 +375,16 @@ def upgrade_checkouts_view(request): url = reverse(upgrade_view) return HttpResponseRedirect(url) + elif 'tac' not in request.POST: + try: + planid = int(request.POST['plan']) + url = reverse('upgrade_confirm_view',kwargs={'planid':planid}) + messages.error(request,"You must review and acknowledge the terms and conditions") + return HttpResponseRedirect(url) + except IndexError: + messages.error(request,"There was an error in the payment form") + url = reverse('billing_view') + return HttpResponseRedirect(url) else: messages.error(request,"There was an error in the payment form") url = reverse(upgrade_view) @@ -409,6 +418,16 @@ def downgrade_checkouts_view(request): messages.error(request,"There was a problem with your transaction") url = reverse(upgrade_view) return HttpResponseRedirect(url) + elif 'tac' not in request.POST: + try: + planid = int(request.POST['plan']) + url = reverse('payment_confirm_view',kwargs={'planid':planid}) + messages.error(request,"You must review and acknowledge the terms and conditions") + return HttpResponseRedirect(url) + except IndexError: + messages.error(request,"There was an error in the payment form") + url = reverse('billing_view') + return HttpResponseRedirect(url) else: messages.error(request,"There was an error in the payment form")