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

Bill Payments #311

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
41 changes: 37 additions & 4 deletions cuenca/resources/bill_payments.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,52 @@
from typing import ClassVar, cast
from typing import ClassVar, Optional, cast

from cuenca_validations.types import BillPaymentQuery
from cuenca_validations.types import (
BillPaymentQuery,
BillPaymentRequest,
ServiceProviderFieldType,
)

from .base import Transaction
from .base import Creatable, Transaction
from .resources import retrieve_uri
from .service_providers import ServiceProvider


class BillPayment(Transaction):
class BillPayment(Transaction, Creatable):
_resource: ClassVar = 'bill_payments'
_query_params: ClassVar = BillPaymentQuery

account_number: str
provider_uri: str

@classmethod
def create(
cls,
account_number: str,
amount: int,
provider_id: str,
field_type: ServiceProviderFieldType,
accountholder_name: Optional[str] = None,
user_id: Optional[str] = None,
) -> 'BillPayment':
"""
:param account_number: account number to be paid
:param amount: needs to be in centavos (not pesos)
:param provider_id: ServiceProvider.id
:param field_type: payment type you choose
:param accountholder_name: needed for some services
:param user_id: Source user to take the funds
:return: BillPayment object
"""
req = BillPaymentRequest(
account_number=account_number,
amount=amount,
provider_id=provider_id,
field_type=field_type,
accountholder_name=accountholder_name,
user_id=user_id,
)
return cast('BillPayment', cls._create(**req.dict()))

@property
def provider(self) -> ServiceProvider:
provider = cast(ServiceProvider, retrieve_uri(self.provider_uri))
Expand Down
6 changes: 5 additions & 1 deletion cuenca/resources/service_providers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from typing import ClassVar, List

from cuenca_validations.types import ServiceProviderCategory
from cuenca_validations.types import (
ServiceProviderCategory,
ServiceProviderField,
)

from .base import Queryable, Retrievable

Expand All @@ -11,3 +14,4 @@ class ServiceProvider(Retrievable, Queryable):
name: str
provider_key: str
categories: List[ServiceProviderCategory]
fields: List[ServiceProviderField]
10 changes: 4 additions & 6 deletions cuenca/resources/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
from clabe import Clabe
from cuenca_validations.types import (
Address,
AddressUpdateRequest,
Beneficiary,
KYCFile,
KYCFileUpdateRequest,
PhoneNumber,
TOSAgreement,
TOSRequest,
Expand Down Expand Up @@ -132,11 +130,11 @@ def update(
phone_number: Optional[PhoneNumber] = None,
email_address: Optional[str] = None,
profession: Optional[str] = None,
address: Optional[AddressUpdateRequest] = None,
address: Optional[Address] = None,
beneficiaries: Optional[List[Beneficiary]] = None,
govt_id: Optional[KYCFileUpdateRequest] = None,
proof_of_address: Optional[KYCFileUpdateRequest] = None,
proof_of_life: Optional[KYCFileUpdateRequest] = None,
govt_id: Optional[KYCFile] = None,
proof_of_address: Optional[KYCFile] = None,
proof_of_life: Optional[KYCFile] = None,
terms_of_service: Optional[TOSRequest] = None,
verification_id: Optional[str] = None,
status: Optional[UserStatus] = None,
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.14.1'
__version__ = '0.14.2'
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.10.28
cuenca-validations==0.11.2.dev2
dataclasses>=0.7;python_version<"3.7"
70 changes: 39 additions & 31 deletions tests/resources/cassettes/test_bill_payment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,42 @@ interactions:
Connection:
- keep-alive
User-Agent:
- cuenca-python/0.3.3
- cuenca-python/0.14.2
X-Cuenca-Api-Version:
- '2020-03-19'
method: GET
uri: https://sandbox.cuenca.com/bill_payments/ST01
response:
body:
string: '{"id":"ST01","created_at":"2020-10-05T01:12:46.973000","user_id":"US01","amount":10000,"status":"succeeded","descriptor":"Pago
de servicio","account_number":"(111) 111-1111","provider_uri":"/service_providers/SP01"}'
string: '{"id":"ST01","created_at":"2022-09-09T21:08:11.115000","user_id":"US01","amount":1000,"status":"failed","descriptor":"Pago
de Servicio","account_number":"000000000000000000000000000000","accountholder_name":null,"provider_uri":"/service_providers/SP01","field_id":null,"platform_id":"PT01"}'
headers:
Connection:
- keep-alive
Content-Length:
- '224'
- '370'
Content-Type:
- application/json
Date:
- Mon, 05 Oct 2020 23:56:54 GMT
Via:
- 1.1 72c5987cf6b5170991873937a6e36b80.cloudfront.net (CloudFront)
X-Amz-Cf-Id:
- vPUPB8XgktMziooNHnjTbP2v-wiXIZsW134XChHmw-lw885pV52hpw==
X-Amz-Cf-Pop:
- DFW50-C1
- Mon, 12 Sep 2022 17:28:11 GMT
X-Amzn-Trace-Id:
- Root=1-5f7bb2c5-250155e014a2927a6d49f7f5;Sampled=0
X-Cache:
- Miss from cloudfront
- Root=1-631f6c2a-2730a57538a7cde575f11fcf;Sampled=0
X-Request-Time:
- 'value: 0.648'
x-amz-apigw-id:
- T9je0FM4IAMF5NQ=
- YW3WpG2CCYcFTMw=
x-amzn-Remapped-Connection:
- keep-alive
x-amzn-Remapped-Content-Length:
- '370'
x-amzn-Remapped-Date:
- Mon, 12 Sep 2022 17:28:11 GMT
x-amzn-Remapped-Server:
- nginx/1.22.0
x-amzn-Remapped-x-amzn-RequestId:
- 297a93e0-26cd-4b05-a609-6f16fb9584ac
x-amzn-RequestId:
- 199a3e85-25c7-40b1-81e6-c45f2d81820b
- e3e87aaf-cb0f-4064-9814-77aa97e395df
status:
code: 200
message: OK
Expand All @@ -58,37 +62,41 @@ interactions:
Connection:
- keep-alive
User-Agent:
- cuenca-python/0.3.3
- cuenca-python/0.14.2
X-Cuenca-Api-Version:
- '2020-03-19'
method: GET
uri: https://sandbox.cuenca.com/service_providers/SP01
response:
body:
string: '{"id":"SP01","created_at":"2020-10-05T00:00:48.020000","name":"Telcel","provider_key":"topup_telcel","categories":["mobile_telephone_prepaid"]}'
string: '{"id":"SP01","created_at":"2019-07-15T23:21:48.020000","name":"CFE","provider_key":"electricity_cfe","categories":["electricity"],"fields":[{"is_active":true,"requires_accountholder_name":false,"mask":"000000000000000000000000000000","topup_amounts":[],"type":"barcode"},{"is_active":true,"requires_accountholder_name":false,"mask":"000000000000","topup_amounts":[],"type":"account_number"}]}'
headers:
Connection:
- keep-alive
Content-Length:
- '163'
- '412'
Content-Type:
- application/json
Date:
- Mon, 05 Oct 2020 23:56:55 GMT
Via:
- 1.1 72c5987cf6b5170991873937a6e36b80.cloudfront.net (CloudFront)
X-Amz-Cf-Id:
- A9UIKYCnUwTC067I5RCn2e5D9A4wUWy-yeDFT3BMoUqVIzmX5RXaRw==
X-Amz-Cf-Pop:
- DFW50-C1
- Mon, 12 Sep 2022 17:28:11 GMT
X-Amzn-Trace-Id:
- Root=1-5f7bb2c7-36ea3a3623a06c615355e8a7;Sampled=0
X-Cache:
- Miss from cloudfront
- Root=1-631f6c2b-1f9b9aa63ad8b9080ad1aa8b;Sampled=0
X-Request-Time:
- 'value: 0.326'
x-amz-apigw-id:
- T9jfMHpcoAMF14Q=
- YW3WyE9JCYcFj4w=
x-amzn-Remapped-Connection:
- keep-alive
x-amzn-Remapped-Content-Length:
- '412'
x-amzn-Remapped-Date:
- Mon, 12 Sep 2022 17:28:11 GMT
x-amzn-Remapped-Server:
- nginx/1.22.0
x-amzn-Remapped-x-amzn-RequestId:
- 71c5252e-89c9-45bf-905e-b0ea0048f8bd
x-amzn-RequestId:
- bacb6a7e-6fcc-4645-bd55-5d0dfc08f4e2
- 37186823-58eb-4675-a61c-8ac1eb394ce9
status:
code: 200
message: OK
Expand Down
108 changes: 108 additions & 0 deletions tests/resources/cassettes/test_create_bill_payment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
interactions:
- request:
body: '{"amount": 1000, "field_type": "barcode", "account_number": "000000000000000000000000000000",
"provider_id": "SP01", "user_id": "USMGZJ4vEYQ5SplZR5lcX5bg"}'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Authorization:
- DUMMY
Connection:
- keep-alive
Content-Length:
- '175'
Content-Type:
- application/json
User-Agent:
- cuenca-python/0.14.2
X-Cuenca-Api-Version:
- '2020-03-19'
method: POST
uri: https://sandbox.cuenca.com/bill_payments
response:
body:
string: '{"id":"STGjSUx0_9Rym_ElZbn8gW5g","created_at":"2022-09-12T17:41:18.036250","user_id":"USMGZJ4vEYQ5SplZR5lcX5bg","amount":1000,"status":"submitted","descriptor":"Pago
de Servicio a CFE","account_number":"000000000000000000000000000000","accountholder_name":null,"provider_uri":"/service_providers/SP01","field_id":"SP4qT51xTBPypWCNSBAuREL9","platform_id":"PTAW9CNmJSQ_O8piz-y1NyeA"}'
headers:
Connection:
- keep-alive
Content-Length:
- '401'
Content-Type:
- application/json
Date:
- Mon, 12 Sep 2022 17:41:18 GMT
X-Amzn-Trace-Id:
- Root=1-631f6f3b-2a07ba063f555dae2e758be4;Sampled=0
X-Request-Time:
- 'value: 3.277'
x-amz-apigw-id:
- YW5RSFYpCYcFbhg=
x-amzn-Remapped-Connection:
- keep-alive
x-amzn-Remapped-Content-Length:
- '401'
x-amzn-Remapped-Date:
- Mon, 12 Sep 2022 17:41:18 GMT
x-amzn-Remapped-Server:
- nginx/1.22.0
x-amzn-Remapped-x-amzn-RequestId:
- d9e85c4b-f6d2-4909-80d9-f848720a12ec
x-amzn-RequestId:
- fa9f577b-2d7f-4f42-8d51-2889420af5cd
status:
code: 201
message: Created
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Authorization:
- DUMMY
Connection:
- keep-alive
User-Agent:
- cuenca-python/0.14.2
X-Cuenca-Api-Version:
- '2020-03-19'
method: GET
uri: https://sandbox.cuenca.com/service_providers/SP01
response:
body:
string: '{"id":"SP01","created_at":"2019-07-15T23:21:48.020000","name":"CFE","provider_key":"electricity_cfe","categories":["electricity"],"fields":[{"is_active":true,"requires_accountholder_name":false,"mask":"000000000000000000000000000000","topup_amounts":[],"type":"barcode"},{"is_active":true,"requires_accountholder_name":false,"mask":"000000000000","topup_amounts":[],"type":"account_number"}]}'
headers:
Connection:
- keep-alive
Content-Length:
- '412'
Content-Type:
- application/json
Date:
- Mon, 12 Sep 2022 17:41:18 GMT
X-Amzn-Trace-Id:
- Root=1-631f6f3e-2b6d8b2936fcb61e07a9ccd7;Sampled=0
X-Request-Time:
- 'value: 0.344'
x-amz-apigw-id:
- YW5RzGr9CYcFzmg=
x-amzn-Remapped-Connection:
- keep-alive
x-amzn-Remapped-Content-Length:
- '412'
x-amzn-Remapped-Date:
- Mon, 12 Sep 2022 17:41:18 GMT
x-amzn-Remapped-Server:
- nginx/1.22.0
x-amzn-Remapped-x-amzn-RequestId:
- d45822cf-13eb-467b-82ba-f31af89f6bf5
x-amzn-RequestId:
- 6071e186-dad0-421a-b301-1c4f371123b5
status:
code: 200
message: OK
version: 1
34 changes: 19 additions & 15 deletions tests/resources/cassettes/test_service_provider.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,41 @@ interactions:
Connection:
- keep-alive
User-Agent:
- cuenca-python/0.3.3
- cuenca-python/0.14.2
X-Cuenca-Api-Version:
- '2020-03-19'
method: GET
uri: https://sandbox.cuenca.com/service_providers/SP01
response:
body:
string: '{"id":"SP01","created_at":"2020-10-05T00:00:48.020000","name":"Telcel","provider_key":"topup_telcel","categories":["mobile_telephone_prepaid"]}'
string: '{"id":"SP01","created_at":"2019-07-15T23:21:48.020000","name":"CFE","provider_key":"electricity_cfe","categories":["electricity"],"fields":[{"is_active":true,"requires_accountholder_name":false,"mask":"000000000000000000000000000000","topup_amounts":[],"type":"barcode"},{"is_active":true,"requires_accountholder_name":false,"mask":"000000000000","topup_amounts":[],"type":"account_number"}]}'
headers:
Connection:
- keep-alive
Content-Length:
- '143'
- '412'
Content-Type:
- application/json
Date:
- Mon, 05 Oct 2020 23:57:35 GMT
Via:
- 1.1 efcb172d06d66d2afa4eb747b3b88605.cloudfront.net (CloudFront)
X-Amz-Cf-Id:
- iWGW67QhiyoL-aZIypsTLH6C5bvPqRCgV_g44Fi0P4vOx333rMny_Q==
X-Amz-Cf-Pop:
- DFW50-C1
- Mon, 12 Sep 2022 17:04:32 GMT
X-Amzn-Trace-Id:
- Root=1-5f7bb2ef-0ce8f8fa299012df0c8a8103;Sampled=0
X-Cache:
- Miss from cloudfront
- Root=1-631f669d-21de2ba7666426d91dcb9880;Sampled=0
X-Request-Time:
- 'value: 2.924'
x-amz-apigw-id:
- T9jlZE16IAMFybg=
- YWz4sFA4iYcFpWA=
x-amzn-Remapped-Connection:
- keep-alive
x-amzn-Remapped-Content-Length:
- '412'
x-amzn-Remapped-Date:
- Mon, 12 Sep 2022 17:04:32 GMT
x-amzn-Remapped-Server:
- nginx/1.22.0
x-amzn-Remapped-x-amzn-RequestId:
- 69191bbf-d841-4d7f-90aa-7d8e9e2585bd
x-amzn-RequestId:
- 55e6aec9-7e04-4158-a418-478cc49101d4
- 4d1ea458-d9d5-47ec-893c-4b747cba50ef
status:
code: 200
message: OK
Expand Down
Loading