Stripe抛出无效的整数错误

时间:2017-08-02 06:31:49

标签: node.js stripe-payments payment-gateway payment payment-processing

我无法按条款收取49.99美元的金额。我正在通过以下链接,但没有锻炼

Stripe Checkout Price error - Invalid Integer

Stripe Rails: Invalid integer: 1.06

我想按原样收取金额。我不想完成付款

 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
    };

4 个答案:

答案 0 :(得分:7)

Stripe只允许价格中的整数值,因此需要将价格(金额)更改为分(* 100),所以现在您的代码金额为499,在条带sdashboard中您可以看到49.99更多详情检查链接

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

答案 1 :(得分:0)

按照stripe与rails集成的步骤进行操作:

的Gemfile

gem 'stripe'

运行

bundle install

配置/初始化/ stripe.rb

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

模型中的逻辑

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

Stripe.com -> Subscriptions -> plans

下创建计划

答案 2 :(得分:0)

您可以使用以下方法,因为它将帮助您使用十进制值作为金额并在发票和付款期间显示相同的金额。

金额:Math.round(49.99 * 100)

答案 3 :(得分:0)

Stripe 允许整数值作为价格,如果您想收取 49.99 美元,则将其乘以 100。

stripe 允许的最小价格单位是分。

599 cents = $5.99