0

Я работал над платежами через Stripe Gateway через Active Merchant gem в приложении Rails 4.Stripe Gateway on Active Merchant не работает

Я пришел по этому 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>' 

Может вы предлагаете обходной путь для этой ошибки?

+1

У вас есть установленный полосовой жемчуг? Отправьте свой файл gem, когда получите шанс. – bkunzi01

+0

эй, спасибо ... у меня был драгоценный камень, но он не требовал этого. спасибо за помощь :) – srishabh

+0

Спасибо, upvote! lol в любое время;) – bkunzi01

ответ

0

так это выглядит как простой обходной путь, как предложил @ bkunzi01

я думал, что активный торговец уже используется полоса в файле ActiveMerchant::Billing::StripeGateway, но это не так.

просто включен require 'stripe' в верхней части сценария и транзакция прошла успешно :)

0

Я думаю, вам просто нужно добавить требуют «» JSON. нет необходимости добавлять полоску в свой gemfile