I am testing stripe.However, I am getting an error without going to the confirmation screen.Can someone please help me?oscar/checkout/__init__.pyPAYMENT_EVENT_PURCHASE = 'Purchase'PAYMENT_METHOD_STRIPE = 'Stripe'STRIPE_EMAIL = 'stripeEmail'STRIPE_TOKEN = 'stripeToken'oscar/checkout/views.pyfrom django.conf import settingsfrom oscar.core.loading import get_modelfrom django.utils.decorators import method_decoratorfrom django.views.decorators.csrf import csrf_exemptfrom oscar.apps.checkout.views import PaymentDetailsView as CorePaymentDetailsViewfrom facade import Facadefrom . import PAYMENT_METHOD_STRIPE, PAYMENT_EVENT_PURCHASE, STRIPE_EMAIL, STRIPE_TOKENimport formsSourceType = get_model('payment', 'SourceType')Source = get_model('payment', 'Source')class PaymentDetailsView(CorePaymentDetailsView):@method_decorator(csrf_exempt)def dispatch(self, request, *args, **kwargs):return super(PaymentDetailsView, self).dispatch(request, *args, **kwargs)def get_context_data(self, **kwargs):ctx = super(PaymentDetailsView, self).get_context_data(**kwargs)if self.preview:ctx['stripe_token_form'] = forms.StripeTokenForm(self.request.POST)ctx['order_total_incl_tax_cents'] = (ctx['order_total'].incl_tax * 100).to_integral_value()else:ctx['stripe_publishable_key'] = settings.STRIPE_PUBLISHABLE_KEYreturn ctxdef handle_payment(self, order_number, total, **kwargs):stripe_ref = Facade().charge(order_number,total,card=self.request.POST[STRIPE_TOKEN],description=self.payment_description(order_number, total, **kwargs),metadata=self.payment_metadata(order_number, total, **kwargs))source_type, __ = SourceType.objects.get_or_create(name=PAYMENT_METHOD_STRIPE)source = Source(source_type=source_type,currency=settings.STRIPE_CURRENCY,amount_allocated=total.incl_tax,amount_debited=total.incl_tax,reference=stripe_ref)self.add_payment_source(source)self.add_payment_event(PAYMENT_EVENT_PURCHASE, total.incl_tax)def payment_description(self, order_number, total, **kwargs):return self.request.POST[STRIPE_EMAIL]def payment_metadata(self, order_number, total, **kwargs):return {'order_number': order_number}
oscar/checkout/facade.pyfrom django.conf import settingsfrom oscar.apps.payment.exceptions import UnableToTakePayment, InvalidGatewayRequestErrorimport stripeclass Facade(object):def __init__(self):stripe.api_key = settings.STRIPE_SECRET_KEY@staticmethoddef get_friendly_decline_message(error):return 'The transaction was declined by your bank - please check your bankcard details and try again'@staticmethoddef get_friendly_error_message(error):return 'An error occurred when communicating with the payment gateway.'def charge(self,order_number,total,card,currency=settings.STRIPE_CURRENCY,description=None,metadata=None,**kwargs):try:return stripe.Charge.create(amount=(total.incl_tax * 100).to_integral_value(),currency=currency,card=card,description=description,metadata=(metadata or {'order_number': order_number}),**kwargs).idexcept stripe.CardError as e:raise UnableToTakePayment(self.get_friendly_decline_message(e))except stripe.StripeError as e:raise InvalidGatewayRequestError(self.get_friendly_error_message(e))oscar/checkout/forms.pyfrom django import formsclass StripeTokenForm(forms.Form):stripeEmail = forms.EmailField(widget=forms.HiddenInput())stripeToken = forms.CharField(widget=forms.HiddenInput())/templates/payment_details.html{% extends 'oscar/checkout/payment_details.html' %}{% load currency_filters %}{% load i18n %}{% block title %}{% trans "Payment details" %} | {{ block.super }}{% endblock %}{% block checkout_nav %}{% include 'oscar/checkout/nav.html' with step=3 %}{% endblock %}{% block checkout_title %}{% trans "Enter payment details" %}{% endblock %}{% block order_contents %}{% endblock %}{% block shipping_address %}{% endblock %}{% block shipping_method %}{% endblock %}{% block payment_method %}{% endblock %}{% block payment_details_content %}<form action="{% url 'checkout:preview' %}" class="form-stacked" method="POST">{% csrf_token %}<script src="https://checkout.stripe.com/checkout.js" class="stripe-button" data-key="pk_test_51IPeJYLX4wZLPiB0LpxTUjtSEiLgYeaZmUkUbd1mHG62UvEY3RLB6hvkYyu1D5GA8q9wsdQCg66O11JXLJAvDi8F00GViytWtq"data-amount="{{ order_total_incl_tax_cents }}" data-name="{{ shop_name }}"data-description="{{ basket.num_items }} items ({{ order_total.incl_tax|currency }})"></script></form>{% endblock %}--
https://github.com/django-oscar/django-oscar
http://django-oscar.readthedocs.org/en/latest/
---
You received this message because you are subscribed to the Google Groups "django-oscar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-oscar...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/django-oscar/2527a46f-cda7-428b-84b0-12e720c4a2c0n%40googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/django-oscar/CAP%3D39myDCNviFwHVO3zyR4ksFhRYOyFc7CrFF8QGZXnXOGhD%2BQ%40mail.gmail.com.