Skip to content

Commit

Permalink
Add support to policy id in login, payment and web login (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielpessoa1 authored May 3, 2024
1 parent ab03f7c commit 726d22f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,15 @@ payment_methods: List[PaymentMethod] = [
}
]

policy_id: str = 'policy-id'

assessment: dict = api.register_payment('installation-id',
'account-id',
'external-id',
addresses=addresses,
payment_value=payment_value,
payment_methods=payment_methods)
payment_methods=payment_methods,
policy_id=policy_id)
```

#### Registering Login
Expand All @@ -193,7 +196,12 @@ from incognia.api import IncogniaAPI

api = IncogniaAPI('client-id', 'client-secret')

assessment: dict = api.register_login('installation-id', 'account-id', 'external-id')
policy_id: str = 'policy-id'

assessment: dict = api.register_login('installation-id',
'account-id',
'external-id',
policy_id='policy_id')
```

## Evidences
Expand Down
18 changes: 12 additions & 6 deletions incognia/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def register_payment(self,
addresses: Optional[List[TransactionAddress]] = None,
payment_value: Optional[PaymentValue] = None,
payment_methods: Optional[List[PaymentMethod]] = None,
evaluate: Optional[bool] = None) -> dict:
evaluate: Optional[bool] = None,
policy_id: Optional[str] = None) -> dict:
if not installation_id:
raise IncogniaError('installation_id is required.')
if not account_id:
Expand All @@ -118,7 +119,8 @@ def register_payment(self,
'external_id': external_id,
'addresses': addresses,
'payment_value': payment_value,
'payment_methods': payment_methods
'payment_methods': payment_methods,
'policy_id': policy_id
}
data = encode(body)
return self.__request.post(Endpoints.TRANSACTIONS, headers=headers, params=params,
Expand All @@ -131,7 +133,8 @@ def register_login(self,
installation_id: str,
account_id: str,
external_id: Optional[str] = None,
evaluate: Optional[bool] = None) -> dict:
evaluate: Optional[bool] = None,
policy_id: Optional[str] = None) -> dict:
if not installation_id:
raise IncogniaError('installation_id is required.')
if not account_id:
Expand All @@ -145,7 +148,8 @@ def register_login(self,
'type': 'login',
'installation_id': installation_id,
'account_id': account_id,
'external_id': external_id
'external_id': external_id,
'policy_id': policy_id
}
data = encode(body)
return self.__request.post(Endpoints.TRANSACTIONS, headers=headers, params=params,
Expand All @@ -158,7 +162,8 @@ def register_web_login(self,
session_token: str,
account_id: str,
external_id: Optional[str] = None,
evaluate: Optional[bool] = None) -> dict:
evaluate: Optional[bool] = None,
policy_id: Optional[str] = None) -> dict:
if not session_token:
raise IncogniaError('session_token is required.')
if not account_id:
Expand All @@ -172,7 +177,8 @@ def register_web_login(self,
'type': 'login',
'session_token': session_token,
'account_id': account_id,
'external_id': external_id
'external_id': external_id,
'policy_id': policy_id
}
data = encode(body)
return self.__request.post(Endpoints.TRANSACTIONS, headers=headers, params=params,
Expand Down
21 changes: 15 additions & 6 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class TestIncogniaAPI(TestCase):
REGISTER_VALID_PAYMENT_DATA: Final[bytes] = encode({
'type': 'payment',
'installation_id': f'{INSTALLATION_ID}',
'account_id': f'{ACCOUNT_ID}'
'account_id': f'{ACCOUNT_ID}',
'policy_id': f'{POLICY_ID}'
})
REGISTER_INVALID_PAYMENT_DATA: Final[bytes] = encode({
'type': 'payment',
Expand All @@ -93,12 +94,14 @@ class TestIncogniaAPI(TestCase):
REGISTER_VALID_LOGIN_DATA: Final[bytes] = encode({
'type': 'login',
'installation_id': f'{INSTALLATION_ID}',
'account_id': f'{ACCOUNT_ID}'
'account_id': f'{ACCOUNT_ID}',
'policy_id': f'{POLICY_ID}'
})
REGISTER_VALID_WEB_LOGIN_DATA: Final[bytes] = encode({
'type': 'login',
'session_token': f'{SESSION_TOKEN}',
'account_id': f'{ACCOUNT_ID}'
'account_id': f'{ACCOUNT_ID}',
'policy_id': f'{POLICY_ID}'
})
REGISTER_INVALID_LOGIN_DATA: Final[bytes] = encode({
'type': 'login',
Expand Down Expand Up @@ -277,7 +280,9 @@ def test_register_payment_when_required_fields_are_valid_should_work(

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

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

mock_token_manager_get.assert_called()
mock_base_request_post.assert_called_with(Endpoints.TRANSACTIONS,
Expand Down Expand Up @@ -337,7 +342,9 @@ def test_register_login_when_required_fields_are_valid_should_work(

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

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

mock_token_manager_get.assert_called()
mock_base_request_post.assert_called_with(Endpoints.TRANSACTIONS,
Expand Down Expand Up @@ -397,7 +404,9 @@ def test_register_web_login_when_required_fields_are_valid_should_work(

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

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

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

0 comments on commit 726d22f

Please sign in to comment.