diff --git a/cuenca/resources/__init__.py b/cuenca/resources/__init__.py index 6b6e287f..cabdd52e 100644 --- a/cuenca/resources/__init__.py +++ b/cuenca/resources/__init__.py @@ -13,6 +13,7 @@ 'Deposit', 'Identity', 'IdentityEvent', + 'InternationalTransfer', 'LoginToken', 'Saving', 'ServiceProvider', @@ -40,6 +41,7 @@ from .deposits import Deposit from .identities import Identity from .identity_events import IdentityEvent +from .international_transfers import InternationalTransfer from .login_tokens import LoginToken from .resources import RESOURCES from .savings import Saving @@ -70,6 +72,7 @@ Deposit, Identity, IdentityEvent, + InternationalTransfer, LoginToken, Saving, Session, diff --git a/cuenca/resources/international_transfers.py b/cuenca/resources/international_transfers.py new file mode 100644 index 00000000..8bf5621d --- /dev/null +++ b/cuenca/resources/international_transfers.py @@ -0,0 +1,71 @@ +import datetime as dt +from typing import ClassVar, cast + +from cuenca_validations.types import ( + Country, + Currency, + InternationalTransferQuery, + InternationalTransferRequest, + InternationalTransferUpdateRequest, + TransactionStatus, +) +from pydantic.dataclasses import dataclass + +from .base import Creatable, Queryable, Retrievable, Updateable + + +@dataclass +class InternationalTransfer(Creatable, Retrievable, Updateable, Queryable): + _resource: ClassVar = 'international_transfers' + _query_params: ClassVar = InternationalTransferQuery + + user_id: str + updated_at: dt.datetime + idempotency_key: str + bank_number: str + account_number: str + account_country: Country + account_name: str + received_amount: int + received_currency: Currency + sent_amount: int + sent_currency: Currency + status: TransactionStatus + + @classmethod + def create( + cls, + user_id: str, + idempotency_key: str, + bank_number: str, + account_number: str, + account_country: Country, + account_name: str, + received_amount: int, + received_currency: Currency, + sent_amount: int, + sent_currency: Currency, + ) -> 'InternationalTransfer': + req = InternationalTransferRequest( + user_id=user_id, + idempotency_key=idempotency_key, + bank_number=bank_number, + account_number=account_number, + account_country=account_country, + account_name=account_name, + received_amount=received_amount, + received_currency=received_currency, + sent_amount=sent_amount, + sent_currency=sent_currency, + ) + return cast('InternationalTransfer', cls._create(**req.dict())) + + @classmethod + def update( + cls, + transfer_id: str, + status: TransactionStatus = None, + ) -> 'InternationalTransfer': + req = InternationalTransferUpdateRequest(status=status) + resp = cls._update(transfer_id, **req.dict()) + return cast('InternationalTransfer', resp) diff --git a/cuenca/resources/transfers.py b/cuenca/resources/transfers.py index 5f5185e2..80495d25 100644 --- a/cuenca/resources/transfers.py +++ b/cuenca/resources/transfers.py @@ -41,6 +41,7 @@ def create( descriptor: str, recipient_name: str, idempotency_key: Optional[str] = None, + user_id: Optional[str] = None, ) -> 'Transfer': """ :param account_number: CLABE @@ -67,6 +68,7 @@ def create( descriptor=descriptor, recipient_name=recipient_name, idempotency_key=idempotency_key, + user_id=user_id, ) return cast('Transfer', cls._create(**req.dict())) diff --git a/cuenca/version.py b/cuenca/version.py index d29ae318..c8a8310f 100644 --- a/cuenca/version.py +++ b/cuenca/version.py @@ -1,3 +1,3 @@ -__version__ = '0.7.14' +__version__ = '0.7.18.dev2' CLIENT_VERSION = __version__ API_VERSION = '2020-03-19' diff --git a/requirements.txt b/requirements.txt index 1ec335b4..7206fc45 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ requests==2.27.1 -cuenca-validations==0.9.18 +cuenca-validations==0.9.19.dev5 dataclasses>=0.7;python_version<"3.7" diff --git a/tests/conftest.py b/tests/conftest.py index eb06ce37..c921e3d0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,7 +2,7 @@ from typing import Dict import pytest -from cuenca_validations.types import Country, Gender, State +from cuenca_validations.types import Country, Currency, Gender, State import cuenca @@ -60,3 +60,19 @@ def user_request() -> Dict: ), ) return user_dict + + +@pytest.fixture +def international_transfer() -> Dict: + return dict( + user_id='UShhSTmmy_R2y6KvQsGnTTMw', + idempotency_key="MY_UNIQUE_KEY", + bank_number="001287364", + account_number="1024357689", + account_country=Country.US, + account_name="Amanda Brown", + received_amount=20825, + received_currency=Currency.mxn, + sent_amount=1000, + sent_currency=Currency.usd, + ) diff --git a/tests/resources/cassettes/test_complete_flow_international_transfers.yaml b/tests/resources/cassettes/test_complete_flow_international_transfers.yaml new file mode 100644 index 00000000..7daa5ca4 --- /dev/null +++ b/tests/resources/cassettes/test_complete_flow_international_transfers.yaml @@ -0,0 +1,220 @@ +interactions: +- request: + body: '{"user_id": "UShhSTmmy_R2y6KvQsGnTTMw", "idempotency_key": "MY_UNIQUE_KEY", + "bank_number": "001287364", "account_number": "1024357689", "account_country": + "US", "account_name": "Amanda Brown", "received_amount": 20825, "received_currency": + "mxn", "sent_amount": 1000, "sent_currency": "usd"}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Authorization: + - DUMMY + Connection: + - keep-alive + Content-Length: + - '294' + Content-Type: + - application/json + User-Agent: + - cuenca-python/0.7.14 + X-Cuenca-Api-Version: + - '2020-03-19' + method: POST + uri: https://sandbox.cuenca.com/international_transfers + response: + body: + string: '{"id":"ITR99YzKs-RBWY0yqT9OU8Ig","created_at":"2022-02-23T02:38:24.829896","updated_at":"2022-02-23T02:38:24.830008","platform_id":"PTW68GgAc_QPmNCmgajmctLg","user_id":"UShhSTmmy_R2y6KvQsGnTTMw","idempotency_key":"MY_UNIQUE_KEY","bank_number":"001287364","account_number":"1024357689","account_country":"US","account_name":"Amanda + Brown","received_amount":20825,"received_currency":"mxn","sent_amount":1000,"sent_currency":"usd","status":"created"}' + headers: + Connection: + - keep-alive + Content-Length: + - '451' + Content-Type: + - application/json + Date: + - Wed, 23 Feb 2022 02:38:25 GMT + X-Amzn-Trace-Id: + - Root=1-62159e20-7ef7e32c44d016c502d37456;Sampled=0 + X-Request-Time: + - 'value: 0.599' + x-amz-apigw-id: + - N-WlHGSAiYcFinQ= + x-amzn-Remapped-Connection: + - keep-alive + x-amzn-Remapped-Content-Length: + - '451' + x-amzn-Remapped-Date: + - Wed, 23 Feb 2022 02:38:25 GMT + x-amzn-Remapped-Server: + - nginx/1.20.2 + x-amzn-Remapped-x-amzn-RequestId: + - 36afccd4-6cad-4fcc-bf42-454a10b05e66 + x-amzn-RequestId: + - 75c0b373-d9d3-44a0-816e-39dd36568a1b + status: + code: 201 + message: Created +- request: + body: '{"user_id": "UShhSTmmy_R2y6KvQsGnTTMw", "type": "session.international_transfers"}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Authorization: + - DUMMY + Connection: + - keep-alive + Content-Length: + - '82' + Content-Type: + - application/json + User-Agent: + - cuenca-python/0.7.14 + X-Cuenca-Api-Version: + - '2020-03-19' + method: POST + uri: https://sandbox.cuenca.com/sessions + response: + body: + string: '{"id":"SSsRTCbNj_QuetY7NXKDV9JA","created_at":"2022-02-23T02:38:27.556105","user_id":"UShhSTmmy_R2y6KvQsGnTTMw","platform_id":"PTW68GgAc_QPmNCmgajmctLg","expires_at":"2022-02-23T02:48:27.556113","success_url":null,"failure_url":null,"type":"session.international_transfers"}' + headers: + Connection: + - keep-alive + Content-Length: + - '274' + Content-Type: + - application/json + Date: + - Wed, 23 Feb 2022 02:38:27 GMT + X-Request-Time: + - 'value: 0.128' + x-amz-apigw-id: + - N-WlkEUNCYcF-aQ= + x-amzn-Remapped-Connection: + - keep-alive + x-amzn-Remapped-Content-Length: + - '274' + x-amzn-Remapped-Date: + - Wed, 23 Feb 2022 02:38:27 GMT + x-amzn-Remapped-Server: + - nginx/1.20.2 + x-amzn-RequestId: + - eef6fe1b-e4ee-45eb-9ab1-37ccc81bfcc9 + status: + code: 201 + message: Created +- request: + body: '{"status": "submitted"}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Authorization: + - DUMMY + Connection: + - keep-alive + Content-Length: + - '23' + Content-Type: + - application/json + User-Agent: + - cuenca-python/0.7.14 + X-Cuenca-Api-Version: + - '2020-03-19' + X-Cuenca-SessionId: + - SSsRTCbNj_QuetY7NXKDV9JA + method: PATCH + uri: https://sandbox.cuenca.com/international_transfers/ITR99YzKs-RBWY0yqT9OU8Ig + response: + body: + string: '{"id":"ITR99YzKs-RBWY0yqT9OU8Ig","created_at":"2022-02-23T02:38:24.829000","updated_at":"2022-02-23T02:38:27.936699","platform_id":"PTW68GgAc_QPmNCmgajmctLg","user_id":"UShhSTmmy_R2y6KvQsGnTTMw","idempotency_key":"MY_UNIQUE_KEY","bank_number":"001287364","account_number":"1024357689","account_country":"US","account_name":"Amanda + Brown","received_amount":20825,"received_currency":"mxn","sent_amount":1000,"sent_currency":"usd","status":"submitted"}' + headers: + Connection: + - keep-alive + Content-Length: + - '453' + Content-Type: + - application/json + Date: + - Wed, 23 Feb 2022 02:38:28 GMT + X-Amzn-Trace-Id: + - Root=1-62159e23-6a5355b50c76438932276b5a;Sampled=0 + X-Request-Time: + - 'value: 0.552' + x-amz-apigw-id: + - N-WlmHnDiYcFS3g= + x-amzn-Remapped-Connection: + - keep-alive + x-amzn-Remapped-Content-Length: + - '453' + x-amzn-Remapped-Date: + - Wed, 23 Feb 2022 02:38:28 GMT + x-amzn-Remapped-Server: + - nginx/1.20.2 + x-amzn-Remapped-x-amzn-RequestId: + - e2d46dd5-9d9f-48c7-8252-64b4948311a8 + x-amzn-RequestId: + - 35dc7e41-4691-4ea9-ba48-7d9d908975b6 + status: + code: 201 + message: Created +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Authorization: + - DUMMY + Connection: + - keep-alive + User-Agent: + - cuenca-python/0.7.14 + X-Cuenca-Api-Version: + - '2020-03-19' + X-Cuenca-SessionId: + - SSsRTCbNj_QuetY7NXKDV9JA + method: GET + uri: https://sandbox.cuenca.com/international_transfers/ITR99YzKs-RBWY0yqT9OU8Ig + response: + body: + string: '{"id":"ITR99YzKs-RBWY0yqT9OU8Ig","created_at":"2022-02-23T02:38:24.829000","updated_at":"2022-02-23T02:38:27.936000","platform_id":"PTW68GgAc_QPmNCmgajmctLg","user_id":"UShhSTmmy_R2y6KvQsGnTTMw","idempotency_key":"MY_UNIQUE_KEY","bank_number":"001287364","account_number":"1024357689","account_country":"US","account_name":"Amanda + Brown","received_amount":20825,"received_currency":"mxn","sent_amount":1000,"sent_currency":"usd","status":"succeeded"}' + headers: + Connection: + - keep-alive + Content-Length: + - '453' + Content-Type: + - application/json + Date: + - Wed, 23 Feb 2022 02:38:28 GMT + X-Amzn-Trace-Id: + - Root=1-62159e24-1279be201ddb13244f73668c;Sampled=0 + X-Request-Time: + - 'value: 0.446' + x-amz-apigw-id: + - N-WltFqoCYcF70g= + x-amzn-Remapped-Connection: + - keep-alive + x-amzn-Remapped-Content-Length: + - '453' + x-amzn-Remapped-Date: + - Wed, 23 Feb 2022 02:38:28 GMT + x-amzn-Remapped-Server: + - nginx/1.20.2 + x-amzn-Remapped-x-amzn-RequestId: + - 5a6784ec-9a5a-4e55-b0f2-6338131242c8 + x-amzn-RequestId: + - ea533480-c82d-45c2-8274-99ae94837f09 + status: + code: 200 + message: OK +version: 1 diff --git a/tests/resources/cassettes/test_create_international_transfer.yaml b/tests/resources/cassettes/test_create_international_transfer.yaml new file mode 100644 index 00000000..49f28984 --- /dev/null +++ b/tests/resources/cassettes/test_create_international_transfer.yaml @@ -0,0 +1,173 @@ +interactions: +- request: + body: '{"user_id": "UShhSTmmy_R2y6KvQsGnTTMw", "idempotency_key": "MY_UNIQUE_KEY", + "bank_number": "001287364", "account_number": "1024357689", "account_country": + "US", "account_name": "Amanda Brown", "received_amount": 20825, "received_currency": + "mxn", "sent_amount": 1000, "sent_currency": "usd"}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Authorization: + - DUMMY + Connection: + - keep-alive + Content-Length: + - '291' + Content-Type: + - application/json + User-Agent: + - cuenca-python/0.7.14 + X-Cuenca-Api-Version: + - '2020-03-19' + method: POST + uri: https://sandbox.cuenca.com/international_transfers + response: + body: + string: '{"id":"ITeGc6ZBb8S96zqDhtY0AO3g","created_at":"2022-02-23T01:56:46.622466","updated_at":"2022-02-23T01:56:46.622597","platform_id":"PTW68GgAc_QPmNCmgajmctLg","user_id":"UShhSTmmy_R2y6KvQsGnTTMw","idempotency_key":"MY_UNIQUE_KEY","bank_number":"001287364","account_number":"1024357689","account_country":"US","account_name":"Amanda + Brown","received_amount":20825,"received_currency":"mxn","sent_amount":1000,"sent_currency":"usd","status":"created"}' + headers: + Connection: + - keep-alive + Content-Length: + - '448' + Content-Type: + - application/json + Date: + - Wed, 23 Feb 2022 01:56:47 GMT + X-Amzn-Trace-Id: + - Root=1-6215945e-1125a62466cd96ce7807492c;Sampled=0 + X-Request-Time: + - 'value: 0.913' + x-amz-apigw-id: + - N-QexH2miYcFUnw= + x-amzn-Remapped-Connection: + - keep-alive + x-amzn-Remapped-Content-Length: + - '448' + x-amzn-Remapped-Date: + - Wed, 23 Feb 2022 01:56:47 GMT + x-amzn-Remapped-Server: + - nginx/1.20.2 + x-amzn-Remapped-x-amzn-RequestId: + - 78bf7fa7-4e01-4a8a-b88e-1ba44997f20c + x-amzn-RequestId: + - e7657397-ba8f-46d0-9e9d-ca214884d02b + status: + code: 201 + message: Created +- request: + body: '{"user_id": "UShhSTmmy_R2y6KvQsGnTTMw", "idempotency_key": "MY_UNIQUE_KEY", + "bank_number": "001287364", "account_number": "1024357689", "account_country": + "US", "account_name": "Amanda Brown", "received_amount": 20825, "received_currency": + "mxn", "sent_amount": 1000, "sent_currency": "usd"}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Authorization: + - DUMMY + Connection: + - keep-alive + Content-Length: + - '291' + Content-Type: + - application/json + User-Agent: + - cuenca-python/0.7.14 + X-Cuenca-Api-Version: + - '2020-03-19' + method: POST + uri: https://sandbox.cuenca.com/international_transfers + response: + body: + string: '{"id":"ITeGc6ZBb8S96zqDhtY0AO3g","created_at":"2022-02-23T01:56:46.622000","updated_at":"2022-02-23T01:56:46.622000","platform_id":"PTW68GgAc_QPmNCmgajmctLg","user_id":"UShhSTmmy_R2y6KvQsGnTTMw","idempotency_key":"MY_UNIQUE_KEY","bank_number":"001287364","account_number":"1024357689","account_country":"US","account_name":"Amanda + Brown","received_amount":20825,"received_currency":"mxn","sent_amount":1000,"sent_currency":"usd","status":"created"}' + headers: + Connection: + - keep-alive + Content-Length: + - '448' + Content-Type: + - application/json + Date: + - Wed, 23 Feb 2022 01:56:47 GMT + X-Amzn-Trace-Id: + - Root=1-6215945f-123f04087b571f6729fc6d0e;Sampled=0 + X-Request-Time: + - 'value: 0.307' + x-amz-apigw-id: + - N-Qe8FH8CYcF6ng= + x-amzn-Remapped-Connection: + - keep-alive + x-amzn-Remapped-Content-Length: + - '448' + x-amzn-Remapped-Date: + - Wed, 23 Feb 2022 01:56:47 GMT + x-amzn-Remapped-Server: + - nginx/1.20.2 + x-amzn-Remapped-x-amzn-RequestId: + - b8d4637e-cce5-47d4-89f4-95fae2464c24 + x-amzn-RequestId: + - 0fbf471b-8bb6-4054-a771-22b2ce47d423 + status: + code: 200 + message: OK +- request: + body: '{"user_id": "UShhSTmmy_R2y6KvQsGnTTMw", "idempotency_key": "MY_UNIQUE_KEY", + "bank_number": "001287364", "account_number": "9876543210", "account_country": + "US", "account_name": "Amanda Brown", "received_amount": 20825, "received_currency": + "mxn", "sent_amount": 1000, "sent_currency": "usd"}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Authorization: + - DUMMY + Connection: + - keep-alive + Content-Length: + - '291' + Content-Type: + - application/json + User-Agent: + - cuenca-python/0.7.14 + X-Cuenca-Api-Version: + - '2020-03-19' + method: POST + uri: https://sandbox.cuenca.com/international_transfers + response: + body: + string: '{"error":"Duplicated idempotency key"}' + headers: + Connection: + - keep-alive + Content-Length: + - '38' + Content-Type: + - application/json + Date: + - Wed, 23 Feb 2022 01:56:48 GMT + X-Amzn-Trace-Id: + - Root=1-6215945f-2433554a66d2a9dc0781d6ae;Sampled=0 + x-amz-apigw-id: + - N-QfBF6FCYcFV-Q= + x-amzn-Remapped-Connection: + - keep-alive + x-amzn-Remapped-Content-Length: + - '38' + x-amzn-Remapped-Date: + - Wed, 23 Feb 2022 01:56:48 GMT + x-amzn-Remapped-Server: + - nginx/1.20.2 + x-amzn-Remapped-x-amzn-RequestId: + - fbe703c7-a120-4ab3-8d30-0c0c3c97763b + x-amzn-RequestId: + - 89efda13-627e-4489-9ea6-d665fb741660 + status: + code: 400 + message: Bad Request +version: 1 diff --git a/tests/resources/cassettes/test_query_international_transfer.yaml b/tests/resources/cassettes/test_query_international_transfer.yaml new file mode 100644 index 00000000..5ef023a0 --- /dev/null +++ b/tests/resources/cassettes/test_query_international_transfer.yaml @@ -0,0 +1,53 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Authorization: + - DUMMY + Connection: + - keep-alive + User-Agent: + - cuenca-python/0.7.14 + X-Cuenca-Api-Version: + - '2020-03-19' + method: GET + uri: https://sandbox.cuenca.com/international_transfers?limit=2&idempotency_key=MY_UNIQUE_KEY + response: + body: + string: '{"items":[{"id":"ITeGc6ZBb8S96zqDhtY0AO3g","created_at":"2022-02-23T01:56:46.622000","updated_at":"2022-02-23T01:56:46.622000","platform_id":"PTW68GgAc_QPmNCmgajmctLg","user_id":"UShhSTmmy_R2y6KvQsGnTTMw","idempotency_key":"MY_UNIQUE_KEY","bank_number":"001287364","account_number":"1024357689","account_country":"US","account_name":"Amanda + Brown","received_amount":20825,"received_currency":"mxn","sent_amount":1000,"sent_currency":"usd","status":"created"}],"next_page_uri":null}' + headers: + Connection: + - keep-alive + Content-Length: + - '481' + Content-Type: + - application/json + Date: + - Wed, 23 Feb 2022 02:03:48 GMT + X-Amzn-Trace-Id: + - Root=1-62159604-46e776d03d47ab3270d2b021;Sampled=0 + X-Request-Time: + - 'value: 0.296' + x-amz-apigw-id: + - N-RgsHHKCYcFUnw= + x-amzn-Remapped-Connection: + - keep-alive + x-amzn-Remapped-Content-Length: + - '481' + x-amzn-Remapped-Date: + - Wed, 23 Feb 2022 02:03:48 GMT + x-amzn-Remapped-Server: + - nginx/1.20.2 + x-amzn-Remapped-x-amzn-RequestId: + - b387b922-8de7-4bc9-a086-b45f25630185 + x-amzn-RequestId: + - 411a55ef-86c8-418d-b430-83e94e03c970 + status: + code: 200 + message: OK +version: 1 diff --git a/tests/resources/cassettes/test_retrieve_international_transfer.yaml b/tests/resources/cassettes/test_retrieve_international_transfer.yaml new file mode 100644 index 00000000..dcce4abd --- /dev/null +++ b/tests/resources/cassettes/test_retrieve_international_transfer.yaml @@ -0,0 +1,53 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Authorization: + - DUMMY + Connection: + - keep-alive + User-Agent: + - cuenca-python/0.7.14 + X-Cuenca-Api-Version: + - '2020-03-19' + method: GET + uri: https://sandbox.cuenca.com/international_transfers/ITeGc6ZBb8S96zqDhtY0AO3g + response: + body: + string: '{"id":"ITeGc6ZBb8S96zqDhtY0AO3g","created_at":"2022-02-23T01:56:46.622000","updated_at":"2022-02-23T01:56:46.622000","platform_id":"PTW68GgAc_QPmNCmgajmctLg","user_id":"UShhSTmmy_R2y6KvQsGnTTMw","idempotency_key":"MY_UNIQUE_KEY","bank_number":"001287364","account_number":"1024357689","account_country":"US","account_name":"Amanda + Brown","received_amount":20825,"received_currency":"mxn","sent_amount":1000,"sent_currency":"usd","status":"created"}' + headers: + Connection: + - keep-alive + Content-Length: + - '448' + Content-Type: + - application/json + Date: + - Wed, 23 Feb 2022 02:00:20 GMT + X-Amzn-Trace-Id: + - Root=1-62159533-00f074b1485bbb7d14ce1398;Sampled=0 + X-Request-Time: + - 'value: 0.237' + x-amz-apigw-id: + - N-RAIG17CYcFzZA= + x-amzn-Remapped-Connection: + - keep-alive + x-amzn-Remapped-Content-Length: + - '448' + x-amzn-Remapped-Date: + - Wed, 23 Feb 2022 02:00:20 GMT + x-amzn-Remapped-Server: + - nginx/1.20.2 + x-amzn-Remapped-x-amzn-RequestId: + - c9da1146-bc6f-4ef5-823a-f62d2a6b9a2c + x-amzn-RequestId: + - 4ed3eef8-a5e1-448d-81bf-e28fb98e2da1 + status: + code: 200 + message: OK +version: 1 diff --git a/tests/resources/cassettes/test_update_international_transfer.yaml b/tests/resources/cassettes/test_update_international_transfer.yaml new file mode 100644 index 00000000..ef6057f8 --- /dev/null +++ b/tests/resources/cassettes/test_update_international_transfer.yaml @@ -0,0 +1,57 @@ +interactions: +- request: + body: '{"status": "failed"}' + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Authorization: + - DUMMY + Connection: + - keep-alive + Content-Length: + - '20' + Content-Type: + - application/json + User-Agent: + - cuenca-python/0.7.14 + X-Cuenca-Api-Version: + - '2020-03-19' + method: PATCH + uri: https://sandbox.cuenca.com/international_transfers/ITeGc6ZBb8S96zqDhtY0AO3g + response: + body: + string: '{"id":"ITeGc6ZBb8S96zqDhtY0AO3g","created_at":"2022-02-23T01:56:46.622000","updated_at":"2022-02-23T02:09:34.047772","platform_id":"PTW68GgAc_QPmNCmgajmctLg","user_id":"UShhSTmmy_R2y6KvQsGnTTMw","idempotency_key":"MY_UNIQUE_KEY","bank_number":"001287364","account_number":"1024357689","account_country":"US","account_name":"Amanda + Brown","received_amount":20825,"received_currency":"mxn","sent_amount":1000,"sent_currency":"usd","status":"failed"}' + headers: + Connection: + - keep-alive + Content-Length: + - '447' + Content-Type: + - application/json + Date: + - Wed, 23 Feb 2022 02:09:34 GMT + X-Amzn-Trace-Id: + - Root=1-6215975b-4d2b1c31222b0d0054a9134c;Sampled=0 + X-Request-Time: + - 'value: 3.231' + x-amz-apigw-id: + - N-SWRERLCYcFosQ= + x-amzn-Remapped-Connection: + - keep-alive + x-amzn-Remapped-Content-Length: + - '447' + x-amzn-Remapped-Date: + - Wed, 23 Feb 2022 02:09:34 GMT + x-amzn-Remapped-Server: + - nginx/1.20.2 + x-amzn-Remapped-x-amzn-RequestId: + - 63b15d14-8b69-4678-b305-37e4fd7e29f9 + x-amzn-RequestId: + - 87b14fa5-130c-45ea-9f41-f1ceb7e44443 + status: + code: 201 + message: Created +version: 1 diff --git a/tests/resources/test_international_transfers.py b/tests/resources/test_international_transfers.py new file mode 100644 index 00000000..f1be164b --- /dev/null +++ b/tests/resources/test_international_transfers.py @@ -0,0 +1,72 @@ +import pytest +from cuenca_validations.types import SessionType, TransactionStatus + +import cuenca +from cuenca.exc import CuencaResponseException +from cuenca.resources import InternationalTransfer, Session + + +@pytest.mark.vcr +def test_create_international_transfer(international_transfer): + transfer = InternationalTransfer.create(**international_transfer) + transfer_id = transfer.id + assert transfer_id is not None + assert transfer.status == TransactionStatus.created + + # Create again with same data, return same transaction + transfer = InternationalTransfer.create(**international_transfer) + assert transfer.id == transfer_id + + # Duplicate your idempotency key with another data + international_transfer['account_number'] = '9876543210' + with pytest.raises(CuencaResponseException): + InternationalTransfer.create(**international_transfer) + + +@pytest.mark.vcr +def test_retrieve_international_transfer(): + transfer_id = 'ITeGc6ZBb8S96zqDhtY0AO3g' + transfer = InternationalTransfer.retrieve(transfer_id) + assert transfer.id == transfer_id + + +@pytest.mark.vcr +def test_query_international_transfer(): + your_id = 'MY_UNIQUE_KEY' + transfer = InternationalTransfer.one(idempotency_key=your_id) + assert transfer.idempotency_key == your_id + + +@pytest.mark.vcr +def test_update_international_transfer(): + transfer_id = 'ITeGc6ZBb8S96zqDhtY0AO3g' + # Cancel the transfer updating value to failed + new_status = TransactionStatus.failed + transfer = InternationalTransfer.update(transfer_id, new_status) + assert transfer.id == transfer_id + assert transfer.status == new_status + + +@pytest.mark.vcr +def test_complete_flow_international_transfers(international_transfer): + # platform create an international transfer for user + transfer = InternationalTransfer.create(**international_transfer) + transfer_id = transfer.id + assert transfer_id is not None + assert transfer.status == TransactionStatus.created + + # Create a Session Token to allow user confirm or reject. + user_id = international_transfer['user_id'] + session = Session.create(user_id, SessionType.international_transfers) + token = session.id + + # Using the session token, User has to confirm and submit the transfer + cuenca.configure(session_token=token, api_key=None, api_secret=None) + submitted = TransactionStatus.submitted + transfer = InternationalTransfer.update(transfer_id, status=submitted) + assert transfer.id == transfer_id + assert transfer.status == submitted + + # After SPEI deposit was received, status will change + transfer.refresh() + assert transfer.status == TransactionStatus.succeeded