Skip to content

Commit 2158a59

Browse files
rogelioLpzpachCode
andauthored
Add user_id to create transfers (#279)
* user_id for transfers * clabe and balance for users * tests * add user_id to Transfer * Revert "add user_id to Transfer" This reverts commit e4b419d. * version Co-authored-by: pachCode <arturo@cuenca.com>
1 parent 4029b81 commit 2158a59

File tree

7 files changed

+194
-26
lines changed

7 files changed

+194
-26
lines changed

cuenca/resources/transfers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def create(
3939
descriptor: str,
4040
recipient_name: str,
4141
idempotency_key: Optional[str] = None,
42+
user_id: Optional[str] = None,
4243
) -> 'Transfer':
4344
"""
4445
:param account_number: CLABE
@@ -47,6 +48,7 @@ def create(
4748
:param recipient_name: name of recipient
4849
:param idempotency_key: must be unique for each transfer to avoid
4950
duplicates
51+
:param user_id: Source user to take the funds
5052
:return: Transfer object
5153
5254
The recommended idempotency_key scheme:
@@ -65,6 +67,7 @@ def create(
6567
descriptor=descriptor,
6668
recipient_name=recipient_name,
6769
idempotency_key=idempotency_key,
70+
user_id=user_id,
6871
)
6972
return cast('Transfer', cls._create(**req.dict()))
7073

cuenca/resources/users.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime as dt
22
from typing import ClassVar, List, Optional, cast
33

4+
from clabe import Clabe
45
from cuenca_validations.types import (
56
Address,
67
AddressUpdateRequest,
@@ -19,6 +20,7 @@
1920
from pydantic import EmailStr
2021

2122
from ..http import Session, session as global_session
23+
from .balance_entries import BalanceEntry
2224
from .base import Creatable, Queryable, Retrievable, Updateable
2325
from .identities import Identity
2426
from .resources import retrieve_uri
@@ -43,6 +45,12 @@ class User(Creatable, Retrievable, Updateable, Queryable):
4345
proof_of_life: Optional[KYCFile]
4446
beneficiaries: Optional[List[Beneficiary]]
4547
platform_id: Optional[str] = None
48+
clabe: Optional[Clabe] = None
49+
50+
@property
51+
def balance(self) -> int:
52+
be = cast(BalanceEntry, BalanceEntry.first(user_id=self.id))
53+
return be.rolling_balance if be else 0
4654

4755
class Config:
4856
fields = {

cuenca/version.py

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

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
requests==2.27.1
2-
cuenca-validations==0.10.12
2+
cuenca-validations==0.10.13
33
dataclasses>=0.7;python_version<"3.7"

tests/resources/cassettes/test_user_create.yaml

Lines changed: 73 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,46 @@ interactions:
1717
Content-Type:
1818
- application/json
1919
User-Agent:
20-
- cuenca-python/0.7.15.dev3
20+
- cuenca-python/0.13.0.dev0
2121
X-Cuenca-Api-Version:
2222
- '2020-03-19'
2323
method: POST
2424
uri: https://sandbox.cuenca.com/curp_validations
2525
response:
2626
body:
27-
string: "{\"id\":\"CVkd_IzIDPTSOulVJpQY2urQ\",\"created_at\":\"2022-02-09T17:42:56.383485\",\"names\":\"Jos\xE9\",\"first_surname\":\"L\xF3pez\",\"second_surname\":\"Hern\xE1ndez\",\"date_of_birth\":\"1966-06-06\",\"country_of_birth\":\"MX\",\"state_of_birth\":\"DF\",\"gender\":\"male\",\"nationality\":\"MX\",\"manual_curp\":null,\"calculated_curp\":\"LOHJ660606HDFPRS02\",\"validated_curp\":\"LOHJ660606HDFPRS02\",\"renapo_curp_match\":true,\"renapo_full_match\":true}"
27+
string: "{\"id\":\"CV82OsliJJRBazgSxh2wveXg\",\"created_at\":\"2022-06-16T17:25:41.655304\",\"names\":\"Jos\xE9\",\"first_surname\":\"L\xF3pez\",\"second_surname\":\"Hern\xE1ndez\",\"date_of_birth\":\"1966-06-06\",\"country_of_birth\":\"MX\",\"state_of_birth\":\"YN\",\"gender\":\"female\",\"nationality\":\"MX\",\"manual_curp\":null,\"calculated_curp\":\"LOHJ660606HDFPRS02\",\"validated_curp\":\"LOHJ660606HDFPRS02\",\"renapo_curp_match\":true,\"renapo_full_match\":false}"
2828
headers:
2929
Connection:
3030
- keep-alive
3131
Content-Length:
32-
- '402'
32+
- '405'
3333
Content-Type:
3434
- application/json
3535
Date:
36-
- Wed, 09 Feb 2022 17:42:56 GMT
36+
- Thu, 16 Jun 2022 17:25:41 GMT
3737
X-Request-Time:
38-
- 'value: 0.282'
38+
- 'value: 0.476'
3939
x-amz-apigw-id:
40-
- NSR9EFulCYcFqRA=
40+
- T00fWHuLIAMF3dg=
4141
x-amzn-Remapped-Connection:
4242
- keep-alive
4343
x-amzn-Remapped-Content-Length:
44-
- '402'
44+
- '405'
4545
x-amzn-Remapped-Date:
46-
- Wed, 09 Feb 2022 17:42:56 GMT
46+
- Thu, 16 Jun 2022 17:25:41 GMT
4747
x-amzn-Remapped-Server:
48-
- nginx/1.20.2
48+
- nginx/1.22.0
4949
x-amzn-RequestId:
50-
- ae052cd0-e6d5-4b68-94fd-0ce487426564
50+
- e1f4ecd5-a2e1-4816-97d6-f011bf3b8131
5151
status:
5252
code: 201
5353
message: Created
5454
- request:
5555
body: '{"curp": "LOHJ660606HDFPRS02", "phone_number": "+525511223344", "email_address":
5656
"jose@test.com", "profession": "employee", "address": {"street": "calle 1",
5757
"ext_number": "2", "postal_code": "09900", "state": "DF", "country": "MX", "city":
58-
null, "int_number": "3"}}'
58+
null, "int_number": "3", "full_name": null}, "required_level": null, "phone_verification_id":
59+
null, "email_verification_id": null}'
5960
headers:
6061
Accept:
6162
- '*/*'
@@ -66,43 +67,91 @@ interactions:
6667
Connection:
6768
- keep-alive
6869
Content-Length:
69-
- '265'
70+
- '370'
7071
Content-Type:
7172
- application/json
7273
User-Agent:
73-
- cuenca-python/0.7.15.dev3
74+
- cuenca-python/0.13.0.dev0
7475
X-Cuenca-Api-Version:
7576
- '2020-03-19'
7677
method: POST
7778
uri: https://sandbox.cuenca.com/users
7879
response:
7980
body:
80-
string: "{\"id\":\"USCM-zlFcNQk6ue4gZ_mTGeQ\",\"identity_uri\":\"/identities/IDKWLi_wUoTty6WXXg9xfKFQ\",\"created_at\":\"2022-02-09T17:42:56.965055\",\"updated_at\":\"2022-02-09T17:42:57.008600\",\"platform_id\":\"PTW68GgAc_QPmNCmgajmctLg\",\"level\":0,\"phone_number\":\"+525511223344\",\"email_address\":\"jose@test.com\",\"profession\":\"employee\",\"status\":\"active\",\"terms_of_service\":null,\"blacklist_validation_status\":\"not_verified\",\"address\":{\"street\":\"calle
81-
1\",\"ext_number\":\"2\",\"int_number\":\"3\",\"postal_code\":\"09900\",\"state\":\"DF\",\"city\":null,\"country\":\"MX\",\"created_at\":\"2022-02-09T17:42:56.964930\"},\"govt_id\":null,\"proof_of_address\":null,\"proof_of_life\":null,\"beneficiaries\":null,\"names\":\"Jos\xE9\",\"first_surname\":\"L\xF3pez\",\"second_surname\":\"Hern\xE1ndez\",\"curp\":\"LOHJ660606HDFPRS02\",\"required_level\":4}"
81+
string: "{\"id\":\"USlen-v7UQSqqZTGVe3vQmLQ\",\"identity_uri\":\"/identities/IDtyYLgoJTRZq2xAabU5Mbzg\",\"created_at\":\"2022-06-16T17:25:41.983660\",\"updated_at\":\"2022-06-16T17:25:41.984049\",\"platform_id\":\"PTW68GgAc_QPmNCmgajmctLg\",\"level\":0,\"required_level\":4,\"phone_number\":\"+525511223344\",\"email_address\":\"jose@test.com\",\"profession\":\"employee\",\"clabe\":null,\"status\":\"active\",\"terms_of_service\":null,\"blacklist_validation_status\":\"not_verified\",\"address\":{\"street\":\"calle
82+
1\",\"ext_number\":\"2\",\"int_number\":\"3\",\"postal_code\":\"09900\",\"state\":\"DF\",\"city\":null,\"country\":\"MX\",\"created_at\":\"2022-06-16T17:25:41.983529\",\"full_name\":null},\"govt_id\":null,\"proof_of_address\":null,\"proof_of_life\":null,\"beneficiaries\":null,\"names\":\"Jos\xE9\",\"first_surname\":\"L\xF3pez\",\"second_surname\":\"Hern\xE1ndez\",\"curp\":\"LOHJ660606HDFPRS02\",\"rfc\":\"LOHJ660606MMA\"}"
8283
headers:
8384
Connection:
8485
- keep-alive
8586
Content-Length:
86-
- '745'
87+
- '816'
8788
Content-Type:
8889
- application/json
8990
Date:
90-
- Wed, 09 Feb 2022 17:42:57 GMT
91-
X-Request-Time:
92-
- 'value: 0.955'
91+
- Thu, 16 Jun 2022 17:25:43 GMT
9392
x-amz-apigw-id:
94-
- NSR9JGSgCYcFgcQ=
93+
- T00fcEBhoAMFYxw=
9594
x-amzn-Remapped-Connection:
9695
- keep-alive
9796
x-amzn-Remapped-Content-Length:
98-
- '745'
97+
- '816'
9998
x-amzn-Remapped-Date:
100-
- Wed, 09 Feb 2022 17:42:57 GMT
99+
- Thu, 16 Jun 2022 17:25:43 GMT
101100
x-amzn-Remapped-Server:
102-
- nginx/1.20.2
101+
- nginx/1.22.0
103102
x-amzn-RequestId:
104-
- 327dc915-14bd-46fe-9abe-288010257709
103+
- 1ba15a8d-b928-47b8-b75e-2294787ad01a
105104
status:
106105
code: 201
107106
message: Created
107+
- request:
108+
body: null
109+
headers:
110+
Accept:
111+
- '*/*'
112+
Accept-Encoding:
113+
- gzip, deflate
114+
Authorization:
115+
- DUMMY
116+
Connection:
117+
- keep-alive
118+
User-Agent:
119+
- cuenca-python/0.13.0.dev0
120+
X-Cuenca-Api-Version:
121+
- '2020-03-19'
122+
method: GET
123+
uri: https://sandbox.cuenca.com/balance_entries?limit=1&user_id=USlen-v7UQSqqZTGVe3vQmLQ
124+
response:
125+
body:
126+
string: '{"items":[],"next_page_uri":null}'
127+
headers:
128+
Connection:
129+
- keep-alive
130+
Content-Length:
131+
- '33'
132+
Content-Type:
133+
- application/json
134+
Date:
135+
- Thu, 16 Jun 2022 17:25:47 GMT
136+
X-Amzn-Trace-Id:
137+
- Root=1-62ab6797-5c1bf24d35a83e7325b4bb7c;Sampled=0
138+
X-Request-Time:
139+
- 'value: 4.092'
140+
x-amz-apigw-id:
141+
- T00fqEtPIAMFyfQ=
142+
x-amzn-Remapped-Connection:
143+
- keep-alive
144+
x-amzn-Remapped-Content-Length:
145+
- '33'
146+
x-amzn-Remapped-Date:
147+
- Thu, 16 Jun 2022 17:25:47 GMT
148+
x-amzn-Remapped-Server:
149+
- nginx/1.22.0
150+
x-amzn-Remapped-x-amzn-RequestId:
151+
- 9e06c5b4-d3e5-431d-b82d-62025c522142
152+
x-amzn-RequestId:
153+
- acd5feab-4a37-4e63-bf2b-ad9acf471246
154+
status:
155+
code: 200
156+
message: OK
108157
version: 1
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Authorization:
10+
- DUMMY
11+
Connection:
12+
- keep-alive
13+
User-Agent:
14+
- cuenca-python/0.13.0.dev1
15+
X-Cuenca-Api-Version:
16+
- '2020-03-19'
17+
method: GET
18+
uri: https://sandbox.cuenca.com/users/USlen-v7UQSqqZTGVe3vQmLQ
19+
response:
20+
body:
21+
string: '{"id":"USlen-v7UQSqqZTGVe3vQmLQ","created_at":"2022-06-16T17:25:41.983000","updated_at":"2022-06-16T17:28:15.920000","identity_uri":"/identities/IDtyYLgoJTRZq2xAabU5Mbzg","level":1,"required_level":4,"phone_number":"+525511223344","email_address":"jose@test.com","profession":"employee","terms_of_service":{"version":"2021-02-01","ip":"201.141.118.106","location":"9.3953792,-99.139584,12"},"status":"active","address":{"street":"calle
22+
1","ext_number":"2","postal_code":"09900","state":"DF","country":"MX","city":null,"int_number":"3","full_name":null},"govt_id":null,"proof_of_address":null,"proof_of_life":null,"beneficiaries":null,"platform_id":"PTW68GgAc_QPmNCmgajmctLg","clabe":"646180157078771514"}'
23+
headers:
24+
Connection:
25+
- keep-alive
26+
Content-Length:
27+
- '704'
28+
Content-Type:
29+
- application/json
30+
Date:
31+
- Thu, 16 Jun 2022 18:10:07 GMT
32+
x-amz-apigw-id:
33+
- T06_7HcyIAMFojg=
34+
x-amzn-Remapped-Connection:
35+
- keep-alive
36+
x-amzn-Remapped-Content-Length:
37+
- '704'
38+
x-amzn-Remapped-Date:
39+
- Thu, 16 Jun 2022 18:10:07 GMT
40+
x-amzn-Remapped-Server:
41+
- nginx/1.22.0
42+
x-amzn-RequestId:
43+
- 6ddcf474-f95c-453f-9529-f9558c88f45c
44+
status:
45+
code: 200
46+
message: OK
47+
- request:
48+
body: null
49+
headers:
50+
Accept:
51+
- '*/*'
52+
Accept-Encoding:
53+
- gzip, deflate
54+
Authorization:
55+
- DUMMY
56+
Connection:
57+
- keep-alive
58+
User-Agent:
59+
- cuenca-python/0.13.0.dev1
60+
X-Cuenca-Api-Version:
61+
- '2020-03-19'
62+
method: GET
63+
uri: https://sandbox.cuenca.com/balance_entries?limit=1&user_id=USlen-v7UQSqqZTGVe3vQmLQ
64+
response:
65+
body:
66+
string: '{"items":[{"id":"LE2RIZfRqk2PKqgT3iKTODZF","created_at":"2022-06-16T17:28:43.893000","user_id":"USlen-v7UQSqqZTGVe3vQmLQ","name":"TECNOLOGIA
67+
EN ENTRETENIMIENTO CALIPLAY S","amount":10000,"descriptor":"Test2","rolling_balance":10000,"type":"credit","related_transaction_uri":"/deposits/SP2XLNMGbLt795Wy8hrCrLL","funding_instrument_uri":"/accounts/ACr66xA29pWqOQOs3FLkH6oA","wallet_id":"default"}],"next_page_uri":null}'
68+
headers:
69+
Connection:
70+
- keep-alive
71+
Content-Length:
72+
- '417'
73+
Content-Type:
74+
- application/json
75+
Date:
76+
- Thu, 16 Jun 2022 18:10:16 GMT
77+
X-Amzn-Trace-Id:
78+
- Root=1-62ab7204-4c26d5e13c22e8ff1cc811d8;Sampled=0
79+
X-Request-Time:
80+
- 'value: 3.708'
81+
x-amz-apigw-id:
82+
- T07AwHGFIAMF5KA=
83+
x-amzn-Remapped-Connection:
84+
- keep-alive
85+
x-amzn-Remapped-Content-Length:
86+
- '417'
87+
x-amzn-Remapped-Date:
88+
- Thu, 16 Jun 2022 18:10:16 GMT
89+
x-amzn-Remapped-Server:
90+
- nginx/1.22.0
91+
x-amzn-Remapped-x-amzn-RequestId:
92+
- 480430da-0659-4277-a370-cb50f9c04dd0
93+
x-amzn-RequestId:
94+
- 9cad408b-e641-4cec-b289-7422a65b07f1
95+
status:
96+
code: 200
97+
message: OK
98+
version: 1

tests/resources/test_users.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def test_user_create(user_request, curp_validation_request):
1212
user = User.create(**user_request)
1313
assert user.id is not None
1414
assert user.level == 0
15+
assert not user.clabe
16+
assert user.balance == 0
1517

1618

1719
@pytest.mark.vcr
@@ -37,6 +39,14 @@ def test_user_update():
3739
assert all(item in user.to_dict().keys() for item in changes.keys())
3840

3941

42+
@pytest.mark.vcr
43+
def test_user_fetch_balance(user_request, curp_validation_request):
44+
user_id = 'USlen-v7UQSqqZTGVe3vQmLQ'
45+
user = User.retrieve(user_id)
46+
assert user.clabe
47+
assert user.balance == 10000
48+
49+
4050
@pytest.mark.vcr
4151
def test_user_identity_retrieve():
4252
user_id = 'USCM-zlFcNQk6ue4gZ_mTGeQ'

0 commit comments

Comments
 (0)