Reputation: 1755
I have integrated Django with Stripe. After I submit the card details in the frontend , it gives below error
InvalidRequestError at /api/ChargeView/
As per Indian regulations, export transactions require a customer name and address. More info here: https://stripe.com/docs/india-exports
How can I ask the customers to fill the address in the checkout page ?
If the customers billing address exists, how can I pass it to checkout page ?
VIEWS.PY
class HomeView(TemplateView):
template_name = 'backend/index1.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['key'] = settings.STRIPE_PUBLISHABLE_KEY
return context
class ChargeView(TemplateView):
def post(self, request):
charge = stripe.Charge.create(
amount=100,
currency='GBP',
description='Hat purchase.',
source=request.POST['stripeToken']
)
return HttpResponse('<p>Thank you for your payment!</p>')
CHECK OUT PAGE
<form action="{% url 'payments-charge' %}" method="POST">
{% csrf_token %}
<script
src="https://checkout.stripe.com/checkout.js"
class="stripe-button"
data-key="{{ key }}"
data-description="You are purchasing: Hat from this site."
data-amount="100"
data-currency="gbp"
data-locale="auto"
></script>
</form>
The possible error location is the ChargeView section. I have installed the Stripe app with Django and configured the test keys.
Upvotes: 0
Views: 505
Reputation: 25622
The solution you're using is a legacy version of Checkout that has been deprecated well over a year ago. Stripe since then built a brand new version of Checkout which is documented here: https://stripe.com/docs/payments/checkout
That version handles a lot more features beyond simply collecting the card details, such as supporting multiple line items, 3D Secure authentication, new payment methods such as iDEAL with more coming.
You should make sure that you move to that newer version and drop Legacy Checkout as you're building a new integration.
Upvotes: 1