Search code examples
ruby-on-railsactivemerchantoctal

Rails Activermerchant Truscommerce Capture Transid Invalid Octal Digit


I have a file named purchase.rb that I am using to test Activemerchant with Trustcommerce:

require "rubygems" require "active_merchant"

Use the TrustCommerce test servers

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}

# Validating the card automatically detects the card type

if credit_card.valid?

# Create a gateway object for the TrustCommerce service

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

# response = gateway.authorize(amount, credit_card)

# This is transid received from sandbox with authorize() ran before

   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

end

I run ruby purchase.rb on the terminal and I get: Invalid octal digit because of 027-0004842047. Anybody know how to get around this? Does it make a difference if I actually build a rails app instead of running the file like this with ruby command? Thanks


Solution

  • Stupid me...

    This solved the issue: trans_id = '027-0004842047'

    I had to treat it as a string