added downgrades & upgrades
This commit is contained in:
@@ -72,6 +72,11 @@
|
|||||||
|
|
||||||
<input type="hidden" id="nonce" name="payment_method_nonce" />
|
<input type="hidden" id="nonce" name="payment_method_nonce" />
|
||||||
<input type="hidden" id="plan" name="plan" value="{{ plan.id }}">
|
<input type="hidden" id="plan" name="plan" value="{{ plan.id }}">
|
||||||
|
<p>
|
||||||
|
<input id="tac" type="checkbox" name="tac" value="tac">I have taken note of the
|
||||||
|
<a href="/rowers/legal/#refunds" target="_blank">Refund and Cancellation</a>
|
||||||
|
Policy and agree with the <a href="/rowers/legal/" target="_blank">Terms of Service</a>.
|
||||||
|
</p>
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<button type="submit" id="submit-button"><span>Downgrade to the € {{ plan.price|currency }} plan</span></button>
|
<button type="submit" id="submit-button"><span>Downgrade to the € {{ plan.price|currency }} plan</span></button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -93,6 +93,11 @@
|
|||||||
|
|
||||||
<input type="hidden" id="nonce" name="payment_method_nonce" />
|
<input type="hidden" id="nonce" name="payment_method_nonce" />
|
||||||
<input type="hidden" id="plan" name="plan" value="{{ plan.id }}">
|
<input type="hidden" id="plan" name="plan" value="{{ plan.id }}">
|
||||||
|
<p>
|
||||||
|
<input id="tac" type="checkbox" name="tac" value="tac">I have taken note of the
|
||||||
|
<a href="/rowers/legal/#refunds" target="_blank">Refund and Cancellation</a>
|
||||||
|
Policy and agree with the <a href="/rowers/legal/" target="_blank">Terms of Service</a>.
|
||||||
|
</p>
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<button type="submit" id="submit-button"><span>Upgrade to the € {{ plan.price|currency }} plan</span></button>
|
<button type="submit" id="submit-button"><span>Upgrade to the € {{ plan.price|currency }} plan</span></button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -366,6 +366,7 @@ class PaymentTest(TestCase):
|
|||||||
'amount':'15.00',
|
'amount':'15.00',
|
||||||
'plan': plans[1].id,
|
'plan': plans[1].id,
|
||||||
'payment_method_nonce': 'aap',
|
'payment_method_nonce': 'aap',
|
||||||
|
'tac':'tac',
|
||||||
}
|
}
|
||||||
|
|
||||||
form = BillingForm(form_data)
|
form = BillingForm(form_data)
|
||||||
@@ -410,6 +411,7 @@ class PaymentTest(TestCase):
|
|||||||
'amount':'15.00',
|
'amount':'15.00',
|
||||||
'plan': plans[1].id,
|
'plan': plans[1].id,
|
||||||
'payment_method_nonce': 'aap',
|
'payment_method_nonce': 'aap',
|
||||||
|
'tac':'tac',
|
||||||
}
|
}
|
||||||
|
|
||||||
form = BillingForm(form_data)
|
form = BillingForm(form_data)
|
||||||
@@ -453,6 +455,7 @@ class PaymentTest(TestCase):
|
|||||||
'amount':'15.00',
|
'amount':'15.00',
|
||||||
'plan': plans[1].id,
|
'plan': plans[1].id,
|
||||||
'payment_method_nonce': 'aap',
|
'payment_method_nonce': 'aap',
|
||||||
|
'tac':'tac',
|
||||||
}
|
}
|
||||||
|
|
||||||
form = BillingForm(form_data)
|
form = BillingForm(form_data)
|
||||||
@@ -470,3 +473,136 @@ class PaymentTest(TestCase):
|
|||||||
expected_url = '/rowers/downgradecompleted/',
|
expected_url = '/rowers/downgradecompleted/',
|
||||||
status_code=302,target_status_code=200)
|
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)
|
||||||
|
|
||||||
|
|||||||
@@ -316,7 +316,6 @@ def checkouts_view(request):
|
|||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
form = BillingForm(request.POST)
|
form = BillingForm(request.POST)
|
||||||
print request.POST
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
data = form.cleaned_data
|
data = form.cleaned_data
|
||||||
success,amount = braintreestuff.create_subscription(r,data)
|
success,amount = braintreestuff.create_subscription(r,data)
|
||||||
@@ -333,7 +332,7 @@ def checkouts_view(request):
|
|||||||
elif 'tac' not in request.POST:
|
elif 'tac' not in request.POST:
|
||||||
try:
|
try:
|
||||||
planid = int(request.POST['plan'])
|
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")
|
messages.error(request,"You must review and acknowledge the terms and conditions")
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@@ -376,6 +375,16 @@ def upgrade_checkouts_view(request):
|
|||||||
url = reverse(upgrade_view)
|
url = reverse(upgrade_view)
|
||||||
return HttpResponseRedirect(url)
|
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:
|
else:
|
||||||
messages.error(request,"There was an error in the payment form")
|
messages.error(request,"There was an error in the payment form")
|
||||||
url = reverse(upgrade_view)
|
url = reverse(upgrade_view)
|
||||||
@@ -409,6 +418,16 @@ def downgrade_checkouts_view(request):
|
|||||||
messages.error(request,"There was a problem with your transaction")
|
messages.error(request,"There was a problem with your transaction")
|
||||||
url = reverse(upgrade_view)
|
url = reverse(upgrade_view)
|
||||||
return HttpResponseRedirect(url)
|
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:
|
else:
|
||||||
messages.error(request,"There was an error in the payment form")
|
messages.error(request,"There was an error in the payment form")
|
||||||
|
|||||||
Reference in New Issue
Block a user