Show more helpful error messages w/ declined cards.
parent
e294ff90ad
commit
1ce8f0cf72
|
@ -29,7 +29,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if request.GET.declined %}
|
{% if request.GET.declined %}
|
||||||
<div class="alert alert-error" style="margin: 30px;">
|
<div class="alert alert-error" style="margin: 30px;">
|
||||||
<strong>Your card was declined.</strong> You have not been charged. Please try again.
|
<strong>{{ request.GET.declined }}</strong> You have not been charged. Please try again.
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<form class="form-horizontal static-box" id="pro-signup" method="post" action="/pro/complete/{% if 'plan' in request.GET %}?plan={{ request.GET.plan }}{% endif %}">
|
<form class="form-horizontal static-box" id="pro-signup" method="post" action="/pro/complete/{% if 'plan' in request.GET %}?plan={{ request.GET.plan }}{% endif %}">
|
||||||
|
|
10
views.py
10
views.py
|
@ -2,6 +2,7 @@ from accounts.models import UserProfile
|
||||||
from annoying.decorators import ajax_request
|
from annoying.decorators import ajax_request
|
||||||
from blogs.views import blog_list
|
from blogs.views import blog_list
|
||||||
from django.http import HttpResponseRedirect, HttpResponseBadRequest
|
from django.http import HttpResponseRedirect, HttpResponseBadRequest
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from annoying.decorators import ajax_request, render_to
|
from annoying.decorators import ajax_request, render_to
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response
|
||||||
|
@ -102,17 +103,18 @@ def pro_complete(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
|
||||||
token = request.POST['token']
|
token = request.POST['token']
|
||||||
stripe.api_key = os.environ.get('STRIPE_SECRET_KEY', '')
|
stripe.api_key = os.environ.get('STRIPE_SECRET_KEY', settings.STRIPE_SECRET_KEY)
|
||||||
|
|
||||||
|
try:
|
||||||
customer = stripe.Customer.create(email=request.user.email,
|
customer = stripe.Customer.create(email=request.user.email,
|
||||||
card=token)
|
card=token)
|
||||||
try:
|
|
||||||
stripe.Charge.create(amount=2900,
|
stripe.Charge.create(amount=2900,
|
||||||
currency='usd',
|
currency='usd',
|
||||||
customer=customer.id,
|
customer=customer.id,
|
||||||
description='Snipt.net')
|
description='Snipt.net')
|
||||||
except stripe.CardError:
|
except stripe.CardError, e:
|
||||||
return HttpResponseRedirect('/pro/?declined=true')
|
error_message = e.json_body['error']['message']
|
||||||
|
return HttpResponseRedirect('/pro/?declined=%s' % error_message or 'Your card was declined.')
|
||||||
|
|
||||||
profile = request.user.profile
|
profile = request.user.profile
|
||||||
profile.is_pro = True
|
profile.is_pro = True
|
||||||
|
|
Loading…
Reference in New Issue