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

IPG Gateway: override store id #4619

Merged
merged 1 commit into from
Nov 2, 2022
Merged
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 @@ -24,6 +24,7 @@
* Alelo: Trigger access token refresh on 404 [curiousepic] #4614
* DLocal: Add Network Tokens [gasb150] #4608
* Redsys: enable NTID generation with zero-value verify [jcreiff] #4615
* IPG: Add support for passing in `store_id` on transactions [aenand] #4619

== Version 1.127.0 (September 20th, 2022)
* BraintreeBlue: Add venmo profile_id [molbrown] #4512
Expand Down
19 changes: 12 additions & 7 deletions lib/active_merchant/billing/gateways/ipg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,40 @@ def initialize(options = {})
def purchase(money, payment, options = {})
xml = build_purchase_and_authorize_request(money, payment, options)

commit('sale', xml)
commit('sale', xml, options)
end

def authorize(money, payment, options = {})
xml = build_purchase_and_authorize_request(money, payment, options)

commit('preAuth', xml)
commit('preAuth', xml, options)
end

def capture(money, authorization, options = {})
xml = build_capture_and_refund_request(money, authorization, options)

commit('postAuth', xml)
commit('postAuth', xml, options)
end

def refund(money, authorization, options = {})
xml = build_capture_and_refund_request(money, authorization, options)

commit('return', xml)
commit('return', xml, options)
end

def void(authorization, options = {})
xml = Builder::XmlMarkup.new(indent: 2)
add_transaction_details(xml, options.merge!({ order_id: authorization }))

commit('void', xml)
commit('void', xml, options)
end

def store(credit_card, options = {})
@hosted_data_id = options[:hosted_data_id] || generate_unique_id
xml = Builder::XmlMarkup.new(indent: 2)
add_storage_item(xml, credit_card, options)

commit('vault', xml)
commit('vault', xml, options)
end

def unstore(hosted_data_id)
Expand Down Expand Up @@ -343,7 +343,12 @@ def ipg_action_namespaces
}
end

def commit(action, request)
def override_store_id(options)
@credentials[:store_id] = options[:store_id] if options[:store_id].present?
end

def commit(action, request, options = {})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making the options param optional and cleaning up the other method calls

override_store_id(options)
url = (test? ? test_url : live_url)
soap_request = build_soap_request(action, request)
response = parse(ssl_post(url, soap_request, build_header))
Expand Down
7 changes: 7 additions & 0 deletions test/remote/gateways/remote_ipg_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ def test_failed_purchase
assert_equal 'SGS-050005', response.error_code
end

def test_failed_purchase_with_passed_in_store_id
# passing in a bad store id results in a 401 unauthorized error
assert_raises(ActiveMerchant::ResponseError) do
@gateway.purchase(@amount, @declined_card, @options.merge({ store_id: '1234' }))
end
end

def test_successful_authorize_and_capture
order_id = generate_unique_id
response = @gateway.authorize(@amount, @credit_card, @options.merge!({ order_id: order_id }))
Expand Down
11 changes: 11 additions & 0 deletions test/unit/gateways/ipg_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ def test_successful_purchase_with_recurring_type
assert_success response
end

def test_successful_purchase_with_store_id
response = stub_comms do
@gateway.purchase(@amount, @credit_card, @options.merge({ store_id: '1234' }))
end.check_request do |_endpoint, data, _headers|
doc = REXML::Document.new(data)
assert_match('1234', REXML::XPath.first(doc, '//v1:StoreId').text)
end.respond_with(successful_purchase_response)

assert_success response
end

def test_successful_purchase_with_payment_token
payment_token = 'ABC123'

Expand Down