[RUBY] About Invalid Request Error in Payjp

An error appears during the introduction of Payjp's card payment function

Image from Gyazo

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.)

First, grasp the content of the error

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

Image from Gyazo

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.

Cause

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.

Solution

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.

At the end

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

About Invalid Request Error in Payjp
About the error message Invalid redeclaration of'***'
About No Method Error
About eval in Ruby
Invalid route name, already in use: Error resolution for'new_user_session'
Error handling in Graphql-ruby
About redirect_to in form_with
About docker.credentials.errors.StoreErrorTraceback in wsl2
[PAY.JP] About setting environment variables-Courage to delete when in trouble-
Fixed NVIDIA Docker related signature invalid error in apt update
Avoid Yubaba's error in Java
NameError in Income # index error
About validation methods in JUnit
About Spring Framework context error
ActiveRecord :: NotNullViolation in Devise error
About regular expressions in Ruby
Error in rails db: migrate
npm error in docker tutorial
Error in Spring database connection
About abstract classes in java