Skip to content

Commit 49aa7ee

Browse files
author
Keryc Diaz
authored
Related resource and funding intrument (#123)
1 parent b3b667b commit 49aa7ee

24 files changed

+493
-1166
lines changed
Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
from typing import ClassVar, cast
1+
from typing import ClassVar, TypeVar, cast
22

3-
from cuenca_validations.types import EntryType, RelatedTransaction
3+
from cuenca_validations.types import EntryType
44
from pydantic.dataclasses import dataclass
55

6-
from cuenca import resources
7-
8-
from .base import Queryable, Retrievable
6+
from .accounts import Account
7+
from .base import Queryable, Retrievable, Transaction
8+
from .cards import Card
99
from .resources import retrieve_uri
10+
from .service_providers import ServiceProvider
11+
12+
FundingInstrument = TypeVar(
13+
'FundingInstrument', Account, ServiceProvider, Card
14+
)
1015

1116

1217
@dataclass
@@ -18,10 +23,16 @@ class BalanceEntry(Retrievable, Queryable):
1823
name: str
1924
rolling_balance: int
2025
type: EntryType
21-
related_transaction_uri: RelatedTransaction
26+
related_transaction_uri: str
27+
funding_instrument_uri: str
28+
29+
@property # type: ignore
30+
def related_transaction(self) -> Transaction:
31+
return cast(Transaction, retrieve_uri(self.related_transaction_uri))
2232

2333
@property # type: ignore
24-
def related_transaction(self):
25-
rt = self.related_transaction_uri
26-
resource = getattr(resources, rt.get_model())
27-
return cast(resource, retrieve_uri(rt)) if resource else None
34+
def funding_instrument(self) -> FundingInstrument:
35+
return cast(
36+
FundingInstrument,
37+
retrieve_uri(self.funding_instrument_uri),
38+
)

cuenca/resources/commissions.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
from typing import ClassVar, Optional, cast
1+
from typing import ClassVar, cast
22

3-
from cuenca_validations.types import (
4-
CommissionType,
5-
EntryType,
6-
RelatedTransaction,
7-
)
3+
from cuenca_validations.types import CommissionType, EntryType
84
from pydantic.dataclasses import dataclass
95

10-
from cuenca import resources
11-
126
from .base import Transaction
137
from .resources import retrieve_uri
148

@@ -20,12 +14,8 @@ class Commission(Transaction):
2014
_resource: ClassVar = 'commissions'
2115

2216
type: CommissionType
23-
related_transaction_uri: Optional[RelatedTransaction]
17+
related_transaction_uri: str
2418

2519
@property # type: ignore
26-
def related_transaction(self):
27-
rt = self.related_transaction_uri
28-
if not rt:
29-
return None
30-
resource = getattr(resources, rt.get_model())
31-
return cast(resource, retrieve_uri(rt)) if resource else None
20+
def related_transaction(self) -> Transaction:
21+
return cast(Transaction, retrieve_uri(self.related_transaction_uri))

cuenca/resources/deposits.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ class Deposit(Transaction):
1414
_query_params: ClassVar = DepositQuery
1515

1616
network: DepositNetwork
17-
source_uri: Optional[str]
17+
source_uri: str
1818
tracking_key: Optional[str] # clave rastreo if network is SPEI
1919

2020
@property # type: ignore
21-
def source(self) -> Optional[Account]:
22-
if self.source_uri is None: # cash deposit
23-
acct = None
24-
else:
25-
acct = cast(Account, retrieve_uri(self.source_uri))
26-
return acct
21+
def source(self) -> Account:
22+
return cast(Account, retrieve_uri(self.source_uri))

cuenca/resources/transfers.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,12 @@ class Transfer(Transaction, Creatable):
2626
account_number: str
2727
idempotency_key: str
2828
network: TransferNetwork
29+
destination_uri: str
2930
tracking_key: Optional[str] # clave rastreo if network is SPEI
30-
destination_uri: Optional[str] # defined after confirmation of receipt
3131

3232
@property # type: ignore
3333
def destination(self) -> Optional[Account]:
34-
if self.destination_uri is None:
35-
acct = None
36-
else:
37-
acct = cast(Account, retrieve_uri(self.destination_uri))
38-
return acct
34+
return cast(Account, retrieve_uri(self.destination_uri))
3935

4036
@classmethod
4137
def create(

cuenca/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = '0.6.4'
1+
__version__ = '0.6.5'
22
CLIENT_VERSION = __version__
33
API_VERSION = '2020-03-19'

tests/resources/cassettes/test_balance_entry_related_transaction_not_exist.yaml

Lines changed: 0 additions & 103 deletions
This file was deleted.

tests/resources/cassettes/test_balance_entry_retrieve.yaml

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interactions:
2323
response:
2424
body:
2525
string: '{"id":"TV01","created_at":"2020-10-15T22:27:53.712000","user_id":"US4PCNV8rLB2wqBfORzIAXUl","name":"Dep\u00f3sito
26-
de efectivo","amount":25000,"descriptor":"Deposito v\u00eda paynet auth 304054","rolling_balance":144519,"type":"credit","related_transaction_uri":"/deposits/CDI7SJOifauN5WnqfMhXK4R"}'
26+
de efectivo","amount":25000,"descriptor":"Deposito v\u00eda paynet auth 304054","rolling_balance":144519,"type":"credit","related_transaction_uri":"/deposits/CDI7SJOifauN5WnqfMhXK4R","funding_instrument_uri":"/accounts/BA01"}'
2727
headers:
2828
Connection:
2929
- keep-alive
@@ -74,7 +74,7 @@ interactions:
7474
response:
7575
body:
7676
string: '{"id":"CDI7SJOifauN5WnqfMhXK4R","created_at":"2020-10-15T22:27:53.827000","user_id":"US4PCNV8rLB2wqBfORzIAXUl","amount":25000,"status":"succeeded","descriptor":"Deposito
77-
v\u00eda paynet auth 304054","source_uri":null,"network":"cash","tracking_key":null}'
77+
v\u00eda paynet auth 304054","source_uri":"/accounts/BA01","network":"cash","tracking_key":null}'
7878
headers:
7979
Connection:
8080
- keep-alive
@@ -101,4 +101,51 @@ interactions:
101101
status:
102102
code: 200
103103
message: OK
104+
- request:
105+
body: null
106+
headers:
107+
Accept:
108+
- '*/*'
109+
Accept-Encoding:
110+
- gzip, deflate
111+
Authorization:
112+
- DUMMY
113+
Connection:
114+
- keep-alive
115+
User-Agent:
116+
- cuenca-python/0.2.0.dev1
117+
X-Cuenca-Api-Version:
118+
- '2020-03-19'
119+
method: GET
120+
uri: https://sandbox.cuenca.com/accounts/BA01
121+
response:
122+
body:
123+
string: '{"id":"BA01","created_at":"2020-06-03T02:43:52.922000","name":"Frida
124+
Kahlo","account_number":"072691004495711499","institution_name":"Banorte/Ixe"}'
125+
headers:
126+
Connection:
127+
- keep-alive
128+
Content-Length:
129+
- '147'
130+
Content-Type:
131+
- application/json
132+
Date:
133+
- Tue, 16 Jun 2020 04:32:14 GMT
134+
Via:
135+
- 1.1 738c4d7519e726c557e6997ecf719e4b.cloudfront.net (CloudFront)
136+
X-Amz-Cf-Id:
137+
- 3um0wIx959TPYgV9OOAd-EcmImhJCL0EENfjLsbJo6N5l_zPG_lByQ==
138+
X-Amz-Cf-Pop:
139+
- IAH50-C3
140+
X-Amzn-Trace-Id:
141+
- Root=1-5ee84b4e-89001b2256aa31154faffe45;Sampled=0
142+
X-Cache:
143+
- Miss from cloudfront
144+
x-amz-apigw-id:
145+
- ONC0RHYuoAMF3pw=
146+
x-amzn-RequestId:
147+
- c4451173-95e6-4636-b7b8-6f268b4c9918
148+
status:
149+
code: 200
150+
message: OK
104151
version: 1

tests/resources/cassettes/test_commission_retrieve.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interactions:
2323
response:
2424
body:
2525
string: '{"id":"COXXX","created_at":"2020-09-24T00:29:34.830000","user_id":"US2qz3mrAomlP8LWG106tILW","amount":25000,"status":"created","descriptor":"Comisi\u00f3n
26-
(card_request)", "type": "cash_deposit","related_transaction_uri":null}'
26+
(card_request)", "type": "cash_deposit","related_transaction_uri":"/deposits/CDXXX"}'
2727
headers:
2828
Connection:
2929
- keep-alive

tests/resources/cassettes/test_commission_retrieve_witw_cash_deposit.yaml renamed to tests/resources/cassettes/test_commission_retrieve_with_cash_deposit.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ interactions:
7474
response:
7575
body:
7676
string: '{"id":"CDXXX","created_at":"2020-09-30T19:38:29.234000","user_id":"USXXX","amount":2002,"status":"succeeded","descriptor":"Deposito
77-
v\u00eda paynet auth 648695","source_uri":null,"network":"cash","tracking_key":null}'
77+
v\u00eda paynet auth 648695","source_uri":"/accounts/BA01","network":"cash","tracking_key":null}'
7878
headers:
7979
Connection:
8080
- keep-alive

tests/resources/cassettes/test_commission_retrieve_witw_cash_transfer.yaml renamed to tests/resources/cassettes/test_commission_retrieve_with_cash_transfer.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ interactions:
7474
response:
7575
body:
7676
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
77-
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"}'
77+
85d91ea6-76b6-49ab-913b-0481e8df7379","amount":8888,"descriptor":"lambda","idempotency_key":"b2bf01cb-da5f-4a42-9462-23078b81b6ea","status":"failed","network":"spei","destination_uri":"/accounts/BA01","tracking_key":null,"user_id":"USXXX"}'
7878
headers:
7979
Connection:
8080
- keep-alive

0 commit comments

Comments
 (0)