Skip to content

Commit

Permalink
IPG Gateway: override store id
Browse files Browse the repository at this point in the history
ECS-2655

The IPG gateway requires a `store_id` to be
used as part of the authentication. This
value is correlates to a given merchant and
is currently saved on the gateway initalize.
By saving it only then, it prevents merchants
with submerchants from using this gateway.

This commit adds a new optional field that
will override the saved `store_id` with one
passed in for that merchant.

Test Summary
Remote:
18 tests, 54 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
  • Loading branch information
aenand committed Nov 2, 2022
1 parent 5a9b19d commit ab92469
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
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 = {})
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

0 comments on commit ab92469

Please sign in to comment.