From 7f035e108b64f88c5d10077ac147d4d1cbb4624d Mon Sep 17 00:00:00 2001 From: Lucas Gomes Date: Wed, 14 Aug 2024 16:44:32 -0300 Subject: [PATCH 1/5] Removing required installation id on client methods --- lib/incognia_api/api.rb | 13 ++++---- spec/incognia_spec.rb | 74 ++++++++++++++++++++--------------------- 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/lib/incognia_api/api.rb b/lib/incognia_api/api.rb index 0aea807..3273b1f 100644 --- a/lib/incognia_api/api.rb +++ b/lib/incognia_api/api.rb @@ -15,8 +15,8 @@ def initialize(client_id:, client_secret:) host: "https://api.incognia.com/api") end - def register_signup(installation_id:, address: nil, **opts) - params = { installation_id: installation_id } + def register_signup(address: nil, **opts) + params = {} params.merge!(opts) params.merge!(address&.to_hash) if address @@ -29,11 +29,10 @@ def register_signup(installation_id:, address: nil, **opts) SignupAssessment.from_hash(response.body) if response.success? end - def register_login(installation_id:, account_id:, **opts) + def register_login(account_id:, **opts) params = { type: :login, - installation_id: installation_id, - account_id: account_id, + account_id: account_id } params.merge!(opts) @@ -67,8 +66,8 @@ def register_feedback(event:, occurred_at: nil, expires_at: nil, timestamp: nil, response.success? end - def register_payment(installation_id:, account_id:, **opts) - params = { installation_id: installation_id, account_id: account_id, type: :payment } + def register_payment(account_id:, **opts) + params = { account_id: account_id, type: :payment } params.merge!(opts) response = connection.request( diff --git a/spec/incognia_spec.rb b/spec/incognia_spec.rb index 9677d8e..0154ebc 100644 --- a/spec/incognia_spec.rb +++ b/spec/incognia_spec.rb @@ -41,13 +41,13 @@ module Incognia let(:structured_address) { Address.new(structured: structured_format ) } let(:address) { Address.new(line: line_format) } let(:coordinates_address) { Address.new(coordinates: coordinates_format) } - let(:installation_id) { SecureRandom.uuid } + let(:request_token) { SecureRandom.uuid } it "when successful returns the resource" do stub_token_request stub_signup_request - signup = api.register_signup(installation_id: installation_id, address: address) + signup = api.register_signup(request_token: request_token, address: address) expected = JSON.parse(unknown_signup_fixture, symbolize_names: true) expect(signup.id). @@ -58,66 +58,66 @@ module Incognia end context "HTTP request" do - it "hits the endpoint with installation_id" do + it "hits the endpoint with request_token" do stub_token_request stub = stub_signup_request stub.with( - body: { installation_id: installation_id }, + body: { request_token: request_token }, headers: { 'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/ } ) - api.register_signup(installation_id: installation_id) + api.register_signup(request_token: request_token) expect(stub).to have_been_made.once end - it "hits the endpoint with installation_id and address_line" do + it "hits the endpoint with request_token and address_line" do stub_token_request stub = stub_signup_request stub.with( - body: { installation_id: installation_id, address_line: line_format }, + body: { request_token: request_token, address_line: line_format }, headers: { 'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/ } ) - api.register_signup(installation_id: installation_id, address: address) + api.register_signup(request_token: request_token, address: address) expect(stub).to have_been_made.once end - it "hits the endpoint with installation_id and structured_address" do + it "hits the endpoint with request_token and structured_address" do stub_token_request stub = stub_signup_request stub.with( - body: { installation_id: installation_id, structured_address: structured_format }, + body: { request_token: request_token, structured_address: structured_format }, headers: { 'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/ } ) - api.register_signup(installation_id: installation_id, address: structured_address) + api.register_signup(request_token: request_token, address: structured_address) expect(stub).to have_been_made.once end - it "hits the endpoint with installation_id and coordinates" do + it "hits the endpoint with request_token and coordinates" do stub_token_request stub = stub_signup_request stub.with( - body: { installation_id: installation_id, address_coordinates: coordinates_format }, + body: { request_token: request_token, address_coordinates: coordinates_format }, headers: { 'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/ } ) - api.register_signup(installation_id: installation_id, address: coordinates_address) + api.register_signup(request_token: request_token, address: coordinates_address) expect(stub).to have_been_made.once end @@ -128,14 +128,14 @@ module Incognia stub_token_request stub = stub_signup_request.with( - body: { installation_id: installation_id }.merge(opts), + body: { request_token: request_token }.merge(opts), headers: { 'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/ } ) - login = api.register_signup( - installation_id: installation_id, + api.register_signup( + request_token: request_token, **opts ) @@ -158,7 +158,7 @@ module Incognia end describe "#register_login" do - let(:installation_id) { SecureRandom.uuid } + let(:request_token) { SecureRandom.uuid } let(:account_id) { SecureRandom.uuid } it "when successful returns the resource" do @@ -166,7 +166,7 @@ module Incognia stub_login_request login = api.register_login( - installation_id: installation_id, + request_token: request_token, account_id: account_id ) @@ -177,21 +177,21 @@ module Incognia end context "HTTP request" do - it "hits the endpoint with installation_id and account_id" do + it "hits the endpoint with request_token and account_id" do stub_token_request stub = stub_login_request.with( body: { type: 'login', - installation_id: installation_id, account_id: account_id + request_token: request_token, account_id: account_id }, headers: { 'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/ } ) - login = api.register_login( - installation_id: installation_id, + api.register_login( + request_token: request_token, account_id: account_id ) @@ -206,16 +206,16 @@ module Incognia stub = stub_login_request.with( body: { type: 'login', - installation_id: installation_id, - account_id: account_id, + request_token: request_token, + account_id: account_id }.merge(opts), headers: { 'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/ } ) - login = api.register_login( - installation_id: installation_id, + api.register_login( + request_token: request_token, account_id: account_id, **opts ) @@ -239,7 +239,7 @@ module Incognia end describe "#register_payment" do - let(:installation_id) { SecureRandom.uuid } + let(:request_token) { SecureRandom.uuid } let(:account_id) { SecureRandom.uuid } it "when successful returns the resource" do @@ -247,7 +247,7 @@ module Incognia stub_payment_request payment = api.register_payment( - installation_id: installation_id, + request_token: request_token, account_id: account_id ) @@ -258,21 +258,21 @@ module Incognia end context "HTTP request" do - it "hits the endpoint with installation_id and account_id" do + it "hits the endpoint with request_token and account_id" do stub_token_request stub = stub_payment_request.with( body: { type: 'payment', - installation_id: installation_id, account_id: account_id + request_token: request_token, account_id: account_id }, headers: { 'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/ } ) - payment = api.register_payment( - installation_id: installation_id, + api.register_payment( + request_token: request_token, account_id: account_id ) @@ -287,7 +287,7 @@ module Incognia stub = stub_payment_request.with( body: { type: 'payment', - installation_id: installation_id, + request_token: request_token, account_id: account_id }.merge(opts), headers: { @@ -295,8 +295,8 @@ module Incognia } ) - payment = api.register_payment( - installation_id: installation_id, + api.register_payment( + request_token: request_token, account_id: account_id, **opts ) @@ -505,7 +505,7 @@ module Incognia end end - it_behaves_like 'receiving ids', :installation_id + it_behaves_like 'receiving ids', :request_token it_behaves_like 'receiving ids', :account_id it_behaves_like 'receiving ids', :external_id it_behaves_like 'receiving ids', :signup_id From 27facc38d4dd8fa353613f01ee3f3c23e4618e9e Mon Sep 17 00:00:00 2001 From: Lucas Gomes Date: Wed, 14 Aug 2024 17:39:49 -0300 Subject: [PATCH 2/5] Use request token instead installation id on README.md --- README.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 2ccd731..3dc6cc8 100644 --- a/README.md +++ b/README.md @@ -49,14 +49,14 @@ For sandbox credentials, refer to the [API testing guide](). ### Registering a Signup -This method registers a new signup for the given installation and address, returning a signup assessment, containing the risk assessment and supporting evidence: +This method registers a new signup for the given request token and address, returning a signup assessment, containing the risk assessment and supporting evidence: ```ruby address = Incognia::Address.new(line: "West 34th Street, New York City, NY 10001") -installation_id = "WlMksW+jh5GPhqWBorsV8yDihoSHHpmt+DpjJ7eYxpHhuO/5tuHTuA..." +request_token = "WlMksW+jh5GPhqWBorsV8yDihoSHHpmt+DpjJ7eYxpHhuO/5tuHTuA..." assessment = api.register_signup( - installation_id: installation_id, + request_token: request_token, address: address ) @@ -68,11 +68,11 @@ It also supports optional parameters, for example: ```ruby address = Incognia::Address.new(line: "West 34th Street, New York City, NY 10001") -installation_id = "WlMksW+jh5GPhqWBorsV8yDihoSHHpmt+DpjJ7eYxpHhuO/5tuHTuA..." +request_token = "WlMksW+jh5GPhqWBorsV8yDihoSHHpmt+DpjJ7eYxpHhuO/5tuHTuA..." external_id = "7b02736a-7718-4b83-8982-f68fb6f501fa" assessment = api.register_signup( - installation_id: installation_id, + request_token: request_token, address: address, external_id: external_id ) @@ -82,14 +82,14 @@ assessment = api.register_signup( ### Registering a Login -This method registers a new login for the given installation and account, returning a login assessment, containing the risk assessment and supporting evidence: +This method registers a new login for the given request token and account, returning a login assessment, containing the risk assessment and supporting evidence: ```ruby -installation_id = "WlMksW+jh5GPhqWBorsV8yDihoSHHpmt+DpjJ7eYxpHhuO/5tuHTuA..." +request_token = "WlMksW+jh5GPhqWBorsV8yDihoSHHpmt+DpjJ7eYxpHhuO/5tuHTuA..." account_id = 'account-identifier-123' assessment = api.register_login( - installation_id: installation_id, + request_token: request_token, account_id: account_id, ) @@ -100,12 +100,12 @@ assessment = api.register_login( It also supports optional parameters, for example: ```ruby -installation_id = "WlMksW+jh5GPhqWBorsV8yDihoSHHpmt+DpjJ7eYxpHhuO/5tuHTuA..." +request_token = "WlMksW+jh5GPhqWBorsV8yDihoSHHpmt+DpjJ7eYxpHhuO/5tuHTuA..." account_id = 'account-identifier-123' external_id = 'some-external-identifier' assessment = api.register_login( - installation_id: installation_id, + request_token: request_token, account_id: account_id, external_id: external_id, eval: false # can be used to register a new login without evaluating it @@ -116,12 +116,12 @@ assessment = api.register_login( ### Registering Payment -This method registers a new payment for the given installation and account, returning a `hash`, +This method registers a new payment for the given request token and account, returning a `hash`, containing the risk assessment and supporting evidence. ```ruby assessment = api.register_payment( - installation_id: 'installation-id', + request_token: 'request-token', account_id: 'account-id' ) @@ -181,7 +181,7 @@ payment_methods = [ ] assessment = api.register_payment( - installation_id: 'installation-id', + request_token: 'request-token', account_id: 'account-id', external_id: 'external-id', addresses: addresses, @@ -202,14 +202,14 @@ The `expires_at` argument should be a _Time_, _DateTime_ or an date in **RFC 333 ```ruby -installation_id = 'installation-id' +request_token = 'request-token' account_id = 'account-id' occurred_at = DateTime.parse('2024-07-22T15:20:00Z') success = api.register_feedback( event: Incognia::Constants::FeedbackEvent::ACCOUNT_TAKEOVER, occurred_at: occurred_at, - installation_id: installation_id, + request_token: request_token, account_id: account_id ) @@ -222,7 +222,7 @@ For custom fraud, set the value of `event` with the corresponding code: success = api.register_feedback( event: 'custom_fraud_name', occurred_at: occurred_at, - installation_id: installation_id, + request_token: request_token, account_id: account_id ) From bebb61fb9d295a54baa83d2fea50db4bf58385a4 Mon Sep 17 00:00:00 2001 From: Lucas Gomes Date: Mon, 19 Aug 2024 08:09:14 -0300 Subject: [PATCH 3/5] Add new version description --- CHANGELOG.md | 4 ++++ lib/incognia_api/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fe632a..4a1051e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## [Unreleased] +## [1.2.0] - 2024-08-26 + +- Removes the requirement to send installation id to register signup, login and payment + ## [1.1.0] - 2024-07-24 - Add support to passing request_token and occurred_at to #register_feedback diff --git a/lib/incognia_api/version.rb b/lib/incognia_api/version.rb index 93de543..9db9f87 100644 --- a/lib/incognia_api/version.rb +++ b/lib/incognia_api/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Incognia - VERSION = "1.1.0" + VERSION = "1.2.0" end From 71cd15f627124d4a359f4ca67b85bc6f59e1793e Mon Sep 17 00:00:00 2001 From: Lucas Gomes Date: Sat, 24 Aug 2024 19:32:38 -0300 Subject: [PATCH 4/5] Specify the desired token for evaluating risk assessments and improvement tests --- Gemfile.lock | 2 +- lib/incognia_api/api.rb | 9 ++- spec/incognia_spec.rb | 118 ++++++++++++++++++++++++---------------- 3 files changed, 78 insertions(+), 51 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2b3346c..92282f0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - incognia_api (1.1.0) + incognia_api (1.2.0) faraday (~> 1.10) faraday_middleware (~> 1.2) diff --git a/lib/incognia_api/api.rb b/lib/incognia_api/api.rb index 3273b1f..21fbdcc 100644 --- a/lib/incognia_api/api.rb +++ b/lib/incognia_api/api.rb @@ -15,8 +15,9 @@ def initialize(client_id:, client_secret:) host: "https://api.incognia.com/api") end - def register_signup(address: nil, **opts) + def register_signup(request_token: nil, address: nil, **opts) params = {} + params.merge!({ request_token: request_token }) if request_token params.merge!(opts) params.merge!(address&.to_hash) if address @@ -29,11 +30,12 @@ def register_signup(address: nil, **opts) SignupAssessment.from_hash(response.body) if response.success? end - def register_login(account_id:, **opts) + def register_login(account_id:, request_token: nil, **opts) params = { type: :login, account_id: account_id } + params.merge!({ request_token: request_token }) if request_token params.merge!(opts) response = connection.request( @@ -66,8 +68,9 @@ def register_feedback(event:, occurred_at: nil, expires_at: nil, timestamp: nil, response.success? end - def register_payment(account_id:, **opts) + def register_payment(account_id:, request_token: nil, **opts) params = { account_id: account_id, type: :payment } + params.merge!({ request_token: request_token }) if request_token params.merge!(opts) response = connection.request( diff --git a/spec/incognia_spec.rb b/spec/incognia_spec.rb index 0154ebc..3305d58 100644 --- a/spec/incognia_spec.rb +++ b/spec/incognia_spec.rb @@ -58,27 +58,34 @@ module Incognia end context "HTTP request" do - it "hits the endpoint with request_token" do - stub_token_request + shared_examples_for 'receiving one of the required tokens' do |token_name| + let(:token_value) { SecureRandom.uuid } - stub = stub_signup_request - stub.with( - body: { request_token: request_token }, - headers: { - 'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/ - } - ) + it "hits the endpoint with #{token_name}" do + stub_token_request - api.register_signup(request_token: request_token) + stub = stub_signup_request + stub.with( + body: { token_name => token_value }, + headers: { + 'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/ + } + ) - expect(stub).to have_been_made.once + api.register_signup(token_name => token_value) + + expect(stub).to have_been_made.once + end end + it_behaves_like 'receiving one of the required tokens', :request_token + it_behaves_like 'receiving one of the required tokens', :installation_id + it_behaves_like 'receiving one of the required tokens', :session_token + it "hits the endpoint with request_token and address_line" do stub_token_request - stub = stub_signup_request - stub.with( + stub = stub_signup_request.with( body: { request_token: request_token, address_line: line_format }, headers: { 'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/ @@ -154,7 +161,6 @@ module Incognia end end end - end describe "#register_login" do @@ -177,27 +183,36 @@ module Incognia end context "HTTP request" do - it "hits the endpoint with request_token and account_id" do - stub_token_request + shared_examples_for 'receiving one of the required tokens with account_id' do |token_name| + let(:token_value) { SecureRandom.uuid } - stub = stub_login_request.with( - body: { - type: 'login', - request_token: request_token, account_id: account_id - }, - headers: { - 'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/ - } - ) + it "hits the endpoint with #{token_name} and account_id" do + stub_token_request - api.register_login( - request_token: request_token, - account_id: account_id - ) + stub = stub_login_request.with( + body: { + type: 'login', + account_id: account_id, + token_name => token_value + }, + headers: { + 'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/ + } + ) - expect(stub).to have_been_made.once + api.register_login( + account_id: account_id, + token_name => token_value + ) + + expect(stub).to have_been_made.once + end end + it_behaves_like 'receiving one of the required tokens with account_id', :request_token + it_behaves_like 'receiving one of the required tokens with account_id', :installation_id + it_behaves_like 'receiving one of the required tokens with account_id', :session_token + context 'when receiving any other optional arguments' do shared_examples_for 'receiving optional args' do |optional_arguments| it "hits the endpoint also with #{optional_arguments}" do @@ -258,27 +273,36 @@ module Incognia end context "HTTP request" do - it "hits the endpoint with request_token and account_id" do - stub_token_request + shared_examples_for 'receiving one of the required tokens with account_id' do |token_name| + let(:token_value) { SecureRandom.uuid } - stub = stub_payment_request.with( - body: { - type: 'payment', - request_token: request_token, account_id: account_id - }, - headers: { - 'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/ - } - ) + it "hits the endpoint with #{token_name} and account_id" do + stub_token_request - api.register_payment( - request_token: request_token, - account_id: account_id - ) + stub = stub_payment_request.with( + body: { + type: 'payment', + account_id: account_id, + token_name => token_value + }, + headers: { + 'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/ + } + ) - expect(stub).to have_been_made.once + api.register_payment( + account_id: account_id, + token_name => token_value + ) + + expect(stub).to have_been_made.once + end end + it_behaves_like 'receiving one of the required tokens with account_id', :request_token + it_behaves_like 'receiving one of the required tokens with account_id', :installation_id + it_behaves_like 'receiving one of the required tokens with account_id', :session_token + context 'when receiving any other optional arguments' do shared_examples_for 'receiving optional args' do |optional_arguments| it "hits the endpoint also with #{optional_arguments}" do @@ -305,7 +329,7 @@ module Incognia end end - it_behaves_like 'receiving optional args', 'external_id', 'payment request', 'aaa' do + it_behaves_like 'receiving optional args', 'external_id' do let(:opts) { { external_id: 'external-id' } } end it_behaves_like 'receiving optional args', 'payment_value' do From ec0842b293ede0aa622787f7f03e3d0e250b6849 Mon Sep 17 00:00:00 2001 From: Lucas Gomes Date: Mon, 26 Aug 2024 12:28:13 -0300 Subject: [PATCH 5/5] Use compact to remove null parameters on assessments methods --- lib/incognia_api/api.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/incognia_api/api.rb b/lib/incognia_api/api.rb index 21fbdcc..7293c1e 100644 --- a/lib/incognia_api/api.rb +++ b/lib/incognia_api/api.rb @@ -16,8 +16,7 @@ def initialize(client_id:, client_secret:) end def register_signup(request_token: nil, address: nil, **opts) - params = {} - params.merge!({ request_token: request_token }) if request_token + params = { request_token: request_token }.compact params.merge!(opts) params.merge!(address&.to_hash) if address @@ -33,9 +32,9 @@ def register_signup(request_token: nil, address: nil, **opts) def register_login(account_id:, request_token: nil, **opts) params = { type: :login, - account_id: account_id - } - params.merge!({ request_token: request_token }) if request_token + account_id: account_id, + request_token: request_token + }.compact params.merge!(opts) response = connection.request( @@ -69,8 +68,11 @@ def register_feedback(event:, occurred_at: nil, expires_at: nil, timestamp: nil, end def register_payment(account_id:, request_token: nil, **opts) - params = { account_id: account_id, type: :payment } - params.merge!({ request_token: request_token }) if request_token + params = { + type: :payment, + account_id: account_id, + request_token: request_token + }.compact params.merge!(opts) response = connection.request(