Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SecurePayAU: Allow custom request_timeout #4001

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/active_merchant/billing/gateways/secure_pay_au.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ class SecurePayAuGateway < Gateway
# The name of the gateway
self.display_name = 'SecurePay'

class_attribute :request_timeout
self.request_timeout = 60

self.money_format = :cents
self.default_currency = 'AUD'

Expand Down Expand Up @@ -61,6 +58,10 @@ def initialize(options = {})
super
end

def request_timeout
@options[:request_timeout] || 60
end

def purchase(money, credit_card_or_stored_id, options = {})
if credit_card_or_stored_id.respond_to?(:number)
requires!(options, :order_id)
Expand Down
10 changes: 8 additions & 2 deletions test/remote/gateways/remote_secure_pay_au_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ class MyCreditCard
include ActiveMerchant::Billing::CreditCardMethods
attr_accessor :number, :month, :year, :first_name, :last_name, :verification_value, :brand

def initialize(params)
params.each { |k,v| instance_variable_set("@#{k.to_s}".to_sym,v) }
end

def verification_value?
!@verification_value.blank?
end
Expand Down Expand Up @@ -94,10 +98,11 @@ def test_failed_refund

assert response = @gateway.refund(@amount + 1, authorization)
assert_failure response
assert_equal 'Only $1.0 available for refund', response.message
assert_equal 'Only 1.00 AUD available for refund', response.message
end

def test_successful_void
omit("It appears that SecurePayAU no longer supports void")
assert response = @gateway.authorize(@amount, @credit_card, @options)
assert_success response

Expand All @@ -110,13 +115,14 @@ def test_successful_void
end

def test_failed_void
omit("It appears that SecurePayAU no longer supports void")
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_success response
authorization = response.authorization

assert response = @gateway.void(authorization + '1')
assert_failure response
assert_equal 'Unable to retrieve original FDR txn', response.message
assert_equal 'Transaction type not available', response.message
end

def test_successful_unstore
Expand Down
17 changes: 17 additions & 0 deletions test/unit/gateways/secure_pay_au_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,23 @@ def test_successful_triggered_payment
assert_equal 'test3', response.params['client_id']
end

def test_request_timeout_default
stub_comms(@gateway, :ssl_request) do
@gateway.purchase(@amount, @credit_card, @options)
end.check_request do |method, endpoint, data, headers|
assert_match(/<timeoutValue>60/, data)
end.respond_with(successful_purchase_response)
end

def test_override_request_timeout
gateway = SecurePayAuGateway.new(login: 'login', password: 'password', request_timeout: 44)
stub_comms(gateway, :ssl_request) do
gateway.purchase(@amount, @credit_card, @options)
end.check_request do |method, endpoint, data, headers|
assert_match(/<timeoutValue>44/, data)
end.respond_with(successful_purchase_response)
end

def test_scrub
assert_equal @gateway.scrub(pre_scrub), post_scrub
end
Expand Down