Skip to content

Commit dbd1eb3

Browse files
author
Keryc Diaz
authored
Card Transactions (#80)
* init card transactions * fix init CardTransaction * tests card_transactions * fix tests, name val * generate new cassetes * comments of review * fix comment matin * ..http.utils.create_awaitable is only for python 3.6 * function in function * change get_event_loop to .run * use ThreadPoolExecutor * fix syntax * make format * lineal code * with with * update version cuenca-validations * version for pre release * version for pre release 1 * fix end * pre release version * update version final
1 parent 4293abc commit dbd1eb3

11 files changed

+497
-3
lines changed

cuenca/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
'Account',
55
'BalanceEntry',
66
'BillPayment',
7+
'CardTransaction',
78
'Commission',
89
'Deposit',
910
'ServiceProvider',
@@ -19,6 +20,7 @@
1920
ApiKey,
2021
BalanceEntry,
2122
BillPayment,
23+
CardTransaction,
2224
Commission,
2325
Deposit,
2426
ServiceProvider,

cuenca/resources/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
'BalanceEntry',
55
'BillPayment',
66
'Card',
7+
'CardTransaction',
78
'Commission',
89
'Deposit',
910
'ServiceProvider',
@@ -15,6 +16,7 @@
1516
from .api_keys import ApiKey
1617
from .balance_entries import BalanceEntry
1718
from .bill_payments import BillPayment
19+
from .card_transactions import CardTransaction
1820
from .cards import Card
1921
from .commissions import Commission
2022
from .deposits import Deposit
@@ -30,6 +32,7 @@
3032
BalanceEntry,
3133
BillPayment,
3234
Card,
35+
CardTransaction,
3336
Commission,
3437
Deposit,
3538
ServiceProvider,
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from typing import ClassVar, List, Optional, cast
2+
3+
from cuenca_validations.types import (
4+
CardErrorType,
5+
CardNetwork,
6+
CardTransactionType,
7+
CardType,
8+
)
9+
from pydantic.dataclasses import dataclass
10+
11+
from .base import Transaction
12+
from .resources import retrieve_uris
13+
14+
15+
@dataclass
16+
class CardTransaction(Transaction):
17+
_resource: ClassVar = 'card_transactions'
18+
19+
type: CardTransactionType
20+
network: CardNetwork
21+
related_card_transaction_uris: List[str]
22+
card_id: str
23+
card_last4: str
24+
card_type: CardType
25+
metadata: dict
26+
error_type: Optional[CardErrorType]
27+
28+
@property # type: ignore
29+
def related_card_transactions(self) -> Optional[List['CardTransaction']]:
30+
if not self.related_card_transaction_uris:
31+
return None
32+
return cast(
33+
List['CardTransaction'],
34+
retrieve_uris(self.related_card_transaction_uris),
35+
)

cuenca/resources/resources.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import re
2-
from typing import Dict, cast
2+
from concurrent.futures import ThreadPoolExecutor
3+
from typing import Dict, List, cast
34

45
from .base import Retrievable
56

@@ -13,3 +14,8 @@ def retrieve_uri(uri: str) -> Retrievable:
1314
raise ValueError(f'uri is not a valid format: {uri}')
1415
resource, id_ = m.groups()
1516
return cast(Retrievable, RESOURCES[resource].retrieve(id_))
17+
18+
19+
def retrieve_uris(uris: List[str]) -> List[Retrievable]:
20+
with ThreadPoolExecutor(max_workers=len(uris)) as executor:
21+
return [ct for ct in executor.map(retrieve_uri, [uri for uri in uris])]

cuenca/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = '0.3.8'
1+
__version__ = '0.3.9'
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,4 +1,4 @@
11
requests==2.24.0
2-
cuenca-validations==0.6.4
2+
cuenca-validations==0.6.6
33
dataclasses>=0.7;python_version<"3.7"
44
aws-requests-auth==0.4.3
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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.3.6
15+
X-Cuenca-Api-Version:
16+
- '2020-03-19'
17+
x-amz-content-sha256:
18+
- e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
19+
x-amz-date:
20+
- 20201029T211344Z
21+
method: GET
22+
uri: https://sandbox.cuenca.com/card_transactions/CT002
23+
response:
24+
body:
25+
string: '{"id":"CT002","created_at":"2020-10-29T18:04:37.414000","user_id":"US4PCNV8rLB2wqBfORzIAXUl","amount":300,"status":"created","descriptor":"Superama
26+
Michoacan","type":"refund","network":"visa","related_card_transaction_uris":["/card_transactions/CT001"],"card_id":"CA001","card_last4":"0359","card_type":"virtual","metadata":{"authorizer_number":null,"card_acceptor":null,"commission":null,"currency_code":"484","is_cvv":null,"pos_capabilty":null,"prosa_transaction_id":"38007","retrieval_reference":"444838149","track_data_method":null,"transaction_reference":null},"error_type":null}'
27+
headers:
28+
Connection:
29+
- keep-alive
30+
Content-Length:
31+
- '659'
32+
Content-Type:
33+
- application/json
34+
Date:
35+
- Thu, 29 Oct 2020 21:13:44 GMT
36+
Via:
37+
- 1.1 fef232a36f2d64e8401caff3be58f4fc.cloudfront.net (CloudFront)
38+
X-Amz-Cf-Id:
39+
- 4WuDXoq-_GWtMLx6kiNBPWtX2BpR211K3UJSdnbP24GiScNcXF2HlQ==
40+
X-Amz-Cf-Pop:
41+
- IAH50-C1
42+
X-Amzn-Trace-Id:
43+
- Root=1-5f9b3088-54cfc3235bfff8a00655b709;Sampled=0
44+
X-Cache:
45+
- Miss from cloudfront
46+
x-amz-apigw-id:
47+
- VMSFZGONoAMF7zA=
48+
x-amzn-RequestId:
49+
- 0d065a8f-9a36-47ec-88b1-1b3bfcb1e215
50+
status:
51+
code: 200
52+
message: OK
53+
- request:
54+
body: null
55+
headers:
56+
Accept:
57+
- '*/*'
58+
Accept-Encoding:
59+
- gzip, deflate
60+
Authorization:
61+
- DUMMY
62+
Connection:
63+
- keep-alive
64+
User-Agent:
65+
- cuenca-python/0.3.6
66+
X-Cuenca-Api-Version:
67+
- '2020-03-19'
68+
x-amz-content-sha256:
69+
- e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
70+
x-amz-date:
71+
- 20201029T211344Z
72+
method: GET
73+
uri: https://sandbox.cuenca.com/card_transactions/CT001
74+
response:
75+
body:
76+
string: '{"id":"CT001","created_at":"2020-10-29T18:04:37.396000","user_id":"US4PCNV8rLB2wqBfORzIAXUl","amount":300,"status":"created","descriptor":"Superama
77+
Michoacan","type":"auth","network":"visa","related_card_transaction_uris":["/card_transactions/CT002","/card_transactions/CT2pnV82umR0FnxWsDwHBFq","/card_transactions/CTXoLAkUBeZY7arY4XyuaYp"],"card_id":"CA001","card_last4":"0359","card_type":"virtual","metadata":{"authorizer_number":null,"card_acceptor":null,"commission":null,"currency_code":"484","is_cvv":null,"pos_capabilty":null,"prosa_transaction_id":"36776","retrieval_reference":"691159329","track_data_method":null,"transaction_reference":null},"error_type":null}'
78+
headers:
79+
Connection:
80+
- keep-alive
81+
Content-Length:
82+
- '747'
83+
Content-Type:
84+
- application/json
85+
Date:
86+
- Thu, 29 Oct 2020 21:13:45 GMT
87+
Via:
88+
- 1.1 fef232a36f2d64e8401caff3be58f4fc.cloudfront.net (CloudFront)
89+
X-Amz-Cf-Id:
90+
- LIS9DTnDXufnad7kEAG_UcUfcFs7laqNSgFpJx5vwbGGeAXMACHszA==
91+
X-Amz-Cf-Pop:
92+
- IAH50-C1
93+
X-Amzn-Trace-Id:
94+
- Root=1-5f9b3089-4586ce643d7ee31e3c819823;Sampled=0
95+
X-Cache:
96+
- Miss from cloudfront
97+
x-amz-apigw-id:
98+
- VMSFbFGyIAMFcMQ=
99+
x-amzn-RequestId:
100+
- 99f43c26-2aea-4de7-b03d-9113ff28a3ed
101+
status:
102+
code: 200
103+
message: OK
104+
version: 1
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.3.6
15+
X-Cuenca-Api-Version:
16+
- '2020-03-19'
17+
x-amz-content-sha256:
18+
- e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
19+
x-amz-date:
20+
- 20201029T211345Z
21+
method: GET
22+
uri: https://sandbox.cuenca.com/card_transactions/CT004
23+
response:
24+
body:
25+
string: '{"id":"CT004","created_at":"2020-10-29T18:04:36.318000","user_id":"US4PCNV8rLB2wqBfORzIAXUl","amount":300,"status":"failed","descriptor":"Superama
26+
Michoacan","type":"expiration","network":"visa","related_card_transaction_uris":[],"card_id":"CA001","card_last4":"0359","card_type":"virtual","metadata":{"authorizer_number":null,"card_acceptor":null,"commission":null,"currency_code":"484","is_cvv":null,"pos_capabilty":null,"prosa_transaction_id":"68697","retrieval_reference":"899493694","track_data_method":null,"transaction_reference":null},"error_type":null}'
27+
headers:
28+
Connection:
29+
- keep-alive
30+
Content-Length:
31+
- '641'
32+
Content-Type:
33+
- application/json
34+
Date:
35+
- Thu, 29 Oct 2020 21:13:45 GMT
36+
Via:
37+
- 1.1 a75dce573e80f2f2d03981a80f910c42.cloudfront.net (CloudFront)
38+
X-Amz-Cf-Id:
39+
- c5u29_nf3YTSb7F-8JyhufTnieVVTDY59jXwr2jdJ3qcuEcSVEPO3A==
40+
X-Amz-Cf-Pop:
41+
- IAH50-C1
42+
X-Amzn-Trace-Id:
43+
- Root=1-5f9b3089-501105c97ed0766d4d07559f;Sampled=0
44+
X-Cache:
45+
- Miss from cloudfront
46+
x-amz-apigw-id:
47+
- VMSFiGpHIAMFlbw=
48+
x-amzn-RequestId:
49+
- 18ec27c1-e875-47ea-84aa-3b12bb4cb0b1
50+
status:
51+
code: 200
52+
message: OK
53+
version: 1

0 commit comments

Comments
 (0)