Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid Parameter Error #84

Open
SaurabhBagade opened this issue Aug 13, 2021 · 2 comments
Open

Invalid Parameter Error #84

SaurabhBagade opened this issue Aug 13, 2021 · 2 comments

Comments

@SaurabhBagade
Copy link

SaurabhBagade commented Aug 13, 2021

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('/')
@Mayson90
Copy link

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.

@Mayson90
Copy link

Just find a solution...you could use testing token for visa card - "source": "tok_visa"

It will work with card number 4242424242424242 just to make sure that stripe works.

https://stripe.com/docs/testing#cards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants