Class: TigerPayment::Response
- Inherits:
-
Object
- Object
- TigerPayment::Response
- Defined in:
- lib/tiger-payment/response.rb
Overview
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.
response.response_code
response.
Constant Summary collapse
- RESPONSE =
{ :approved => "1", :declined => "2", :errors => "3" }
- DEFAULT_MESSAGE =
"No Message Provided"
- RESPONSE_CODE_MESSAGES =
{ "100" => "Transaction was Approved", "200" => "Transaction was Declined by Processor", "200" => "Do Not Honor", "201" => "Insufficient Funds", "202" => "Over Limit", "203" => "Transaction not allowed", "220" => "Incorrect Payment Data", "221" => "No Such card Issuer", "222" => "No Card Number on file with Issuer", "223" => "Expired Card", "224" => "Invalid Expiration Date", "225" => "Invalid Security Code", "240" => "Call Issuer for Further Information", "250" => "Pick Up Card", "251" => "Lost Card", "252" => "Stolen Card", "253" => "Fraudulant Card", "260" => "Declined with further Instructions Available (see response text)", "261" => "Declined - Stop All Recurring Payments", "262" => "Declined - Stop this Recurring Program", "263" => "Declined - Update Cardholder Data Available", "264" => "Declined - Retry in a few days", "300" => "Transaction was Rejected by Gateway", "400" => "Transaction Error Returned by Processor", "410" => "Invalid Merchant Configuration", "411" => "Merchant Account is Inactive", "420" => "Communication Error", "421" => "Communication Error with Issuer", "430" => "Duplicate Transaction at Processor", "440" => "Processor Format Error", "441" => "Invalid Transaction Information", "460" => "Processor Feature not Available", "461" => "Unsupported Card Type" }
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#response_code ⇒ Object
readonly
Returns the value of attribute response_code.
-
#transaction_id ⇒ Object
readonly
Returns the value of attribute transaction_id.
Class Method Summary collapse
- .build_customers_from_xml(response_string) ⇒ Object
- .build_from_string(response_string) ⇒ Object
- .build_transactions_from_xml(response_string) ⇒ Object
Instance Method Summary collapse
- #approved? ⇒ Boolean
- #declined? ⇒ Boolean
- #has_errors? ⇒ Boolean
-
#initialize(params) ⇒ Response
constructor
A new instance of Response.
- #response_code_message ⇒ Object
Constructor Details
#initialize(params) ⇒ Response
Returns a new instance of Response.
103 104 105 106 107 108 |
# 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 |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
101 102 103 |
# File 'lib/tiger-payment/response.rb', line 101 def @message end |
#response_code ⇒ Object (readonly)
Returns the value of attribute response_code.
101 102 103 |
# File 'lib/tiger-payment/response.rb', line 101 def response_code @response_code end |
#transaction_id ⇒ Object (readonly)
Returns the value of attribute transaction_id.
101 102 103 |
# File 'lib/tiger-payment/response.rb', line 101 def transaction_id @transaction_id end |
Class Method Details
.build_customers_from_xml(response_string) ⇒ Object
90 91 92 93 |
# 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) ⇒ Object
81 82 83 84 85 86 87 88 |
# 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) ⇒ Object
95 96 97 98 |
# 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 |
Instance Method Details
#approved? ⇒ Boolean
110 111 112 |
# File 'lib/tiger-payment/response.rb', line 110 def approved? @response == RESPONSE[:approved] end |
#declined? ⇒ Boolean
114 115 116 |
# File 'lib/tiger-payment/response.rb', line 114 def declined? @response == RESPONSE[:declined] end |
#has_errors? ⇒ Boolean
118 119 120 |
# File 'lib/tiger-payment/response.rb', line 118 def has_errors? @response == RESPONSE[:errors] end |
#response_code_message ⇒ Object
122 123 124 |
# File 'lib/tiger-payment/response.rb', line 122 def RESPONSE_CODE_MESSAGES[@response_code] || DEFAULT_MESSAGE end |