Skip to content

Commit 5c4688b

Browse files
authored
added BillPayment and ServiceProvider resources (#58)
* added billy_payments and service_providers * changed service_provider fields and query type for bill_payments * added tests for new resources and fixed BillPayment model * added categories to ServiceProvider * removed ServiceProvider resource, not going in that direction yet * readded ServiceProvider as a resource * added tests for ServiceProvider resource * bump version * testing pr workflow
1 parent 8885032 commit 5c4688b

File tree

11 files changed

+219
-4
lines changed

11 files changed

+219
-4
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: test
22

3-
on: push
3+
on: [push, pull_request]
44

55
jobs:
66
lint:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SHELL := bash
22
PATH := ./venv/bin:${PATH}
3-
PYTHON = python3.7
3+
PYTHON = python3.8
44
PROJECT = cuenca
55
isort = isort $(PROJECT) tests setup.py examples
66
black = black -S -l 79 --target-version py38 $(PROJECT) tests setup.py examples

cuenca/resources/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@
22
'ApiKey',
33
'Account',
44
'BalanceEntry',
5+
'BillPayment',
56
'Card',
67
'Commission',
78
'Deposit',
9+
'ServiceProvider',
810
'Transfer',
911
'WhatsappTransfer',
1012
]
1113

1214
from .accounts import Account
1315
from .api_keys import ApiKey
1416
from .balance_entries import BalanceEntry
17+
from .bill_payments import BillPayment
1518
from .cards import Card
1619
from .commissions import Commission
1720
from .deposits import Deposit
1821
from .resources import RESOURCES
22+
from .service_providers import ServiceProvider
1923
from .transfers import Transfer
2024
from .whatsapp_transfers import WhatsappTransfer
2125

@@ -24,9 +28,11 @@
2428
ApiKey,
2529
Account,
2630
BalanceEntry,
31+
BillPayment,
2732
Card,
2833
Commission,
2934
Deposit,
35+
ServiceProvider,
3036
Transfer,
3137
WhatsappTransfer,
3238
]

cuenca/resources/bill_payments.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from dataclasses import dataclass
2+
from typing import ClassVar, cast
3+
4+
from cuenca_validations.types import BillPaymentQuery
5+
6+
from .base import Transaction
7+
from .resources import retrieve_uri
8+
from .service_providers import ServiceProvider
9+
10+
11+
@dataclass
12+
class BillPayment(Transaction):
13+
_resource: ClassVar = 'bill_payments'
14+
_query_params: ClassVar = BillPaymentQuery
15+
16+
account_number: str
17+
provider_uri: str
18+
19+
@property
20+
def provider(self) -> ServiceProvider:
21+
provider = cast(ServiceProvider, retrieve_uri(self.provider_uri))
22+
return provider

cuenca/resources/resources.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from .base import Retrievable
55

6-
ENDPOINT_RE = re.compile(r'.*/(?P<resource>[a-z]+)/(?P<id>.+)$')
6+
ENDPOINT_RE = re.compile(r'.*/(?P<resource>[a-z_]+)/(?P<id>.+)$')
77
RESOURCES: Dict[str, Retrievable] = {} # set in ./__init__.py after imports
88

99

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from dataclasses import dataclass
2+
from typing import ClassVar, List
3+
4+
from cuenca_validations.types import ServiceProviderCategory
5+
6+
from .base import Queryable, Retrievable
7+
8+
9+
@dataclass
10+
class ServiceProvider(Retrievable, Queryable):
11+
_resource: ClassVar = 'service_providers'
12+
13+
name: str
14+
provider_key: str
15+
categories: List[ServiceProviderCategory]

cuenca/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = '0.3.4'
1+
__version__ = '0.3.5'
22
CLIENT_VERSION = __version__
33
API_VERSION = '2020-03-19'
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Authorization:
10+
- DUMMY
11+
Connection:
12+
- keep-alive
13+
User-Agent:
14+
- cuenca-python/0.3.3
15+
X-Cuenca-Api-Version:
16+
- '2020-03-19'
17+
method: GET
18+
uri: https://sandbox.cuenca.com/bill_payments/ST01
19+
response:
20+
body:
21+
string: '{"id":"ST01","created_at":"2020-10-05T01:12:46.973000","user_id":"US01","amount":10000,"status":"succeeded","descriptor":"Pago
22+
de servicio","account_number":"(111) 111-1111","provider_uri":"/service_providers/SP01"}'
23+
headers:
24+
Connection:
25+
- keep-alive
26+
Content-Length:
27+
- '224'
28+
Content-Type:
29+
- application/json
30+
Date:
31+
- Mon, 05 Oct 2020 23:56:54 GMT
32+
Via:
33+
- 1.1 72c5987cf6b5170991873937a6e36b80.cloudfront.net (CloudFront)
34+
X-Amz-Cf-Id:
35+
- vPUPB8XgktMziooNHnjTbP2v-wiXIZsW134XChHmw-lw885pV52hpw==
36+
X-Amz-Cf-Pop:
37+
- DFW50-C1
38+
X-Amzn-Trace-Id:
39+
- Root=1-5f7bb2c5-250155e014a2927a6d49f7f5;Sampled=0
40+
X-Cache:
41+
- Miss from cloudfront
42+
x-amz-apigw-id:
43+
- T9je0FM4IAMF5NQ=
44+
x-amzn-RequestId:
45+
- 199a3e85-25c7-40b1-81e6-c45f2d81820b
46+
status:
47+
code: 200
48+
message: OK
49+
- request:
50+
body: null
51+
headers:
52+
Accept:
53+
- '*/*'
54+
Accept-Encoding:
55+
- gzip, deflate
56+
Authorization:
57+
- DUMMY
58+
Connection:
59+
- keep-alive
60+
User-Agent:
61+
- cuenca-python/0.3.3
62+
X-Cuenca-Api-Version:
63+
- '2020-03-19'
64+
method: GET
65+
uri: https://sandbox.cuenca.com/service_providers/SP01
66+
response:
67+
body:
68+
string: '{"id":"SP01","created_at":"2020-10-05T00:00:48.020000","name":"Telcel","provider_key":"topup_telcel","categories":["mobile_telephone_prepaid"]}'
69+
headers:
70+
Connection:
71+
- keep-alive
72+
Content-Length:
73+
- '163'
74+
Content-Type:
75+
- application/json
76+
Date:
77+
- Mon, 05 Oct 2020 23:56:55 GMT
78+
Via:
79+
- 1.1 72c5987cf6b5170991873937a6e36b80.cloudfront.net (CloudFront)
80+
X-Amz-Cf-Id:
81+
- A9UIKYCnUwTC067I5RCn2e5D9A4wUWy-yeDFT3BMoUqVIzmX5RXaRw==
82+
X-Amz-Cf-Pop:
83+
- DFW50-C1
84+
X-Amzn-Trace-Id:
85+
- Root=1-5f7bb2c7-36ea3a3623a06c615355e8a7;Sampled=0
86+
X-Cache:
87+
- Miss from cloudfront
88+
x-amz-apigw-id:
89+
- T9jfMHpcoAMF14Q=
90+
x-amzn-RequestId:
91+
- bacb6a7e-6fcc-4645-bd55-5d0dfc08f4e2
92+
status:
93+
code: 200
94+
message: OK
95+
version: 1
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Accept:
6+
- '*/*'
7+
Accept-Encoding:
8+
- gzip, deflate
9+
Authorization:
10+
- DUMMY
11+
Connection:
12+
- keep-alive
13+
User-Agent:
14+
- cuenca-python/0.3.3
15+
X-Cuenca-Api-Version:
16+
- '2020-03-19'
17+
method: GET
18+
uri: https://sandbox.cuenca.com/service_providers/SP01
19+
response:
20+
body:
21+
string: '{"id":"SP01","created_at":"2020-10-05T00:00:48.020000","name":"Telcel","provider_key":"topup_telcel","categories":["mobile_telephone_prepaid"]}'
22+
headers:
23+
Connection:
24+
- keep-alive
25+
Content-Length:
26+
- '143'
27+
Content-Type:
28+
- application/json
29+
Date:
30+
- Mon, 05 Oct 2020 23:57:35 GMT
31+
Via:
32+
- 1.1 efcb172d06d66d2afa4eb747b3b88605.cloudfront.net (CloudFront)
33+
X-Amz-Cf-Id:
34+
- iWGW67QhiyoL-aZIypsTLH6C5bvPqRCgV_g44Fi0P4vOx333rMny_Q==
35+
X-Amz-Cf-Pop:
36+
- DFW50-C1
37+
X-Amzn-Trace-Id:
38+
- Root=1-5f7bb2ef-0ce8f8fa299012df0c8a8103;Sampled=0
39+
X-Cache:
40+
- Miss from cloudfront
41+
x-amz-apigw-id:
42+
- T9jlZE16IAMFybg=
43+
x-amzn-RequestId:
44+
- 55e6aec9-7e04-4158-a418-478cc49101d4
45+
status:
46+
code: 200
47+
message: OK
48+
version: 1
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import pytest
2+
3+
from cuenca.resources import BillPayment
4+
5+
6+
@pytest.mark.vcr
7+
def test_bill_payment():
8+
id_bill_payment = 'ST01'
9+
bill_payment = BillPayment.retrieve(id_bill_payment)
10+
assert bill_payment.id == id_bill_payment
11+
# It should always have a provider
12+
provider = bill_payment.provider
13+
assert provider is not None

0 commit comments

Comments
 (0)