Skip to content

Commit

Permalink
Merge pull request #28 from inloco/feat/support-request-token
Browse files Browse the repository at this point in the history
Chore: Support request token
  • Loading branch information
lucaswilliamgomes authored Aug 26, 2024
2 parents d58bd87 + ec0842b commit d8c97a1
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 98 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
incognia_api (1.1.0)
incognia_api (1.2.0)
faraday (~> 1.10)
faraday_middleware (~> 1.2)

Expand Down
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand All @@ -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
)
Expand All @@ -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,
)

Expand All @@ -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
Expand All @@ -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'
)

Expand Down Expand Up @@ -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,
Expand All @@ -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
)

Expand All @@ -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
)

Expand Down
18 changes: 11 additions & 7 deletions lib/incognia_api/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion lib/incognia_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Incognia
VERSION = "1.1.0"
VERSION = "1.2.0"
end
Loading

0 comments on commit d8c97a1

Please sign in to comment.