Issue
Below is my setup of stripe in Django ,
view.py
def charge(request):
if request.method == 'POST' :
resp = " Payment Successful !"
try:
token = request.POST['stripeToken']
charge = stripe.Charge.create(
amount=2000, # amount in cents, again
currency="usd",
source=token,
description="Example charge"
)
print >>sys.stderr, 'Success Logger !'
except stripe.error.CardError as e:
resp = str(e)
urls.py
urlpatterns = patterns('',
url(r'^$', views.home, name='home'),
url(r'^sign_in$', views.sign_in, name='sign_in'),
url(r'^sign_out$', views.sign_out, name='sign_out'),
url(r'^register$', views.register, name='register'),
url(r'^edit$', views.edit, name='edit'),
url(r'^charge$', views.charge, name='charge'),
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
)
user.html
{% extends "page.html" %}
{% block main %}
<div class="row">
<div class="span6 columns">
</div>
</div>
<p>Welcome {{ user.name }}.</p>
<p>Your credit card ends with {{ user.last_4_digits }} (<a href="{% url edit %}">change</a>)</p>
<form action="/charge" method="POST" id="payment_form">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_xFLF8rLaykv0tiGXFkhMj5XF"
data-amount="2000"
data-name="Vevanesca"
data-description="2 widgets ($20.00)"
data-image="/128x128.png"
data-locale="auto">
</script>
</form>
{% endblock %}
I'm using the default checkout.js provided by stripe . Once the payment overlay pops up, I type in the test details . Next thing, after a few second it redirects to /charge
with an Error 403 Forbidden CSRF verification failed. Request aborted
.
How can I resolve this ? I just want to setup a simple test gateway using stripe .
Solution
For a quick and dirty fix, just remove 'django.middleware.csrf.CsrfViewMiddleware'
from the MIDDLEWARE_CLASSES
entry in settings.py
.
See https://docs.djangoproject.com/en/1.9/ref/csrf/ for more info.
Answered By - John Gordon
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.