lib/active_merchant/billing/gateways/exact.rb in activemerchant-1.2.1 vs lib/active_merchant/billing/gateways/exact.rb in activemerchant-1.3.0
- old
+ new
@@ -37,15 +37,11 @@
self.supported_cardtypes = [:visa, :master, :american_express, :jcb, :discover]
self.supported_countries = ['CA', 'US']
self.homepage_url = 'http://www.e-xact.com'
self.display_name = 'E-xact'
-
- attr_reader :url
- attr_reader :response
- attr_reader :options
-
+
def initialize(options = {})
requires!(options, :login, :password)
@options = options
if TEST_LOGINS.include?( { :login => options[:login], :password => options[:password] } )
@@ -58,22 +54,14 @@
def test?
@test_mode || Base.gateway_mode == :test
end
def authorize(money, credit_card, options = {})
- if result = test_result_from_cc_number(credit_card.number)
- return result
- end
-
commit(:authorization, build_sale_or_authorization_request(money, credit_card, options))
end
def purchase(money, credit_card, options = {})
- if result = test_result_from_cc_number(credit_card.number)
- return result
- end
-
commit(:sale, build_sale_or_authorization_request(money, credit_card, options))
end
def capture(money, authorization, options = {})
commit(:capture, build_capture_or_credit_request(money, authorization, options))
@@ -174,25 +162,29 @@
def expdate(credit_card)
"#{format(credit_card.month, :two_digits)}#{format(credit_card.year, :two_digits)}"
end
def commit(action, request)
- data = ssl_post(URL, build_request(action, request), POST_HEADERS)
+ response = parse(ssl_post(URL, build_request(action, request), POST_HEADERS))
- @response = parse(data)
+ Response.new(successful?(response), message_from(response), response,
+ :test => test?,
+ :authorization => authorization_from(response),
+ :avs_result => { :code => response[:avs] },
+ :cvv_result => response[:cvv2]
+ )
+ end
- success = @response[:transaction_approved] == SUCCESS
-
- authorization = if @response[:authorization_num] && @response[:transaction_tag]
+ def successful?(response)
+ response[:transaction_approved] == SUCCESS
+ end
+
+ def authorization_from(response)
+ if response[:authorization_num] && response[:transaction_tag]
"#{response[:authorization_num]};#{response[:transaction_tag]}"
- else
+ else
''
- end
-
- Response.new(success, message_from(@response), @response,
- :test => test?,
- :authorization => authorization
- )
+ end
end
def message_from(response)
if response[:faultcode] && response[:faultstring]
response[:faultstring]