Stripe API issue in Ruby

30 views Asked by At

I get the following error when I use the Stripe API for Rails.

enter image description here

The error occurs when:

  • I use the token with parameters,
  • I directly create the map without parameters in Rails console. The code only worked when I used the code below. -
Stripe.api_key = 'sk_test_51OxaxrHv50QCG0VIMSQ1gFDxuQpV5V2T2qsGb2GklU4Fq2WJszkD2Tq0z9zVI6ZL.....'
Stripe::Token.create({
  card: {
    number: '4242424242424242',
    exp_month: '5',
    exp_year: '2024',
    cvc: '314',
  },
})

I have used the following function to create a map with parameters. -

  def create_card_token(params)
    Stripe::Token.create({
      card: {
        number: params[:card_number].to_s,
        exp_month: params[:exp_month].to_s,
        exp_year: params[:exp_year].to_s,
        cvc: params[:cvc].to_s,
      },
    })
  end

Can anyone help me fix this error or tell me where I am going wrong with my code.

1

There are 1 answers

0
hanzo On

As you can see from the support URL shared in the error: https://support.stripe.com/questions/enabling-access-to-raw-card-data-apis Sending RAW PAN (card data) to Stripe APIs has additional requirements and requires approval from Stripe.

If your account is already approved to send raw card details then you'd likely want to check if your Stripe instance is using the correct API key when you make the API call by setting card details from params

Alternatively, a better approach to storing payment methods is to use SetupIntents API as recommended here: https://docs.stripe.com/payments/save-and-reuse