Reply
Highlighted
Member
Posts: 1
Registered: ‎11-14-2017

Ruby on Rails Variables for Information

I keep getting errors when I try to use variables instead of inserting exact details. Here is my current code:

 


request = CreateTransactionRequest.new

@amount = session[:form_total]
request.transactionRequest = TransactionRequestType.new()
request.transactionRequest.amount = @amount
request.transactionRequest.payment = PaymentType.new
request.transactionRequest.payment.creditCard = CreditCardType.new('4111111111111111','0220','123')
request.transactionRequest.transactionType = TransactionTypeEnum::AuthCaptureTransaction

 For this example, it gives me an error that a valid amount is required. The issue is that it isn't just there. In CreditCardType.new, you'll see in this example that there are test numbers. Those work. However, if I replace them with variables, it will not work and will give me an error for that as well.

 

Any ideas? Thank you!

Highlighted
Authorize.Net Expert
Posts: 27
Registered: ‎11-22-2017

Re: Ruby on Rails Variables for Information

Hi @camerson2017,

The reason why you are getting this error is because 'amount' is not a normal variable in your case. It is an instance variable. Getting and setting instance variable is a bit different in case of ruby. The change is only reflected after it is instantiated via calling class method or while the instantiation of a class. Here's is an example:

 

class Hi
  def callme
    @hello = "hello"
  end
endh = Hi.new
p h.instance_variables 

h.callmep h.instance_variables

# Output
[]
["@hello"]

 

 

Hope this helps!