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/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/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 ) diff --git a/lib/incognia_api/api.rb b/lib/incognia_api/api.rb index 0aea807..7293c1e 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(request_token: nil, address: nil, **opts) + params = { request_token: request_token }.compact params.merge!(opts) params.merge!(address&.to_hash) if address @@ -29,12 +29,12 @@ 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:, request_token: nil, **opts) params = { type: :login, - installation_id: installation_id, account_id: account_id, - } + request_token: request_token + }.compact params.merge!(opts) response = connection.request( @@ -67,8 +67,12 @@ 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:, request_token: nil, **opts) + params = { + type: :payment, + account_id: account_id, + request_token: request_token + }.compact params.merge!(opts) response = connection.request( 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 diff --git a/spec/incognia_spec.rb b/spec/incognia_spec.rb index 9677d8e..3305d58 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,73 @@ module Incognia end context "HTTP request" do - it "hits the endpoint with installation_id" 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: { installation_id: installation_id }, - headers: { - 'Content-Type' => 'application/json', 'Authorization' => /Bearer.*/ - } - ) + it "hits the endpoint with #{token_name}" do + stub_token_request - api.register_signup(installation_id: installation_id) + 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 "hits the endpoint with installation_id and address_line" do + 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( - body: { installation_id: installation_id, address_line: line_format }, + stub = stub_signup_request.with( + 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 +135,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 ) @@ -154,11 +161,10 @@ module Incognia end end end - 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 +172,7 @@ module Incognia stub_login_request login = api.register_login( - installation_id: installation_id, + request_token: request_token, account_id: account_id ) @@ -177,27 +183,36 @@ module Incognia end context "HTTP request" do - it "hits the endpoint with installation_id 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', - installation_id: installation_id, 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 - login = api.register_login( - installation_id: installation_id, - 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 @@ -206,16 +221,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 +254,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 +262,7 @@ module Incognia stub_payment_request payment = api.register_payment( - installation_id: installation_id, + request_token: request_token, account_id: account_id ) @@ -258,27 +273,36 @@ module Incognia end context "HTTP request" do - it "hits the endpoint with installation_id 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', - installation_id: installation_id, 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 - payment = api.register_payment( - installation_id: installation_id, - 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 @@ -287,7 +311,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 +319,8 @@ module Incognia } ) - payment = api.register_payment( - installation_id: installation_id, + api.register_payment( + request_token: request_token, account_id: account_id, **opts ) @@ -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 @@ -505,7 +529,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