错误(状态402)(请求req_QPLfwLnwBf2OeY)您的卡资金不足

时间:2019-09-25 10:12:58

标签: ruby-on-rails-5 stripe-payments

使用Rails 5.02和Ruby 2.3,并带有Stripe gem'stripe'

我的扣款代码如下:

     begin
    # Use Stripe's library to make requests...
    charge = Stripe::Charge.create(
        :customer => 1234,
        :amount => 100, ## i.e 1$
        :description => "job payment",
        :currency => 'usd',
        capture: false,
        metadata: {'transaction' => transaction_id},
    )

    if !charge.review
      charge.capture
    end

    if charge.paid?
      @job_payment.invoice_id = transaction_id
      @job_payment.transaction_date = Time.now
      @job_payment.save
      @job.update(job_payment_status: 'paid', expiry_date: Time.now + 30.days)
      puts 'Job Payment.....'
      job_payment_done_email(@job, @job_payment.invoice_id)
    end

  rescue Stripe::CardError => e
    flash[:error] = "Insufficient funds!"
    Rails.logger.info '***********Begin Exception*********'
    Rails.logger.info e
    Rails.logger.info "Amount = " + @amount.to_s
    Rails.logger.info '***********End Exception*********'
  rescue Stripe::RateLimitError => e
    # Too many requests made to the API too quickly
    flash[:error] = "Too many requests made to the API too quickly!"
  rescue Stripe::InvalidRequestError => e
    # Invalid parameters were supplied to Stripe's API
    flash[:error] = "Invalid parameters were supplied to payment gateway!"
  rescue Stripe::AuthenticationError => e
    # Authentication with Stripe's API failed
    flash[:error] = "Payment authentication problem!"
  rescue Stripe::APIConnectionError => e
    # Network communication with Stripe failed
    flash[:error] = "Payment can not be completed due to the network problem with payment gateway!"
  rescue Stripe::StripeError => e
    # Display a very generic error to the user, and maybe send
    # yourself an email
    flash[:error] = "Something went wrong inside server while payment in stripe!"
  rescue => e
    # Something else happened, completely unrelated to Stripe
    flash[:error] = "Something went wrong inside server while payment!"
  end

由于出现以下余额不足错误而导致交易停滞:

  

(状态402)(请求req_QPLfwLnwBf2OeY)您的卡不足   资金。

相反,如果金额少于期望的金额,那么它应该告诉js自己弹出,但是在服务器端出现此错误,但是卡中已经有1000卢比的金额

0 个答案:

没有答案