活动商家上的条带网关不工作

Posted

技术标签:

【中文标题】活动商家上的条带网关不工作【英文标题】:Stripe Gateway on Active Merchant not working 【发布时间】:2016-09-12 09:03:22 【问题描述】:

我正在通过 Rails 4 应用程序上的 Active Merchant gem 通过 Stripe Gateway 进行付款。

我来到了这个script,并通过观看其他一些资源制作了一个类似的脚本,如下所示:

require 'active_merchant'

# Use the TrustCommerce test servers
ActiveMerchant::Billing::Base.mode = :test

gateway = ActiveMerchant::Billing::StripeGateway.new(:login => Rails.application.secrets.stripe_secret_key)

# ActiveMerchant accepts all amounts as Integer values in cents
amount = 1000  # $10.00

# The card verification value is also known as CVV2, CVC2, or CID
credit_card = ActiveMerchant::Billing::CreditCard.new(
                :first_name         => 'Bob',
                :last_name          => 'Bobsen',
                :number             => '4242424242424242',
                :month              => '8',
                :year               => Time.now.year+1,
                :verification_value => '000')

purchase_options = 
      :ip => "127.0.0.1",
      :billing_address => 
        :name     => "Ryan Bates",
        :address1 => "123 Main St.",
        :city     => "New York",
        :state    => "NY",
        :country  => "US",
        :zip      => "10001"
      
    

# Validating the card automatically detects the card type
if credit_card.validate.empty?
  # Capture $10 from the credit card
  response = gateway.purchase(amount, credit_card, purchase_options)

  if response.success?
    puts "Successfully charged $#sprintf("%.2f", amount / 100) to the credit card #credit_card.display_number"
  else
    raise StandardError, response.message
  end
end

但此脚本会生成错误并显示以下错误日志:

/Library/Ruby/Gems/2.0.0/gems/activemerchant-1.58.0/lib/active_merchant/billing/gateways/stripe.rb:469:in `rescue in api_request': uninitialized constant ActiveMerchant::Billing::StripeGateway::JSON (NameError)
        from /Library/Ruby/Gems/2.0.0/gems/activemerchant-1.58.0/lib/active_merchant/billing/gateways/stripe.rb:463:in `api_request'
        from /Library/Ruby/Gems/2.0.0/gems/activemerchant-1.58.0/lib/active_merchant/billing/gateways/stripe.rb:477:in `commit'
        from /Library/Ruby/Gems/2.0.0/gems/activemerchant-1.58.0/lib/active_merchant/billing/gateways/stripe.rb:100:in `block (2 levels) in purchase'
        from /Library/Ruby/Gems/2.0.0/gems/activemerchant-1.58.0/lib/active_merchant/billing/response.rb:59:in `process'
        from /Library/Ruby/Gems/2.0.0/gems/activemerchant-1.58.0/lib/active_merchant/billing/gateways/stripe.rb:98:in `block in purchase'
        from /Library/Ruby/Gems/2.0.0/gems/activemerchant-1.58.0/lib/active_merchant/billing/response.rb:45:in `tap'
        from /Library/Ruby/Gems/2.0.0/gems/activemerchant-1.58.0/lib/active_merchant/billing/response.rb:45:in `run'
        from /Library/Ruby/Gems/2.0.0/gems/activemerchant-1.58.0/lib/active_merchant/billing/gateways/stripe.rb:93:in `purchase'
        from stripe.rb:35:in `<main>'

您能否建议解决此错误的方法?

【问题讨论】:

你安装了stripe gem吗?有机会时发布您的 gem 文件。 嘿,谢谢...我有宝石,但不需要它。感谢您的帮助:) 感谢我的支持!随时大声笑;) 【参考方案1】:

我认为你只需要添加 require 'json'。无需将条带添加到您的 gemfile

【讨论】:

【参考方案2】:

所以它看起来像@bkunzi01 建议的一个简单的解决方法

我认为活跃的商家已经在其ActiveMerchant::Billing::StripeGateway 文件中使用了条带,但它没有。

刚刚在脚本顶部包含require 'stripe',交易成功:)

【讨论】:

以上是关于活动商家上的条带网关不工作的主要内容,如果未能解决你的问题,请参考以下文章

什么是 gem 支持多产支付网关?

如何在条带支付网关中生成令牌

如何使用 paypal / ruby​​ on rails / 活跃商家创建安全的信用卡网关

处理许多商家网关的信用卡处理库?

flowable工作流分支汇聚

为狂欢商务添加一个活跃的商家异地支付网关