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: Send order ID for payments with stored card #3979

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Decidir: Pass CVV for NT [almalee24] #5205
* NMI: Add customer vault fields [yunnydang] #5215
* CheckoutV2: Add inquire method [almalee24] #5209
* SecurePayAU: Send order ID for payments with stored card [dacook] #3979

== Version 1.137.0 (August 2, 2024)
* Unlock dependency on `rexml` to allow fixing a CVE (#5181).
Expand Down
5 changes: 3 additions & 2 deletions lib/active_merchant/billing/gateways/secure_pay_au.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def build_request(action, body)
end

def commit(action, request)
response = parse(ssl_post(test? ? self.test_url : self.live_url, build_request(action, request)))
response = parse(ssl_post(test? ? self.test_url : self.live_url, build_request(action, request), {"Content-Type" => "text/xml; charset=utf-8"}))

Response.new(
success?(response),
Expand All @@ -207,6 +207,7 @@ def build_periodic_item(action, money, credit_card, options)
end
xml.tag! 'amount', amount(money)
xml.tag! 'periodicType', PERIODIC_TYPES[action] if PERIODIC_TYPES[action]
xml.tag! 'transactionReference', options[:order_id] if options[:order_id]

xml.target!
end
Expand Down Expand Up @@ -241,7 +242,7 @@ def build_periodic_request(body)

def commit_periodic(request)
my_request = build_periodic_request(request)
response = parse(ssl_post(test? ? self.test_periodic_url : self.live_periodic_url, my_request))
response = parse(ssl_post(test? ? self.test_periodic_url : self.live_periodic_url, my_request, {"Content-Type" => "text/xml; charset=utf-8"}))

Response.new(
success?(response),
Expand Down
11 changes: 9 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 All @@ -17,7 +21,7 @@ def setup
@credit_card = credit_card('4242424242424242', { month: 9, year: 15 })

@options = {
order_id: '2',
order_id: 'order123',
billing_address: address,
description: 'Store Purchase'
}
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,6 +115,7 @@ 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
Expand Down Expand Up @@ -160,6 +166,7 @@ def test_successful_triggered_payment
assert response = @gateway.purchase(12300, 'test1234', @options)
assert_success response
assert_equal response.params['amount'], '12300'
assert_equal response.params['ponum'], 'order123'

assert_equal 'Approved', response.message
end
Expand Down
10 changes: 9 additions & 1 deletion test/unit/gateways/secure_pay_au_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def setup
@amount = 100

@options = {
order_id: '1',
order_id: 'order123',
billing_address: address,
description: 'Store Purchase'
}
Expand Down Expand Up @@ -79,6 +79,14 @@ def test_purchase_with_stored_id_calls_commit_periodic
@gateway.purchase(@amount, '123', @options)
end

def test_periodic_payment_submits_order_id
stub_comms(@gateway, :ssl_request) do
@gateway.purchase(@amount, '123', @options)
end.check_request do |method, endpoint, data, headers|
assert_match(/<transactionReference>order123<\/transactionReference>/, data)
end.respond_with(successful_purchase_response)
end

def test_purchase_with_creditcard_calls_commit_with_purchase
@gateway.expects(:commit).with(:purchase, anything)

Expand Down