From 55b176637f24f0ebbebea0b112412145c933eff0 Mon Sep 17 00:00:00 2001 From: Jhoan Buitrago Date: Wed, 11 Dec 2024 17:53:40 -0500 Subject: [PATCH] Priority: fix for bin lookup Description ------------------------- Send 8 digits for bin lookups instead of 7. Unit tests ------------------------- 6159 tests, 80990 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 100% passed Remote tests ------------------------- 31 tests, 84 assertions, 5 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 83.871% passed Failures not related to changes Rubocop ------------------------- 808 files inspected, no offenses detected --- CHANGELOG | 1 + .../billing/gateways/priority.rb | 4 +- test/unit/gateways/priority_test.rb | 111 ++++++++++++++++++ 3 files changed, 114 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 99f0c29030e..9845ebb4c82 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -106,6 +106,7 @@ * Hi Pay: Don't add 3ds when :three_ds_2 is missing [Buitragox] #5355 * SecurePayAU: Send order ID for payments with stored card [dacook] #3979 * Orbital: Add XSD version testing to unit test [almalee24] #5375 +* Priority: fix for bin lookup [Buitragox] #5366 == Version 1.137.0 (August 2, 2024) * Unlock dependency on `rexml` to allow fixing a CVE (#5181). diff --git a/lib/active_merchant/billing/gateways/priority.rb b/lib/active_merchant/billing/gateways/priority.rb index d7308246730..d7b1f0f4cdb 100644 --- a/lib/active_merchant/billing/gateways/priority.rb +++ b/lib/active_merchant/billing/gateways/priority.rb @@ -315,7 +315,7 @@ def url(action, params, ref_number: '', credit_card_number: nil) when 'void' base_url + "/#{ref_number}?force=true" when 'verify' - (verify_url + '?search=') + credit_card_number.to_s[0..6] + (verify_url + '?search=') + credit_card_number.to_s[0..7] when 'get_payment_status', 'close_batch' batch_url + "/#{params}" when 'create_jwt' @@ -366,7 +366,7 @@ def parse(body) end def success_from(response, action) - return !response['bank'].empty? if action == 'verify' && response['bank'] + return !response['bank'].empty? if action == 'verify' && response['bank'] && !response.dig('bank', 'name').blank? %w[Approved Open Success Settled Voided].include?(response['status']) end diff --git a/test/unit/gateways/priority_test.rb b/test/unit/gateways/priority_test.rb index f3087237ff6..5ffee4c8b40 100644 --- a/test/unit/gateways/priority_test.rb +++ b/test/unit/gateways/priority_test.rb @@ -342,6 +342,26 @@ def test_failed_credit_invalid_credit_card_month assert response.test? end + def test_successful_verify + @gateway.stubs(:create_jwt).returns(jwt_response) + + response = stub_comms(@gateway, :ssl_get) do + @gateway.verify(@credit_card) + end.respond_with(successful_bin_search_response) + + assert_success response + end + + def test_failed_verify_no_bank + @gateway.stubs(:create_jwt).returns(jwt_response) + + response = stub_comms(@gateway, :ssl_get) do + @gateway.verify(credit_card('4242424242424242')) + end.respond_with(no_bank_bin_search_response) + + assert_failure response + end + def successful_refund_response %( { @@ -1422,4 +1442,95 @@ def failed_credit_response } ) end + + def jwt_response + response = { + processorName: 'TSYS', + jwtToken: 'eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InZvcnRleDAwMDEifQ.eyJ1aWQiOiIxMjc2QzU5Qi03OUJFLTQ5QzEtQkE4Ri01RTM0MkFENzBGQjkiLCJncmFudHMiOlsiZ2xvYmFsIiwicHBzOm14LW1lcmNoYW50IiwibWVyY2hhbnQ6MTAwMDAwMzMxMCIsInhtaWQ6ODczOTczMTIwODY2MTM0NCJdLCJyb2xlIjoibXgtbWVyY2hhbnQtcmVwb3J0IiwiZmx5SW5BbGxvd2VkIjpmYWxzZSwidXNlck5hbWUiOiJzeXN0ZW11c2VyLm14bWVyY2hhbnQiLCJpYXQiOjE3MzQxMTk3ODIsImV4cCI6MTczNDIwNjE4MiwiYXVkIjoiaHR0cHM6Ly9zYW5kYm94Lm14bWVyY2hhbnQuY29tIiwiaXNzIjoiaHR0cHM6Ly9zYW5kYm94Lm14bWVyY2hhbnQuY29tIiwic3ViIjoiblNGQ0V5eHdkVG9vOHhJOWVNcldMUWRnIn0.Tvm7c_YXQupGXCn2Pf6MlN0VMnTVZxHFn4OQ2ojaSyMJUq4tTFdf8xPqAbQql-JEaekZfUJmwbGF_zaxgY4VKQ' + } + + ActiveMerchant::Billing::Response.new( + true, + response, + response + ) + end + + def successful_bin_search_response + %( + { + "id": "41111111", + "bin": "41111111", + "bank": { + "www": "www.jpmorganchase.com", + "name": "JPMORGAN CHASE BANK N.A.", + "phone": "416-981-9200" + }, + "type": "", + "brand": "VISA", + "level": "", + "source": "pci.bindb.com", + "country": { + "iso": "840", + "info": "Wilmington", + "name": "United States", + "abbreviation2": "US", + "abbreviation3": "USA" + }, + "created": "2024-02-15T15:58:38.306Z", + "creator": { + "id": "system", + "user": "system" + }, + "prepaid": null, + "business": null, + "modified": "2024-02-15T15:58:38.306Z", + "modifier": { + "id": "system", + "user": "system" + }, + "reloadable": null, + "isCreditCard": true + } + ) + end + + def no_bank_bin_search_response + %( + { + "id": "42424242", + "bin": "42424242", + "bank": { + "www": "", + "name": "", + "phone": "" + }, + "type": "CREDIT", + "brand": "VISA", + "level": "CLASSIC", + "source": "pci.bindb.com", + "country": { + "iso": "826", + "info": "", + "name": "United Kingdom", + "abbreviation2": "GB", + "abbreviation3": "GBR" + }, + "created": "2023-04-03T12:39:37.033Z", + "creator": { + "id": "system", + "user": "system" + }, + "prepaid": false, + "business": false, + "modified": "2024-01-16T06:29:37.125Z", + "modifier": { + "id": "system", + "user": "system" + }, + "reloadable": false, + "isCreditCard": true + } + ) + end end