diff --git a/cuenca/resources/terms_of_service.py b/cuenca/resources/terms_of_service.py index c73bc696..a7355f47 100644 --- a/cuenca/resources/terms_of_service.py +++ b/cuenca/resources/terms_of_service.py @@ -1,8 +1,7 @@ import datetime as dt -from typing import ClassVar +from typing import ClassVar, Optional from cuenca_validations.types import TermsOfService as TermsOfServiceEnum -from cuenca_validations.types.general import SerializableHttpUrl from .base import Queryable, Retrievable @@ -11,8 +10,7 @@ class TermsOfService(Retrievable, Queryable): _resource: ClassVar = 'terms_of_service' id: str - is_active: bool created_at: dt.datetime + deactivated_at: Optional[dt.datetime] = None type: TermsOfServiceEnum version: str - uri: SerializableHttpUrl diff --git a/cuenca/resources/users_tos_agreements.py b/cuenca/resources/users_tos_agreements.py index 05ea588a..904e1d59 100644 --- a/cuenca/resources/users_tos_agreements.py +++ b/cuenca/resources/users_tos_agreements.py @@ -1,8 +1,13 @@ import datetime as dt -from typing import ClassVar +from typing import ClassVar, Optional from cuenca_validations.types.general import SerializableHttpUrl +from cuenca_validations.types.requests import ( + FileCuencaUrl, + UserTOSAgreementRequest, +) +from ..http import Session, session as global_session from .base import Creatable, Queryable, Retrievable @@ -12,10 +17,27 @@ class UserTOSAgreement(Creatable, Retrievable, Queryable): id: str created_at: dt.datetime updated_at: dt.datetime - terms_of_service: str + terms_of_service_uri: str user_id: str ip: str location: str - digital_signature: str - signed_document_url: SerializableHttpUrl - notification_id: str + digital_signature: Optional[str] = None + signature_image_url: Optional[FileCuencaUrl] = None + signed_document_url: Optional[SerializableHttpUrl] = None + notification_id: Optional[str] = None + + @classmethod + def create( + cls, + location: str, + tos_id: str, + signature_image_url: Optional[FileCuencaUrl] = None, + *, + session: Session = global_session, + ) -> 'UserTOSAgreement': + req = UserTOSAgreementRequest( + location=location, + tos_id=tos_id, + signature_image_url=signature_image_url, + ) + return cls._create(session=session, **req.model_dump()) diff --git a/cuenca/resources/verifications.py b/cuenca/resources/verifications.py index ca34707d..cf7a0214 100644 --- a/cuenca/resources/verifications.py +++ b/cuenca/resources/verifications.py @@ -39,12 +39,9 @@ def create( cls, recipient: str, type: VerificationType, - platform_id: str, session: Session = global_session, ) -> 'Verification': - req = VerificationRequest( - recipient=recipient, type=type, platform_id=platform_id - ) + req = VerificationRequest(recipient=recipient, type=type) return cls._create(**req.model_dump(), session=session) @classmethod diff --git a/cuenca/version.py b/cuenca/version.py index 8c121fec..a6cf70fb 100644 --- a/cuenca/version.py +++ b/cuenca/version.py @@ -1,3 +1,3 @@ -__version__ = '2.1.5' +__version__ = '2.1.6' CLIENT_VERSION = __version__ API_VERSION = '2020-03-19' diff --git a/requirements.txt b/requirements.txt index b2c46c75..c6f3d6a4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ requests==2.32.3 -cuenca-validations==2.1.8 +cuenca-validations==2.1.11 pydantic-extra-types==2.10.2 diff --git a/tests/resources/cassettes/test_user_tos_agreements_create.yaml b/tests/resources/cassettes/test_user_tos_agreements_create.yaml new file mode 100644 index 00000000..bd7946a8 --- /dev/null +++ b/tests/resources/cassettes/test_user_tos_agreements_create.yaml @@ -0,0 +1,47 @@ +interactions: +- request: + body: '{"tos_id": "TS67f5bf03c1fc891bdf36090d", "location": {"latitude": 9.3953792, + "longitude": -99.139584}, "signature_image_url": null}' + headers: + Authorization: + - DUMMY + Content-Length: + - '131' + Content-Type: + - application/json + User-Agent: + - cuenca-python/2.1.6.dev3 + X-Cuenca-Api-Version: + - '2020-03-19' + method: POST + uri: https://sandbox.cuenca.com/users_tos_agreements + response: + body: + string: '{"id":"UAlyeG0IgKSFi3ZZ2NPKjk3g","created_at":"2025-07-16T21:43:54.817163","updated_at":"2025-07-16T21:43:54.817510","user_id":"USS2gTzkh_Sm2ZPZGtfNOK_Q","terms_of_service_uri":"/terms_of_service/TS67f5bf03c1fc891bdf36090d","ip":"201.141.55.234","location":"9.3953792,-99.139584","signature_image_url":null,"digital_signature":null,"signed_document_url":null,"notification_id":null}' + headers: + Connection: + - keep-alive + Content-Length: + - '382' + Content-Type: + - application/json + Date: + - Wed, 16 Jul 2025 21:43:55 GMT + X-Request-Time: + - 'value: 0.827' + x-amz-apigw-id: + - N0l8OEVHiYcEBdA= + x-amzn-Remapped-Connection: + - keep-alive + x-amzn-Remapped-Content-Length: + - '382' + x-amzn-Remapped-Date: + - Wed, 16 Jul 2025 21:43:55 GMT + x-amzn-Remapped-Server: + - nginx/1.28.0 + x-amzn-RequestId: + - 7e9162b9-6ea8-4592-b28a-502ef7a89345 + status: + code: 201 + message: Created +version: 1 diff --git a/tests/resources/cassettes/test_verification_email_create.yaml b/tests/resources/cassettes/test_verification_email_create.yaml index 0eb28d21..17b75e93 100644 --- a/tests/resources/cassettes/test_verification_email_create.yaml +++ b/tests/resources/cassettes/test_verification_email_create.yaml @@ -1,29 +1,20 @@ interactions: - request: - body: '{"type": "email", "sender": "mail@cuenca.com", "platform_id": - "PL01"}' + body: '{"type": "email", "recipient": "mail@cuenca.com"}' headers: - Accept: - - '*/*' - Accept-Encoding: - - gzip, deflate - Authorization: - - DUMMY - Connection: - - keep-alive Content-Length: - - '82' + - '49' Content-Type: - application/json User-Agent: - - cuenca-python/0.8.0.dev0 + - cuenca-python/2.1.5 X-Cuenca-Api-Version: - '2020-03-19' method: POST uri: https://sandbox.cuenca.com/verifications response: body: - string: '{"id":"VE01","recipient":"mail@cuenca.com","platform_id":"PL01","api_key":null,"type":"email","created_at":"2022-03-16T22:33:21.930707","updated_at":"2022-03-16T22:33:21.931013","deactivated_at":null}' + string: '{"id":"VEG30ywu-KQnWdel9gpz1a-Q","identity_id":null,"platform_id":"PTZbBlk__kQt-wfwzP5nwA9A","created_at":"2025-07-15T22:28:11.987007","updated_at":"2025-07-15T22:28:11.987284","deactivated_at":null,"recipient":"mail@cuenca.com","language":"en","type":"email"}' headers: Connection: - keep-alive @@ -32,21 +23,19 @@ interactions: Content-Type: - application/json Date: - - Wed, 16 Mar 2022 22:33:22 GMT - X-Request-Time: - - 'value: 0.323' + - Tue, 15 Jul 2025 22:28:12 GMT x-amz-apigw-id: - - PGTTzHY-iYcF1zQ= + - NxZfaEnciYcEr9g= x-amzn-Remapped-Connection: - keep-alive x-amzn-Remapped-Content-Length: - '260' x-amzn-Remapped-Date: - - Wed, 16 Mar 2022 22:33:22 GMT + - Tue, 15 Jul 2025 22:28:12 GMT x-amzn-Remapped-Server: - - nginx/1.20.2 + - nginx/1.28.0 x-amzn-RequestId: - - 1403b526-7466-4985-bf8a-b8e6c156e527 + - 2fe363d1-fc8d-4fd5-ba59-e41a88c08711 status: code: 201 message: Created diff --git a/tests/resources/cassettes/test_verification_phone_create.yaml b/tests/resources/cassettes/test_verification_phone_create.yaml index 56849b98..5e5cdd37 100644 --- a/tests/resources/cassettes/test_verification_phone_create.yaml +++ b/tests/resources/cassettes/test_verification_phone_create.yaml @@ -1,29 +1,20 @@ interactions: - request: - body: '{"type": "phone", "sender": "+525555555555", "platform_id": - "PL01"}' + body: '{"type": "phone", "recipient": "+525555555555"}' headers: - Accept: - - '*/*' - Accept-Encoding: - - gzip, deflate - Authorization: - - DUMMY - Connection: - - keep-alive Content-Length: - - '80' + - '47' Content-Type: - application/json User-Agent: - - cuenca-python/0.8.0.dev0 + - cuenca-python/2.1.5 X-Cuenca-Api-Version: - '2020-03-19' method: POST uri: https://sandbox.cuenca.com/verifications response: body: - string: '{"id":"VE02","recipient":"+525555555555","platform_id":"PL01","api_key":null,"type":"phone","created_at":"2022-03-16T22:33:22.657205","updated_at":"2022-03-16T22:33:22.657613","deactivated_at":null}' + string: '{"id":"VEPsf1IUMGT-C0bSFIvPZ17Q","identity_id":null,"platform_id":"PTZbBlk__kQt-wfwzP5nwA9A","created_at":"2025-07-15T22:31:24.231812","updated_at":"2025-07-15T22:31:24.232089","deactivated_at":null,"recipient":"+525555555555","language":"en","type":"phone"}' headers: Connection: - keep-alive @@ -32,21 +23,19 @@ interactions: Content-Type: - application/json Date: - - Wed, 16 Mar 2022 22:33:22 GMT - X-Request-Time: - - 'value: 0.285' + - Tue, 15 Jul 2025 22:31:24 GMT x-amz-apigw-id: - - PGTT7EO2CYcFQ_w= + - NxZ9dHQeiYcEYyw= x-amzn-Remapped-Connection: - keep-alive x-amzn-Remapped-Content-Length: - '258' x-amzn-Remapped-Date: - - Wed, 16 Mar 2022 22:33:22 GMT + - Tue, 15 Jul 2025 22:31:24 GMT x-amzn-Remapped-Server: - - nginx/1.20.2 + - nginx/1.28.0 x-amzn-RequestId: - - 7be1235d-09b6-4bc2-b1d9-93b96ac66519 + - 742a0869-1f8f-487e-9e8c-bed92bb9a923 status: code: 201 message: Created diff --git a/tests/resources/test_users.py b/tests/resources/test_users.py index c8746e1e..2df4ba45 100644 --- a/tests/resources/test_users.py +++ b/tests/resources/test_users.py @@ -83,7 +83,6 @@ def test_user_update_user_email_from_verification(): ver = Verification.create( recipient='mail@cuenca.com', type=VerificationType.email, - platform_id='PL01', ) user = User.update(user_id, email_verification_id=ver.id) assert user.to_dict()['email_address'] == ver.recipient diff --git a/tests/resources/test_users_tos_agreements.py b/tests/resources/test_users_tos_agreements.py new file mode 100644 index 00000000..93a41caa --- /dev/null +++ b/tests/resources/test_users_tos_agreements.py @@ -0,0 +1,12 @@ +import pytest + +from cuenca.resources import UserTOSAgreement + + +@pytest.mark.vcr +def test_user_tos_agreements_create() -> None: + tos = UserTOSAgreement.create( + location="9.3953792,-99.139584", + tos_id="TS67f5bf03c1fc891bdf36090d", + ) + assert tos.id diff --git a/tests/resources/test_verifications.py b/tests/resources/test_verifications.py index 11fb6226..03a7895a 100644 --- a/tests/resources/test_verifications.py +++ b/tests/resources/test_verifications.py @@ -10,7 +10,6 @@ def test_verification_email_create(): verification: Verification = Verification.create( recipient='mail@cuenca.com', type=VerificationType.email, - platform_id='PL01', ) assert verification.id @@ -20,7 +19,6 @@ def test_verification_phone_create(): verification: Verification = Verification.create( recipient='+525555555555', type=VerificationType.phone, - platform_id='PL01', ) assert verification.id