Skip to content

Commit

Permalink
Card Transactions (#80)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Keryc Diaz authored Nov 6, 2020
1 parent 4293abc commit dbd1eb3
Show file tree
Hide file tree
Showing 11 changed files with 497 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cuenca/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'Account',
'BalanceEntry',
'BillPayment',
'CardTransaction',
'Commission',
'Deposit',
'ServiceProvider',
Expand All @@ -19,6 +20,7 @@
ApiKey,
BalanceEntry,
BillPayment,
CardTransaction,
Commission,
Deposit,
ServiceProvider,
Expand Down
3 changes: 3 additions & 0 deletions cuenca/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'BalanceEntry',
'BillPayment',
'Card',
'CardTransaction',
'Commission',
'Deposit',
'ServiceProvider',
Expand All @@ -15,6 +16,7 @@
from .api_keys import ApiKey
from .balance_entries import BalanceEntry
from .bill_payments import BillPayment
from .card_transactions import CardTransaction
from .cards import Card
from .commissions import Commission
from .deposits import Deposit
Expand All @@ -30,6 +32,7 @@
BalanceEntry,
BillPayment,
Card,
CardTransaction,
Commission,
Deposit,
ServiceProvider,
Expand Down
35 changes: 35 additions & 0 deletions cuenca/resources/card_transactions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from typing import ClassVar, List, Optional, cast

from cuenca_validations.types import (
CardErrorType,
CardNetwork,
CardTransactionType,
CardType,
)
from pydantic.dataclasses import dataclass

from .base import Transaction
from .resources import retrieve_uris


@dataclass
class CardTransaction(Transaction):
_resource: ClassVar = 'card_transactions'

type: CardTransactionType
network: CardNetwork
related_card_transaction_uris: List[str]
card_id: str
card_last4: str
card_type: CardType
metadata: dict
error_type: Optional[CardErrorType]

@property # type: ignore
def related_card_transactions(self) -> Optional[List['CardTransaction']]:
if not self.related_card_transaction_uris:
return None
return cast(
List['CardTransaction'],
retrieve_uris(self.related_card_transaction_uris),
)
8 changes: 7 additions & 1 deletion cuenca/resources/resources.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
from typing import Dict, cast
from concurrent.futures import ThreadPoolExecutor
from typing import Dict, List, cast

from .base import Retrievable

Expand All @@ -13,3 +14,8 @@ def retrieve_uri(uri: str) -> Retrievable:
raise ValueError(f'uri is not a valid format: {uri}')
resource, id_ = m.groups()
return cast(Retrievable, RESOURCES[resource].retrieve(id_))


def retrieve_uris(uris: List[str]) -> List[Retrievable]:
with ThreadPoolExecutor(max_workers=len(uris)) as executor:
return [ct for ct in executor.map(retrieve_uri, [uri for uri in uris])]
2 changes: 1 addition & 1 deletion cuenca/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '0.3.8'
__version__ = '0.3.9'
CLIENT_VERSION = __version__
API_VERSION = '2020-03-19'
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
requests==2.24.0
cuenca-validations==0.6.4
cuenca-validations==0.6.6
dataclasses>=0.7;python_version<"3.7"
aws-requests-auth==0.4.3
104 changes: 104 additions & 0 deletions tests/resources/cassettes/test_card_transaction_child_retrieve.yaml
Original file line number Diff line number Diff line change
@@ -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.6
X-Cuenca-Api-Version:
- '2020-03-19'
x-amz-content-sha256:
- e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-amz-date:
- 20201029T211344Z
method: GET
uri: https://sandbox.cuenca.com/card_transactions/CT002
response:
body:
string: '{"id":"CT002","created_at":"2020-10-29T18:04:37.414000","user_id":"US4PCNV8rLB2wqBfORzIAXUl","amount":300,"status":"created","descriptor":"Superama
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}'
headers:
Connection:
- keep-alive
Content-Length:
- '659'
Content-Type:
- application/json
Date:
- Thu, 29 Oct 2020 21:13:44 GMT
Via:
- 1.1 fef232a36f2d64e8401caff3be58f4fc.cloudfront.net (CloudFront)
X-Amz-Cf-Id:
- 4WuDXoq-_GWtMLx6kiNBPWtX2BpR211K3UJSdnbP24GiScNcXF2HlQ==
X-Amz-Cf-Pop:
- IAH50-C1
X-Amzn-Trace-Id:
- Root=1-5f9b3088-54cfc3235bfff8a00655b709;Sampled=0
X-Cache:
- Miss from cloudfront
x-amz-apigw-id:
- VMSFZGONoAMF7zA=
x-amzn-RequestId:
- 0d065a8f-9a36-47ec-88b1-1b3bfcb1e215
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.6
X-Cuenca-Api-Version:
- '2020-03-19'
x-amz-content-sha256:
- e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-amz-date:
- 20201029T211344Z
method: GET
uri: https://sandbox.cuenca.com/card_transactions/CT001
response:
body:
string: '{"id":"CT001","created_at":"2020-10-29T18:04:37.396000","user_id":"US4PCNV8rLB2wqBfORzIAXUl","amount":300,"status":"created","descriptor":"Superama
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}'
headers:
Connection:
- keep-alive
Content-Length:
- '747'
Content-Type:
- application/json
Date:
- Thu, 29 Oct 2020 21:13:45 GMT
Via:
- 1.1 fef232a36f2d64e8401caff3be58f4fc.cloudfront.net (CloudFront)
X-Amz-Cf-Id:
- LIS9DTnDXufnad7kEAG_UcUfcFs7laqNSgFpJx5vwbGGeAXMACHszA==
X-Amz-Cf-Pop:
- IAH50-C1
X-Amzn-Trace-Id:
- Root=1-5f9b3089-4586ce643d7ee31e3c819823;Sampled=0
X-Cache:
- Miss from cloudfront
x-amz-apigw-id:
- VMSFbFGyIAMFcMQ=
x-amzn-RequestId:
- 99f43c26-2aea-4de7-b03d-9113ff28a3ed
status:
code: 200
message: OK
version: 1
Original file line number Diff line number Diff line change
@@ -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.6
X-Cuenca-Api-Version:
- '2020-03-19'
x-amz-content-sha256:
- e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
x-amz-date:
- 20201029T211345Z
method: GET
uri: https://sandbox.cuenca.com/card_transactions/CT004
response:
body:
string: '{"id":"CT004","created_at":"2020-10-29T18:04:36.318000","user_id":"US4PCNV8rLB2wqBfORzIAXUl","amount":300,"status":"failed","descriptor":"Superama
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}'
headers:
Connection:
- keep-alive
Content-Length:
- '641'
Content-Type:
- application/json
Date:
- Thu, 29 Oct 2020 21:13:45 GMT
Via:
- 1.1 a75dce573e80f2f2d03981a80f910c42.cloudfront.net (CloudFront)
X-Amz-Cf-Id:
- c5u29_nf3YTSb7F-8JyhufTnieVVTDY59jXwr2jdJ3qcuEcSVEPO3A==
X-Amz-Cf-Pop:
- IAH50-C1
X-Amzn-Trace-Id:
- Root=1-5f9b3089-501105c97ed0766d4d07559f;Sampled=0
X-Cache:
- Miss from cloudfront
x-amz-apigw-id:
- VMSFiGpHIAMFlbw=
x-amzn-RequestId:
- 18ec27c1-e875-47ea-84aa-3b12bb4cb0b1
status:
code: 200
message: OK
version: 1
Loading

0 comments on commit dbd1eb3

Please sign in to comment.