An error appears during the introduction of Payjp's card payment function
Payjp::InvalidRequestError This time I will do about this. (By the way, the description of api_key = ENV [~~] is an environment variable. It will be the value you set yourself.)
What is InvalidRequestError: Meaning an invalid request.
Then below that What is Missing required param to charge: What is missing_param is what appears if the required parameters are not set
That is, in this case there are no parameters required for charge. It means that · · ·
If you are used to it, you can easily solve it, but I was not sure, so if you go down as it is
Description.
Here is a review of the status code
Status code | Contents |
---|---|
100~ | Processing is ongoing |
200~ | success |
300~ | redirect |
400~ | Client side error |
500~ | Server-side error |
Strictly more detailed, but roughly like this
Isn't the client side a problem because the status code is 400 this time? I made a hypothesis. The first hypothesis is a mistake in the description of the model and url of form_with. The second hypothesis is ...
After spending a few hours, it was all useless.
There was something I had to look at from the status code.
amount: user_order_params[:price],
card: user_order_params[:token],
currency: 'jpy'
Part of. Since it is set to pay the amount set by the seller to purchase, there is no price information in this user_order_params because the amount was not directly entered and sent. This was the cause of the error.
In the feature we are implementing now, the value price is stored in a location called the items table. Therefore,
amount: user_order_params[:price],
↓
amount: @item.price,
This solved it safely.
It was the last rush, but the reason is that I am writing this article after the correction. Simply put, if you force an error statement to write an article and you don't understand the original code, you're in trouble.
Next time, I would like to make a note of the correction progress and proceed while capturing images. It was a reflection.
Recommended Posts