简体   繁体   中英

Integrating Stripe on Rails 5. Error : Your card is not supported for this currency

I've installed the gem 'stripe-rails to integrate stripe into my rails project.

For some reason Stripe is constantly throwing me an error that reads "Your card is not supported for this currency." when I'm using their test cards

This is the JSON response body.

 {
  "error": {
  "message": "Your card is not supported for this currency.",
  "type": "card_error",
  "param": "number",
  "code": "card_declined",
  "decline_code": "currency_not_supported"
 }
}

My order controller.

 def create
   @order = Order.new(product_id: params[:product_id])
   @product = Product.find(params[:product_id])
   stripe_token = params[:stripeToken]
   payment_type = params[:stripeTokenType]
   customer_email = params[:stripeEmail]
   Stripe.api_key = Rails.configuration.stripe.secret_key
   Stripe::Charge.create (
   amount: @product.price* 100,
   currency:"sgd",
   source: stripe_token
   )
 end

The form to submit stripe payment.

                 <%= form_for [@product, Order.new], method: :post do %>
                  <script
                    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
                    data-key="pk_test_pTJ7JEFGxnr5gdgtDG33ZhTt"
                    data-amount=<%= @product.price * 100 %>
                    data-name="Fruit Ninja"
                    data-description="Buy <%= @product.name %>"
                    data-image="https://stripe.com/img/documentation/checkout/marketplace.png"
                    data-locale="auto">
                  </script>
                <% end %>

I've added the javascript script tag which Stripe provides in application.html.erb

   <script type="text/javascript" src="https://js.stripe.com/v2/"></script>

I've tried all the test cards but seem to be getting thrown the same error.

thanks everyone for your replies. I realized changing my country in business settings to US solved the issue. For some reason Stripe test cards do not work in Singapore. I've tried every single card including

4000007020000003

which was returning an error. The only apparent solution was changing my location. I've emailed stripe support.

Based on the Stripe docs , you'd need to use the test card 4000007020000003 if you'd like to test with SGD (Singapore Dollars). Check the "Asia-Pacific" tab there for the exact details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM