lib/active_merchant/billing/gateways/linkpoint.rb in activemerchant-1.0.3 vs lib/active_merchant/billing/gateways/linkpoint.rb in activemerchant-1.1.0
- old
+ new
@@ -125,25 +125,27 @@
#
cattr_accessor :pem_file
TEST_URL = 'https://staging.linkpt.net:1129/'
LIVE_URL = 'https://secure.linkpt.net:1129/'
+
+ # We don't have the certificate to verify LinkPoint
+ self.ssl_strict = false
# @options = {
# :store_number => options[:login],
# :result => test? ? "GOOD" : "LIVE"
# }.update(options)
def initialize(options = {})
requires!(options, :login)
@options = {
- :result => 'LIVE'
+ :result => 'LIVE',
+ :pem => LinkpointGateway.pem_file
}.update(options)
- @pem = @options[:pem] || LinkpointGateway.pem_file
-
- raise ArgumentError, "You need to pass in your pem file using the :pem parameter or set it globally using ActiveMerchant::Billing::LinkpointGateway.pem_file = File.read( File.dirname(__FILE__) + '/../mycert.pem' ) or similar" if @pem.nil?
+ raise ArgumentError, "You need to pass in your pem file using the :pem parameter or set it globally using ActiveMerchant::Billing::LinkpointGateway.pem_file = File.read( File.dirname(__FILE__) + '/../mycert.pem' ) or similar" if @options[:pem].blank?
end
# Send a purchase request with periodic options
# Recurring Options
# :action =>
@@ -243,20 +245,20 @@
def test?
@options[:test] || Base.gateway_mode == :test
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
if creditcard and result = test_result_from_cc_number(parameters[:creditcard][:cardnumber])
return result
end
- data = ssl_post post_data(parameters)
+ data = ssl_post(url, post_data(parameters))
@response = parse(data)
success = (@response[:approved] == "APPROVED")
message = response[:message]
@@ -286,11 +288,11 @@
order.delete(elem) if elem.size == 0
end
return xml.to_s
end
-
+
# Set up the parameters hash just once so we don't have to do it
# for every action.
def parameters(money, creditcard, options = {})
params = {
@@ -405,26 +407,9 @@
xml.root.elements.each do |node|
response[node.name.downcase.sub(/^r_/, '').to_sym] = normalize(node.text)
end unless xml.root.nil?
response
- end
-
- # Redefine ssl_post to use our PEM file
- def ssl_post(data)
-
- raise "PEM file invalid or missing!" unless @pem =~ %r{RSA.*CERTIFICATE}m
-
- uri = URI.parse(test? ? TEST_URL : LIVE_URL)
-
- http = Net::HTTP.new(uri.host, uri.port)
-
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless @ssl_strict
- http.use_ssl = true
- http.cert = OpenSSL::X509::Certificate.new(@pem)
- http.key = OpenSSL::PKey::RSA.new(@pem)
-
- http.post(uri.path, data).body
end
# Make a ruby type out of the response string
def normalize(field)
case field