活跃商户上的 Stripe Gateway 不工作
Stripe Gateway on Active Merchant not working
我正在 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 # .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 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>'
你能建议解决此错误的方法吗?
所以它看起来像是@bkunzi01
建议的简单解决方法
我认为活跃的商家已经在其 ActiveMerchant::Billing::StripeGateway
文件中使用了条纹,但事实并非如此。
刚刚在脚本顶部包含 require 'stripe'
,交易成功:)
我想你只需要添加 require 'json'。无需将 strip 添加到您的 gemfile
我正在 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 # .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 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>'
你能建议解决此错误的方法吗?
所以它看起来像是@bkunzi01
建议的简单解决方法我认为活跃的商家已经在其 ActiveMerchant::Billing::StripeGateway
文件中使用了条纹,但事实并非如此。
刚刚在脚本顶部包含 require 'stripe'
,交易成功:)
我想你只需要添加 require 'json'。无需将 strip 添加到您的 gemfile