Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions incognia/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def __get_authorization_header(self) -> dict:

def register_new_signup(self,
request_token: Optional[str],
tenant_id: Optional[str] = None,
related_web_request_token: Optional[str] = None,
address_line: Optional[str] = None,
structured_address: Optional[StructuredAddress] = None,
address_coordinates: Optional[Coordinates] = None,
Expand All @@ -50,6 +52,8 @@ def register_new_signup(self,
headers.update(JSON_CONTENT_HEADER)
body = {
'request_token': request_token,
'tenant_id': tenant_id,
'related_web_request_token': related_web_request_token,
'address_line': address_line,
'structured_address': structured_address,
'address_coordinates': address_coordinates,
Expand All @@ -69,6 +73,7 @@ def register_new_signup(self,

def register_new_web_signup(self,
request_token: Optional[str],
tenant_id: Optional[str] = None,
policy_id: Optional[str] = None,
account_id: Optional[str] = None,
custom_properties: Optional[dict] = None,
Expand All @@ -81,6 +86,7 @@ def register_new_web_signup(self,
headers.update(JSON_CONTENT_HEADER)
body = {
'request_token': request_token,
'tenant_id': tenant_id,
'policy_id': policy_id,
'account_id': account_id,
'custom_properties': custom_properties,
Expand Down Expand Up @@ -152,7 +158,9 @@ def register_payment(self,
store_id: Optional[str] = None,
person_id: Optional[PersonID] = None,
debtor_account: Optional[BankAccountInfo] = None,
creditor_account: Optional[BankAccountInfo] = None) -> dict:
creditor_account: Optional[BankAccountInfo] = None,
tenant_id: Optional[str] = None,
related_web_request_token: Optional[str] = None) -> dict:
if not request_token:
raise IncogniaError('request_token is required.')
if not account_id:
Expand Down Expand Up @@ -190,6 +198,8 @@ def register_payment(self,
'person_id': person_id,
'debtor_account': debtor_account,
'creditor_account': creditor_account,
'tenant_id': tenant_id,
'related_web_request_token': related_web_request_token,
}
data = encode(body)
return self.__request.post(Endpoints.TRANSACTIONS, headers=headers, params=params,
Expand All @@ -208,7 +218,9 @@ def register_login(self,
device_os: Optional[str] = None,
app_version: Optional[str] = None,
custom_properties: Optional[dict] = None,
person_id: Optional[PersonID] = None) -> dict:
person_id: Optional[PersonID] = None,
tenant_id: Optional[str] = None,
related_web_request_token: Optional[str] = None) -> dict:

if not request_token:
raise IncogniaError('request_token is required.')
Expand Down Expand Up @@ -240,6 +252,8 @@ def register_login(self,
'app_version': app_version,
'custom_properties': custom_properties,
'person_id': person_id,
'tenant_id': tenant_id,
'related_web_request_token': related_web_request_token,
}
data = encode(body)
return self.__request.post(Endpoints.TRANSACTIONS, headers=headers, params=params,
Expand All @@ -255,7 +269,8 @@ def register_web_login(self,
evaluate: Optional[bool] = None,
policy_id: Optional[str] = None,
custom_properties: Optional[dict] = None,
person_id: Optional[PersonID] = None) -> dict:
person_id: Optional[PersonID] = None,
tenant_id: Optional[str] = None) -> dict:
if not request_token:
raise IncogniaError('request_token is required.')
if not account_id:
Expand All @@ -273,6 +288,7 @@ def register_web_login(self,
'policy_id': policy_id,
'custom_properties': custom_properties,
'person_id': person_id,
'tenant_id': tenant_id,
}
data = encode(body)
return self.__request.post(Endpoints.TRANSACTIONS, headers=headers, params=params,
Expand Down
48 changes: 34 additions & 14 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class TestIncogniaAPI(TestCase):
ADDRESS_LINE: Final[str] = 'ANY_ADDRESS_LINE'
DEVICE_OS: Final[str] = 'ANY_DEVICE_OS'
APP_VERSION: Final[str] = 'ANY_APP_VERSION'
TENANT_ID: Final[str] = 'TENANT_ID'
RELATED_WEB_REQUEST_TOKEN: Final[str] = 'RELATED_WEB_REQUEST_TOKEN'
PERSON_ID: Final[dict] = {
'type': 'cpf',
'value': '12345678901'
Expand Down Expand Up @@ -72,6 +74,8 @@ class TestIncogniaAPI(TestCase):
}
FULL_REGISTER_SIGNUP_DATA: Final[bytes] = encode({
'request_token': f'{REQUEST_TOKEN}',
'tenant_id': TENANT_ID,
'related_web_request_token': RELATED_WEB_REQUEST_TOKEN,
'address_line': f'{ADDRESS_LINE}',
'structured_address': STRUCTURED_ADDRESS,
'address_coordinates': ADDRESS_COORDINATES,
Expand All @@ -91,6 +95,7 @@ class TestIncogniaAPI(TestCase):
})
FULL_REGISTER_WEB_SIGNUP_DATA: Final[bytes] = encode({
'request_token': f'{REQUEST_TOKEN}',
'tenant_id': TENANT_ID,
'policy_id': f'{POLICY_ID}',
'account_id': f'{ACCOUNT_ID}',
'custom_properties': CUSTOM_PROPERTIES,
Expand Down Expand Up @@ -207,7 +212,9 @@ class TestIncogniaAPI(TestCase):
'store_id': f'{STORE_ID}',
'person_id': PERSON_ID,
'debtor_account': BANK_ACCOUNT_INFO,
'creditor_account': BANK_ACCOUNT_INFO
'creditor_account': BANK_ACCOUNT_INFO,
'tenant_id': TENANT_ID,
'related_web_request_token': RELATED_WEB_REQUEST_TOKEN
})
REGISTER_VALID_PAYMENT_DATA_WITH_LOCATION: Final[bytes] = encode({
'type': 'payment',
Expand Down Expand Up @@ -245,6 +252,8 @@ class TestIncogniaAPI(TestCase):
'app_version': f'{APP_VERSION}',
'custom_properties': CUSTOM_PROPERTIES,
'person_id': PERSON_ID,
'tenant_id': TENANT_ID,
'related_web_request_token': RELATED_WEB_REQUEST_TOKEN
})
REGISTER_VALID_WEB_LOGIN_DATA: Final[bytes] = encode({
'type': 'login',
Expand All @@ -259,7 +268,8 @@ class TestIncogniaAPI(TestCase):
'external_id': f'{EXTERNAL_ID}',
'policy_id': f'{POLICY_ID}',
'custom_properties': CUSTOM_PROPERTIES,
'person_id': PERSON_ID
'person_id': PERSON_ID,
'tenant_id': TENANT_ID,
})
REGISTER_INVALID_LOGIN_DATA: Final[bytes] = encode({
'type': 'login',
Expand Down Expand Up @@ -328,6 +338,8 @@ def test_register_new_signup_when_request_token_is_valid_should_return_full_vali
device_os=self.DEVICE_OS,
app_version=self.APP_VERSION,
person_id=self.PERSON_ID,
tenant_id=self.TENANT_ID,
related_web_request_token=self.RELATED_WEB_REQUEST_TOKEN,
custom_properties=self.CUSTOM_PROPERTIES)

mock_token_manager_get.assert_called()
Expand All @@ -348,7 +360,8 @@ def test_register_new_web_signup_when_request_token_is_valid_should_return_full_
policy_id=self.POLICY_ID,
account_id=self.ACCOUNT_ID,
custom_properties=self.CUSTOM_PROPERTIES,
person_id=self.PERSON_ID)
person_id=self.PERSON_ID,
tenant_id=self.TENANT_ID)

mock_token_manager_get.assert_called()
mock_base_request_post.assert_called_with(Endpoints.SIGNUPS,
Expand Down Expand Up @@ -529,7 +542,9 @@ def test_register_payment_with_all_fields_should_work(
store_id=self.STORE_ID,
person_id=self.PERSON_ID,
debtor_account=self.BANK_ACCOUNT_INFO,
creditor_account=self.BANK_ACCOUNT_INFO
creditor_account=self.BANK_ACCOUNT_INFO,
tenant_id=self.TENANT_ID,
related_web_request_token=self.RELATED_WEB_REQUEST_TOKEN,
)

mock_token_manager_get.assert_called()
Expand Down Expand Up @@ -681,7 +696,8 @@ def test_register_web_login_when_all_fields_are_valid_should_work(
external_id=self.EXTERNAL_ID,
policy_id=self.POLICY_ID,
custom_properties=self.CUSTOM_PROPERTIES,
person_id=self.PERSON_ID)
person_id=self.PERSON_ID,
tenant_id=self.TENANT_ID,)
mock_token_manager_get.assert_called()
mock_base_request_post.assert_called_with(Endpoints.TRANSACTIONS,
headers=self.AUTH_AND_JSON_CONTENT_HEADERS,
Expand Down Expand Up @@ -765,15 +781,19 @@ def test_register_login_with_all_fields_should_work(

api = IncogniaAPI(self.CLIENT_ID, self.CLIENT_SECRET)

request_response = api.register_login(self.REQUEST_TOKEN,
self.ACCOUNT_ID,
location=self.LOCATION,
external_id=self.EXTERNAL_ID,
policy_id=self.POLICY_ID,
device_os=self.DEVICE_OS,
app_version=self.APP_VERSION,
custom_properties=self.CUSTOM_PROPERTIES,
person_id=self.PERSON_ID)
request_response = api.register_login(
self.REQUEST_TOKEN,
self.ACCOUNT_ID,
location=self.LOCATION,
external_id=self.EXTERNAL_ID,
policy_id=self.POLICY_ID,
device_os=self.DEVICE_OS,
app_version=self.APP_VERSION,
custom_properties=self.CUSTOM_PROPERTIES,
person_id=self.PERSON_ID,
tenant_id=self.TENANT_ID,
related_web_request_token=self.RELATED_WEB_REQUEST_TOKEN,
)

mock_token_manager_get.assert_called()
mock_base_request_post.assert_called_with(Endpoints.TRANSACTIONS,
Expand Down
Loading