Skip to content

Commit 9a3f652

Browse files
authored
Verifications 🛂 (#242)
* First Approach of Verifications * Lint * Verifications review * New cassettes done * receiver instead of sender * Reviews done * Changes in our cassettes * CV version and chaanging tests * Alex reviews done * Review done
1 parent 140e0ee commit 9a3f652

14 files changed

+424
-3
lines changed

‎cuenca/__init__.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
'UserCredential',
2828
'UserEvent',
2929
'UserLogin',
30+
'Verification',
3031
'WalletTransaction',
3132
'Webhook',
3233
'WhatsappTransfer',
@@ -65,6 +66,7 @@
6566
UserCredential,
6667
UserEvent,
6768
UserLogin,
69+
Verification,
6870
WalletTransaction,
6971
Webhook,
7072
WhatsappTransfer,

‎cuenca/resources/__init__.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
'User',
2626
'UserEvent',
2727
'UserLogin',
28+
'Verification',
2829
'WalletTransaction',
2930
'Webhook',
3031
'WhatsappTransfer',
@@ -58,6 +59,7 @@
5859
from .user_events import UserEvent
5960
from .user_logins import UserLogin
6061
from .users import User
62+
from .verifications import Verification
6163
from .wallet_transactions import WalletTransaction
6264
from .webhooks import Webhook
6365
from .whatsapp_transfers import WhatsappTransfer
@@ -91,6 +93,7 @@
9193
UserCredential,
9294
UserEvent,
9395
UserLogin,
96+
Verification,
9497
WalletTransaction,
9598
WhatsappTransfer,
9699
Webhook,

‎cuenca/resources/base.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def _create(cls, *, session: Session = global_session, **data) -> Resource:
7171

7272
@dataclass
7373
class Updateable(Resource):
74+
7475
updated_at: dt.datetime
7576

7677
@classmethod
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import datetime as dt
2+
from typing import ClassVar, Optional, Union, cast
3+
4+
from cuenca_validations.types import (
5+
VerificationAttemptRequest,
6+
VerificationRequest,
7+
VerificationType,
8+
)
9+
from cuenca_validations.types.identities import PhoneNumber
10+
from pydantic import EmailStr
11+
from pydantic.dataclasses import dataclass
12+
13+
from ..http import Session, session as global_session
14+
from .base import Creatable, Updateable
15+
16+
17+
@dataclass
18+
class Verification(Creatable, Updateable):
19+
_resource: ClassVar = 'verifications'
20+
21+
recipient: Union[EmailStr, PhoneNumber]
22+
type: VerificationType
23+
created_at: dt.datetime
24+
deactivated_at: Optional[dt.datetime]
25+
26+
@classmethod
27+
def create(
28+
cls,
29+
recipient: str,
30+
type: VerificationType,
31+
platform_id: str,
32+
session: Session = global_session,
33+
) -> 'Verification':
34+
req = VerificationRequest(
35+
recipient=recipient, type=type, platform_id=platform_id
36+
)
37+
return cast('Verification', cls._create(**req.dict(), session=session))
38+
39+
@classmethod
40+
def verify(
41+
cls,
42+
id: str,
43+
code: str,
44+
session: Session = global_session,
45+
) -> 'Verification':
46+
req = VerificationAttemptRequest(code=code)
47+
return cast(
48+
'Verification',
49+
cls._update(id=id, **req.dict(), session=session),
50+
)

‎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.19'
1+
__version__ = '0.8.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.9.23
2+
cuenca-validations==0.10.0
33
dataclasses>=0.7;python_version<"3.7"

‎setup.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
install_requires=[
2626
'requests>=2.24,<28',
2727
'dataclasses>=0.7;python_version<"3.7"',
28-
'cuenca-validations>=0.9.23,<=0.10.*',
28+
'cuenca-validations>=0.10.0,<0.11.0',
2929
],
3030
classifiers=[
3131
'Programming Language :: Python :: 3',
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
interactions:
2+
- request:
3+
body: '{"type": "email", "sender": "mail@cuenca.com", "platform_id":
4+
"PL01"}'
5+
headers:
6+
Accept:
7+
- '*/*'
8+
Accept-Encoding:
9+
- gzip, deflate
10+
Authorization:
11+
- DUMMY
12+
Connection:
13+
- keep-alive
14+
Content-Length:
15+
- '82'
16+
Content-Type:
17+
- application/json
18+
User-Agent:
19+
- cuenca-python/0.8.0.dev0
20+
X-Cuenca-Api-Version:
21+
- '2020-03-19'
22+
method: POST
23+
uri: https://sandbox.cuenca.com/verifications
24+
response:
25+
body:
26+
string: '{"id":"VE01","recipient":"mail@cuenca.com","platform_id":"PL01","api_key":null,"type":"email","created_at":"2022-03-16T22:33:21.930707","updated_at":"2022-03-16T22:33:21.931013","deactivated_at":null}'
27+
headers:
28+
Connection:
29+
- keep-alive
30+
Content-Length:
31+
- '260'
32+
Content-Type:
33+
- application/json
34+
Date:
35+
- Wed, 16 Mar 2022 22:33:22 GMT
36+
X-Request-Time:
37+
- 'value: 0.323'
38+
x-amz-apigw-id:
39+
- PGTTzHY-iYcF1zQ=
40+
x-amzn-Remapped-Connection:
41+
- keep-alive
42+
x-amzn-Remapped-Content-Length:
43+
- '260'
44+
x-amzn-Remapped-Date:
45+
- Wed, 16 Mar 2022 22:33:22 GMT
46+
x-amzn-Remapped-Server:
47+
- nginx/1.20.2
48+
x-amzn-RequestId:
49+
- 1403b526-7466-4985-bf8a-b8e6c156e527
50+
status:
51+
code: 201
52+
message: Created
53+
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: '{"type": "phone", "sender": "+525555555555", "platform_id":
4+
"PL01"}'
5+
headers:
6+
Accept:
7+
- '*/*'
8+
Accept-Encoding:
9+
- gzip, deflate
10+
Authorization:
11+
- DUMMY
12+
Connection:
13+
- keep-alive
14+
Content-Length:
15+
- '80'
16+
Content-Type:
17+
- application/json
18+
User-Agent:
19+
- cuenca-python/0.8.0.dev0
20+
X-Cuenca-Api-Version:
21+
- '2020-03-19'
22+
method: POST
23+
uri: https://sandbox.cuenca.com/verifications
24+
response:
25+
body:
26+
string: '{"id":"VE02","recipient":"+525555555555","platform_id":"PL01","api_key":null,"type":"phone","created_at":"2022-03-16T22:33:22.657205","updated_at":"2022-03-16T22:33:22.657613","deactivated_at":null}'
27+
headers:
28+
Connection:
29+
- keep-alive
30+
Content-Length:
31+
- '258'
32+
Content-Type:
33+
- application/json
34+
Date:
35+
- Wed, 16 Mar 2022 22:33:22 GMT
36+
X-Request-Time:
37+
- 'value: 0.285'
38+
x-amz-apigw-id:
39+
- PGTT7EO2CYcFQ_w=
40+
x-amzn-Remapped-Connection:
41+
- keep-alive
42+
x-amzn-Remapped-Content-Length:
43+
- '258'
44+
x-amzn-Remapped-Date:
45+
- Wed, 16 Mar 2022 22:33:22 GMT
46+
x-amzn-Remapped-Server:
47+
- nginx/1.20.2
48+
x-amzn-RequestId:
49+
- 7be1235d-09b6-4bc2-b1d9-93b96ac66519
50+
status:
51+
code: 201
52+
message: Created
53+
version: 1
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
interactions:
2+
- request:
3+
body: '{"code": "299566"}'
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Authorization:
10+
- DUMMY
11+
Connection:
12+
- keep-alive
13+
Content-Length:
14+
- '18'
15+
Content-Type:
16+
- application/json
17+
User-Agent:
18+
- cuenca-python/0.8.0.dev0
19+
X-Cuenca-Api-Version:
20+
- '2020-03-19'
21+
method: PATCH
22+
uri: https://sandbox.cuenca.com/verifications/VE02
23+
response:
24+
body:
25+
string: '{"id":"VE02","recipient":"+525529372492","platform_id":"PTW68GgAc_QPmNCmgajmctLg","api_key":null,"type":"phone","created_at":"2022-03-16T18:16:31.555000","updated_at":"2022-03-16T22:35:08.856519","deactivated_at":null}'
26+
headers:
27+
Connection:
28+
- keep-alive
29+
Content-Length:
30+
- '337'
31+
Content-Type:
32+
- application/json
33+
Date:
34+
- Wed, 16 Mar 2022 22:35:08 GMT
35+
X-Request-Time:
36+
- 'value: 0.120'
37+
x-amz-apigw-id:
38+
- PGTkhGjHCYcF4Rw=
39+
x-amzn-Remapped-Connection:
40+
- keep-alive
41+
x-amzn-Remapped-Content-Length:
42+
- '337'
43+
x-amzn-Remapped-Date:
44+
- Wed, 16 Mar 2022 22:35:08 GMT
45+
x-amzn-Remapped-Server:
46+
- nginx/1.20.2
47+
x-amzn-RequestId:
48+
- e6c9d46f-bc19-4cf9-bca1-e44e9e3841c6
49+
status:
50+
code: 200
51+
message: OK
52+
version: 1

0 commit comments

Comments
 (0)