我有一个名为 purchase.rb 的文件,我用它来测试带有 Trustcommerce 的 Activemerchant:
需要“rubygems”需要“active_merchant”
使用 TrustCommerce 测试服务器
ActiveMerchant::Billing::Base.mode = :test amount = 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 得到: Invalid octal digit because of 027-0004842047。有人知道如何解决这个问题吗?如果我实际构建一个 Rails 应用程序而不是使用 ruby 命令运行这样的文件,会有什么不同吗?谢谢