You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an issue with the card payment of stripe. So when I did according to the youtube video and tried a dummy card number. It just threw me a, 'Invalid Parameter error'. Can anyone help me with that?
Here is my PaymentView...
class PaymentView(View):
def get(self, *args, **kwargs):
return render(self.request, "payment.html")
def post(self, *args, **kwargs):
order = Order.objects.get(user=self.request.user, ordered=False)
token = self.request.POST.get('stripeToken')
amount = order.get_total()
try:
charge = stripe.Charge.create(
amount=amount,
currency="usd",
source=token,
)
payment = Payment()
payment.stripe_charge_id = charge['id']
payment.user = self.request.user
payment.amount = amount
payment.save()
order.ordered = True
order.payment = payment
order.save()
messages.success(self.request, 'Your order has been successful !')
return redirect('/')
except stripe.error.CardError as e:
# Since it's a decline, stripe.error.CardError will be caught
body = e.json_body
err = body.get('error', {})
print('Status is: %s' % e.http_status)
print('Code is: %s' % e.code)
# param is '' in this case
print('Param is: %s' % e.param)
print('Message is: %s' % e.user_message)
return redirect('/')
except stripe.error.RateLimitError as e:
# Too many requests made to the API too quickly
messages.error(self.request, 'Rate Limit Error')
return redirect('/')
except stripe.error.InvalidRequestError as e:
# Invalid parameters were supplied to Stripe's API
messages.error(self.request, 'Invalid parameters')
return redirect('/')
except stripe.error.AuthenticationError as e:
# Authentication with Stripe's API failed
# (maybe you changed API keys recently)
messages.error(self.request, 'Not authenticated')
return redirect('/')
except stripe.error.APIConnectionError as e:
# Network communication with Stripe failed
messages.error(self.request, 'Network error')
return redirect('/')
except stripe.error.StripeError as e:
# Display a very generic error to the user, and maybe send
# yourself an email
messages.error(
self.request, 'Something went wrong! Please try again !')
return redirect('/')
except Exception as e:
# Something else happened, completely unrelated to Stripe
messages.error(
self.request, 'A serious error occured! We have been notified!')
return redirect('/')
The text was updated successfully, but these errors were encountered:
I'm faced with the same error, In my case from stripe side - POST body recieved without "source".
It seems self.request.POST.get('stripeToken') not working. Something wrong in payment.html script part...if past some generic token id in source body (stripe.Charge.create) it will show in stripe logs.
I have an issue with the card payment of stripe. So when I did according to the youtube video and tried a dummy card number. It just threw me a, 'Invalid Parameter error'. Can anyone help me with that?
Here is my PaymentView...
The text was updated successfully, but these errors were encountered: