Skip to content

Commit 9ab94b2

Browse files
chiqeen03rogelioLpzpachCode
authored
Recursos para card-authorizer (#146)
* test commit * resources * propeerty bin * resource CardValidation * tests * Fix name * models in init * Errors for arpc * New field for ARPC * card_id to number * update pin interface * card_data in cards-validations * arpc and rebase * track_data_method * Version * Test for ARQC resource * Testing card_validations * Coverage * removing pin_block * Bump cuenca-validations * Version * arpc comments * lint * update cuenca-valdiations * update version * Lint Co-authored-by: rogelioLpz <rogelio.lpz94@gmail.com> Co-authored-by: Pach <arturo@cuenca.com>
1 parent 0773a50 commit 9ab94b2

File tree

13 files changed

+422
-3
lines changed

13 files changed

+422
-3
lines changed

cuenca/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
'__version__',
33
'ApiKey',
44
'Account',
5+
'Arpc',
56
'BalanceEntry',
67
'BillPayment',
78
'Card',
89
'CardActivation',
910
'CardTransaction',
11+
'CardValidation',
1012
'Commission',
1113
'Deposit',
1214
'LoginToken',
@@ -24,11 +26,13 @@
2426
from .resources import (
2527
Account,
2628
ApiKey,
29+
Arpc,
2730
BalanceEntry,
2831
BillPayment,
2932
Card,
3033
CardActivation,
3134
CardTransaction,
35+
CardValidation,
3236
Commission,
3337
Deposit,
3438
LoginToken,

cuenca/resources/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
__all__ = [
22
'ApiKey',
33
'Account',
4+
'Arpc',
45
'BalanceEntry',
56
'BillPayment',
67
'Card',
78
'CardActivation',
89
'CardTransaction',
10+
'CardValidation',
911
'Commission',
1012
'Deposit',
1113
'LoginToken',
@@ -18,10 +20,12 @@
1820

1921
from .accounts import Account
2022
from .api_keys import ApiKey
23+
from .arpc import Arpc
2124
from .balance_entries import BalanceEntry
2225
from .bill_payments import BillPayment
2326
from .card_activations import CardActivation
2427
from .card_transactions import CardTransaction
28+
from .card_validations import CardValidation
2529
from .cards import Card
2630
from .commissions import Commission
2731
from .deposits import Deposit
@@ -38,11 +42,13 @@
3842
resource_classes = [
3943
ApiKey,
4044
Account,
45+
Arpc,
4146
BalanceEntry,
4247
BillPayment,
4348
Card,
4449
CardActivation,
4550
CardTransaction,
51+
CardValidation,
4652
Commission,
4753
Deposit,
4854
LoginToken,

cuenca/resources/arpc.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import datetime as dt
2+
from typing import ClassVar, Optional, cast
3+
4+
from cuenca_validations.types.requests import ARPCRequest
5+
from pydantic.dataclasses import dataclass
6+
7+
from ..http import Session, session as global_session
8+
from .base import Creatable
9+
10+
11+
@dataclass
12+
class Arpc(Creatable):
13+
"""
14+
An ARPC (Authorisation Response Cryptogram) is generated by the issuer
15+
to authorize EMV transactions (Chip, Contactless)
16+
17+
The point of sales terminal or ATM generate an ARQC (Authorization Request
18+
Cryptogram) to obtain authorization for transactions.
19+
After, the issuer has to verified the ARQC and generate an ARPC.
20+
Finally the ARPC is sent back to the point of sales terminal to authorize
21+
the transaction and validate the issuer as authentic
22+
"""
23+
24+
_resource: ClassVar = 'arpc'
25+
26+
created_at: dt.datetime
27+
card_uri: str
28+
is_valid_arqc: Optional[bool]
29+
arpc: Optional[str]
30+
err: Optional[str]
31+
32+
@classmethod
33+
def create(
34+
cls,
35+
number: str,
36+
arqc: str,
37+
arpc_method: str,
38+
transaction_data: str,
39+
response_code: str,
40+
transaction_counter: str,
41+
pan_sequence: str,
42+
unique_number: str,
43+
track_data_method: str,
44+
*,
45+
session: Session = global_session,
46+
) -> 'Arpc':
47+
req = ARPCRequest(
48+
number=number,
49+
arqc=arqc,
50+
arpc_method=arpc_method,
51+
transaction_data=transaction_data,
52+
response_code=response_code,
53+
transaction_counter=transaction_counter,
54+
pan_sequence=pan_sequence,
55+
unique_number=unique_number,
56+
track_data_method=track_data_method,
57+
)
58+
return cast('Arpc', cls._create(session=session, **req.dict()))
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import datetime as dt
2+
from typing import ClassVar, Optional, cast
3+
4+
from cuenca_validations.types import CardStatus, CardType
5+
from cuenca_validations.types.requests import CardValidationRequest
6+
from pydantic.dataclasses import dataclass
7+
8+
from ..http import Session, session as global_session
9+
from .base import Creatable
10+
from .cards import Card
11+
from .resources import retrieve_uri
12+
13+
14+
@dataclass
15+
class CardValidation(Creatable):
16+
_resource: ClassVar = 'card_validations'
17+
18+
created_at: dt.datetime
19+
card_uri: str
20+
user_id: str
21+
card_status: CardStatus
22+
card_type: CardType
23+
is_valid_cvv: Optional[bool]
24+
is_valid_cvv2: Optional[bool]
25+
is_valid_icvv: Optional[bool]
26+
is_valid_pin_block: Optional[bool]
27+
is_valid_exp_date: Optional[bool]
28+
is_expired: bool
29+
30+
@classmethod
31+
def create(
32+
cls,
33+
number: str,
34+
cvv: Optional[str] = None,
35+
cvv2: Optional[str] = None,
36+
icvv: Optional[str] = None,
37+
exp_month: Optional[int] = None,
38+
exp_year: Optional[int] = None,
39+
pin_block: Optional[str] = None,
40+
*,
41+
session: Session = global_session,
42+
) -> 'CardValidation':
43+
req = CardValidationRequest(
44+
number=number,
45+
cvv=cvv,
46+
cvv2=cvv2,
47+
icvv=icvv,
48+
exp_month=exp_month,
49+
exp_year=exp_year,
50+
pin_block=pin_block,
51+
)
52+
return cast(
53+
'CardValidation', cls._create(session=session, **req.dict())
54+
)
55+
56+
@property
57+
def card(self) -> Card:
58+
return cast(Card, retrieve_uri(self.card_uri))
59+
60+
@property
61+
def card_id(self) -> str:
62+
return self.card_uri.split('/')[-1]
63+
64+
@property
65+
def is_active(self):
66+
return self.card_status == CardStatus.active

cuenca/resources/cards.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class Card(Retrievable, Queryable, Creatable, Updateable):
3535
def last_4_digits(self):
3636
return self.number[-4:]
3737

38+
@property
39+
def bin(self):
40+
return self.number[:6]
41+
3842
@classmethod
3943
def create(
4044
cls,
@@ -64,6 +68,7 @@ def update(
6468
cls,
6569
card_id: str,
6670
status: Optional[CardStatus] = None,
71+
pin_block: Optional[str] = None,
6772
*,
6873
session: Session = global_session,
6974
) -> 'Card':
@@ -73,9 +78,11 @@ def update(
7378
7479
:param card_id: existing card_id
7580
:param status:
81+
:param pin_block
82+
:param session:
7683
:return: Updated card object
7784
"""
78-
req = CardUpdateRequest(status=status)
85+
req = CardUpdateRequest(status=status, pin_block=pin_block)
7986
resp = cls._update(card_id, session=session, **req.dict())
8087
return cast('Card', resp)
8188

cuenca/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = '0.7.4'
1+
__version__ = '0.7.5'
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.25.1
2-
cuenca-validations==0.9.2
2+
cuenca-validations==0.9.3
33
dataclasses>=0.7;python_version<"3.7"
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
interactions:
2+
- request:
3+
body: '{"number": "1234567890123403", "arqc": "DB3C77D5469C53C6", "arpc_method":
4+
"1", "transaction_data": "somerandomtransactiondata",
5+
"response_code": "0010", "transaction_counter": "001D", "pan_sequence": "01",
6+
"unique_number": "42D6A016", "track_data_method": "terminal"}'
7+
headers:
8+
Accept:
9+
- '*/*'
10+
Accept-Encoding:
11+
- gzip, deflate
12+
Authorization:
13+
- DUMMY
14+
Connection:
15+
- keep-alive
16+
Content-Length:
17+
- '320'
18+
Content-Type:
19+
- application/json
20+
User-Agent:
21+
- cuenca-python/0.7.5
22+
X-Cuenca-Api-Version:
23+
- '2020-03-19'
24+
method: POST
25+
uri: https://sandbox.cuenca.com/arpc
26+
response:
27+
body:
28+
string: '{"id":"ARfuiaeihfusbcibec","created_at":"2021-04-14T20:27:45.485000","card_uri":"/cards/CAoawhiursbcbeac","is_valid_arqc":true,"arpc":"16404ADAFB227B4D","err":null}'
29+
headers:
30+
Connection:
31+
- keep-alive
32+
Content-Length:
33+
- '178'
34+
Content-Type:
35+
- application/json
36+
Date:
37+
- Wed, 14 Apr 2021 20:27:45 GMT
38+
X-Amzn-Trace-Id:
39+
- Root=1-60775040-62cf8efc0574bee15063442b;Sampled=0
40+
X-Request-Time:
41+
- 'value: 1.001'
42+
x-amz-apigw-id:
43+
- dyl6HE7DiYcFdVg=
44+
x-amzn-Remapped-Connection:
45+
- keep-alive
46+
x-amzn-Remapped-Content-Length:
47+
- '178'
48+
x-amzn-Remapped-Date:
49+
- Wed, 14 Apr 2021 20:27:45 GMT
50+
x-amzn-Remapped-Server:
51+
- nginx/1.18.0
52+
x-amzn-Remapped-x-amzn-RequestId:
53+
- fc51600d-4747-4443-89f1-a3c4040831b1
54+
x-amzn-RequestId:
55+
- 342cac75-f28e-486d-9c8d-51923caf0624
56+
status:
57+
code: 201
58+
message: Created
59+
version: 1
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
interactions:
2+
- request:
3+
body: '{"pin_block": "7AC814A636D901BE"}'
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Authorization:
10+
- DUMMY
11+
Connection:
12+
- keep-alive
13+
Content-Length:
14+
- '33'
15+
Content-Type:
16+
- application/json
17+
User-Agent:
18+
- cuenca-python/0.7.5
19+
X-Cuenca-Api-Version:
20+
- '2020-03-19'
21+
method: PATCH
22+
uri: https://sandbox.cuenca.com/cards/CAycvo_X9TQoKOKsaAvdqn3w
23+
response:
24+
body:
25+
string: '{"id":"CAycvo_X9TQoKOKsaAvdqn3w","created_at":"2021-03-11T22:54:35.337000","updated_at":"2021-03-11T23:45:23.266000","user_id":"USfeauhf3873g85","number":"1234567890123403","exp_month":2,"exp_year":25,"cvv2":"150","type":"physical","status":"active","pin":"6725","issuer":"cuenca","funding_type":"debit","pin_block":"461F248CA285A5CB","batch":null,"manufacturer":null,"cvv":"685","icvv":"399","pin_block_switch":"7AC814A636D901BE","pin_block_embosser":"26641FB1CB03B667"}'
26+
headers:
27+
Connection:
28+
- keep-alive
29+
Content-Length:
30+
- '480'
31+
Content-Type:
32+
- application/json
33+
Date:
34+
- Wed, 14 Apr 2021 23:05:36 GMT
35+
X-Amzn-Trace-Id:
36+
- Root=1-60777538-1d5098837edce6774d61ecb7;Sampled=0
37+
X-Request-Time:
38+
- 'value: 7.757'
39+
x-amz-apigw-id:
40+
- dy9A0EDaCYcFWzw=
41+
x-amzn-Remapped-Connection:
42+
- keep-alive
43+
x-amzn-Remapped-Content-Length:
44+
- '480'
45+
x-amzn-Remapped-Date:
46+
- Wed, 14 Apr 2021 23:05:36 GMT
47+
x-amzn-Remapped-Server:
48+
- nginx/1.18.0
49+
x-amzn-Remapped-x-amzn-RequestId:
50+
- 85b2184b-d132-46d8-9fc3-2abb4167eb0f
51+
x-amzn-RequestId:
52+
- 07367a9e-1066-419a-8048-07dabe32595d
53+
status:
54+
code: 200
55+
message: OK
56+
version: 1

0 commit comments

Comments
 (0)