Skip to content

Commit

Permalink
Add requestToken to all flows
Browse files Browse the repository at this point in the history
  • Loading branch information
aninhalbuquerque committed Aug 15, 2024
1 parent 3f9b08e commit a0368b9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
24 changes: 16 additions & 8 deletions incognia/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def register_new_signup(self,
address_coordinates: Optional[Coordinates] = None,
external_id: Optional[str] = None,
policy_id: Optional[str] = None,
account_id: Optional[str] = None) -> dict:
account_id: Optional[str] = None,
request_token: Optional[str] = None) -> dict:
if not installation_id:
raise IncogniaError('installation_id is required.')

Expand All @@ -40,7 +41,8 @@ def register_new_signup(self,
'address_coordinates': address_coordinates,
'external_id': external_id,
'policy_id': policy_id,
'account_id': account_id
'account_id': account_id,
'request_token': request_token
}
data = encode(body)
return self.__request.post(Endpoints.SIGNUPS, headers=headers, data=data)
Expand Down Expand Up @@ -104,7 +106,8 @@ def register_payment(self,
payment_value: Optional[PaymentValue] = None,
payment_methods: Optional[List[PaymentMethod]] = None,
evaluate: Optional[bool] = None,
policy_id: Optional[str] = None) -> dict:
policy_id: Optional[str] = None,
request_token: Optional[str] = None) -> dict:
if not installation_id:
raise IncogniaError('installation_id is required.')
if not account_id:
Expand All @@ -122,7 +125,8 @@ def register_payment(self,
'addresses': addresses,
'payment_value': payment_value,
'payment_methods': payment_methods,
'policy_id': policy_id
'policy_id': policy_id,
'request_token': request_token
}
data = encode(body)
return self.__request.post(Endpoints.TRANSACTIONS, headers=headers, params=params,
Expand All @@ -136,7 +140,8 @@ def register_login(self,
account_id: str,
external_id: Optional[str] = None,
evaluate: Optional[bool] = None,
policy_id: Optional[str] = None) -> dict:
policy_id: Optional[str] = None,
request_token: Optional[str] = None) -> dict:
if not installation_id:
raise IncogniaError('installation_id is required.')
if not account_id:
Expand All @@ -151,7 +156,8 @@ def register_login(self,
'installation_id': installation_id,
'account_id': account_id,
'external_id': external_id,
'policy_id': policy_id
'policy_id': policy_id,
'request_token': request_token
}
data = encode(body)
return self.__request.post(Endpoints.TRANSACTIONS, headers=headers, params=params,
Expand All @@ -165,7 +171,8 @@ def register_web_login(self,
account_id: str,
external_id: Optional[str] = None,
evaluate: Optional[bool] = None,
policy_id: Optional[str] = None) -> dict:
policy_id: Optional[str] = None,
request_token: Optional[str] = None) -> dict:
if not session_token:
raise IncogniaError('session_token is required.')
if not account_id:
Expand All @@ -180,7 +187,8 @@ def register_web_login(self,
'session_token': session_token,
'account_id': account_id,
'external_id': external_id,
'policy_id': policy_id
'policy_id': policy_id,
'request_token': request_token
}
data = encode(body)
return self.__request.post(Endpoints.TRANSACTIONS, headers=headers, params=params,
Expand Down
24 changes: 16 additions & 8 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class TestIncogniaAPI(TestCase):
'address_coordinates': ADDRESS_COORDINATES,
'external_id': f'{EXTERNAL_ID}',
'policy_id': f'{POLICY_ID}',
'account_id': f'{ACCOUNT_ID}'
'account_id': f'{ACCOUNT_ID}',
'request_token': f'{REQUEST_TOKEN}'
})
OK_STATUS_CODE: Final[int] = 200
CLIENT_ERROR_CODE: Final[int] = 400
Expand Down Expand Up @@ -101,7 +102,8 @@ class TestIncogniaAPI(TestCase):
'type': 'payment',
'installation_id': f'{INSTALLATION_ID}',
'account_id': f'{ACCOUNT_ID}',
'policy_id': f'{POLICY_ID}'
'policy_id': f'{POLICY_ID}',
'request_token': f'{REQUEST_TOKEN}',
})
REGISTER_INVALID_PAYMENT_DATA: Final[bytes] = encode({
'type': 'payment',
Expand All @@ -112,13 +114,15 @@ class TestIncogniaAPI(TestCase):
'type': 'login',
'installation_id': f'{INSTALLATION_ID}',
'account_id': f'{ACCOUNT_ID}',
'policy_id': f'{POLICY_ID}'
'policy_id': f'{POLICY_ID}',
'request_token': f'{REQUEST_TOKEN}'
})
REGISTER_VALID_WEB_LOGIN_DATA: Final[bytes] = encode({
'type': 'login',
'session_token': f'{SESSION_TOKEN}',
'account_id': f'{ACCOUNT_ID}',
'policy_id': f'{POLICY_ID}'
'policy_id': f'{POLICY_ID}',
'request_token': f'{REQUEST_TOKEN}'
})
REGISTER_INVALID_LOGIN_DATA: Final[bytes] = encode({
'type': 'login',
Expand Down Expand Up @@ -161,7 +165,8 @@ def test_register_new_signup_when_installation_id_is_valid_should_return_full_va
address_coordinates=self.ADDRESS_COORDINATES,
external_id=self.EXTERNAL_ID,
policy_id=self.POLICY_ID,
account_id=self.ACCOUNT_ID)
account_id=self.ACCOUNT_ID,
request_token=self.REQUEST_TOKEN)

mock_token_manager_get.assert_called()
mock_base_request_post.assert_called_with(Endpoints.SIGNUPS,
Expand Down Expand Up @@ -312,7 +317,8 @@ def test_register_payment_when_required_fields_are_valid_should_work(

request_response = api.register_payment(self.INSTALLATION_ID,
self.ACCOUNT_ID,
policy_id=self.POLICY_ID)
policy_id=self.POLICY_ID,
request_token=self.REQUEST_TOKEN)

mock_token_manager_get.assert_called()
mock_base_request_post.assert_called_with(Endpoints.TRANSACTIONS,
Expand Down Expand Up @@ -374,7 +380,8 @@ def test_register_login_when_required_fields_are_valid_should_work(

request_response = api.register_login(self.INSTALLATION_ID,
self.ACCOUNT_ID,
policy_id=self.POLICY_ID)
policy_id=self.POLICY_ID,
request_token=self.REQUEST_TOKEN)

mock_token_manager_get.assert_called()
mock_base_request_post.assert_called_with(Endpoints.TRANSACTIONS,
Expand Down Expand Up @@ -436,7 +443,8 @@ def test_register_web_login_when_required_fields_are_valid_should_work(

request_response = api.register_web_login(self.SESSION_TOKEN,
self.ACCOUNT_ID,
policy_id=self.POLICY_ID)
policy_id=self.POLICY_ID,
request_token=self.REQUEST_TOKEN)

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

0 comments on commit a0368b9

Please sign in to comment.