From 04a4a383102a84cc35f5411a28047b24ae78bb0a Mon Sep 17 00:00:00 2001 From: imran-bayonet Date: Mon, 5 Mar 2018 12:03:08 -0600 Subject: [PATCH 1/3] Remove feedback endpoint from Ecommerce wrapper --- lib/bayonet_client/ecommerce.rb | 21 ++++++++++----------- lib/bayonet_client/lending.rb | 13 ++++++++----- lib/bayonet_client/response.rb | 11 ++++------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/lib/bayonet_client/ecommerce.rb b/lib/bayonet_client/ecommerce.rb index 3fac263..09430de 100644 --- a/lib/bayonet_client/ecommerce.rb +++ b/lib/bayonet_client/ecommerce.rb @@ -3,36 +3,35 @@ module BayonetClient class Ecommerce - def self.consulting(params) - BayonetClient::ApiHelper.request('/consulting', params) - end - def self.feedback(params) - BayonetClient::ApiHelper.request('/feedback', params) + BASE_PATH = "/sigma" + + def self.consult(params) + BayonetClient::ApiHelper.request("#{BASE_PATH}/consult", params) end def self.feedback_historical(params) - BayonetClient::ApiHelper.request('/feedback-historical', params) + BayonetClient::ApiHelper.request("#{BASE_PATH}/feedback-historical", params) end def self.update_transaction(params) - BayonetClient::ApiHelper.request('/update-transaction', params) + BayonetClient::ApiHelper.request("#{BASE_PATH}/update-transaction", params) end def self.whitelist(params) - BayonetClient::ApiHelper.request('/labels/whitelist/add', params) + BayonetClient::ApiHelper.request("#{BASE_PATH}/labels/whitelist/add", params) end def self.remove_from_whitelist(params) - BayonetClient::ApiHelper.request('/labels/whitelist/remove', params) + BayonetClient::ApiHelper.request("#{BASE_PATH}/labels/whitelist/remove", params) end def self.block(params) - BayonetClient::ApiHelper.request('/labels/block/add', params) + BayonetClient::ApiHelper.request("#{BASE_PATH}/labels/block/add", params) end def self.remove_from_block(params) - BayonetClient::ApiHelper.request('/labels/block/remove', params) + BayonetClient::ApiHelper.request("#{BASE_PATH}/labels/block/remove", params) end end diff --git a/lib/bayonet_client/lending.rb b/lib/bayonet_client/lending.rb index 541bf75..1255204 100644 --- a/lib/bayonet_client/lending.rb +++ b/lib/bayonet_client/lending.rb @@ -3,24 +3,27 @@ module BayonetClient class Lending + + BASE_PATH = "/lending" + def self.report_transaction(params) - BayonetClient::ApiHelper.request('/lending/transaction/report', params) + BayonetClient::ApiHelper.request("#{BASE_PATH}/transaction/report", params) end def self.report_transaction_and_consult(params) - BayonetClient::ApiHelper.request('/lending/transaction/report?consult=true', params) + BayonetClient::ApiHelper.request("#{BASE_PATH}/transaction/report?consult=true", params) end def self.consult(params) - BayonetClient::ApiHelper.request('/lending/consult', params) + BayonetClient::ApiHelper.request("#{BASE_PATH}/consult", params) end def self.feedback(params) - BayonetClient::ApiHelper.request('/lending/feedback', params) + BayonetClient::ApiHelper.request("#{BASE_PATH}/feedback", params) end def self.feedback_historical(params) - BayonetClient::ApiHelper.request('/lending/feedback-historical', params) + BayonetClient::ApiHelper.request("#{BASE_PATH}/feedback-historical", params) end end diff --git a/lib/bayonet_client/response.rb b/lib/bayonet_client/response.rb index 2285bbd..3272896 100644 --- a/lib/bayonet_client/response.rb +++ b/lib/bayonet_client/response.rb @@ -3,21 +3,18 @@ module BayonetClient class BayonetResponse - attr_accessor :feedback_api_trans_code, :rules_triggered, - :risk_level, :payload, :reason_code, + attr_accessor :rules_triggered, + :decision, :payload, :reason_code, :reason_message, :request_body, :bayonet_fingerprint, :raw def initialize(parsed_response) - if parsed_response.key?('feedback_api_trans_code') - self.feedback_api_trans_code = parsed_response['feedback_api_trans_code'] - end if parsed_response.key?('rules_triggered') self.rules_triggered = parsed_response['rules_triggered'] end - if parsed_response.key?('risk_level') - self.risk_level = parsed_response['risk_level'] + if parsed_response.key?('decision') + self.decision = parsed_response['decision'] end if parsed_response.key?('payload') self.payload = parsed_response['payload'] From ec1f3fe3b689973f444ef9cfa54ebd1e52fd12ed Mon Sep 17 00:00:00 2001 From: imran-bayonet Date: Mon, 5 Mar 2018 12:23:44 -0600 Subject: [PATCH 2/3] Update tests for the new ecommerce flow --- spec/bayonet_client_spec.rb | 60 +++++++++++++++++------------------ spec/fixtures/api_params.yaml | 8 ++--- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/spec/bayonet_client_spec.rb b/spec/bayonet_client_spec.rb index d2a2a0f..5c07b2a 100644 --- a/spec/bayonet_client_spec.rb +++ b/spec/bayonet_client_spec.rb @@ -23,10 +23,10 @@ def keys_to_symbols(hash) end @invalid_api_key = load_fixture('invalid_api_key') - - @params_consulting = keys_to_symbols load_fixture('params_consulting') - @params_feedback = keys_to_symbols load_fixture('params_feedback') - @params_feedback_trans_code = keys_to_symbols load_fixture('params_feedback') + # generate a random transaction id + @transaction_id = (0...8).map { (65 + rand(26)).chr }.join + @params_consult = keys_to_symbols load_fixture('params_consult') + @params_update_transaction = keys_to_symbols load_fixture('params_update_transaction') @params_feedback_historical = keys_to_symbols load_fixture('params_feedback_historical') @params_get_fingerprint_data = keys_to_symbols load_fixture('params_get_fingerprint_data') end @@ -45,73 +45,62 @@ def keys_to_symbols(hash) end end - describe 'ConsultingEndpoint' do + describe 'ConsultEndpoint' do it 'should return error on invalid api key' do BayonetClient.configure(@invalid_api_key, @api_version) expect{ - BayonetClient::Ecommerce.consulting(@params_consulting) + BayonetClient::Ecommerce.consult(@params_consult) }.to raise_error(BayonetClient::BayonetError) end it 'should validate api_key' do begin BayonetClient.configure(@invalid_api_key, @api_version) - BayonetClient::Ecommerce.consulting(@params_consulting) + BayonetClient::Ecommerce.consult(@params_consult) rescue BayonetClient::BayonetError => e expect(e.reason_code).to eq(12) end end it 'should return success' do + @params_consult[:transaction_id] = @transaction_id BayonetClient.configure(@api_key, @api_version) - r = BayonetClient::Ecommerce.consulting(@params_consulting) - @params_feedback_trans_code[:feedback_api_trans_code] = r.feedback_api_trans_code + r = BayonetClient::Ecommerce.consult(@params_consult) expect(r.reason_code).to eq(0) end - - it 'should return feedback_api_trans_code' do - BayonetClient.configure(@api_key, @api_version) - r = BayonetClient::Ecommerce.consulting(@params_consulting) - expect(r.feedback_api_trans_code).to_not be_nil - end end - describe 'FeedbackEndpoint' do + describe 'TransactionUpdateEndpoint' do it 'should return error on invalid api key' do BayonetClient.configure(@invalid_api_key, @api_version) expect{ - BayonetClient::Ecommerce.feedback(@params_feedback) + BayonetClient::Ecommerce.update_transaction(@params_update_transaction) }.to raise_error(BayonetClient::BayonetError) end it 'should validate api_key' do BayonetClient.configure(@invalid_api_key, @api_version) begin - BayonetClient::Ecommerce.feedback(@params_feedback) + BayonetClient::Ecommerce.update_transaction(@params_update_transaction) rescue BayonetClient::BayonetError => e expect(e.reason_code).to eq(12) end end - it 'should return error on invalid feedback api trans code' do + it 'should return error on invalid transaction id' do + # generate a random transaction id + invalid_transaction_id = (0...8).map { (65 + rand(26)).chr }.join + @params_update_transaction[:transaction_id] = invalid_transaction_id BayonetClient.configure(@api_key, @api_version) expect{ - BayonetClient::Ecommerce.feedback(@params_feedback) + BayonetClient::Ecommerce.update_transaction(@params_update_transaction) }.to raise_error(BayonetClient::BayonetError) end - it 'should validate feedback api trans code' do - BayonetClient.configure(@api_key, @api_version) - begin - BayonetClient::Ecommerce.feedback(@params_feedback) - rescue BayonetClient::BayonetError => e - expect(e.reason_code).to eq(87) - end - end - - it 'should return success on feedback' do + it 'should return success' do + @params_update_transaction[:transaction_id] = @transaction_id BayonetClient.configure(@api_key, @api_version) - r = BayonetClient::Ecommerce.feedback(@params_feedback_trans_code) + r = BayonetClient::Ecommerce.update_transaction(@params_update_transaction) expect(r.reason_code).to eq(0) end @@ -133,6 +122,15 @@ def keys_to_symbols(hash) expect(e.reason_code).to eq(12) end end + + it 'should return success' do + # generate a random transaction id + transaction_id = (0...8).map { (65 + rand(26)).chr }.join + @params_feedback_historical[:transaction_id] = transaction_id + BayonetClient.configure(@api_key, @api_version) + r = BayonetClient::Ecommerce.feedback_historical(@params_feedback_historical) + expect(r.reason_code).to eq(0) + end end describe 'GetFingerprintDataEndpoint' do diff --git a/spec/fixtures/api_params.yaml b/spec/fixtures/api_params.yaml index a4a3163..d5369d5 100644 --- a/spec/fixtures/api_params.yaml +++ b/spec/fixtures/api_params.yaml @@ -1,6 +1,6 @@ invalid_api_key: invalid-api-key -params_consulting: { +params_consult: { email: test_ruby@bayonet.io, consumer_name: test ruby consumer name, consumer_internal_id: test_ruby_1, @@ -27,6 +27,7 @@ params_consulting: { }, payment_method: card, transaction_time: 1476813671, + transaction_id: test_ruby_123, payment_gateway: stripe, channel: ecommerce, coupon: test_ruby_coupon, @@ -41,10 +42,9 @@ params_consulting: { ] } -params_feedback: { +params_update_transaction: { transaction_status: success, - transaction_id: test_ruby_123, - feedback_api_trans_code: xxx + transaction_id: test_ruby_123 } params_feedback_historical: { From 3d2cce9612e27fd16e366d172e3a6906015e727c Mon Sep 17 00:00:00 2001 From: imran-bayonet Date: Mon, 5 Mar 2018 12:37:28 -0600 Subject: [PATCH 3/3] Version bump --- lib/bayonet_client/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bayonet_client/version.rb b/lib/bayonet_client/version.rb index f0b692b..ddaa047 100644 --- a/lib/bayonet_client/version.rb +++ b/lib/bayonet_client/version.rb @@ -1,4 +1,4 @@ module BayonetClient - VERSION = '2.1.1' + VERSION = '2.1.2' SUPPORTED_API_VERSIONS = ['2'] end