Stripe throws invalid integer error

时间秒杀一切 提交于 2019-12-13 15:01:42

问题


I am unable to charge the amount $49.99 in stripe. I am going through the following links but nothing workout

Stripe Checkout Price error - Invalid Integer

Stripe Rails: Invalid integer: 1.06

I would like to charge the amount as it is. I don't want to round off the payment

 stripe.charges.create({
    // Charge the customer in stripe
// amount: req.query.amount,
    amount: 49.99,
    currency: 'usd',
    customer: req.customer
  }).then(function(charge) {
    // Use and save the charge info in our db
    var successTransaction = {
      stripeId: charge.customer,
      transactionId: charge.id,
      amount: charge.amount,
      currency: charge.currency,
      message: charge.outcome.seller_message,
      paidStatus: charge.paid,
      summary: charge
    };

回答1:


Stripe allow only integer value in price so need to change your price (amount) into cent by (*100 ) so now your code amount is 499 and in stripe sdashboard you see the 49.99 for more details check the link :

https://stripe.com/docs/api#charges




回答2:


Follow steps for stripe integration with rails:

Gemfile

gem 'stripe'

run

bundle install

config/initializer/stripe.rb

Rails.configuration.stripe = {
    :publishable_key => "paste_stripe_key",
    :secret_key      => "paste_stripe_secret"
}

Logic in model

def self.process_stripe_payment(params, email)
    amt = sprintf('%.2f', params[:total_amount])
    plan = "plan_#{amt}"
    card_token = Stripe::Token.create( :card => {
        :name => params[:card_name],
        :number => params[:card_number],
        :exp_month => params[:exp_month],
        :exp_year => params[:exp_year],
        :cvc => params[:card_cvv] })

    customer_params = {:card => card_token[:id], :plan => plan, :email => email}

    stripe_customer = Stripe::Customer.create(customer_params)
    return true
  end

create plans under Stripe.com -> Subscriptions -> plans



来源:https://stackoverflow.com/questions/45453090/stripe-throws-invalid-integer-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!