Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

International Transfers #229

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cuenca/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
'Deposit',
'Identity',
'IdentityEvent',
'InternationalTransfer',
'LoginToken',
'Saving',
'ServiceProvider',
Expand Down Expand Up @@ -40,6 +41,7 @@
from .deposits import Deposit
from .identities import Identity
from .identity_events import IdentityEvent
from .international_transfers import InternationalTransfer
from .login_tokens import LoginToken
from .resources import RESOURCES
from .savings import Saving
Expand Down Expand Up @@ -70,6 +72,7 @@
Deposit,
Identity,
IdentityEvent,
InternationalTransfer,
LoginToken,
Saving,
Session,
Expand Down
71 changes: 71 additions & 0 deletions cuenca/resources/international_transfers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import datetime as dt
from typing import ClassVar, cast

from cuenca_validations.types import (
Country,
Currency,
InternationalTransferQuery,
InternationalTransferRequest,
InternationalTransferUpdateRequest,
TransactionStatus,
)
from pydantic.dataclasses import dataclass

from .base import Creatable, Queryable, Retrievable, Updateable


@dataclass
class InternationalTransfer(Creatable, Retrievable, Updateable, Queryable):
_resource: ClassVar = 'international_transfers'
_query_params: ClassVar = InternationalTransferQuery

user_id: str
updated_at: dt.datetime
idempotency_key: str
bank_number: str
account_number: str
account_country: Country
account_name: str
received_amount: int
received_currency: Currency
sent_amount: int
sent_currency: Currency
status: TransactionStatus

@classmethod
def create(
cls,
user_id: str,
idempotency_key: str,
bank_number: str,
account_number: str,
account_country: Country,
account_name: str,
received_amount: int,
received_currency: Currency,
sent_amount: int,
sent_currency: Currency,
) -> 'InternationalTransfer':
req = InternationalTransferRequest(
user_id=user_id,
idempotency_key=idempotency_key,
bank_number=bank_number,
account_number=account_number,
account_country=account_country,
account_name=account_name,
received_amount=received_amount,
received_currency=received_currency,
sent_amount=sent_amount,
sent_currency=sent_currency,
)
return cast('InternationalTransfer', cls._create(**req.dict()))

@classmethod
def update(
cls,
transfer_id: str,
status: TransactionStatus = None,
) -> 'InternationalTransfer':
req = InternationalTransferUpdateRequest(status=status)
resp = cls._update(transfer_id, **req.dict())
return cast('InternationalTransfer', resp)
2 changes: 2 additions & 0 deletions cuenca/resources/transfers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def create(
descriptor: str,
recipient_name: str,
idempotency_key: Optional[str] = None,
user_id: Optional[str] = None,
) -> 'Transfer':
"""
:param account_number: CLABE
Expand All @@ -67,6 +68,7 @@ def create(
descriptor=descriptor,
recipient_name=recipient_name,
idempotency_key=idempotency_key,
user_id=user_id,
)
return cast('Transfer', cls._create(**req.dict()))

Expand Down
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.7.14'
__version__ = '0.7.18.dev2'
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,3 +1,3 @@
requests==2.27.1
cuenca-validations==0.9.18
cuenca-validations==0.9.19.dev5
dataclasses>=0.7;python_version<"3.7"
18 changes: 17 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Dict

import pytest
from cuenca_validations.types import Country, Gender, State
from cuenca_validations.types import Country, Currency, Gender, State

import cuenca

Expand Down Expand Up @@ -60,3 +60,19 @@ def user_request() -> Dict:
),
)
return user_dict


@pytest.fixture
def international_transfer() -> Dict:
return dict(
user_id='UShhSTmmy_R2y6KvQsGnTTMw',
idempotency_key="MY_UNIQUE_KEY",
bank_number="001287364",
account_number="1024357689",
account_country=Country.US,
account_name="Amanda Brown",
received_amount=20825,
received_currency=Currency.mxn,
sent_amount=1000,
sent_currency=Currency.usd,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
interactions:
- request:
body: '{"user_id": "UShhSTmmy_R2y6KvQsGnTTMw", "idempotency_key": "MY_UNIQUE_KEY",
"bank_number": "001287364", "account_number": "1024357689", "account_country":
"US", "account_name": "Amanda Brown", "received_amount": 20825, "received_currency":
"mxn", "sent_amount": 1000, "sent_currency": "usd"}'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Authorization:
- DUMMY
Connection:
- keep-alive
Content-Length:
- '294'
Content-Type:
- application/json
User-Agent:
- cuenca-python/0.7.14
X-Cuenca-Api-Version:
- '2020-03-19'
method: POST
uri: https://sandbox.cuenca.com/international_transfers
response:
body:
string: '{"id":"ITR99YzKs-RBWY0yqT9OU8Ig","created_at":"2022-02-23T02:38:24.829896","updated_at":"2022-02-23T02:38:24.830008","platform_id":"PTW68GgAc_QPmNCmgajmctLg","user_id":"UShhSTmmy_R2y6KvQsGnTTMw","idempotency_key":"MY_UNIQUE_KEY","bank_number":"001287364","account_number":"1024357689","account_country":"US","account_name":"Amanda
Brown","received_amount":20825,"received_currency":"mxn","sent_amount":1000,"sent_currency":"usd","status":"created"}'
headers:
Connection:
- keep-alive
Content-Length:
- '451'
Content-Type:
- application/json
Date:
- Wed, 23 Feb 2022 02:38:25 GMT
X-Amzn-Trace-Id:
- Root=1-62159e20-7ef7e32c44d016c502d37456;Sampled=0
X-Request-Time:
- 'value: 0.599'
x-amz-apigw-id:
- N-WlHGSAiYcFinQ=
x-amzn-Remapped-Connection:
- keep-alive
x-amzn-Remapped-Content-Length:
- '451'
x-amzn-Remapped-Date:
- Wed, 23 Feb 2022 02:38:25 GMT
x-amzn-Remapped-Server:
- nginx/1.20.2
x-amzn-Remapped-x-amzn-RequestId:
- 36afccd4-6cad-4fcc-bf42-454a10b05e66
x-amzn-RequestId:
- 75c0b373-d9d3-44a0-816e-39dd36568a1b
status:
code: 201
message: Created
- request:
body: '{"user_id": "UShhSTmmy_R2y6KvQsGnTTMw", "type": "session.international_transfers"}'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Authorization:
- DUMMY
Connection:
- keep-alive
Content-Length:
- '82'
Content-Type:
- application/json
User-Agent:
- cuenca-python/0.7.14
X-Cuenca-Api-Version:
- '2020-03-19'
method: POST
uri: https://sandbox.cuenca.com/sessions
response:
body:
string: '{"id":"SSsRTCbNj_QuetY7NXKDV9JA","created_at":"2022-02-23T02:38:27.556105","user_id":"UShhSTmmy_R2y6KvQsGnTTMw","platform_id":"PTW68GgAc_QPmNCmgajmctLg","expires_at":"2022-02-23T02:48:27.556113","success_url":null,"failure_url":null,"type":"session.international_transfers"}'
headers:
Connection:
- keep-alive
Content-Length:
- '274'
Content-Type:
- application/json
Date:
- Wed, 23 Feb 2022 02:38:27 GMT
X-Request-Time:
- 'value: 0.128'
x-amz-apigw-id:
- N-WlkEUNCYcF-aQ=
x-amzn-Remapped-Connection:
- keep-alive
x-amzn-Remapped-Content-Length:
- '274'
x-amzn-Remapped-Date:
- Wed, 23 Feb 2022 02:38:27 GMT
x-amzn-Remapped-Server:
- nginx/1.20.2
x-amzn-RequestId:
- eef6fe1b-e4ee-45eb-9ab1-37ccc81bfcc9
status:
code: 201
message: Created
- request:
body: '{"status": "submitted"}'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Authorization:
- DUMMY
Connection:
- keep-alive
Content-Length:
- '23'
Content-Type:
- application/json
User-Agent:
- cuenca-python/0.7.14
X-Cuenca-Api-Version:
- '2020-03-19'
X-Cuenca-SessionId:
- SSsRTCbNj_QuetY7NXKDV9JA
method: PATCH
uri: https://sandbox.cuenca.com/international_transfers/ITR99YzKs-RBWY0yqT9OU8Ig
response:
body:
string: '{"id":"ITR99YzKs-RBWY0yqT9OU8Ig","created_at":"2022-02-23T02:38:24.829000","updated_at":"2022-02-23T02:38:27.936699","platform_id":"PTW68GgAc_QPmNCmgajmctLg","user_id":"UShhSTmmy_R2y6KvQsGnTTMw","idempotency_key":"MY_UNIQUE_KEY","bank_number":"001287364","account_number":"1024357689","account_country":"US","account_name":"Amanda
Brown","received_amount":20825,"received_currency":"mxn","sent_amount":1000,"sent_currency":"usd","status":"submitted"}'
headers:
Connection:
- keep-alive
Content-Length:
- '453'
Content-Type:
- application/json
Date:
- Wed, 23 Feb 2022 02:38:28 GMT
X-Amzn-Trace-Id:
- Root=1-62159e23-6a5355b50c76438932276b5a;Sampled=0
X-Request-Time:
- 'value: 0.552'
x-amz-apigw-id:
- N-WlmHnDiYcFS3g=
x-amzn-Remapped-Connection:
- keep-alive
x-amzn-Remapped-Content-Length:
- '453'
x-amzn-Remapped-Date:
- Wed, 23 Feb 2022 02:38:28 GMT
x-amzn-Remapped-Server:
- nginx/1.20.2
x-amzn-Remapped-x-amzn-RequestId:
- e2d46dd5-9d9f-48c7-8252-64b4948311a8
x-amzn-RequestId:
- 35dc7e41-4691-4ea9-ba48-7d9d908975b6
status:
code: 201
message: Created
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Authorization:
- DUMMY
Connection:
- keep-alive
User-Agent:
- cuenca-python/0.7.14
X-Cuenca-Api-Version:
- '2020-03-19'
X-Cuenca-SessionId:
- SSsRTCbNj_QuetY7NXKDV9JA
method: GET
uri: https://sandbox.cuenca.com/international_transfers/ITR99YzKs-RBWY0yqT9OU8Ig
response:
body:
string: '{"id":"ITR99YzKs-RBWY0yqT9OU8Ig","created_at":"2022-02-23T02:38:24.829000","updated_at":"2022-02-23T02:38:27.936000","platform_id":"PTW68GgAc_QPmNCmgajmctLg","user_id":"UShhSTmmy_R2y6KvQsGnTTMw","idempotency_key":"MY_UNIQUE_KEY","bank_number":"001287364","account_number":"1024357689","account_country":"US","account_name":"Amanda
Brown","received_amount":20825,"received_currency":"mxn","sent_amount":1000,"sent_currency":"usd","status":"succeeded"}'
headers:
Connection:
- keep-alive
Content-Length:
- '453'
Content-Type:
- application/json
Date:
- Wed, 23 Feb 2022 02:38:28 GMT
X-Amzn-Trace-Id:
- Root=1-62159e24-1279be201ddb13244f73668c;Sampled=0
X-Request-Time:
- 'value: 0.446'
x-amz-apigw-id:
- N-WltFqoCYcF70g=
x-amzn-Remapped-Connection:
- keep-alive
x-amzn-Remapped-Content-Length:
- '453'
x-amzn-Remapped-Date:
- Wed, 23 Feb 2022 02:38:28 GMT
x-amzn-Remapped-Server:
- nginx/1.20.2
x-amzn-Remapped-x-amzn-RequestId:
- 5a6784ec-9a5a-4e55-b0f2-6338131242c8
x-amzn-RequestId:
- ea533480-c82d-45c2-8274-99ae94837f09
status:
code: 200
message: OK
version: 1
Loading