Class: ActiveTiger::Response
- Inherits:
-
Object
- Object
- ActiveTiger::Response
- Defined in:
- lib/activetiger/response.rb
Overview
Overview
The Response object describes what happened to your Gateway request. Let’s set up a response object.
gateway = ActiveTiger::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
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.
93 94 95 96 97 98 |
# File 'lib/activetiger/response.rb', line 93 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.
91 92 93 |
# File 'lib/activetiger/response.rb', line 91 def @message end |
#response_code ⇒ Object (readonly)
Returns the value of attribute response_code.
91 92 93 |
# File 'lib/activetiger/response.rb', line 91 def response_code @response_code end |
#transaction_id ⇒ Object (readonly)
Returns the value of attribute transaction_id.
91 92 93 |
# File 'lib/activetiger/response.rb', line 91 def transaction_id @transaction_id end |
Class Method Details
.build_from_string(response_string) ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/activetiger/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 |
Instance Method Details
#approved? ⇒ Boolean
100 101 102 |
# File 'lib/activetiger/response.rb', line 100 def approved? @response == RESPONSE[:approved] end |
#declined? ⇒ Boolean
104 105 106 |
# File 'lib/activetiger/response.rb', line 104 def declined? @response == RESPONSE[:declined] end |
#has_errors? ⇒ Boolean
108 109 110 |
# File 'lib/activetiger/response.rb', line 108 def has_errors? @response == RESPONSE[:errors] end |
#response_code_message ⇒ Object
112 113 114 |
# File 'lib/activetiger/response.rb', line 112 def RESPONSE_CODE_MESSAGES[@response_code] || DEFAULT_MESSAGE end |