Rails Activermerchant Truscommerce捕获Transid无效的八进制数字

时间:2011-05-09 04:22:57

标签: ruby-on-rails activemerchant octal

我有一个名为purchase.rb的文件,用于通过Trustcommerce测试Activemerchant:

需要“rubygems” 需要“active_merchant”

使用TrustCommerce测试服务器

ActiveMerchant :: Billing :: Base.mode =:test     金额= 1000

credit_card = ActiveMerchant::Billing::CreditCard.new(
             :first_name         => 'againchangeD',
             :last_name          => 'Tessdsdst',
             :number             => '4242424242424242',
             :month              => '8',
             :year               => '2012',
             :verification_value => '123'

           )


billing_address = { :address1 => '9909 Down the Road',
    :city => 'San Francisco', :state => 'CA',
    :country => 'US', :zip => '23456', :phone => '(555)555-5555'}


options = {:billing_address => billing_address}

#验证卡会自动检测卡类型

if credit_card.valid?

#为TrustCommerce服务创建一个网关对象

gateway = ActiveMerchant::Billing::TrustCommerceGateway.new(
           :login => "xxxxxx",
           :password => "xxxxxx"
         )

#response = gateway.authorize(amount,credit_card)

#这是从沙盒收到的transid,其中authorize()在

之前运行
   trans_id = 027-0004842047
   response = gateway.capture(amount,trans_id)


   if response.success?
       good = 'yes'
   puts "Successful #{good}"
   else
       puts "NO"
       raise StandardError, response.message
   end

我在终端上运行ruby purchase.rb,得到:因为027-0004842047,无效的八进制数字。谁知道怎么解决这个问题?如果我实际构建一个rails应用程序而不是使用ruby命令运行这样的文件,它会有所不同吗?感谢

1 个答案:

答案 0 :(得分:0)

愚蠢的我......

这解决了这个问题: trans_id ='027-0004842047'

我不得不将其视为字符串