class TigerPayment::Response
Overview¶ ↑
The Response
object describes what happened to your Gateway
request. Let's set up a response object.
gateway = TigerPayment::Gateway.new(:username => "foo", :password => "password") response = gateway.sale( :ccnumber => '4111111111111111', :ccexp => '1010', :amount => '1.00' )
Status¶ ↑
When you get your response back from the Gateway
, you can quickly check the status using three methods; approved?
, declined?
and has_errors?
The status is completely dependent on the response code from the gateway.
if response.approved? puts "awesome" elsif response.declined? puts "someone doesn't have the cash, or the wrong card info" elsif response.has_errors? puts "there was probably a problem with the gateway or something" end
Messages¶ ↑
There are three types of messages you can get from the response; the message, the response code, and the response_code_message.
response.message response.response_code response.response_code_message
Constants
- DEFAULT_MESSAGE
- RESPONSE
- RESPONSE_CODE_MESSAGES
Attributes
message[R]
response_code[R]
transaction_id[R]
Public Class Methods
build_customers_from_xml(response_string)
click to toggle source
# File lib/tiger-payment/response.rb, line 90 def build_customers_from_xml(response_string) response = XmlSimple.xml_in(response_string) customers = Array(response['customer_vault'].first['customer']).map{|c| TigerPayment::Customer.new(c)} end
build_from_string(response_string)
click to toggle source
# File lib/tiger-payment/response.rb, line 81 def build_from_string(response_string) params = response_string.split("&").inject({}) do |hash, string_pair| key, val = string_pair.split("=") hash.merge(key.to_sym => val) end self.new(params) end
build_transactions_from_xml(response_string)
click to toggle source
# File lib/tiger-payment/response.rb, line 95 def build_transactions_from_xml(response_string) response = XmlSimple.xml_in(response_string) transactions = Array(response['transaction']).map{|t| TigerPayment::Transaction.new(t)} end
new(params)
click to toggle source
# File lib/tiger-payment/response.rb, line 103 def initialize(params) @response = params[:response] @transaction_id = params[:transactionid] @response_code = params[:response_code] @message = params[:responsetext] end
Public Instance Methods
approved?()
click to toggle source
# File lib/tiger-payment/response.rb, line 110 def approved? @response == RESPONSE[:approved] end
declined?()
click to toggle source
# File lib/tiger-payment/response.rb, line 114 def declined? @response == RESPONSE[:declined] end
has_errors?()
click to toggle source
# File lib/tiger-payment/response.rb, line 118 def has_errors? @response == RESPONSE[:errors] end
response_code_message()
click to toggle source
# File lib/tiger-payment/response.rb, line 122 def response_code_message RESPONSE_CODE_MESSAGES[@response_code] || DEFAULT_MESSAGE end