diff --git a/cuenca/__init__.py b/cuenca/__init__.py index 38a31cc0..24a47108 100644 --- a/cuenca/__init__.py +++ b/cuenca/__init__.py @@ -3,6 +3,7 @@ 'ApiKey', 'Account', 'BalanceEntry', + 'Commission', 'Deposit', 'Transfer', 'WhatsappTransfer', @@ -15,6 +16,7 @@ Account, ApiKey, BalanceEntry, + Commission, Deposit, Transfer, WhatsappTransfer, diff --git a/cuenca/resources/commissions.py b/cuenca/resources/commissions.py index ccb61206..df7c8da5 100644 --- a/cuenca/resources/commissions.py +++ b/cuenca/resources/commissions.py @@ -1,12 +1,31 @@ -from typing import ClassVar, Optional +from typing import ClassVar, Optional, cast +from cuenca_validations.types import ( + CommissionType, + EntryType, + RelatedTransaction, +) from pydantic.dataclasses import dataclass +from cuenca import resources + from .base import Transaction +from .resources import retrieve_uri + +mapper = {CommissionType.cash_deposit: EntryType.credit} @dataclass class Commission(Transaction): _resource: ClassVar = 'commissions' - related_transaction_uri: Optional[str] + type: CommissionType + related_transaction_uri: Optional[RelatedTransaction] + + @property # type: ignore + def related_transaction(self): + rt = self.related_transaction_uri + if not rt: + return None + resource = getattr(resources, rt.get_model()) + return cast(resource, retrieve_uri(rt)) if resource else None diff --git a/cuenca/version.py b/cuenca/version.py index ce2b9d97..bbdfdb4c 100644 --- a/cuenca/version.py +++ b/cuenca/version.py @@ -1,3 +1,3 @@ -__version__ = '0.3.2' +__version__ = '0.3.4' CLIENT_VERSION = __version__ API_VERSION = '2020-03-19' diff --git a/requirements.txt b/requirements.txt index 1433a036..88f8dbab 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ requests==2.24.0 -cuenca-validations==0.5.7 +cuenca-validations==0.6.2 dataclasses>=0.7;python_version<"3.7" aws-requests-auth==0.4.3 diff --git a/tests/resources/cassettes/test_commission_retrieve.yaml b/tests/resources/cassettes/test_commission_retrieve.yaml new file mode 100644 index 00000000..b8d23ddc --- /dev/null +++ b/tests/resources/cassettes/test_commission_retrieve.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.3.2 + X-Cuenca-Api-Version: + - '2020-03-19' + x-amz-content-sha256: + - e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + x-amz-date: + - 20201001T182731Z + method: GET + uri: https://sandbox.cuenca.com/commissions/COXXX + response: + body: + string: '{"id":"COXXX","created_at":"2020-09-24T00:29:34.830000","user_id":"US2qz3mrAomlP8LWG106tILW","amount":25000,"status":"created","descriptor":"Comisi\u00f3n + (card_request)", "type": "cash_deposit","related_transaction_uri":null}' + headers: + Connection: + - keep-alive + Content-Length: + - '220' + Content-Type: + - application/json + Date: + - Thu, 01 Oct 2020 18:27:35 GMT + Via: + - 1.1 73f86570b09a38dfaa856857b5578e7e.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - vytdtvve_zN6caN21ZDTayVxVQ2-d1rDKmoG02Ut1V04G2SOrxtzfg== + X-Amz-Cf-Pop: + - DFW55-C1 + X-Amzn-Trace-Id: + - Root=1-5f761f95-7f1856a72145666d5107c55e;Sampled=0 + X-Cache: + - Miss from cloudfront + x-amz-apigw-id: + - TvnfVGIEIAMFa_Q= + x-amzn-RequestId: + - ab9b3780-d7c6-4628-98cf-5553b3de80a1 + status: + code: 200 + message: OK +version: 1 diff --git a/tests/resources/cassettes/test_commission_retrieve_witw_cash_deposit.yaml b/tests/resources/cassettes/test_commission_retrieve_witw_cash_deposit.yaml new file mode 100644 index 00000000..374559c3 --- /dev/null +++ b/tests/resources/cassettes/test_commission_retrieve_witw_cash_deposit.yaml @@ -0,0 +1,104 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Authorization: + - DUMMY + Connection: + - keep-alive + User-Agent: + - cuenca-python/0.3.2 + X-Cuenca-Api-Version: + - '2020-03-19' + x-amz-content-sha256: + - e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + x-amz-date: + - 20201001T185704Z + method: GET + uri: https://sandbox.cuenca.com/commissions/COXXX + response: + body: + string: '{"id":"COXXX","created_at":"2020-09-30T19:38:33.361000","user_id":"USXXX","amount":1000,"status":"succeeded","descriptor":"Comisi\u00f3n + (cash_deposit)", "type": "cash_deposit","related_transaction_uri":"/deposits/CDXXX"}' + headers: + Connection: + - keep-alive + Content-Length: + - '254' + Content-Type: + - application/json + Date: + - Thu, 01 Oct 2020 18:57:04 GMT + Via: + - 1.1 73f86570b09a38dfaa856857b5578e7e.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - qhDyaKeW0Ocibu9DAsgRAOGZDLKAh4Ch8h7bgUOzErlF2enEXVrNLw== + X-Amz-Cf-Pop: + - DFW55-C1 + X-Amzn-Trace-Id: + - Root=1-5f762680-5dbf128e0175d0637dc90d9b;Sampled=0 + X-Cache: + - Miss from cloudfront + x-amz-apigw-id: + - Tvr0KGBuoAMFvDw= + x-amzn-RequestId: + - f2476afc-8fb5-491f-ad79-2f365e55797d + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Authorization: + - DUMMY + Connection: + - keep-alive + User-Agent: + - cuenca-python/0.3.2 + X-Cuenca-Api-Version: + - '2020-03-19' + x-amz-content-sha256: + - e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + x-amz-date: + - 20201001T185705Z + method: GET + uri: https://sandbox.cuenca.com/deposits/CDXXX + response: + body: + string: '{"id":"CDXXX","created_at":"2020-09-30T19:38:29.234000","user_id":"USXXX","amount":2002,"status":"succeeded","descriptor":"Deposito + v\u00eda paynet auth 648695","source_uri":null,"network":"cash","tracking_key":null}' + headers: + Connection: + - keep-alive + Content-Length: + - '254' + Content-Type: + - application/json + Date: + - Thu, 01 Oct 2020 18:57:05 GMT + Via: + - 1.1 73f86570b09a38dfaa856857b5578e7e.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - zWYNKGEjQ8P0PF_azgGX01euUv3Jl0T4dejiLXjDJdvQ4_FvG81F2A== + X-Amz-Cf-Pop: + - DFW55-C1 + X-Amzn-Trace-Id: + - Root=1-5f762681-2c39d73d0760e8f37ffbe378;Sampled=0 + X-Cache: + - Miss from cloudfront + x-amz-apigw-id: + - Tvr0OFKJIAMFYng= + x-amzn-RequestId: + - 1e7a83a6-88a1-443d-a175-1f35152b6cda + status: + code: 200 + message: OK +version: 1 diff --git a/tests/resources/cassettes/test_commission_retrieve_witw_cash_transfer.yaml b/tests/resources/cassettes/test_commission_retrieve_witw_cash_transfer.yaml new file mode 100644 index 00000000..12420a64 --- /dev/null +++ b/tests/resources/cassettes/test_commission_retrieve_witw_cash_transfer.yaml @@ -0,0 +1,104 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Authorization: + - DUMMY + Connection: + - keep-alive + User-Agent: + - cuenca-python/0.3.2 + X-Cuenca-Api-Version: + - '2020-03-19' + x-amz-content-sha256: + - e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + x-amz-date: + - 20201001T185704Z + method: GET + uri: https://sandbox.cuenca.com/commissions/COXXX + response: + body: + string: '{"id":"COXXX","created_at":"2020-09-30T19:38:33.361000","user_id":"USXXX","amount":1000,"status":"succeeded","descriptor":"Comisi\u00f3n + (cash_transfer)", "type": "cash_deposit","related_transaction_uri":"/transfers/SP5XXX"}' + headers: + Connection: + - keep-alive + Content-Length: + - '254' + Content-Type: + - application/json + Date: + - Thu, 01 Oct 2020 18:57:04 GMT + Via: + - 1.1 73f86570b09a38dfaa856857b5578e7e.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - qhDyaKeW0Ocibu9DAsgRAOGZDLKAh4Ch8h7bgUOzErlF2enEXVrNLw== + X-Amz-Cf-Pop: + - DFW55-C1 + X-Amzn-Trace-Id: + - Root=1-5f762680-5dbf128e0175d0637dc90d9b;Sampled=0 + X-Cache: + - Miss from cloudfront + x-amz-apigw-id: + - Tvr0KGBuoAMFvDw= + x-amzn-RequestId: + - f2476afc-8fb5-491f-ad79-2f365e55797d + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Authorization: + - DUMMY + Connection: + - keep-alive + User-Agent: + - cuenca-python/0.3.2 + X-Cuenca-Api-Version: + - '2020-03-19' + x-amz-content-sha256: + - e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + x-amz-date: + - 20201001T185705Z + method: GET + uri: https://sandbox.cuenca.com/transfers/SP5XXX + response: + body: + string: '{"id":"SP5XXX","created_at":"2020-05-08T23:12:25.042000","updated_at":"2020-05-08T23:12:28.854000","account_number":"646180157013244941","recipient_name":"test + 85d91ea6-76b6-49ab-913b-0481e8df7379","amount":8888,"descriptor":"lambda","idempotency_key":"b2bf01cb-da5f-4a42-9462-23078b81b6ea","status":"failed","network":"spei","destination_uri":null,"tracking_key":null,"user_id":"USXXX"}' + headers: + Connection: + - keep-alive + Content-Length: + - '254' + Content-Type: + - application/json + Date: + - Thu, 01 Oct 2020 18:57:05 GMT + Via: + - 1.1 73f86570b09a38dfaa856857b5578e7e.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - zWYNKGEjQ8P0PF_azgGX01euUv3Jl0T4dejiLXjDJdvQ4_FvG81F2A== + X-Amz-Cf-Pop: + - DFW55-C1 + X-Amzn-Trace-Id: + - Root=1-5f762681-2c39d73d0760e8f37ffbe378;Sampled=0 + X-Cache: + - Miss from cloudfront + x-amz-apigw-id: + - Tvr0OFKJIAMFYng= + x-amzn-RequestId: + - 1e7a83a6-88a1-443d-a175-1f35152b6cda + status: + code: 200 + message: OK +version: 1 \ No newline at end of file diff --git a/tests/resources/cassettes/test_commission_retrieve_witw_deposit.yaml b/tests/resources/cassettes/test_commission_retrieve_witw_deposit.yaml new file mode 100644 index 00000000..1dff755e --- /dev/null +++ b/tests/resources/cassettes/test_commission_retrieve_witw_deposit.yaml @@ -0,0 +1,151 @@ +interactions: +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Authorization: + - DUMMY + Connection: + - keep-alive + User-Agent: + - cuenca-python/0.3.2 + X-Cuenca-Api-Version: + - '2020-03-19' + x-amz-content-sha256: + - e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + x-amz-date: + - 20201001T185431Z + method: GET + uri: https://sandbox.cuenca.com/commissions/COXXX + response: + body: + string: '{"id":"COXXX","created_at":"2020-09-30T19:38:33.361000","user_id":"USXXX","amount":1000,"status":"succeeded","descriptor":"Comisi\u00f3n + (cash_deposit)", "type": "cash_deposit", "related_transaction_uri":"/deposits/CDXXX"}' + headers: + Connection: + - keep-alive + Content-Length: + - '254' + Content-Type: + - application/json + Date: + - Thu, 01 Oct 2020 18:54:34 GMT + Via: + - 1.1 f1c5a27e35ac834b32534347282b3496.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - keCcR7RWtZwUkvvQwg179i-07LRC7irc-rhVOvYcIsDd-QRSspGFxg== + X-Amz-Cf-Pop: + - DFW55-C1 + X-Amzn-Trace-Id: + - Root=1-5f7625e8-623fb6e2469d1fd105d95db2;Sampled=0 + X-Cache: + - Miss from cloudfront + x-amz-apigw-id: + - TvrcRHKtoAMFzqg= + x-amzn-RequestId: + - ac8833e6-b241-41b5-b7cc-7a7c3b67cb3f + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Connection: + - keep-alive + User-Agent: + - python-requests/2.24.0 + method: GET + uri: https://sandbox.cuenca.com/config/route_configuration.json + response: + body: + string: "{\n \"default_route\": \"/oaxaca\",\n \"routes\": {\n \ + \ \"cards\": \"/knox\",\n \"api_keys\": \"/authed\"\n }\n}\n" + headers: + Accept-Ranges: + - bytes + Age: + - '1622' + Connection: + - keep-alive + Content-Length: + - '114' + Content-Type: + - application/json + Date: + - Thu, 01 Oct 2020 18:27:33 GMT + ETag: + - '"f35b9f1de4b47e51d5a9b8706ef54e6b"' + Last-Modified: + - Tue, 15 Sep 2020 22:51:15 GMT + Server: + - AmazonS3 + Via: + - 1.1 19934e8c827f304089a6e45a640882cd.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - qPWYfE69Ef2tZYj9FciaKOvxYaD84CHV1P-eeqRX8BLnX2Tspp3ufA== + X-Amz-Cf-Pop: + - DFW55-C1 + X-Cache: + - Hit from cloudfront + status: + code: 200 + message: OK +- request: + body: null + headers: + Accept: + - '*/*' + Accept-Encoding: + - gzip, deflate + Authorization: + - DUMMY + Connection: + - keep-alive + User-Agent: + - cuenca-python/0.3.2 + X-Cuenca-Api-Version: + - '2020-03-19' + x-amz-content-sha256: + - e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 + x-amz-date: + - 20201001T185434Z + method: GET + uri: https://sandbox.cuenca.com/deposits/CDXXX + response: + body: + string: '{"id":"CDXXX","created_at":"2020-09-30T19:38:29.234000","user_id":"USXXX","amount":2002,"status":"succeeded","descriptor":"Deposito + v\u00eda paynet auth 648695","source_uri":null,"network":"cash","tracking_key":null}' + headers: + Connection: + - keep-alive + Content-Length: + - '254' + Content-Type: + - application/json + Date: + - Thu, 01 Oct 2020 18:54:34 GMT + Via: + - 1.1 f1c5a27e35ac834b32534347282b3496.cloudfront.net (CloudFront) + X-Amz-Cf-Id: + - cJdHs2JkvbhNt4_tcuMuHMgHScIR7FEg4WyK_LaD4oPc6tOri6ZbrA== + X-Amz-Cf-Pop: + - DFW55-C1 + X-Amzn-Trace-Id: + - Root=1-5f7625ea-58076a0b771124a4530ef77a;Sampled=0 + X-Cache: + - Miss from cloudfront + x-amz-apigw-id: + - TvrcrE9yoAMF4eQ= + x-amzn-RequestId: + - e45a9eba-29d6-4774-b463-3bf6e1295944 + status: + code: 200 + message: OK +version: 1 diff --git a/tests/resources/test_commissions.py b/tests/resources/test_commissions.py new file mode 100644 index 00000000..5422825d --- /dev/null +++ b/tests/resources/test_commissions.py @@ -0,0 +1,33 @@ +import pytest + +from cuenca import Commission, Deposit, Transfer + + +@pytest.mark.vcr +def test_commission_retrieve(): + id_commission = 'COXXX' + commission: Commission = Commission.retrieve(id_commission) + assert commission.id == id_commission + assert not commission.related_transaction + + +@pytest.mark.vcr +def test_commission_retrieve_witw_cash_deposit(): + id_commission = 'COXXX' + commission: Commission = Commission.retrieve(id_commission) + assert commission.id == id_commission + related_transaction = commission.related_transaction + assert related_transaction + assert type(related_transaction) == Deposit + assert related_transaction.network == 'cash' + + +@pytest.mark.vcr +def test_commission_retrieve_witw_cash_transfer(): + id_commission = 'COXXX' + commission: Commission = Commission.retrieve(id_commission) + assert commission.id == id_commission + related_transaction = commission.related_transaction + assert related_transaction + assert type(related_transaction) == Transfer + assert related_transaction.network == 'spei'