Skip to content

Commit

Permalink
Clean up rake gateways:hosts output
Browse files Browse the repository at this point in the history
  • Loading branch information
ntalbott committed Feb 25, 2015
1 parent f979e18 commit 389477e
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 84 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,5 +1,7 @@
= ActiveMerchant CHANGELOG

* Clean up `rake gateways:hosts` output [ntalbott]

== Version 1.47.0 (February 25, 2015)

* Authorize.Net: Properly send name in shipping address line, when shipping address is provided [girasquid]
Expand Down
14 changes: 13 additions & 1 deletion Rakefile
Expand Up @@ -76,7 +76,19 @@ namespace :gateways do

desc 'Print the list of destination hosts with port'
task :hosts do
OutboundHosts.list
hosts, invalid_lines = OutboundHosts.list

hosts.each do |host|
puts host
end

unless invalid_lines.empty?
puts
puts "Unable to parse:"
invalid_lines.each do |line|
puts line
end
end
end

desc 'Test that gateways allow SSL verify_peer'
Expand Down
17 changes: 8 additions & 9 deletions lib/active_merchant/billing/gateways/epay.rb
@@ -1,8 +1,7 @@
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class EpayGateway < Gateway
API_HOST = 'ssl.ditonlinebetalingssystem.dk'
self.live_url = 'https://' + API_HOST + '/remote/payment'
self.live_url = 'https://ssl.ditonlinebetalingssystem.dk/'

self.default_currency = 'DKK'
self.money_format = :cents
Expand Down Expand Up @@ -175,14 +174,14 @@ def messages(epay, pbs = nil)
def soap_post(method, params)
data = xml_builder(params, method)
headers = make_headers(data, method)
REXML::Document.new(ssl_post('https://' + API_HOST + '/remote/payment.asmx', data, headers))
REXML::Document.new(ssl_post(live_url + 'remote/payment.asmx', data, headers))
end

def do_authorize(params)
headers = {}
headers['Referer'] = (options[:password] || "activemerchant.org")

response = raw_ssl_request(:post, 'https://' + API_HOST + '/auth/default.aspx', authorize_post_data(params), headers)
response = raw_ssl_request(:post, live_url + 'auth/default.aspx', authorize_post_data(params), headers)

# Authorize gives the response back by redirecting with the values in
# the URL query
Expand Down Expand Up @@ -233,9 +232,9 @@ def do_void(params)
def make_headers(data, soap_call)
{
'Content-Type' => 'text/xml; charset=utf-8',
'Host' => API_HOST,
'Host' => "ssl.ditonlinebetalingssystem.dk",
'Content-Length' => data.size.to_s,
'SOAPAction' => self.live_url + '/' + soap_call
'SOAPAction' => self.live_url + 'remote/payment/' + soap_call
}
end

Expand All @@ -246,7 +245,7 @@ def xml_builder(params, soap_call)
'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
'xmlns:soap' => 'http://schemas.xmlsoap.org/soap/envelope/' } do
xml.tag! 'soap:Body' do
xml.tag! soap_call, { 'xmlns' => self.live_url } do
xml.tag! soap_call, { 'xmlns' => "#{self.live_url}remote/payment" } do
xml.tag! 'merchantnumber', @options[:login]
xml.tag! 'transactionid', params[:transaction]
xml.tag! 'amount', params[:amount].to_s if soap_call != 'delete'
Expand All @@ -259,8 +258,8 @@ def xml_builder(params, soap_call)
def authorize_post_data(params = {})
params[:language] = '2'
params[:cms] = 'activemerchant'
params[:accepturl] = 'https://ssl.ditonlinebetalingssystem.dk/auth/default.aspx?accept=1'
params[:declineurl] = 'https://ssl.ditonlinebetalingssystem.dk/auth/default.aspx?decline=1'
params[:accepturl] = live_url + 'auth/default.aspx?accept=1'
params[:declineurl] = live_url + 'auth/default.aspx?decline=1'
params[:merchantnumber] = @options[:login]

params.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
Expand Down
2 changes: 1 addition & 1 deletion lib/active_merchant/billing/gateways/iridium.rb
Expand Up @@ -366,7 +366,7 @@ def add_merchant_data(xml, options)
def commit(request, options)
requires!(options, :action)
response = parse(ssl_post(test? ? self.test_url : self.live_url, request,
{"SOAPAction" => "https://www.thepaymentgateway.net/#{options[:action]}",
{"SOAPAction" => "https://www.thepaymentgateway.net/" + options[:action],
"Content-Type" => "text/xml; charset=utf-8" }))

success = response[:transaction_result][:status_code] == "0"
Expand Down
5 changes: 3 additions & 2 deletions lib/active_merchant/billing/gateways/paymill.rb
Expand Up @@ -10,6 +10,7 @@ class PaymillGateway < Gateway
self.display_name = 'PAYMILL'
self.money_format = :cents
self.default_currency = 'EUR'
self.live_url = "https://api.paymill.com/v2/"

def initialize(options = {})
requires!(options, :public_key, :private_key)
Expand Down Expand Up @@ -63,9 +64,9 @@ def headers
{ 'Authorization' => ('Basic ' + Base64.strict_encode64("#{@options[:private_key]}:X").chomp) }
end

def commit(method, url, parameters=nil)
def commit(method, action, parameters=nil)
begin
raw_response = ssl_request(method, "https://api.paymill.com/v2/#{url}", post_data(parameters), headers)
raw_response = ssl_request(method, live_url + action, post_data(parameters), headers)
rescue ResponseError => e
begin
parsed = JSON.parse(e.response.body)
Expand Down
23 changes: 13 additions & 10 deletions lib/support/outbound_hosts.rb
Expand Up @@ -2,24 +2,27 @@
require 'set'

class OutboundHosts
def self.list
uris = Set.new
def self.list
hosts = Set.new
invalid_lines = Set.new

Dir['lib/**/*.rb'].each do |file|
content = File.read(file)

content.each_line do |line|
next if line =~ /homepage_url/

if line =~ /("|')(https:\/\/.*)("|')/
uri = URI.parse($2)
uris << [uri.host, uri.port]

if line =~ /("|')(https:\/\/[^'"]*)("|')/
begin
uri = URI.parse($2)
hosts << "#{uri.host}:#{uri.port}"
rescue URI::InvalidURIError
invalid_lines << line
end
end
end
end

uris.each do |uri|
puts "#{uri.first} #{uri.last}"
end
[hosts, invalid_lines]
end
end
end
89 changes: 28 additions & 61 deletions test/remote/gateways/remote_epay_test.rb
Expand Up @@ -10,96 +10,63 @@ def setup
@credit_card_declined = credit_card('3333333333333102')

@amount = 100
@options = { :order_id => '1' }
@options = {order_id: '1'}
end

def test_successful_authorization
assert response = @gateway.authorize(@amount, @credit_card, @options)
assert_equal "1", response.params['accept']
assert_not_nil response.params['tid']
assert_not_nil response.params['cur']
assert_not_nil response.params['amount']
assert_not_nil response.params['orderid']
assert !response.authorization.blank?
def test_successful_purchase
response = @gateway.purchase(@amount, @credit_card, @options)
assert_success response
assert !response.authorization.blank?
assert response.test?
end

def test_failed_authorization
assert response = @gateway.authorize(@amount, @credit_card_declined, @options)
assert_equal '1', response.params['decline']
assert_not_nil response.params['error']
assert_not_nil response.params['errortext']
assert_failure response
assert response.test?
end

def test_successful_purchase
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_equal '1', response.params['accept']
assert_not_nil response.params['tid']
assert_not_nil response.params['cur']
assert_not_nil response.params['amount']
assert_not_nil response.params['orderid']
assert !response.authorization.blank?
def test_successful_authorize_and_capture
response = @gateway.authorize(@amount, @credit_card, @options)
assert_success response
assert response.test?
assert !response.authorization.blank?

capture_response = @gateway.capture(@amount, response.authorization)
assert_success capture_response
end

def test_failed_purchase
assert response = @gateway.purchase(@amount, @credit_card_declined, @options)
assert_equal '1', response.params['decline']
assert_not_nil response.params['error']
assert_not_nil response.params['errortext']
def test_failed_authorization
response = @gateway.authorize(@amount, @credit_card_declined, @options)
assert_failure response
assert response.test?
end

def test_successful_capture
authorize_response = @gateway.authorize(@amount, @credit_card, @options)

assert response = @gateway.capture(@amount, authorize_response.authorization)
assert_equal 'true', response.params['result']
assert_success response
assert response.test?
def test_failed_purchase
response = @gateway.purchase(@amount, @credit_card_declined, @options)
assert_failure response
end

def test_failed_capture
assert response = @gateway.capture(@amount, 0)
assert_equal 'false', response.params['result']
response = @gateway.capture(@amount, 0)
assert_failure response
assert response.test?
end

def test_successful_refund
authorize_response = @gateway.purchase(@amount, @credit_card, @options)

assert response = @gateway.refund(@amount, authorize_response.authorization)
assert_equal 'true', response.params['result']
response = @gateway.purchase(@amount, @credit_card, @options)
assert_success response
assert response.test?

refund_response = @gateway.refund(@amount, response.authorization)
assert_success refund_response
end

def test_failed_refund
assert response_refund = @gateway.refund(@amount, 0)
assert_equal 'false', response_refund.params['result']
assert_failure response_refund
assert response_refund.test?
response = @gateway.refund(@amount, 0)
assert_failure response
end

def test_successful_void
authorize_response = @gateway.authorize(@amount, @credit_card, @options)

assert response = @gateway.void(authorize_response.authorization)
assert_equal 'true', response.params['result']
response = @gateway.authorize(@amount, @credit_card, @options)
assert_success response
assert response.test?

void_response = @gateway.void(response.authorization)
assert_success void_response
end

def test_failed_void
assert response_void = @gateway.void(0)
assert_equal 'false', response_void.params['result']
assert_failure response_void
assert response_void.test?
response = @gateway.void(0)
assert_failure response
end
end

0 comments on commit 389477e

Please sign in to comment.