class RocketGate::Response
Attributes
response_code[RW]
xml_document[RW]
Public Class Methods
from_xml(xml)
click to toggle source
# File lib/rocketgate/response.rb, line 7 def self.from_xml(xml) response = self.new.tap do |r| r.xml_document = Nokogiri.parse(xml) r.build! end end
Public Instance Methods
build!()
click to toggle source
# File lib/rocketgate/response.rb, line 14 def build! @response_code = RocketGate::ResponseCode::RESPONSE[find_value('responseCode')] card_type = RocketGate::ResponseCode::CARD_TYPE[find_value('cardDebitCredit')] pay_type = find_value('payType').downcase.to_sym rescue :credit @authorization = RocketGate::Authorization.new.tap do |auth| auth.avs_response = RocketGate::ResponseCode::AVS[find_value('avsResponse')] auth.cvv_response = RocketGate::ResponseCode::CVV[find_value('cvv2Code')] auth.reason_code = RocketGate::ResponseCode::REASON[find_value('reasonCode')] auth.card_type = card_type || pay_type auth.issuer_network = RocketGate::ResponseCode::CARD_BRAND[find_value('cardType')] auth.issuer_name = find_value('cardIssuerName') auth.issuer_phone = find_value('cardIssuerPhone') auth.issuer_url = find_value('cardIssuerURL') auth.auth_code = find_value('authNo') auth.reference_id = find_value('guidNo') auth.approved_amount = find_value('approvedAmount').to_f auth.approved_currency = find_value('approvedCurrency') auth.customer_id = find_value('merchantCustomerID') auth.card_hash = find_value('cardHash') auth.card_expiration = find_value('cardExpiration') auth.card_last_four = find_value('cardLastFour') auth.card_description = find_value('cardDescription') auth.card_country = find_value('cardCountry') end end
confirm!()
click to toggle source
# File lib/rocketgate/response.rb, line 45 def confirm! if success? confirmation = RocketGate::Transaction.new.tap do |tx| tx.reference_id = self.authorization.reference_id tx.type = RocketGate::Transaction::TYPE[:confirmation] end confirmation_response = RocketGate.send_request!(RocketGate::Request.new(confirmation)) if confirmation_response.success? return self # return self instead of the empty confirmation response else raise RocketGate::AuthorizationError.new("Unable to confirm transaction: #{confirmation_response.response_code}") end else raise RocketGate::AuthorizationError.new('Unable to confirm unauthorized transaction') end end
success?()
click to toggle source
# File lib/rocketgate/response.rb, line 67 def success? authorized? && response_code == :success end
Private Instance Methods
find_value(key)
click to toggle source
# File lib/rocketgate/response.rb, line 73 def find_value(key) nodes = xml_document.at('gatewayResponse') if nodes && nodes.children element = nodes % key element.content if element else raise RocketGate::GatewayResponseError.new('Unexpected response format') end end