|
| 1 | +import datetime as dt |
| 2 | +from typing import ClassVar, Optional, cast |
| 3 | + |
| 4 | +from cuenca_validations.types import ( |
| 5 | + BankAccountStatus, |
| 6 | + BankAccountValidationRequest, |
| 7 | + CurpField, |
| 8 | + Rfc, |
| 9 | +) |
| 10 | + |
| 11 | +from ..http import Session, session as global_session |
| 12 | +from .base import Creatable, Retrievable |
| 13 | + |
| 14 | + |
| 15 | +class BankAccountValidation(Creatable, Retrievable): |
| 16 | + _resource: ClassVar = 'bank_account_validations' |
| 17 | + |
| 18 | + created_at: dt.datetime |
| 19 | + account_number: Optional[str] = None |
| 20 | + account_holder: Optional[str] = None |
| 21 | + bank_code: Optional[str] = None |
| 22 | + status: Optional[BankAccountStatus] = None |
| 23 | + curp: Optional[CurpField] = None |
| 24 | + rfc: Optional[Rfc] = None |
| 25 | + |
| 26 | + class Config: |
| 27 | + fields = { |
| 28 | + 'account_number': { |
| 29 | + 'description': 'Account number for validation, can be CARD_NUMBER or CLABE' |
| 30 | + }, |
| 31 | + 'account_holder': { |
| 32 | + 'description': 'The fullname of the owner from the account' |
| 33 | + }, |
| 34 | + 'bank_code': { |
| 35 | + 'description': 'Code of the bank according to https://es.wikipedia.org/wiki/CLABE, this can ' |
| 36 | + 'be retrived from our library https://github.com/cuenca-mx/clabe-python' |
| 37 | + }, |
| 38 | + 'status': { |
| 39 | + 'description': 'Initial status is submitted, then if everthing its fine or not the status can be ' |
| 40 | + 'succeeded or failed' |
| 41 | + }, |
| 42 | + } |
| 43 | + schema_extra = { |
| 44 | + 'example': { |
| 45 | + 'id': 'CVNEUInh69SuKXXmK95sROwQ', |
| 46 | + 'created_at': '2019-08-24T14:15:22Z', |
| 47 | + 'account_number': '646180157098510917', |
| 48 | + 'account_holder': 'Pedrito Sola', |
| 49 | + 'bank_code': '90646', |
| 50 | + 'status': 'succedded', |
| 51 | + 'curp': 'GOCG650418HVZNML08', |
| 52 | + 'rfc': 'GOCG650418HV9', |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + @classmethod |
| 57 | + def create( |
| 58 | + cls, |
| 59 | + account_number: str, |
| 60 | + bank_code: str, |
| 61 | + session: Session = global_session, |
| 62 | + ) -> 'BankAccountValidation': |
| 63 | + req = BankAccountValidationRequest( |
| 64 | + account_number=account_number, |
| 65 | + bank_code=bank_code, |
| 66 | + ) |
| 67 | + return cast( |
| 68 | + 'BankAccountValidation', |
| 69 | + cls._create(session=session, **req.dict()), |
| 70 | + ) |
0 commit comments