|
1 | 1 | import datetime as dt |
2 | | -from typing import ClassVar, Optional, cast |
| 2 | +from typing import ClassVar, Literal, Optional, cast |
3 | 3 |
|
4 | 4 | from cuenca_validations.types import ( |
| 5 | + TransactionStatus, |
5 | 6 | TransferNetwork, |
6 | 7 | TransferQuery, |
7 | 8 | TransferRequest, |
| 9 | + UpdateTransferRequest, |
8 | 10 | ) |
9 | 11 | from cuenca_validations.typing import DictStrAny |
10 | 12 | from requests import HTTPError |
11 | 13 |
|
12 | 14 | from ..exc import CuencaException |
| 15 | +from ..http import Session, session as global_session |
13 | 16 | from .accounts import Account |
14 | | -from .base import Creatable, Transaction |
| 17 | +from .base import Creatable, Transaction, Updateable |
15 | 18 | from .resources import retrieve_uri |
16 | 19 |
|
17 | 20 |
|
18 | | -class Transfer(Transaction, Creatable): |
| 21 | +class Transfer(Transaction, Creatable, Updateable): |
19 | 22 | _resource: ClassVar = 'transfers' |
20 | 23 | _query_params: ClassVar = TransferQuery |
21 | 24 |
|
@@ -71,6 +74,28 @@ def create( |
71 | 74 | ) |
72 | 75 | return cls._create(**req.model_dump()) |
73 | 76 |
|
| 77 | + @classmethod |
| 78 | + def update( |
| 79 | + cls, |
| 80 | + transfer_id: str, |
| 81 | + status: Literal[ |
| 82 | + TransactionStatus.succeeded, |
| 83 | + TransactionStatus.failed, |
| 84 | + ], |
| 85 | + *, |
| 86 | + session: Session = global_session, |
| 87 | + ) -> 'Transfer': |
| 88 | + """ |
| 89 | + Updates the status of a held transfer. |
| 90 | +
|
| 91 | + :param transfer_id: existing transfer_id |
| 92 | + :param status: TransactionStatus.succeeded to approve, or |
| 93 | + TransactionStatus.failed to reject |
| 94 | + :return: Updated transfer object |
| 95 | + """ |
| 96 | + req = UpdateTransferRequest(status=status) |
| 97 | + return cls._update(transfer_id, session=session, **req.model_dump()) |
| 98 | + |
74 | 99 | @classmethod |
75 | 100 | def create_many(cls, requests: list[TransferRequest]) -> DictStrAny: |
76 | 101 | transfers: DictStrAny = dict(submitted=[], errors=[]) |
|
0 commit comments