lib/active_merchant/billing/gateways/linkpoint.rb in activemerchant-1.2.1 vs lib/active_merchant/billing/gateways/linkpoint.rb in activemerchant-1.3.0
- old
+ new
@@ -88,13 +88,10 @@
# IMPORTANT NOTICE:
#
# LinkPoint's Items entity is not yet supported in this module.
#
class LinkpointGateway < Gateway
- attr_reader :response
- attr_reader :options
-
# Your global PEM file. This will be assigned to you by linkpoint
#
# Example:
#
# ActiveMerchant::Billing::LinkpointGateway.pem_file = File.read( File.dirname(__FILE__) + '/../mycert.pem' )
@@ -214,50 +211,46 @@
)
commit(money, nil, options)
end
def test?
- @options[:test] || Base.gateway_mode == :test
+ @options[:test] || super
end
private
# Commit the transaction by posting the XML file to the LinkPoint server
def commit(money, creditcard, options = {})
- parameters = parameters(money, creditcard, options)
- url = test? ? TEST_URL : LIVE_URL
+ response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, post_data(money, creditcard, options)))
- if creditcard and result = test_result_from_cc_number(parameters[:creditcard][:cardnumber])
- return result
- end
-
- data = ssl_post(url, post_data(parameters))
-
- @response = parse(data)
-
- success = (@response[:approved] == "APPROVED")
- message = response[:message]
-
- Response.new(success, message, @response,
+ Response.new(successful?(response), response[:message], response,
:test => test?,
- :authorization => response[:ordernum]
+ :authorization => response[:ordernum],
+ :avs_result => { :code => response[:avs].to_s[2,1] },
+ :cvv_result => response[:avs].to_s[3,1]
)
end
+ def successful?(response)
+ response[:approved] == "APPROVED"
+ end
+
# Build the XML file
- def post_data(parameters = {})
+ def post_data(money, creditcard, options)
+ params = parameters(money, creditcard, options)
+
xml = REXML::Document.new
order = xml.add_element("order")
# Merchant Info
merchantinfo = order.add_element("merchantinfo")
merchantinfo.add_element("configfile").text = @options[:login]
- # Loop over the parameters hash to construct the XML string
- for key, value in parameters
+ # Loop over the params hash to construct the XML string
+ for key, value in params
elem = order.add_element(key.to_s)
- for k, v in parameters[key]
- elem.add_element(k.to_s).text = parameters[key][k].to_s if parameters[key][k]
+ for k, v in params[key]
+ elem.add_element(k.to_s).text = params[key][k].to_s if params[key][k]
end
# Linkpoint doesn't understand empty elements:
order.delete(elem) if elem.size == 0
end
@@ -341,10 +334,10 @@
params[:billing][:company] = billing_address[:company] unless billing_address[:company].blank?
params[:billing][:phone] = billing_address[:phone] unless billing_address[:phone].blank?
params[:billing][:email] = options[:email] unless options[:email].blank?
end
- if shipping_address = options[:shipping_address] || billing_address
+ if shipping_address = options[:shipping_address]
params[:shipping] = {}
params[:shipping][:name] = shipping_address[:name] || creditcard ? creditcard.name : nil
params[:shipping][:address1] = shipping_address[:address1] unless shipping_address[:address1].blank?
params[:shipping][:address2] = shipping_address[:address2] unless shipping_address[:address2].blank?