使用paypal,activemerchant获取错误 - 字段比服务器允许的更长或更短

时间:2016-08-03 18:10:36

标签: ruby-on-rails ruby paypal activemerchant

我正在尝试使用activemerchet实现paypal支付网关,但是获取错误 - A字段比服务器允许更长或更短

我正在使用专业帐户的信用证。我看到了其他SO问题,但没有帮助

    require 'rubygems'
    require 'active_merchant'
    ActiveMerchant::Billing::Base.mode = :test

    gateway = ActiveMerchant::Billing::TrustCommerceGateway.new(
                :login => 'XXX@gmail.com',
                :password => 'my_password',
                :signature => 'my_signature')

    credit_card = ActiveMerchant::Billing::CreditCard.new(
                    :first_name         => 'f_name',
                    :last_name          => 'l_name',
                    :number             => '4032034467080704',
                    :month              => '9',
                    :year               => '2021',
                    :verification_value => '123',
                    :brand => 'VISA'
                    )

    AMOUNT = 1000
      def purchase_options
        {
            ip: "127.0.0.1",
            billing_address: {
                name:      "Flaying Cakes",
                address1:  "123 5th Av.",
                city:      "New York",
                state:     "NY",
                country:   "US",
                zip:       "10001"
            }
        }
      end

if credit_card.validate.empty?
    response = gateway.purchase(AMOUNT, credit_card, purchase_options)
    if response.success?
      puts "Successfully charged to the credit card #{credit_card.display_number}"
    else
       raise StandardError, response.message
    end
else
    puts "credit card is not valid #{credit_card.errors.full_messages.join(". ")}"
end

1 个答案:

答案 0 :(得分:0)

我改变了 gateway = ActiveMerchant::Billing::TrustCommerceGateway.new

gateway = ActiveMerchant::Billing::PaypalGateway.new

它工作正常。