diff --git a/incognia/api.py b/incognia/api.py index 2d97d22..8814d60 100644 --- a/incognia/api.py +++ b/incognia/api.py @@ -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.') @@ -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) @@ -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: @@ -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, @@ -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: @@ -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, @@ -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: @@ -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, diff --git a/tests/test_api.py b/tests/test_api.py index 8cdcfd0..a7952cd 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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 @@ -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', @@ -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', @@ -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, @@ -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, @@ -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, @@ -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,