Skip to content

Commit

Permalink
Replace installation_id and session_token with request token
Browse files Browse the repository at this point in the history
  • Loading branch information
aninhalbuquerque committed Sep 13, 2024
1 parent 9eed693 commit 635ea3b
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 112 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Authentication is done transparently, so you don't need to worry about it.

#### Registering New Signup

This method registers a new signup for the given installation and a structured address, an address
This method registers a new signup for the given request token and a structured address, an address
line or coordinates, returning a `dict`, containing the risk assessment and supporting evidence:

```python3
Expand All @@ -56,30 +56,30 @@ structured_address: StructuredAddress = {
'complements': 'Floor 2',
'postal_code': '10001'
}
assessment: dict = api.register_new_signup('installation-id', structured_address=structured_address)
assessment: dict = api.register_new_signup('request-token', structured_address=structured_address)

# with address line:
address_line: str = '350 Fifth Avenue, Manhattan, New York 10118'
assessment: dict = api.register_new_signup('installation-id', address_line=address_line)
assessment: dict = api.register_new_signup('request-token', address_line=address_line)

# with coordinates, a dict:
coordinates: Coordinates = {
'lat': 40.74836007062138,
'lng': -73.98509720487937
}
assessment: dict = api.register_new_signup('installation-id', address_coordinates=coordinates)
assessment: dict = api.register_new_signup('request-token', address_coordinates=coordinates)

# with external_id:
external_id: str = 'external-id'
assessment: dict = api.register_new_signup('installation-id', external_id=external_id)
assessment: dict = api.register_new_signup('request-token', external_id=external_id)

# with policy_id:
policy_id: str = 'policy-id'
assessment: dict = api.register_new_signup('installation-id', policy_id=policy_id)
assessment: dict = api.register_new_signup('request-token', policy_id=policy_id)

# with account_id:
account_id: str = 'account-id'
assessment: dict = api.register_new_signup('installation-id', account_id=account_id)
assessment: dict = api.register_new_signup('request-token', account_id=account_id)

```

Expand All @@ -97,13 +97,13 @@ api = IncogniaAPI('client-id', 'client-secret')

api.register_feedback(FeedbackEvents.ACCOUNT_TAKEOVER,
occurred_at=dt.datetime(2024, 7, 22, 15, 20, 0, tzinfo=dt.timezone.utc),
installation_id='installation-id',
request_token='request-token',
account_id='account-id')
```

#### Registering Payment

This method registers a new payment for the given installation and account, returning a `dict`,
This method registers a new payment for the given request token and account, returning a `dict`,
containing the risk assessment and supporting evidence.

```python3
Expand Down Expand Up @@ -164,7 +164,7 @@ payment_methods: List[PaymentMethod] = [

policy_id: str = 'policy-id'

assessment: dict = api.register_payment('installation-id',
assessment: dict = api.register_payment('request-token',
'account-id',
'external-id',
addresses=addresses,
Expand All @@ -175,7 +175,7 @@ assessment: dict = api.register_payment('installation-id',

#### Registering Login

This method registers a new login for the given installation and account, returning a `dict`,
This method registers a new login for the given request token and account, returning a `dict`,
containing the risk assessment and supporting evidence.

```python3
Expand All @@ -185,7 +185,7 @@ api = IncogniaAPI('client-id', 'client-secret')

policy_id: str = 'policy-id'

assessment: dict = api.register_login('installation-id',
assessment: dict = api.register_login('request-token',
'account-id',
'external-id',
policy_id='policy_id')
Expand Down
60 changes: 24 additions & 36 deletions incognia/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,27 @@ def __get_authorization_header(self) -> dict:
return {'Authorization': f'{token_type} {access_token}'}

def register_new_signup(self,
installation_id: str,
request_token: Optional[str],
address_line: Optional[str] = None,
structured_address: Optional[StructuredAddress] = None,
address_coordinates: Optional[Coordinates] = None,
external_id: Optional[str] = None,
policy_id: Optional[str] = None,
account_id: Optional[str] = None,
request_token: Optional[str] = None) -> dict:
if not installation_id:
raise IncogniaError('installation_id is required.')
account_id: Optional[str] = None) -> dict:
if not request_token:
raise IncogniaError('request_token is required.')

try:
headers = self.__get_authorization_header()
headers.update(JSON_CONTENT_HEADER)
body = {
'installation_id': installation_id,
'request_token': request_token,
'address_line': address_line,
'structured_address': structured_address,
'address_coordinates': address_coordinates,
'external_id': external_id,
'policy_id': policy_id,
'account_id': account_id,
'request_token': request_token
'account_id': account_id
}
data = encode(body)
return self.__request.post(Endpoints.SIGNUPS, headers=headers, data=data)
Expand All @@ -58,8 +56,6 @@ def register_feedback(self,
payment_id: Optional[str] = None,
signup_id: Optional[str] = None,
account_id: Optional[str] = None,
installation_id: Optional[str] = None,
session_token: Optional[str] = None,
request_token: Optional[str] = None,
occurred_at: dt.datetime = None,
expires_at: dt.datetime = None) -> None:
Expand All @@ -82,8 +78,6 @@ def register_feedback(self,
'payment_id': payment_id,
'signup_id': signup_id,
'account_id': account_id,
'installation_id': installation_id,
'session_token': session_token,
'request_token': request_token
}
if timestamp is not None:
Expand All @@ -99,17 +93,16 @@ def register_feedback(self,
raise IncogniaHTTPError(e) from None

def register_payment(self,
installation_id: str,
request_token: str,
account_id: str,
external_id: Optional[str] = None,
addresses: Optional[List[TransactionAddress]] = None,
payment_value: Optional[PaymentValue] = None,
payment_methods: Optional[List[PaymentMethod]] = None,
evaluate: Optional[bool] = None,
policy_id: Optional[str] = None,
request_token: Optional[str] = None) -> dict:
if not installation_id:
raise IncogniaError('installation_id is required.')
policy_id: Optional[str] = None) -> dict:
if not request_token:
raise IncogniaError('request_token is required.')
if not account_id:
raise IncogniaError('account_id is required.')

Expand All @@ -119,14 +112,13 @@ def register_payment(self,
params = None if evaluate is None else {'eval': evaluate}
body = {
'type': 'payment',
'installation_id': installation_id,
'request_token': request_token,
'account_id': account_id,
'external_id': external_id,
'addresses': addresses,
'payment_value': payment_value,
'payment_methods': payment_methods,
'policy_id': policy_id,
'request_token': request_token
'policy_id': policy_id
}
data = encode(body)
return self.__request.post(Endpoints.TRANSACTIONS, headers=headers, params=params,
Expand All @@ -136,14 +128,13 @@ def register_payment(self,
raise IncogniaHTTPError(e) from None

def register_login(self,
installation_id: str,
request_token: str,
account_id: str,
external_id: Optional[str] = None,
evaluate: Optional[bool] = None,
policy_id: Optional[str] = None,
request_token: Optional[str] = None) -> dict:
if not installation_id:
raise IncogniaError('installation_id is required.')
policy_id: Optional[str] = None) -> dict:
if not request_token:
raise IncogniaError('request_token is required.')
if not account_id:
raise IncogniaError('account_id is required.')

Expand All @@ -153,11 +144,10 @@ def register_login(self,
params = None if evaluate is None else {'eval': evaluate}
body = {
'type': 'login',
'installation_id': installation_id,
'request_token': request_token,
'account_id': account_id,
'external_id': external_id,
'policy_id': policy_id,
'request_token': request_token
'policy_id': policy_id
}
data = encode(body)
return self.__request.post(Endpoints.TRANSACTIONS, headers=headers, params=params,
Expand All @@ -167,14 +157,13 @@ def register_login(self,
raise IncogniaHTTPError(e) from None

def register_web_login(self,
session_token: str,
request_token: str,
account_id: str,
external_id: Optional[str] = None,
evaluate: Optional[bool] = None,
policy_id: Optional[str] = None,
request_token: Optional[str] = None) -> dict:
if not session_token:
raise IncogniaError('session_token is required.')
policy_id: Optional[str] = None) -> dict:
if not request_token:
raise IncogniaError('request_token is required.')
if not account_id:
raise IncogniaError('account_id is required.')

Expand All @@ -184,11 +173,10 @@ def register_web_login(self,
params = None if evaluate is None else {'eval': evaluate}
body = {
'type': 'login',
'session_token': session_token,
'request_token': request_token,
'account_id': account_id,
'external_id': external_id,
'policy_id': policy_id,
'request_token': request_token
'policy_id': policy_id
}
data = encode(body)
return self.__request.post(Endpoints.TRANSACTIONS, headers=headers, params=params,
Expand Down
Loading

0 comments on commit 635ea3b

Please sign in to comment.