From 717460dfd7accc34075008dd3245ec4208d259b5 Mon Sep 17 00:00:00 2001 From: eletroswing Date: Mon, 6 May 2024 19:30:58 -0300 Subject: [PATCH 01/25] feat(structure): add project base structure and initial placeholder funcions --- python_sdk/__init__.py | 0 woovi/__init__.py | 8 ++ woovi/http/__init__.py | 8 ++ woovi/http/http_client.py | 89 ++++++++++++++++ woovi/resources/__init__.py | 37 +++++++ woovi/resources/account.py | 21 ++++ woovi/resources/cashback_fidelity.py | 18 ++++ woovi/resources/charge.py | 27 +++++ woovi/resources/charge_refund.py | 18 ++++ woovi/resources/customer.py | 21 ++++ woovi/resources/partner.py | 27 +++++ woovi/resources/payment.py | 24 +++++ woovi/resources/pix_qr_code.py | 19 ++++ woovi/resources/refund.py | 21 ++++ woovi/resources/sub_account.py | 22 ++++ woovi/resources/subscription.py | 18 ++++ woovi/resources/transactions.py | 18 ++++ woovi/resources/transfer.py | 14 +++ woovi/resources/webhook.py | 21 ++++ woovi/sdk.py | 147 +++++++++++++++++++++++++++ 20 files changed, 578 insertions(+) delete mode 100644 python_sdk/__init__.py create mode 100644 woovi/__init__.py create mode 100644 woovi/http/__init__.py create mode 100644 woovi/http/http_client.py create mode 100644 woovi/resources/__init__.py create mode 100644 woovi/resources/account.py create mode 100644 woovi/resources/cashback_fidelity.py create mode 100644 woovi/resources/charge.py create mode 100644 woovi/resources/charge_refund.py create mode 100644 woovi/resources/customer.py create mode 100644 woovi/resources/partner.py create mode 100644 woovi/resources/payment.py create mode 100644 woovi/resources/pix_qr_code.py create mode 100644 woovi/resources/refund.py create mode 100644 woovi/resources/sub_account.py create mode 100644 woovi/resources/subscription.py create mode 100644 woovi/resources/transactions.py create mode 100644 woovi/resources/transfer.py create mode 100644 woovi/resources/webhook.py create mode 100644 woovi/sdk.py diff --git a/python_sdk/__init__.py b/python_sdk/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/woovi/__init__.py b/woovi/__init__.py new file mode 100644 index 0000000..ebf95d3 --- /dev/null +++ b/woovi/__init__.py @@ -0,0 +1,8 @@ +""" +Module: woovi/__init__.py +""" +from woovi.sdk import SDK as createClient + +__all__ = ( + 'createClient', +) \ No newline at end of file diff --git a/woovi/http/__init__.py b/woovi/http/__init__.py new file mode 100644 index 0000000..a357319 --- /dev/null +++ b/woovi/http/__init__.py @@ -0,0 +1,8 @@ +""" +Module: http/__init__.py +""" +from woovi.http.http_client import HttpClient + +__all__ = ( + 'HttpClient', +) \ No newline at end of file diff --git a/woovi/http/http_client.py b/woovi/http/http_client.py new file mode 100644 index 0000000..04b958f --- /dev/null +++ b/woovi/http/http_client.py @@ -0,0 +1,89 @@ +import requests +from requests.adapters import HTTPAdapter +from urllib3.util import Retry + +class HttpClient: + """ + Default implementation to call all REST API's + """ + + def __init__(self, app_id): + self._app_id = app_id + self.base_url = "https://api.woovi.com" + + def request(self, method, path, maxretries=None, **kwargs): + """Makes a call to the API. + + All **kwargs are passed verbatim to ``requests.request``. + """ + url = self.base_url + path + headers = kwargs.get('headers', {}) + headers['Authorization'] = f'Bearer {self._app_id}' + kwargs['headers'] = headers + + retry_strategy = Retry( + total=maxretries, + status_forcelist=[429, 500, 502, 503, 504] + ) + http = requests.Session() + http.mount("https://", HTTPAdapter(max_retries=retry_strategy)) + with http as session: + api_result = session.request(method, url, **kwargs) + try: + response = { + "status": api_result.status_code, + "response": api_result.json() + } + except ValueError: + response = { + "status": api_result.status_code, + "response": api_result.text + } + + if response["status"] == 400: + error_message = response["response"].get("error", "Unknown Error") + raise ValueError(error_message) + + return response + + def get(self, path, params=None, timeout=None, maxretries=None): + """Makes a GET request to the API""" + return self.request( + "GET", + path=path, + params=params, + timeout=timeout, + maxretries=maxretries, + ) + + def post(self, path, data=None, params=None, timeout=None, maxretries=None): + """Makes a POST request to the API""" + return self.request( + "POST", + path=path, + data=data, + params=params, + timeout=timeout, + maxretries=maxretries, + ) + + def put(self, path, data=None, params=None, timeout=None, maxretries=None): + """Makes a PUT request to the API""" + return self.request( + "PUT", + path=path, + data=data, + params=params, + timeout=timeout, + maxretries=maxretries, + ) + + def delete(self, path, params=None, timeout=None, maxretries=None): + """Makes a DELETE request to the API""" + return self.request( + "DELETE", + path=path, + params=params, + timeout=timeout, + maxretries=maxretries, + ) \ No newline at end of file diff --git a/woovi/resources/__init__.py b/woovi/resources/__init__.py new file mode 100644 index 0000000..3d0a4b8 --- /dev/null +++ b/woovi/resources/__init__.py @@ -0,0 +1,37 @@ +""" +Module: resources/__init__.py +""" +from woovi.config.request_options import RequestOptions +from woovi.http.http_clien import HttpClient + +from woovi.resources.account import Account +from woovi.resources.cashback_fidelity import CashbackFidelity +from woovi.resources.charge_refund import ChargeRefund +from woovi.resources.charge import Charge +from woovi.resources.customer import Customer +from woovi.resources.partner import Partner +from woovi.resources.payment import Payment +from woovi.resources.pix_qr_code import PixQrCode +from woovi.resources.refund import Refund +from woovi.resources.sub_account import SubAccount +from woovi.resources.subscription import Subscription +from woovi.resources.transactions import Transactions +from woovi.resources.transfer import Transfer +from woovi.resources.webhook import Webhook + +__all__ = ( + 'Account', + 'CashbackFidelity', + 'ChargeRefund', + 'Charge', + 'Customer', + 'Partner', + 'Payment', + 'PixQrCode', + 'Refund', + 'SubAccount', + 'Subscription', + 'Transactions', + 'Transfer', + 'Webhook' +) \ No newline at end of file diff --git a/woovi/resources/account.py b/woovi/resources/account.py new file mode 100644 index 0000000..59a6b46 --- /dev/null +++ b/woovi/resources/account.py @@ -0,0 +1,21 @@ +""" + Module: account +""" + +class Account: + """ + Access to Accounts + + [Click here for more info](https://developers.woovi.com/api#tag/account) # pylint: disable=line-too-long + """ + def __init__(self, HttpClient): + self._client = HttpClient + + def get(self): + return + + def list(self): + return + + def withdraw(self): + return \ No newline at end of file diff --git a/woovi/resources/cashback_fidelity.py b/woovi/resources/cashback_fidelity.py new file mode 100644 index 0000000..2bd4ec7 --- /dev/null +++ b/woovi/resources/cashback_fidelity.py @@ -0,0 +1,18 @@ +""" + Module: cashback_fidelity +""" + +class CashbackFidelity: + """ + Access to CashbackFidelity + + [Click here for more info](https://developers.woovi.com/api#tag/cashback-fidelity) # pylint: disable=line-too-long + """ + def __init__(self, HttpClient): + self._client = HttpClient + + def get(self): + return + + def create(self): + return \ No newline at end of file diff --git a/woovi/resources/charge.py b/woovi/resources/charge.py new file mode 100644 index 0000000..c226bfc --- /dev/null +++ b/woovi/resources/charge.py @@ -0,0 +1,27 @@ +""" + Module: charge +""" + +class Charge: + """ + Access to Charge + + [Click here for more info](https://developers.woovi.com/api#tag/charge) # pylint: disable=line-too-long + """ + def __init__(self, HttpClient): + self._client = HttpClient + + def get(self): + return + + def list(self): + return + + def delete(self): + return + + def create(self): + return + + def getQrImage(self): + return \ No newline at end of file diff --git a/woovi/resources/charge_refund.py b/woovi/resources/charge_refund.py new file mode 100644 index 0000000..afea110 --- /dev/null +++ b/woovi/resources/charge_refund.py @@ -0,0 +1,18 @@ +""" + Module: charge_refund +""" + +class ChargeRefund: + """ + Access to ChargeRefund + + [Click here for more info](https://developers.woovi.com/api#tag/charge-refund) # pylint: disable=line-too-long + """ + def __init__(self, HttpClient): + self._client = HttpClient + + def list(self): + return + + def create(self): + return \ No newline at end of file diff --git a/woovi/resources/customer.py b/woovi/resources/customer.py new file mode 100644 index 0000000..a084a09 --- /dev/null +++ b/woovi/resources/customer.py @@ -0,0 +1,21 @@ +""" + Module: customer +""" + +class Customer: + """ + Access to Customer + + [Click here for more info](https://developers.woovi.com/api#tag/customer) # pylint: disable=line-too-long + """ + def __init__(self, HttpClient): + self._client = HttpClient + + def get(self): + return + + def list(self): + return + + def create(self): + return \ No newline at end of file diff --git a/woovi/resources/partner.py b/woovi/resources/partner.py new file mode 100644 index 0000000..8eda126 --- /dev/null +++ b/woovi/resources/partner.py @@ -0,0 +1,27 @@ +""" + Module: partner +""" + +class Partner: + """ + Access to Partner + + [Click here for more info](https://developers.woovi.com/api#tag/partner-(request-access)) # pylint: disable=line-too-long + """ + def __init__(self, HttpClient): + self._client = HttpClient + + def get(self): + return + + def list(self): + return + + def delete(self): + return + + def createPreRegistration(self): + return + + def createApplication(self): + return \ No newline at end of file diff --git a/woovi/resources/payment.py b/woovi/resources/payment.py new file mode 100644 index 0000000..9be4389 --- /dev/null +++ b/woovi/resources/payment.py @@ -0,0 +1,24 @@ +""" + Module: payment +""" + +class Payment: + """ + Access to Payment + + [Click here for more info](https://developers.woovi.com/api#tag/payment-(request-access)) # pylint: disable=line-too-long + """ + def __init__(self, HttpClient): + self._client = HttpClient + + def get(self): + return + + def list(self): + return + + def approve(self): + return + + def create(self): + return \ No newline at end of file diff --git a/woovi/resources/pix_qr_code.py b/woovi/resources/pix_qr_code.py new file mode 100644 index 0000000..697d87f --- /dev/null +++ b/woovi/resources/pix_qr_code.py @@ -0,0 +1,19 @@ +""" + Module: pix-qr-code +""" + +class PixQrCode(): + """ + Access to PixQrCode + + [Click here for more info](https://developers.woovi.com/api#tag/pixQrCode) # pylint: disable=line-too-long + """ + + def get(self): + return + + def list(self): + return + + def create(self): + return \ No newline at end of file diff --git a/woovi/resources/refund.py b/woovi/resources/refund.py new file mode 100644 index 0000000..d2c14c9 --- /dev/null +++ b/woovi/resources/refund.py @@ -0,0 +1,21 @@ +""" + Module: refund +""" + +class Refund: + """ + Access to Refund + + [Click here for more info](https://developers.woovi.com/api#tag/refund) # pylint: disable=line-too-long + """ + def __init__(self, HttpClient): + self._client = HttpClient + + def get(self): + return + + def list(self): + return + + def getQrImage(self): + return \ No newline at end of file diff --git a/woovi/resources/sub_account.py b/woovi/resources/sub_account.py new file mode 100644 index 0000000..672ed2d --- /dev/null +++ b/woovi/resources/sub_account.py @@ -0,0 +1,22 @@ +""" + Module: sub-account +""" + +class SubAccount(): + """ + Access to SubAccount + + [Click here for more info](https://developers.woovi.com/api#tag/sub-account-(request-access)) # pylint: disable=line-too-long + """ + + def get(self): + return + + def list(self): + return + + def withdraw(self): + return + + def create(self): + return \ No newline at end of file diff --git a/woovi/resources/subscription.py b/woovi/resources/subscription.py new file mode 100644 index 0000000..f330903 --- /dev/null +++ b/woovi/resources/subscription.py @@ -0,0 +1,18 @@ +""" + Module: subscription +""" + +class Subscription: + """ + Access to Subscription + + [Click here for more info](https://developers.woovi.com/api#tag/subscription) # pylint: disable=line-too-long + """ + def __init__(self, HttpClient): + self._client = HttpClient + + def get(self): + return + + def create(self): + return \ No newline at end of file diff --git a/woovi/resources/transactions.py b/woovi/resources/transactions.py new file mode 100644 index 0000000..931431a --- /dev/null +++ b/woovi/resources/transactions.py @@ -0,0 +1,18 @@ +""" + Module: transactions +""" + +class Transactions: + """ + Access to Transactions + + [Click here for more info](https://developers.woovi.com/api#tag/transactions) # pylint: disable=line-too-long + """ + def __init__(self, HttpClient): + self._client = HttpClient + + def get(self): + return + + def list(self): + return \ No newline at end of file diff --git a/woovi/resources/transfer.py b/woovi/resources/transfer.py new file mode 100644 index 0000000..c65ab27 --- /dev/null +++ b/woovi/resources/transfer.py @@ -0,0 +1,14 @@ +""" + Module: transfer +""" +class Transfer: + """ + Access to Transfer + + [Click here for more info](https://developers.woovi.com/api#tag/transfer-(request-access)) # pylint: disable=line-too-long + """ + def __init__(self, HttpClient): + self._client = HttpClient + + def create(self): + return \ No newline at end of file diff --git a/woovi/resources/webhook.py b/woovi/resources/webhook.py new file mode 100644 index 0000000..c3f2182 --- /dev/null +++ b/woovi/resources/webhook.py @@ -0,0 +1,21 @@ +""" + Module: webhook +""" + +class Webhook: + """ + Access to Webhook + + [Click here for more info](https://developers.woovi.com/api#tag/webhook) # pylint: disable=line-too-long + """ + def __init__(self, HttpClient): + self._client = HttpClient + + def list(self): + return + + def delete(self): + return + + def create(self): + return \ No newline at end of file diff --git a/woovi/sdk.py b/woovi/sdk.py new file mode 100644 index 0000000..d57938a --- /dev/null +++ b/woovi/sdk.py @@ -0,0 +1,147 @@ +""" +Module: sdk +""" +from woovi.http import HttpClient +from woovi.resources import ( + Account, + CashbackFidelity, + Charge, + ChargeRefund, + Customer, + Partner, + PixQrCode, + Payment, + Refund, + SubAccount, + Subscription, + Transactions, + Transfer, + Webhook +) + +class SDK: + """Generate access to all API' modules, which are: + + 1. Account + 2. CashbackFidelity + 3. Charge + 4. ChargeRefund + 5. Customer + 6. Partner + 7: PixQrCode + 8: Payment + 9: Refund + 10: SubAccount + 11: Subscription + 12: Transactions + 13: Transfer + 14: Webhook + """ + + def __init__( + self, + app_id, + ): + """Construct ur SDK Object to have access to all APIs modules. + Args: + [Click here for more info](https://developers.woovi.com/docs/apis/api-getting-started) + """ + self._http_client = HttpClient(app_id=app_id) + + @property + def account(self): + """ + Returns the attribute value of the function + """ + return Account(HttpClient) + + @property + def cashback_fidelity(self): + """ + Returns the attribute value of the function + """ + return CashbackFidelity(HttpClient) + + @property + def charge(self): + """ + Returns the attribute value of the function + """ + return Charge(HttpClient) + + @property + def charge_refund(self): + """ + Returns the attribute value of the function + """ + return ChargeRefund(HttpClient) + + @property + def customer(self): + """ + Returns the attribute value of the function + """ + return Customer(HttpClient) + + @property + def partner(self): + """ + Returns the attribute value of the function + """ + return Partner(HttpClient) + + @property + def pix_qr_code(self): + """ + Returns the attribute value of the function + """ + return PixQrCode(HttpClient) + + @property + def payment(self): + """ + Returns the attribute value of the function + """ + return Payment(HttpClient) + + @property + def refund(self): + """ + Returns the attribute value of the function + """ + return Refund(HttpClient) + + @property + def sub_account(self): + """ + Returns the attribute value of the function + """ + return SubAccount(HttpClient) + + @property + def subscription(self): + """ + Returns the attribute value of the function + """ + return Subscription(HttpClient) + + @property + def transactions(self): + """ + Returns the attribute value of the function + """ + return Transactions(HttpClient) + + @property + def transfer(self): + """ + Returns the attribute value of the function + """ + return Transfer(HttpClient) + + @property + def webhook(self): + """ + Returns the attribute value of the function + """ + return Webhook(HttpClient) \ No newline at end of file From 2b79ff358ef5b90fe4da36d6838a0e9d89e427a6 Mon Sep 17 00:00:00 2001 From: eletroswing Date: Mon, 6 May 2024 19:31:28 -0300 Subject: [PATCH 02/25] tests(structure): create test files --- tests/test_account.py | 0 tests/test_cashback_fidelity.py | 0 tests/test_charge.py | 0 tests/test_charge_refund.py | 0 tests/test_customer.py | 0 tests/test_partner.py | 0 tests/test_payment.py | 0 tests/test_pix_qr_code.py | 0 tests/test_refund.py | 0 tests/test_sub_account.py | 0 tests/test_subscription.py | 0 tests/test_transactions.py | 0 tests/test_transfer.py | 0 tests/test_webhook.py | 0 tests/webhook.py | 0 15 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/test_account.py create mode 100644 tests/test_cashback_fidelity.py create mode 100644 tests/test_charge.py create mode 100644 tests/test_charge_refund.py create mode 100644 tests/test_customer.py create mode 100644 tests/test_partner.py create mode 100644 tests/test_payment.py create mode 100644 tests/test_pix_qr_code.py create mode 100644 tests/test_refund.py create mode 100644 tests/test_sub_account.py create mode 100644 tests/test_subscription.py create mode 100644 tests/test_transactions.py create mode 100644 tests/test_transfer.py create mode 100644 tests/test_webhook.py create mode 100644 tests/webhook.py diff --git a/tests/test_account.py b/tests/test_account.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_cashback_fidelity.py b/tests/test_cashback_fidelity.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_charge.py b/tests/test_charge.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_charge_refund.py b/tests/test_charge_refund.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_customer.py b/tests/test_customer.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_partner.py b/tests/test_partner.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_payment.py b/tests/test_payment.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_pix_qr_code.py b/tests/test_pix_qr_code.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_refund.py b/tests/test_refund.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_sub_account.py b/tests/test_sub_account.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_subscription.py b/tests/test_subscription.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_transactions.py b/tests/test_transactions.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_transfer.py b/tests/test_transfer.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_webhook.py b/tests/test_webhook.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/webhook.py b/tests/webhook.py new file mode 100644 index 0000000..e69de29 From 4a2cbf8970284350660e74f780dfd83b748b7bbb Mon Sep 17 00:00:00 2001 From: eletroswing Date: Mon, 6 May 2024 19:36:56 -0300 Subject: [PATCH 03/25] fix(dir_name): woovi to openpix --- {woovi => openpix}/__init__.py | 2 +- {woovi => openpix}/http/__init__.py | 2 +- {woovi => openpix}/http/http_client.py | 0 openpix/resources/__init__.py | 36 ++++++++++++++++++ {woovi => openpix}/resources/account.py | 0 .../resources/cashback_fidelity.py | 0 {woovi => openpix}/resources/charge.py | 0 {woovi => openpix}/resources/charge_refund.py | 0 {woovi => openpix}/resources/customer.py | 0 {woovi => openpix}/resources/partner.py | 0 {woovi => openpix}/resources/payment.py | 0 {woovi => openpix}/resources/pix_qr_code.py | 0 {woovi => openpix}/resources/refund.py | 0 {woovi => openpix}/resources/sub_account.py | 0 {woovi => openpix}/resources/subscription.py | 0 {woovi => openpix}/resources/transactions.py | 0 {woovi => openpix}/resources/transfer.py | 0 {woovi => openpix}/resources/webhook.py | 0 {woovi => openpix}/sdk.py | 4 +- woovi/resources/__init__.py | 37 ------------------- 20 files changed, 40 insertions(+), 41 deletions(-) rename {woovi => openpix}/__init__.py (61%) rename {woovi => openpix}/http/__init__.py (57%) rename {woovi => openpix}/http/http_client.py (100%) create mode 100644 openpix/resources/__init__.py rename {woovi => openpix}/resources/account.py (100%) rename {woovi => openpix}/resources/cashback_fidelity.py (100%) rename {woovi => openpix}/resources/charge.py (100%) rename {woovi => openpix}/resources/charge_refund.py (100%) rename {woovi => openpix}/resources/customer.py (100%) rename {woovi => openpix}/resources/partner.py (100%) rename {woovi => openpix}/resources/payment.py (100%) rename {woovi => openpix}/resources/pix_qr_code.py (100%) rename {woovi => openpix}/resources/refund.py (100%) rename {woovi => openpix}/resources/sub_account.py (100%) rename {woovi => openpix}/resources/subscription.py (100%) rename {woovi => openpix}/resources/transactions.py (100%) rename {woovi => openpix}/resources/transfer.py (100%) rename {woovi => openpix}/resources/webhook.py (100%) rename {woovi => openpix}/sdk.py (97%) delete mode 100644 woovi/resources/__init__.py diff --git a/woovi/__init__.py b/openpix/__init__.py similarity index 61% rename from woovi/__init__.py rename to openpix/__init__.py index ebf95d3..f30cf6f 100644 --- a/woovi/__init__.py +++ b/openpix/__init__.py @@ -1,7 +1,7 @@ """ Module: woovi/__init__.py """ -from woovi.sdk import SDK as createClient +from openpix.sdk import SDK as createClient __all__ = ( 'createClient', diff --git a/woovi/http/__init__.py b/openpix/http/__init__.py similarity index 57% rename from woovi/http/__init__.py rename to openpix/http/__init__.py index a357319..9f5d9f2 100644 --- a/woovi/http/__init__.py +++ b/openpix/http/__init__.py @@ -1,7 +1,7 @@ """ Module: http/__init__.py """ -from woovi.http.http_client import HttpClient +from openpix.http.http_client import HttpClient __all__ = ( 'HttpClient', diff --git a/woovi/http/http_client.py b/openpix/http/http_client.py similarity index 100% rename from woovi/http/http_client.py rename to openpix/http/http_client.py diff --git a/openpix/resources/__init__.py b/openpix/resources/__init__.py new file mode 100644 index 0000000..2c00afe --- /dev/null +++ b/openpix/resources/__init__.py @@ -0,0 +1,36 @@ +""" +Module: resources/__init__.py +""" +from openpix.http.http_client import HttpClient + +from openpix.resources.account import Account +from openpix.resources.cashback_fidelity import CashbackFidelity +from openpix.resources.charge_refund import ChargeRefund +from openpix.resources.charge import Charge +from openpix.resources.customer import Customer +from openpix.resources.partner import Partner +from openpix.resources.payment import Payment +from openpix.resources.pix_qr_code import PixQrCode +from openpix.resources.refund import Refund +from openpix.resources.sub_account import SubAccount +from openpix.resources.subscription import Subscription +from openpix.resources.transactions import Transactions +from openpix.resources.transfer import Transfer +from openpix.resources.webhook import Webhook + +__all__ = ( + 'Account', + 'CashbackFidelity', + 'ChargeRefund', + 'Charge', + 'Customer', + 'Partner', + 'Payment', + 'PixQrCode', + 'Refund', + 'SubAccount', + 'Subscription', + 'Transactions', + 'Transfer', + 'Webhook' +) \ No newline at end of file diff --git a/woovi/resources/account.py b/openpix/resources/account.py similarity index 100% rename from woovi/resources/account.py rename to openpix/resources/account.py diff --git a/woovi/resources/cashback_fidelity.py b/openpix/resources/cashback_fidelity.py similarity index 100% rename from woovi/resources/cashback_fidelity.py rename to openpix/resources/cashback_fidelity.py diff --git a/woovi/resources/charge.py b/openpix/resources/charge.py similarity index 100% rename from woovi/resources/charge.py rename to openpix/resources/charge.py diff --git a/woovi/resources/charge_refund.py b/openpix/resources/charge_refund.py similarity index 100% rename from woovi/resources/charge_refund.py rename to openpix/resources/charge_refund.py diff --git a/woovi/resources/customer.py b/openpix/resources/customer.py similarity index 100% rename from woovi/resources/customer.py rename to openpix/resources/customer.py diff --git a/woovi/resources/partner.py b/openpix/resources/partner.py similarity index 100% rename from woovi/resources/partner.py rename to openpix/resources/partner.py diff --git a/woovi/resources/payment.py b/openpix/resources/payment.py similarity index 100% rename from woovi/resources/payment.py rename to openpix/resources/payment.py diff --git a/woovi/resources/pix_qr_code.py b/openpix/resources/pix_qr_code.py similarity index 100% rename from woovi/resources/pix_qr_code.py rename to openpix/resources/pix_qr_code.py diff --git a/woovi/resources/refund.py b/openpix/resources/refund.py similarity index 100% rename from woovi/resources/refund.py rename to openpix/resources/refund.py diff --git a/woovi/resources/sub_account.py b/openpix/resources/sub_account.py similarity index 100% rename from woovi/resources/sub_account.py rename to openpix/resources/sub_account.py diff --git a/woovi/resources/subscription.py b/openpix/resources/subscription.py similarity index 100% rename from woovi/resources/subscription.py rename to openpix/resources/subscription.py diff --git a/woovi/resources/transactions.py b/openpix/resources/transactions.py similarity index 100% rename from woovi/resources/transactions.py rename to openpix/resources/transactions.py diff --git a/woovi/resources/transfer.py b/openpix/resources/transfer.py similarity index 100% rename from woovi/resources/transfer.py rename to openpix/resources/transfer.py diff --git a/woovi/resources/webhook.py b/openpix/resources/webhook.py similarity index 100% rename from woovi/resources/webhook.py rename to openpix/resources/webhook.py diff --git a/woovi/sdk.py b/openpix/sdk.py similarity index 97% rename from woovi/sdk.py rename to openpix/sdk.py index d57938a..f862e01 100644 --- a/woovi/sdk.py +++ b/openpix/sdk.py @@ -1,8 +1,8 @@ """ Module: sdk """ -from woovi.http import HttpClient -from woovi.resources import ( +from openpix.http import HttpClient +from openpix.resources import ( Account, CashbackFidelity, Charge, diff --git a/woovi/resources/__init__.py b/woovi/resources/__init__.py deleted file mode 100644 index 3d0a4b8..0000000 --- a/woovi/resources/__init__.py +++ /dev/null @@ -1,37 +0,0 @@ -""" -Module: resources/__init__.py -""" -from woovi.config.request_options import RequestOptions -from woovi.http.http_clien import HttpClient - -from woovi.resources.account import Account -from woovi.resources.cashback_fidelity import CashbackFidelity -from woovi.resources.charge_refund import ChargeRefund -from woovi.resources.charge import Charge -from woovi.resources.customer import Customer -from woovi.resources.partner import Partner -from woovi.resources.payment import Payment -from woovi.resources.pix_qr_code import PixQrCode -from woovi.resources.refund import Refund -from woovi.resources.sub_account import SubAccount -from woovi.resources.subscription import Subscription -from woovi.resources.transactions import Transactions -from woovi.resources.transfer import Transfer -from woovi.resources.webhook import Webhook - -__all__ = ( - 'Account', - 'CashbackFidelity', - 'ChargeRefund', - 'Charge', - 'Customer', - 'Partner', - 'Payment', - 'PixQrCode', - 'Refund', - 'SubAccount', - 'Subscription', - 'Transactions', - 'Transfer', - 'Webhook' -) \ No newline at end of file From ce286795b0b500cf95f1280699fdab23f96ebedb Mon Sep 17 00:00:00 2001 From: eletroswing Date: Tue, 7 May 2024 18:11:31 -0300 Subject: [PATCH 04/25] fix(http): fix http client --- openpix/http/http_client.py | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/openpix/http/http_client.py b/openpix/http/http_client.py index 04b958f..37dff16 100644 --- a/openpix/http/http_client.py +++ b/openpix/http/http_client.py @@ -18,7 +18,7 @@ def request(self, method, path, maxretries=None, **kwargs): """ url = self.base_url + path headers = kwargs.get('headers', {}) - headers['Authorization'] = f'Bearer {self._app_id}' + headers['Authorization'] = self._app_id kwargs['headers'] = headers retry_strategy = Retry( @@ -29,20 +29,14 @@ def request(self, method, path, maxretries=None, **kwargs): http.mount("https://", HTTPAdapter(max_retries=retry_strategy)) with http as session: api_result = session.request(method, url, **kwargs) - try: - response = { - "status": api_result.status_code, - "response": api_result.json() - } - except ValueError: - response = { - "status": api_result.status_code, - "response": api_result.text - } + + response = { + "status": api_result.status_code, + "response": api_result.json() + } - if response["status"] == 400: - error_message = response["response"].get("error", "Unknown Error") - raise ValueError(error_message) + if response["status"] > 299 and maxretries == 0: + raise ValueError(response["response"]) return response From 97355e7ae3e854dbd39c3dd134efaa9193ecffd3 Mon Sep 17 00:00:00 2001 From: eletroswing Date: Tue, 7 May 2024 20:43:53 -0300 Subject: [PATCH 05/25] add account resource --- openpix/http/http_client.py | 32 +++++++++++++-------- openpix/resources/account.py | 33 +++++++++++++++++----- openpix/resources/account_types.py | 38 +++++++++++++++++++++++++ openpix/resources/cashback_fidelity.py | 3 +- openpix/resources/charge.py | 3 +- openpix/resources/charge_refund.py | 3 +- openpix/resources/customer.py | 3 +- openpix/resources/partner.py | 3 +- openpix/resources/payment.py | 5 ++-- openpix/resources/pix_qr_code.py | 1 + openpix/resources/refund.py | 3 +- openpix/resources/sub_account.py | 1 + openpix/resources/subscription.py | 3 +- openpix/resources/transactions.py | 3 +- openpix/resources/transfer.py | 4 ++- openpix/resources/webhook.py | 3 +- openpix/sdk.py | 39 +++++++++++++------------- openpix/types.py | 8 ++++++ 18 files changed, 139 insertions(+), 49 deletions(-) create mode 100644 openpix/resources/account_types.py create mode 100644 openpix/types.py diff --git a/openpix/http/http_client.py b/openpix/http/http_client.py index 37dff16..9cba82f 100644 --- a/openpix/http/http_client.py +++ b/openpix/http/http_client.py @@ -1,6 +1,7 @@ import requests from requests.adapters import HTTPAdapter from urllib3.util import Retry +from urllib.parse import urlencode, urljoin class HttpClient: """ @@ -11,12 +12,16 @@ def __init__(self, app_id): self._app_id = app_id self.base_url = "https://api.woovi.com" - def request(self, method, path, maxretries=None, **kwargs): + def request(self, method, path, query, maxretries=None, **kwargs): """Makes a call to the API. All **kwargs are passed verbatim to ``requests.request``. """ - url = self.base_url + path + if(query): + query_string = urlencode(query) + url = urljoin(self.base_url + path, '?' + query_string) + else: + url = self.base_url + path headers = kwargs.get('headers', {}) headers['Authorization'] = self._app_id kwargs['headers'] = headers @@ -27,6 +32,7 @@ def request(self, method, path, maxretries=None, **kwargs): ) http = requests.Session() http.mount("https://", HTTPAdapter(max_retries=retry_strategy)) + with http as session: api_result = session.request(method, url, **kwargs) @@ -35,48 +41,52 @@ def request(self, method, path, maxretries=None, **kwargs): "response": api_result.json() } - if response["status"] > 299 and maxretries == 0: + if response["status"] > 299: raise ValueError(response["response"]) return response - def get(self, path, params=None, timeout=None, maxretries=None): + def get(self, path, query = None, params=None, timeout=None, maxretries=None): """Makes a GET request to the API""" return self.request( - "GET", + method="GET", path=path, + query=query, params=params, timeout=timeout, maxretries=maxretries, ) - def post(self, path, data=None, params=None, timeout=None, maxretries=None): + def post(self, path, query = None, data=None, params=None, timeout=None, maxretries=None): """Makes a POST request to the API""" return self.request( - "POST", + method="POST", path=path, + query=query, data=data, params=params, timeout=timeout, maxretries=maxretries, ) - def put(self, path, data=None, params=None, timeout=None, maxretries=None): + def put(self, path, query = None, data=None, params=None, timeout=None, maxretries=None): """Makes a PUT request to the API""" return self.request( - "PUT", + method="PUT", path=path, + query=query, data=data, params=params, timeout=timeout, maxretries=maxretries, ) - def delete(self, path, params=None, timeout=None, maxretries=None): + def delete(self, path, query = None, params=None, timeout=None, maxretries=None): """Makes a DELETE request to the API""" return self.request( - "DELETE", + method="DELETE", path=path, + query=query, params=params, timeout=timeout, maxretries=maxretries, diff --git a/openpix/resources/account.py b/openpix/resources/account.py index 59a6b46..b5eb569 100644 --- a/openpix/resources/account.py +++ b/openpix/resources/account.py @@ -1,6 +1,8 @@ """ Module: account """ +from openpix.http import HttpClient +import account_types class Account: """ @@ -8,14 +10,31 @@ class Account: [Click here for more info](https://developers.woovi.com/api#tag/account) # pylint: disable=line-too-long """ - def __init__(self, HttpClient): + def __init__(self, HttpClient: HttpClient): self._client = HttpClient - def get(self): - return + """Get one account. + Args: + accountId (str): the account unique identifier + [Click here for more info](https://developers.woovi.com/api#tag/account) + """ + def get(self, accountId: str) -> account_types.AccountInfo: + return self._client.get(path=f'/api/v1/account/{accountId}') - def list(self): - return + """Get a list of accounts. + Args: + limit (int): number of content per page + skip (int): number of how many contents will be ignored + [Click here for more info](https://developers.woovi.com/api#tag/account/paths/~1api~1v1~1account~1/get) + """ + def list(self, limit: int = 10, skip: int = 0) -> account_types.AccountList: + return self._client.get(path=f'/api/v1/account', query={"limit": limit, "skip": skip}) - def withdraw(self): - return \ No newline at end of file + """Make a withdraw. + Args: + accountId (str): the account unique identifier + value (int): the value for the withdraw + [Click here for more info](https://developers.woovi.com/api#tag/account/paths/~1api~1v1~1account~1%7BaccountId%7D~1withdraw/post) + """ + def withdraw(self, accountId: str, value: int) -> account_types.AccountWithdraw: + return self._client.post(path=f'/api/v1/account/{accountId}', data={value: value}) \ No newline at end of file diff --git a/openpix/resources/account_types.py b/openpix/resources/account_types.py new file mode 100644 index 0000000..467b37e --- /dev/null +++ b/openpix/resources/account_types.py @@ -0,0 +1,38 @@ +from openpix.types import PageInfo +from typing import List + +class BalanceInfo: + def __init__(self, total: int, blocked: int, available: int): + self.total = total + self.blocked = blocked + self.available = available + +class AccountInfo: + def __init__(self, accountId: str, isDefault: bool, balance: BalanceInfo): + self.accountId = accountId + self.balance = balance + self.isDefault = isDefault + +class TransactionInfo: + def __init__(self, endToEndId: str, value: int): + self.endToEndId = endToEndId + self.value = value + +class WithdrawInfo: + def __init__(self, account: AccountInfo, transaction: TransactionInfo): + self.account = account + self.transaction = transaction + +class AccountGet: + def __init__(self, account: AccountInfo): + self.account = account + + +class AccountList: + def __init__(self, pageInfo: PageInfo, accounts: List[AccountInfo]): + self.pageInfo = pageInfo + self.accounts = accounts + +class AccountWithdraw: + def __init__(self, withdraw: WithdrawInfo): + self.withdraw = withdraw \ No newline at end of file diff --git a/openpix/resources/cashback_fidelity.py b/openpix/resources/cashback_fidelity.py index 2bd4ec7..5993b55 100644 --- a/openpix/resources/cashback_fidelity.py +++ b/openpix/resources/cashback_fidelity.py @@ -1,6 +1,7 @@ """ Module: cashback_fidelity """ +from openpix.http import HttpClient class CashbackFidelity: """ @@ -8,7 +9,7 @@ class CashbackFidelity: [Click here for more info](https://developers.woovi.com/api#tag/cashback-fidelity) # pylint: disable=line-too-long """ - def __init__(self, HttpClient): + def __init__(self, HttpClient: HttpClient): self._client = HttpClient def get(self): diff --git a/openpix/resources/charge.py b/openpix/resources/charge.py index c226bfc..11733e0 100644 --- a/openpix/resources/charge.py +++ b/openpix/resources/charge.py @@ -1,6 +1,7 @@ """ Module: charge """ +from openpix.http import HttpClient class Charge: """ @@ -8,7 +9,7 @@ class Charge: [Click here for more info](https://developers.woovi.com/api#tag/charge) # pylint: disable=line-too-long """ - def __init__(self, HttpClient): + def __init__(self, HttpClient: HttpClient): self._client = HttpClient def get(self): diff --git a/openpix/resources/charge_refund.py b/openpix/resources/charge_refund.py index afea110..367df04 100644 --- a/openpix/resources/charge_refund.py +++ b/openpix/resources/charge_refund.py @@ -1,6 +1,7 @@ """ Module: charge_refund """ +from openpix.http import HttpClient class ChargeRefund: """ @@ -8,7 +9,7 @@ class ChargeRefund: [Click here for more info](https://developers.woovi.com/api#tag/charge-refund) # pylint: disable=line-too-long """ - def __init__(self, HttpClient): + def __init__(self, HttpClient: HttpClient): self._client = HttpClient def list(self): diff --git a/openpix/resources/customer.py b/openpix/resources/customer.py index a084a09..4fea02f 100644 --- a/openpix/resources/customer.py +++ b/openpix/resources/customer.py @@ -1,6 +1,7 @@ """ Module: customer """ +from openpix.http import HttpClient class Customer: """ @@ -8,7 +9,7 @@ class Customer: [Click here for more info](https://developers.woovi.com/api#tag/customer) # pylint: disable=line-too-long """ - def __init__(self, HttpClient): + def __init__(self, HttpClient: HttpClient): self._client = HttpClient def get(self): diff --git a/openpix/resources/partner.py b/openpix/resources/partner.py index 8eda126..df3e16f 100644 --- a/openpix/resources/partner.py +++ b/openpix/resources/partner.py @@ -1,6 +1,7 @@ """ Module: partner """ +from openpix.http import HttpClient class Partner: """ @@ -8,7 +9,7 @@ class Partner: [Click here for more info](https://developers.woovi.com/api#tag/partner-(request-access)) # pylint: disable=line-too-long """ - def __init__(self, HttpClient): + def __init__(self, HttpClient: HttpClient): self._client = HttpClient def get(self): diff --git a/openpix/resources/payment.py b/openpix/resources/payment.py index 9be4389..0b81128 100644 --- a/openpix/resources/payment.py +++ b/openpix/resources/payment.py @@ -1,6 +1,7 @@ """ Module: payment """ +from openpix.http import HttpClient class Payment: """ @@ -8,7 +9,7 @@ class Payment: [Click here for more info](https://developers.woovi.com/api#tag/payment-(request-access)) # pylint: disable=line-too-long """ - def __init__(self, HttpClient): + def __init__(self, HttpClient: HttpClient): self._client = HttpClient def get(self): @@ -20,5 +21,5 @@ def list(self): def approve(self): return - def create(self): + def create(self): return \ No newline at end of file diff --git a/openpix/resources/pix_qr_code.py b/openpix/resources/pix_qr_code.py index 697d87f..5fb3e31 100644 --- a/openpix/resources/pix_qr_code.py +++ b/openpix/resources/pix_qr_code.py @@ -1,6 +1,7 @@ """ Module: pix-qr-code """ +from openpix.http import HttpClient class PixQrCode(): """ diff --git a/openpix/resources/refund.py b/openpix/resources/refund.py index d2c14c9..cf644fa 100644 --- a/openpix/resources/refund.py +++ b/openpix/resources/refund.py @@ -1,6 +1,7 @@ """ Module: refund """ +from openpix.http import HttpClient class Refund: """ @@ -8,7 +9,7 @@ class Refund: [Click here for more info](https://developers.woovi.com/api#tag/refund) # pylint: disable=line-too-long """ - def __init__(self, HttpClient): + def __init__(self, HttpClient: HttpClient): self._client = HttpClient def get(self): diff --git a/openpix/resources/sub_account.py b/openpix/resources/sub_account.py index 672ed2d..3e1c140 100644 --- a/openpix/resources/sub_account.py +++ b/openpix/resources/sub_account.py @@ -1,6 +1,7 @@ """ Module: sub-account """ +from openpix.http import HttpClient class SubAccount(): """ diff --git a/openpix/resources/subscription.py b/openpix/resources/subscription.py index f330903..e9ba1e1 100644 --- a/openpix/resources/subscription.py +++ b/openpix/resources/subscription.py @@ -1,6 +1,7 @@ """ Module: subscription """ +from openpix.http import HttpClient class Subscription: """ @@ -8,7 +9,7 @@ class Subscription: [Click here for more info](https://developers.woovi.com/api#tag/subscription) # pylint: disable=line-too-long """ - def __init__(self, HttpClient): + def __init__(self, HttpClient: HttpClient): self._client = HttpClient def get(self): diff --git a/openpix/resources/transactions.py b/openpix/resources/transactions.py index 931431a..b52d5f7 100644 --- a/openpix/resources/transactions.py +++ b/openpix/resources/transactions.py @@ -1,6 +1,7 @@ """ Module: transactions """ +from openpix.http import HttpClient class Transactions: """ @@ -8,7 +9,7 @@ class Transactions: [Click here for more info](https://developers.woovi.com/api#tag/transactions) # pylint: disable=line-too-long """ - def __init__(self, HttpClient): + def __init__(self, HttpClient: HttpClient): self._client = HttpClient def get(self): diff --git a/openpix/resources/transfer.py b/openpix/resources/transfer.py index c65ab27..a0e6f07 100644 --- a/openpix/resources/transfer.py +++ b/openpix/resources/transfer.py @@ -1,13 +1,15 @@ """ Module: transfer """ +from openpix.http import HttpClient + class Transfer: """ Access to Transfer [Click here for more info](https://developers.woovi.com/api#tag/transfer-(request-access)) # pylint: disable=line-too-long """ - def __init__(self, HttpClient): + def __init__(self, HttpClient: HttpClient): self._client = HttpClient def create(self): diff --git a/openpix/resources/webhook.py b/openpix/resources/webhook.py index c3f2182..e185372 100644 --- a/openpix/resources/webhook.py +++ b/openpix/resources/webhook.py @@ -1,6 +1,7 @@ """ Module: webhook """ +from openpix.http import HttpClient class Webhook: """ @@ -8,7 +9,7 @@ class Webhook: [Click here for more info](https://developers.woovi.com/api#tag/webhook) # pylint: disable=line-too-long """ - def __init__(self, HttpClient): + def __init__(self, HttpClient: HttpClient): self._client = HttpClient def list(self): diff --git a/openpix/sdk.py b/openpix/sdk.py index f862e01..ba5a832 100644 --- a/openpix/sdk.py +++ b/openpix/sdk.py @@ -40,10 +40,11 @@ class SDK: def __init__( self, - app_id, + app_id: str, ): """Construct ur SDK Object to have access to all APIs modules. Args: + app_id (str): A string representing the application ID, which serves as the API key. [Click here for more info](https://developers.woovi.com/docs/apis/api-getting-started) """ self._http_client = HttpClient(app_id=app_id) @@ -53,95 +54,95 @@ def account(self): """ Returns the attribute value of the function """ - return Account(HttpClient) + return Account(self._http_client) @property - def cashback_fidelity(self): + def cashback(self): """ Returns the attribute value of the function """ - return CashbackFidelity(HttpClient) + return CashbackFidelity(self._http_client) @property def charge(self): """ Returns the attribute value of the function """ - return Charge(HttpClient) + return Charge(self._http_client) @property - def charge_refund(self): + def chargeRefund(self): """ Returns the attribute value of the function """ - return ChargeRefund(HttpClient) + return ChargeRefund(self._http_client) @property def customer(self): """ Returns the attribute value of the function """ - return Customer(HttpClient) + return Customer(self._http_client) @property def partner(self): """ Returns the attribute value of the function """ - return Partner(HttpClient) + return Partner(self._http_client) @property - def pix_qr_code(self): + def pixQrCode(self): """ Returns the attribute value of the function """ - return PixQrCode(HttpClient) + return PixQrCode(self._http_client) @property def payment(self): """ Returns the attribute value of the function """ - return Payment(HttpClient) + return Payment(self._http_client) @property def refund(self): """ Returns the attribute value of the function """ - return Refund(HttpClient) + return Refund(self._http_client) @property - def sub_account(self): + def subAccount(self): """ Returns the attribute value of the function """ - return SubAccount(HttpClient) + return SubAccount(self._http_client) @property def subscription(self): """ Returns the attribute value of the function """ - return Subscription(HttpClient) + return Subscription(self._http_client) @property def transactions(self): """ Returns the attribute value of the function """ - return Transactions(HttpClient) + return Transactions(self._http_client) @property def transfer(self): """ Returns the attribute value of the function """ - return Transfer(HttpClient) + return Transfer(self._http_client) @property def webhook(self): """ Returns the attribute value of the function """ - return Webhook(HttpClient) \ No newline at end of file + return Webhook(self._http_client) \ No newline at end of file diff --git a/openpix/types.py b/openpix/types.py new file mode 100644 index 0000000..158d8d2 --- /dev/null +++ b/openpix/types.py @@ -0,0 +1,8 @@ +class PageInfo: + def __init__(self, skip: int, limit: int, totalCount: int, hasPreviousPage: bool, hasNextPage: bool): + self.skip = skip + self.limit = limit + self.totalCount = totalCount + self.hasPreviousPage = hasPreviousPage + self.hasNextPage = hasNextPage + From 2b85ac1b144996deac4b7b573be597353ab48e00 Mon Sep 17 00:00:00 2001 From: eletroswing Date: Tue, 7 May 2024 20:56:23 -0300 Subject: [PATCH 06/25] add resource --- openpix/resources/cashback_fidelity.py | 20 ++++++++++++++++---- openpix/resources/cashback_fidelity_types.py | 15 +++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 openpix/resources/cashback_fidelity_types.py diff --git a/openpix/resources/cashback_fidelity.py b/openpix/resources/cashback_fidelity.py index 5993b55..72578aa 100644 --- a/openpix/resources/cashback_fidelity.py +++ b/openpix/resources/cashback_fidelity.py @@ -2,6 +2,7 @@ Module: cashback_fidelity """ from openpix.http import HttpClient +import cashback_fidelity_types class CashbackFidelity: """ @@ -12,8 +13,19 @@ class CashbackFidelity: def __init__(self, HttpClient: HttpClient): self._client = HttpClient - def get(self): - return + """Get one fidelity. + Args: + taxID (str): the user's tax id document + [Click here for m ore info](https://developers.woovi.com/api#tag/cashback-fidelity/paths/~1api~1v1~1cashback-fidelity~1balance~1%7BtaxID%7D/get) + """ + def get(self, taxID: str) -> cashback_fidelity_types.CashbackGet: + return self._client.get(path=f'/api/v1/cashback-fidelity/balance/{taxID}') - def create(self): - return \ No newline at end of file + """Create one fidelity. + Args: + taxID (str): the user's tax id document + value (int): the fidelity value + [Click here for more info](https://developers.woovi.com/api#tag/cashback-fidelity/paths/~1api~1v1~1cashback-fidelity/post) + """ + def create(self, taxID: str, value: int) -> cashback_fidelity_types.CashbackCreate: + return self._client.post(path=f'/api/v1/cashback-fidelity', data={value: value, taxID: taxID}) \ No newline at end of file diff --git a/openpix/resources/cashback_fidelity_types.py b/openpix/resources/cashback_fidelity_types.py new file mode 100644 index 0000000..1a141f6 --- /dev/null +++ b/openpix/resources/cashback_fidelity_types.py @@ -0,0 +1,15 @@ +from openpix.types import PageInfo + +class CashbackInfo: + def __init__(self, value: int): + self.value: value + +class CashbackGet: + def __init__(self, balance: int, status: str): + self.balance = balance + self.status = status + +class CashbackCreate: + def __init__(self, cashback: CashbackInfo, message: str): + self.cashback = cashback + self.message = message \ No newline at end of file From 7ce2fabc00ff94dd7cc35dc316f6eb8901948a40 Mon Sep 17 00:00:00 2001 From: eletroswing Date: Tue, 7 May 2024 21:17:47 -0300 Subject: [PATCH 07/25] add charge_refund resource --- openpix/resources/cashback_fidelity_types.py | 2 -- openpix/resources/charge_refund.py | 24 ++++++++++++++--- openpix/resources/charge_refund_types.py | 28 ++++++++++++++++++++ 3 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 openpix/resources/charge_refund_types.py diff --git a/openpix/resources/cashback_fidelity_types.py b/openpix/resources/cashback_fidelity_types.py index 1a141f6..55a8481 100644 --- a/openpix/resources/cashback_fidelity_types.py +++ b/openpix/resources/cashback_fidelity_types.py @@ -1,5 +1,3 @@ -from openpix.types import PageInfo - class CashbackInfo: def __init__(self, value: int): self.value: value diff --git a/openpix/resources/charge_refund.py b/openpix/resources/charge_refund.py index 367df04..7f79a4b 100644 --- a/openpix/resources/charge_refund.py +++ b/openpix/resources/charge_refund.py @@ -2,6 +2,7 @@ Module: charge_refund """ from openpix.http import HttpClient +import charge_refund_types class ChargeRefund: """ @@ -12,8 +13,23 @@ class ChargeRefund: def __init__(self, HttpClient: HttpClient): self._client = HttpClient - def list(self): - return + """Get a list of charge refunds. + Args: + id (str): The correlation ID of the charge. + limit (int): number of content per page + skip (int): number of how many contents will be ignored + [Click here for more info](https://developers.woovi.com/api#tag/charge-refund/paths/~1api~1v1~1charge~1%7Bid%7D~1refund/get) + """ + def list(self, id: str, limit: int = 10, skip: int = 0) -> charge_refund_types.ChargeRefundList: + return self._client.get(path=f'/api/v1/charge/{id}/refund', query={"limit": limit, "skip": skip}) - def create(self): - return \ No newline at end of file + """Create a new refund for a charge + Args: + id (str): The correlation ID of the charge. + correlationID (str): Your correlation ID to keep track for this refund + value (int): Value in cents for this refund + comment (str): Comment for this refund. Maximum length of 140 characters. + [Click here for more info](https://developers.woovi.com/api#tag/charge-refund/paths/~1api~1v1~1charge~1%7Bid%7D~1refund/post) + """ + def create(self, id: str, correlationID: str, value: int, comment: str) -> charge_refund_types.ChargeRefundCreate: + return self._client.post(path=f'/api/v1/charge/{id}/refund', data={value: value, correlationID: correlationID, comment: comment}) \ No newline at end of file diff --git a/openpix/resources/charge_refund_types.py b/openpix/resources/charge_refund_types.py new file mode 100644 index 0000000..63bb97a --- /dev/null +++ b/openpix/resources/charge_refund_types.py @@ -0,0 +1,28 @@ +from openpix.types import PageInfo +from typing import List + +class ChargeRefund: + def __init__(self, status: str, value: int, correlationID: str, endToEndId: str, time: str): + self.status = status + self.value = value + self.correlationID = correlationID + self.endToEndId = endToEndId + self.time = time + +class ChargeRefundCreate: + def __init__(self, status: str, value: int, correlationID: str, endToEndId: str, time: str, comment: str): + self.status = status + self.value = value + self.correlationID = correlationID + self.endToEndId = endToEndId + self.time = time + self.comment = comment + +class ChargeRefundList: + def __init__(self, pageInfo: PageInfo, refunds: List[ChargeRefund]): + self.pageInfo = pageInfo + self.refunds = refunds + +class ChargeRefundCreate: + def __init__(self, refund: ChargeRefundCreate): + self.refund = refund \ No newline at end of file From 1b2fbe19a9767a62e7ad350399333cd94f14a73c Mon Sep 17 00:00:00 2001 From: eletroswing Date: Sun, 12 May 2024 12:51:53 -0300 Subject: [PATCH 08/25] feat(resource): adding charge resource --- absurdo.js | 6 ++ openpix/http/http_client.py | 10 ++- openpix/resources/charge.py | 94 ++++++++++++++++--- openpix/resources/charge_types.py | 145 ++++++++++++++++++++++++++++++ 4 files changed, 242 insertions(+), 13 deletions(-) create mode 100644 absurdo.js create mode 100644 openpix/resources/charge_types.py diff --git a/absurdo.js b/absurdo.js new file mode 100644 index 0000000..cbc3d94 --- /dev/null +++ b/absurdo.js @@ -0,0 +1,6 @@ +try { + fetch("some endpoint") +} catch (e) {} +finally { + +} \ No newline at end of file diff --git a/openpix/http/http_client.py b/openpix/http/http_client.py index 9cba82f..bf7b06c 100644 --- a/openpix/http/http_client.py +++ b/openpix/http/http_client.py @@ -12,16 +12,20 @@ def __init__(self, app_id): self._app_id = app_id self.base_url = "https://api.woovi.com" - def request(self, method, path, query, maxretries=None, **kwargs): + def request(self, method, path, query, maxretries=None, data = None, **kwargs): """Makes a call to the API. All **kwargs are passed verbatim to ``requests.request``. """ if(query): - query_string = urlencode(query) + query_string = urlencode({k: v for k, v in query.items() if v is not None}) url = urljoin(self.base_url + path, '?' + query_string) else: url = self.base_url + path + + if(data): + data = {k: v for k, v in data.items() if v is not None} + headers = kwargs.get('headers', {}) headers['Authorization'] = self._app_id kwargs['headers'] = headers @@ -34,7 +38,7 @@ def request(self, method, path, query, maxretries=None, **kwargs): http.mount("https://", HTTPAdapter(max_retries=retry_strategy)) with http as session: - api_result = session.request(method, url, **kwargs) + api_result = session.request(method, url, data=data,**kwargs) response = { "status": api_result.status_code, diff --git a/openpix/resources/charge.py b/openpix/resources/charge.py index 11733e0..75079e6 100644 --- a/openpix/resources/charge.py +++ b/openpix/resources/charge.py @@ -2,6 +2,8 @@ Module: charge """ from openpix.http import HttpClient +import charge_types +from typing import List, Union, Optional class Charge: """ @@ -12,17 +14,89 @@ class Charge: def __init__(self, HttpClient: HttpClient): self._client = HttpClient - def get(self): - return + """Get a charge + Args: + id (str): charge ID or correlation ID. + [Click here for more info](https://developers.woovi.com/api#tag/charge/paths/~1api~1v1~1charge~1%7Bid%7D/delete) + """ + def get(self, id: str) -> charge_types.ChargeGet: + return self._client.get(path=f'/api/v1/charge/{id}') - def list(self): - return + """Get a list of charges. + Args: + start (str): Start date used in the query. Complies with RFC 3339.. + end (str): End date used in the query. Complies with RFC 3339. + status (str): Enum: "ACTIVE" "COMPLETED" "EXPIRED" + customer (str): Customer Correlation ID + limit (int): number of content per page + skip (int): number of how many contents will be ignored + [Click here for more info](https://developers.woovi.com/api#tag/charge/paths/~1api~1v1~1charge/get) + """ + def list(self, start: str = None, end: str = None, status: str = None, customer: str = None, limit: int = 10, skip: int = 0) -> charge_types.ChargeList: + return self._client.get(path=f'/api/v1/charge/', query={"limit": limit, "skip": skip, start: start, end: end, status: status, customer: customer}) - def delete(self): - return + """Delete one charge request + Args: + id (str): charge ID or correlation ID. + [Click here for more info](https://developers.woovi.com/api#tag/charge/paths/~1api~1v1~1charge~1%7Bid%7D/delete) + """ + def delete(self, id:str) -> charge_types.ChargeDelete: + return self._client.delete(path=f'/api/v1/charge/{id}') - def create(self): - return + """create a charge + Args: + return_existing (bool, optional): Make the endpoint idempotent, will return an existent charge if already has a one with the correlationID. - def getQrImage(self): - return \ No newline at end of file + correlationID (str): Your correlation ID to keep track of this charge. + value (int): Value in cents of this charge. + type (str, optional): Charge type. Enum: "DYNAMIC" "OVERDUE". Determines whether a charge will have a deadline, fines, and interests. + comment (str, optional): Comment to be added in infoPagador. + identifier (str, optional): Custom identifier for EMV. + expiresIn (int, optional): Expires the charge in seconds (minimum is 15 minutes). + expiresDate (str, optional): Expiration date of the charge. Only in ISO 8601 format. + customer (CustomerPayload, optional): Customer information. + daysForDueDate (int, optional): Time in days until the charge hits the deadline so fines and interests start applying. Only considered for charges of type OVERDUE. + daysAfterDueDate (int, optional): Time in days that a charge is still payable after the deadline. Only considered for charges of type OVERDUE. + interests (Interests, optional): Interests configuration. Only considered for charges of type OVERDUE. + fines (Fines, optional): Fines configuration. Only considered for charges of type OVERDUE. + discountSettings (dict, optional): Discount settings for the charge. Only considered for charges of type OVERDUE. + additionalInfo (List[AdditionalInfoItem], optional): Additional info of the charge. + enableCashbackPercentage (bool, optional): True to enable cashback and false to disable. + enableCashbackExclusivePercentage (bool, optional): True to enable fidelity cashback and false to disable. + [Click here for more info](https://developers.woovi.com/api#tag/charge/paths/~1api~1v1~1charge/post) + """ + def create(self, return_existing: bool = True, correlationID: str = "", value: int = 0, type: Optional[str] = None, comment: Optional[str] = None, + identifier: Optional[str] = None, expiresIn: Optional[int] = None, expiresDate: Optional[str] = None, + customer: Optional[charge_types.CustomerPayload] = None, daysForDueDate: Optional[int] = None, + daysAfterDueDate: Optional[int] = None, interests: Optional[charge_types.Interests] = None, + fines: Optional[charge_types.Fines] = None, discountSettings: Optional[dict] = None, + additionalInfo: Optional[List[charge_types.AdditionalInfoItem]] = None, enableCashbackPercentage: Optional[bool] = None, + enableCashbackExclusivePercentage: Optional[bool] = None) -> charge_types.ChargeCreate: + return self._client.post(path=f'/api/v1/charge/', query={"return_existing": return_existing}, data={ + correlationID: correlationID, + value: value, + type: type, + comment: comment, + identifier: identifier, + expiresIn: expiresIn, + expiresDate: expiresDate, + customer: customer, + daysAfterDueDate: daysAfterDueDate, + daysForDueDate: daysForDueDate, + fines: fines, + interests: interests, + discountSettings: discountSettings, + additionalInfo: additionalInfo, + enableCashbackExclusivePercentage: enableCashbackExclusivePercentage, + enableCashbackPercentage: enableCashbackPercentage + }) + + + """Get the qr code from a charge + Args: + id (str): charge link payment ID. + size (int): Size for the image. This size should be between 600 and 4096. if the size parameter was not passed, the default value will be 1024. + [Click here for more info](https://developers.woovi.com/api#tag/charge/paths/~1openpix~1charge~1brcode~1image~1%7B:id%7D.png?size=1024/get) + """ + def getQrImage(self, id: str, size: int = 1024) -> str: + return f'https://api.woovi.com/openpix/charge/brcode/image/{id}.png?size={size}' \ No newline at end of file diff --git a/openpix/resources/charge_types.py b/openpix/resources/charge_types.py new file mode 100644 index 0000000..6ff1e23 --- /dev/null +++ b/openpix/resources/charge_types.py @@ -0,0 +1,145 @@ +from openpix.types import PageInfo +from typing import List, Union, Optional + +class ChargeDelete: + def __init__(self, status: str, id: str): + self.status = status + self.id = id + +class CustomerPayload: + def __init__(self, name: str, taxID: Optional[str] = None, email: Optional[str] = None, phone: Optional[str] = None): + self.name = name + self.taxID = taxID + self.email = email + self.phone = phone + +class Interests: + def __init__(self, value: int): + self.value = value + +class Fines: + def __init__(self, value: int): + self.value = value + +class DiscountFixedDate: + def __init__(self, daysActive: int, value: int): + self.daysActive = daysActive + self.value = value + + +class DiscountSettings: + def __init__(self, modality: str, discountFixedDate: DiscountFixedDate): + self.modality = modality + self.discountFixedDate = discountFixedDate + +class AdditionalInfoItem: + def __init__(self, key: str, value: str): + self.key = key + self.value = value + +class ChargeCreate: + def __init__(self, correlationID: str, value: int, type: Optional[str] = None, comment: Optional[str] = None, + identifier: Optional[str] = None, expiresIn: Optional[int] = None, expiresDate: Optional[str] = None, + customer: Optional[CustomerPayload] = None, daysForDueDate: Optional[int] = None, + daysAfterDueDate: Optional[int] = None, interests: Optional[Interests] = None, + fines: Optional[Fines] = None, discountSettings: Optional[DiscountSettings] = None, + additionalInfo: Optional[List[AdditionalInfoItem]] = None, enableCashbackPercentage: Optional[bool] = None, + enableCashbackExclusivePercentage: Optional[bool] = None): + self.correlationID = correlationID + self.value = value + self.type = type + self.comment = comment + self.identifier = identifier + self.expiresIn = expiresIn + self.expiresDate = expiresDate + self.customer = customer + self.daysForDueDate = daysForDueDate + self.daysAfterDueDate = daysAfterDueDate + self.interests = interests + self.fines = fines + self.discountSettings = discountSettings + self.additionalInfo = additionalInfo + self.enableCashbackPercentage = enableCashbackPercentage + self.enableCashbackExclusivePercentage = enableCashbackExclusivePercentage + +class TaxID: + def __init__(self, taxID: str, type: str): + self.taxID = taxID + self.type = type + +class Address: + def __init__(self, zipcode: str, street: str, number: str, neighborhood: str, city: str, state: str, complement: str, country: str): + self.zipcode = zipcode + self.street = street + self.number = number + self.neighborhood = neighborhood + self.city = city + self.state = state + self.complement = complement + self.country = country + +class Customer: + def __init__(self, name: str, email: str, phone: str, taxID: TaxID, correlationID: str, address: Address): + self.name = name + self.email = email + self.phone = phone + self.taxID = taxID + self.correlationID = correlationID + self.address = address + +class AdditionalInfoItem: + def __init__(self, key: str, value: str): + self.key = key + self.value = value + +class Charge: + def __init__(self, value: int, customer: Customer, comment: str, brCode: str, status: str, + correlationID: str, paymentLinkID: str, paymentLinkUrl: str, globalID: str, + transactionID: str, identifier: str, qrCodeImage: str, additionalInfo: List[AdditionalInfoItem], + pixKey: str, createdAt: str, updatedAt: str, expiresIn: str): + self.value = value + self.customer = customer + self.comment = comment + self.brCode = brCode + self.status = status + self.correlationID = correlationID + self.paymentLinkID = paymentLinkID + self.paymentLinkUrl = paymentLinkUrl + self.globalID = globalID + self.transactionID = transactionID + self.identifier = identifier + self.qrCodeImage = qrCodeImage + self.additionalInfo = additionalInfo + self.pixKey = pixKey + self.createdAt = createdAt + self.updatedAt = updatedAt + self.expiresIn = expiresIn + +class EasyCharge: + def __init__(self, value: int, customer: Customer, comment: str, brCode: str, status: str, + correlationID: str, paymentLinkID: str, paymentLinkUrl: str, qrCodeImage: str, additionalInfo: List[AdditionalInfoItem], createdAt: str, updatedAt: str, expiresIn: str, expiresDate: str): + self.status = status + self.value = value + self.customer = customer + self.comment = comment + self.paymentLinkID = paymentLinkID + self.correlationID = correlationID + self.paymentLinkUrl = paymentLinkUrl + self.qrCodeImage = qrCodeImage + self.brCode = brCode + self.additionalInfo = additionalInfo + + self.expiresDate = expiresDate + self.createdAt = createdAt + self.updatedAt = updatedAt + self.expiresIn = expiresIn + + +class ChargeGet: + def __init__(self, charge: Charge): + self.charge = charge + +class ChargeList: + def __init__(self, pageInfo: PageInfo, charges: List[EasyCharge]): + self.pageInfo = pageInfo + self.charges = charges \ No newline at end of file From 8b66555c0255e5105e4167fb45c5b7cd3213262c Mon Sep 17 00:00:00 2001 From: eletroswing Date: Sun, 12 May 2024 13:17:40 -0300 Subject: [PATCH 09/25] feat(resource): transfer resource --- openpix/resources/transfer.py | 5 +++-- openpix/resources/transfer_types.py | 10 ++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 openpix/resources/transfer_types.py diff --git a/openpix/resources/transfer.py b/openpix/resources/transfer.py index a0e6f07..8d8f2fc 100644 --- a/openpix/resources/transfer.py +++ b/openpix/resources/transfer.py @@ -2,6 +2,7 @@ Module: transfer """ from openpix.http import HttpClient +import transfer_types class Transfer: """ @@ -12,5 +13,5 @@ class Transfer: def __init__(self, HttpClient: HttpClient): self._client = HttpClient - def create(self): - return \ No newline at end of file + def create(self, value: str, fromPixKey: str, toPixKey: str) -> transfer_types.Transfer: + return self._client.post(path=f'/api/v1/transfer', data={value: value, fromPixKey: fromPixKey, toPixKey: toPixKey}) \ No newline at end of file diff --git a/openpix/resources/transfer_types.py b/openpix/resources/transfer_types.py new file mode 100644 index 0000000..71626fa --- /dev/null +++ b/openpix/resources/transfer_types.py @@ -0,0 +1,10 @@ +class Transfer: + def __init__(self, value: int, time: str, correlationID: str): + self.value = value + self.time = time + self.correlationID = correlationID + +class TransferCreate: + def __init__(self, transaction: Transfer): + self.transaction = transaction + \ No newline at end of file From c99b7566cb96049774e90b7854e236153fd6ec5c Mon Sep 17 00:00:00 2001 From: eletroswing Date: Wed, 29 May 2024 19:02:05 -0300 Subject: [PATCH 10/25] feat(resource): customer resource --- openpix/http/http_client.py | 12 ++++++++ openpix/resources/customer.py | 48 +++++++++++++++++++++++++---- openpix/resources/customer_types.py | 44 ++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 6 deletions(-) create mode 100644 openpix/resources/customer_types.py diff --git a/openpix/http/http_client.py b/openpix/http/http_client.py index bf7b06c..7d02c16 100644 --- a/openpix/http/http_client.py +++ b/openpix/http/http_client.py @@ -72,6 +72,18 @@ def post(self, path, query = None, data=None, params=None, timeout=None, maxretr timeout=timeout, maxretries=maxretries, ) + + def patch(self, path, query = None, data=None, params=None, timeout=None, maxretries=None): + """Makes a PATCH request to the API""" + return self.request( + method="PATCH", + path=path, + query=query, + data=data, + params=params, + timeout=timeout, + maxretries=maxretries, + ) def put(self, path, query = None, data=None, params=None, timeout=None, maxretries=None): """Makes a PUT request to the API""" diff --git a/openpix/resources/customer.py b/openpix/resources/customer.py index 4fea02f..113bc15 100644 --- a/openpix/resources/customer.py +++ b/openpix/resources/customer.py @@ -3,6 +3,8 @@ """ from openpix.http import HttpClient +import charge_types + class Customer: """ Access to Customer @@ -12,11 +14,45 @@ class Customer: def __init__(self, HttpClient: HttpClient): self._client = HttpClient - def get(self): - return + def get(self, id: str) -> charge_types.CustomerGet: + return self._client.get(path=f'/api/v1/customer/{id}') - def list(self): - return + def list(self, limit: int = 10, skip: int = 0) -> charge_types.ChargeList: + return self._client.get(path=f'/api/v1/customer', query={"limit": limit, "skip": skip}) - def create(self): - return \ No newline at end of file + def create(self, name: str, email: str, phone: str, taxID: str, address: charge_types.Address) -> charge_types.CustomerCreate: + return self._client.post(path=f'/api/v1/customer', data={ + 'name': name, + 'phone': phone, + 'taxID': taxID, + 'email': email, + 'address': { + 'zipcode': address.zipcode, + 'street': address.street, + 'number': address.number, + 'neighborhood': address.neighborhood, + 'city': address.city, + 'state': address.state, + 'complement': address.complement, + 'country': address.country, + } + }) + + def update(self, correlationID: str, name: str, email: str, phone: str, taxID: str, address: charge_types.Address) -> charge_types.CustomerUpdate: + return self._client.patch(path=f'/api/v1/customer/{correlationID}', data={ + 'name': name, + 'phone': phone, + 'taxID': taxID, + 'email': email, + 'address': { + 'zipcode': address.zipcode, + 'street': address.street, + 'number': address.number, + 'neighborhood': address.neighborhood, + 'city': address.city, + 'state': address.state, + 'complement': address.complement, + 'country': address.country, + } + }) + \ No newline at end of file diff --git a/openpix/resources/customer_types.py b/openpix/resources/customer_types.py new file mode 100644 index 0000000..e1aa38c --- /dev/null +++ b/openpix/resources/customer_types.py @@ -0,0 +1,44 @@ +from openpix.types import PageInfo +from typing import List + +class TaxID: + def __init__(self, taxID: str, type: str): + self.taxID = taxID + self.type = type + +class Address: + def __init__(self, zipcode: str, street: str, number: str, neighborhood: str, city: str, state: str, complement: str, country: str): + self.zipcode = zipcode + self.street = street + self.number = number + self.neighborhood = neighborhood + self.city = city + self.state = state + self.complement = complement + self.country = country + +class Customer: + def __init__(self, name: str, email: str, phone: str, taxID: TaxID, correlationID: str, address: Address): + self.name = name + self.email = email + self.phone = phone + self.taxID = taxID + self.correlationID = correlationID + self.address = address + +class CustomerGet: + def __init__(self, customer: Customer): + self.customer = customer + +class CustomerUpdate: + def __init__(self, customer: Customer): + self.customer = customer + +class CustomerCreate: + def __init__(self, customer: Customer): + self.customer = customer + +class CustomerList: + def __init__(self, pageInfo: PageInfo, customers: List[Customer]): + self.pageInfo = pageInfo + self.customers = customers From 1be051f8c27b1f97ad52c4de89e71fe969e3c06c Mon Sep 17 00:00:00 2001 From: eletroswing Date: Wed, 29 May 2024 19:20:59 -0300 Subject: [PATCH 11/25] feat(resource): refund resource --- openpix/resources/refund.py | 40 ++++++++++++++++++++++++++----- openpix/resources/refund_types.py | 24 +++++++++++++++++++ openpix/resources/sub_account.py | 2 ++ 3 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 openpix/resources/refund_types.py diff --git a/openpix/resources/refund.py b/openpix/resources/refund.py index cf644fa..a6194e2 100644 --- a/openpix/resources/refund.py +++ b/openpix/resources/refund.py @@ -2,6 +2,7 @@ Module: refund """ from openpix.http import HttpClient +import refund_types class Refund: """ @@ -12,11 +13,38 @@ class Refund: def __init__(self, HttpClient: HttpClient): self._client = HttpClient - def get(self): - return + """get a refund + Args: + id (str): identifier of your refund. - def list(self): - return + [Click here for more info](https://developers.openpix.com.br/api#tag/refund/paths/~1api~1v1~1refund~1%7Bid%7D/get) + """ + def get(self, id: str) -> refund_types.RefundGet: + return self._client.get(path=f'/api/v1/refund/{id}') + + """list refunds + Args: + limit (int, optional): itens per page, defaults 10. + skip (int, optional): how many itens are gonna be skipped, default 0. + + [Click here for more info](https://developers.openpix.com.br/api#tag/refund/paths/~1api~1v1~1refund/get) + """ + def list(self, limit: int = 10, skip: int = 0) -> refund_types.RefundList: + return self._client.get(path=f'/api/v1/refund', query={"limit": limit, "skip": skip}) - def getQrImage(self): - return \ No newline at end of file + """create a refund + Args: + value (int): value of the refund. + transactionEndToEndId (str): Your transaction ID, or endToEnd ID, to keep track of this refund + correlationID (str): Your correlation ID, unique identifier refund + comment (str): Comment of this refund. Maximum length of 140 characters. + + [Click here for more info](https://developers.openpix.com.br/api#tag/refund/paths/~1api~1v1~1refund/post) + """ + def create(self, value: int, transactionEndToEndId: str, correlationID: str, comment: str) -> refund_types.RefundCreate: + return self._client.post(path=f'/api/v1/refund', data={ + 'comment': comment, + 'correlationID': correlationID, + 'transactionEndToEndId': transactionEndToEndId, + 'value': value + }) \ No newline at end of file diff --git a/openpix/resources/refund_types.py b/openpix/resources/refund_types.py new file mode 100644 index 0000000..a1ce9f8 --- /dev/null +++ b/openpix/resources/refund_types.py @@ -0,0 +1,24 @@ +from openpix.types import PageInfo +from typing import List + +class Refund: + def __init__(self, value: int, status: str, correlationID: str, refundId: str, time: str, comment: str): + self.value = value + self.status = status + self.correlationID = correlationID + self.refundId = refundId + self.time = time + self.comment = comment + +class RefundGet: + def __init__(self, pixTransactionRefund: Refund): + self.pixTransactionRefund = pixTransactionRefund + +class RefundCreate: + def __init__(self, refund: Refund): + self.refund = refund + +class RefundList: + def __init__(self, pageInfo: PageInfo, refunds: List[Refund]): + self.pageInfo = pageInfo + self.refunds = refunds diff --git a/openpix/resources/sub_account.py b/openpix/resources/sub_account.py index 3e1c140..cac38af 100644 --- a/openpix/resources/sub_account.py +++ b/openpix/resources/sub_account.py @@ -9,6 +9,8 @@ class SubAccount(): [Click here for more info](https://developers.woovi.com/api#tag/sub-account-(request-access)) # pylint: disable=line-too-long """ + def __init__(self, HttpClient: HttpClient): + self._client = HttpClient def get(self): return From 0652e88e1a2a6c0f3ca2a2a81af05c6b8d7db535 Mon Sep 17 00:00:00 2001 From: eletroswing Date: Wed, 29 May 2024 19:25:54 -0300 Subject: [PATCH 12/25] fix(customer): adding docs for customer --- openpix/resources/customer.py | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/openpix/resources/customer.py b/openpix/resources/customer.py index 113bc15..6554537 100644 --- a/openpix/resources/customer.py +++ b/openpix/resources/customer.py @@ -14,12 +14,44 @@ class Customer: def __init__(self, HttpClient: HttpClient): self._client = HttpClient + """get a customer + Args: + id (str): identifier of your customer. + + [Click here for more info](https://developers.openpix.com.br/api#tag/customer/paths/~1api~1v1~1customer~1%7Bid%7D/get) + """ def get(self, id: str) -> charge_types.CustomerGet: return self._client.get(path=f'/api/v1/customer/{id}') + """list customers + Args: + limit (int, optional): itens per page, defaults 10. + skip (int, optional): how many itens are gonna be skipped, default 0. + + [Click here for more info](https://developers.openpix.com.br/api#tag/customer/paths/~1api~1v1~1customer~1%7Bid%7D/get) + """ def list(self, limit: int = 10, skip: int = 0) -> charge_types.ChargeList: return self._client.get(path=f'/api/v1/customer', query={"limit": limit, "skip": skip}) + """create a customer + Args: + name (str): name of the customer. + email (str): email of the customer. + phone (str): phone number of your customer. + taxID (str): personal document of your customer. + correlationID (str): Your correlation ID, unique identifier refund. + address (Address): + - zipcode: string + - street: string + - number: string + - neighborhood: string + - city: string + - state: string + - complement: string + - country: string + + [Click here for more info](https://developers.openpix.com.br/api#tag/customer/paths/~1api~1v1~1customer/post) + """ def create(self, name: str, email: str, phone: str, taxID: str, address: charge_types.Address) -> charge_types.CustomerCreate: return self._client.post(path=f'/api/v1/customer', data={ 'name': name, @@ -38,6 +70,25 @@ def create(self, name: str, email: str, phone: str, taxID: str, address: charge_ } }) + """update a customer + Args: + correlationID (str): Your correlation ID, unique identifier refund. + name (str): name of the customer. + email (str): email of the customer. + phone (str): phone number of your customer. + taxID (str): personal document of your customer. + address (Address): + - zipcode: string + - street: string + - number: string + - neighborhood: string + - city: string + - state: string + - complement: string + - country: string + + [Click here for more info](https://developers.openpix.com.br/api#tag/customer/paths/~1api~1v1~1customer/post) + """ def update(self, correlationID: str, name: str, email: str, phone: str, taxID: str, address: charge_types.Address) -> charge_types.CustomerUpdate: return self._client.patch(path=f'/api/v1/customer/{correlationID}', data={ 'name': name, From cec93f6dde8c0ccfb9c68597b9489b6e3f70a120 Mon Sep 17 00:00:00 2001 From: eletroswing Date: Wed, 29 May 2024 19:42:58 -0300 Subject: [PATCH 13/25] feat(resource): payment resource --- openpix/resources/payment.py | 56 +++++++++++++++++++++++++----- openpix/resources/payment_types.py | 52 +++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 8 deletions(-) create mode 100644 openpix/resources/payment_types.py diff --git a/openpix/resources/payment.py b/openpix/resources/payment.py index 0b81128..a1cf122 100644 --- a/openpix/resources/payment.py +++ b/openpix/resources/payment.py @@ -2,6 +2,7 @@ Module: payment """ from openpix.http import HttpClient +import payment_types class Payment: """ @@ -12,14 +13,53 @@ class Payment: def __init__(self, HttpClient: HttpClient): self._client = HttpClient - def get(self): - return + """get a payment + Args: + id (str): identifier of your payment. - def list(self): - return + [Click here for more info](https://developers.openpix.com.br/api#tag/payment-(request-access)/paths/~1api~1v1~1payment~1%7Bid%7D/get) + """ + def get(self, id: str) -> payment_types.PaymentGet: + return self._client.get(path=f'/api/v1/payment/{id}') + + """list payments + Args: + limit (int, optional): itens per page, defaults 10. + skip (int, optional): how many itens are gonna be skipped, default 0. + + [Click here for more info](https://developers.openpix.com.br/api#tag/payment-(request-access)/paths/~1api~1v1~1payment~1%7Bid%7D/get) + """ + def list(self, limit: int = 10, skip: int = 0) -> payment_types.PaymentList: + return self._client.get(path=f'/api/v1/payment', query={"limit": limit, "skip": skip}) - def approve(self): - return + """approve a payment + Args: + correlationID (str): the correlation ID of the payment to be approved - def create(self): - return \ No newline at end of file + [Click here for more info](https://developers.openpix.com.br/api#tag/payment-(request-access)/paths/~1api~1v1~1payment~1approve/post) + """ + def approve(self, correlationID: str) -> payment_types.PaymentApprove: + return self._client.post(path=f'/api/v1/payment/approve', data={ + "correlationID": correlationID + }) + + """create a payment + Args: + To a pix key: + value (int): value of the requested payment in cents + destinationAlias (str): the pix key the payment should be sent to + destinationAliasType (str): the type of the pix key the payment should be sent to + correlationID (str): an unique identifier for your payment + comment (str): the comment that will be send alongisde your payment + sourceAccountId (str): an optional id for the source account of the payment, if not informed will assume the default account + + To a qr code: + qrCode (int): the QR Code to be paid + correlationID (str): an unique identifier for your payment + comment (str): the comment that will be send alongisde your payment + sourceAccountId (str): an optional id for the source account of the payment, if not informed will assume the default account + + [Click here for more info](https://developers.openpix.com.br/api#tag/payment-(request-access)/paths/~1api~1v1~1payment/post) + """ + def create(self, **kwargs) -> payment_types.PaymentCreate: + return self._client.post(path=f'/api/v1/payment', data=kwargs) \ No newline at end of file diff --git a/openpix/resources/payment_types.py b/openpix/resources/payment_types.py new file mode 100644 index 0000000..018fda9 --- /dev/null +++ b/openpix/resources/payment_types.py @@ -0,0 +1,52 @@ +from openpix.types import PageInfo +from typing import List + +class PaymentDestination: + def __init__(self, name: str, taxID: str, pixKey: str, bank: str, branch: str, account: str): + self.name = name + self.taxID = taxID + self.pixKey = pixKey + self.bank = bank + self.branch = branch + self.account = account + +class PaymentTransaction: + def __init__(self, value: int, endToEndId: str, time: str): + self.value = value + self.endToEndId = endToEndId + self.time = time + +class Payment: + def __init__(self, value: int, destinationAlias: str, destinationAliasType: str, qrCode: str, correlationID: str, + comment: str, status: str, sourceAccountId: str, transaction: PaymentTransaction, destination: PaymentDestination): + self.value = value + self.destinationAlias = destinationAlias + self.destinationAliasType = destinationAliasType + self.qrCode = qrCode + self.correlationID = correlationID + self.comment = comment + self.status = status + self.sourceAccountId = sourceAccountId + self.transaction = transaction + self.destination = destination + +class PaymentGet: + def __init__(self, payment: Payment, transaction: PaymentTransaction, destination: PaymentDestination): + self.payment = payment + self.transaction = transaction + self.destination = destination + +class PaymentList: + def __init__(self, pageInfo: PageInfo, payments: List[PaymentGet]): + self.pageInfo = pageInfo + self.payments = payments + +class PaymentApprove: + def __init__(self, payment: Payment, transaction: PaymentTransaction, destination: PaymentDestination): + self.payment = payment + self.transaction = transaction + self.destination = destination + +class PaymentCreate: + def __init__(self, payment: Payment): + self.payment = payment \ No newline at end of file From dd4de1161aa0df58e484ba9ee123eefaaf493332 Mon Sep 17 00:00:00 2001 From: eletroswing Date: Wed, 29 May 2024 20:05:58 -0300 Subject: [PATCH 14/25] feat(resource): partner resource --- openpix/resources/partner.py | 44 +++++++++++++++----- openpix/resources/partner_types.py | 66 ++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 10 deletions(-) create mode 100644 openpix/resources/partner_types.py diff --git a/openpix/resources/partner.py b/openpix/resources/partner.py index df3e16f..1e673e6 100644 --- a/openpix/resources/partner.py +++ b/openpix/resources/partner.py @@ -2,6 +2,7 @@ Module: partner """ from openpix.http import HttpClient +import partner_types class Partner: """ @@ -12,17 +13,40 @@ class Partner: def __init__(self, HttpClient: HttpClient): self._client = HttpClient - def get(self): - return + def get(self, taxID: str) -> partner_types.PartnerGet: + return self._client.get(path=f'/api/v1/partner/company/{taxID}') - def list(self): - return - def delete(self): - return + def list(self, limit: int = 10, skip: int = 0) -> partner_types.PartnerList: + return self._client.get(path=f'/api/v1/partner/company', query={"limit": limit, "skip": skip}) - def createPreRegistration(self): - return + def createPreRegistration(self, preRegistration: partner_types.PreRegistrationCreate, user: partner_types.PreRegistrationUserObject): + return self._client.post(path=f'/api/v1/partner/company', data={ + "preRegistration": { + "name": preRegistration.name, + "taxID": { + "taxID": preRegistration.taxID.taxID, + "type": preRegistration.taxID.type + }, + "website": preRegistration.website + }, + "user": { + "firstName": user.firstName, + "lastName": user.lastName, + "email": user.email, + "phone": user.phone + } + }) - def createApplication(self): - return \ No newline at end of file + def createApplication(self, application: partner_types.Application, taxID: partner_types.TaxId): + return self._client.post(path=f'/api/v1/partner/application', data={ + "application": { + "name": application.name, + "type": application.type + }, + "taxID": { + "taxID": taxID.taxID, + "type": taxID.type + + } + }) \ No newline at end of file diff --git a/openpix/resources/partner_types.py b/openpix/resources/partner_types.py new file mode 100644 index 0000000..1dd4865 --- /dev/null +++ b/openpix/resources/partner_types.py @@ -0,0 +1,66 @@ +from openpix.types import PageInfo +from typing import List + +class TaxIDObjectPayload: + def __init__(self, taxID: str, type: str): + self.taxID = taxID + self.type = type + +class PreRegistrationUserObject: + def __init__(self, firstName: str, lastName: str, email: str, phone: str): + self.firstName = firstName + self.lastName = lastName + self.email = email + self.phone = phone + +class CompanyObjectPayload: + def __init__(self, id: str, name: str, taxID: TaxIDObjectPayload): + self.id = id + self.name = name + self.taxID = taxID + +class AccountObjectPayload: + def __init__(self, clientId: str): + self.clientId = clientId + +class PreRegistrationObjectPayload: + def __init__(self, name: str, taxID: TaxIDObjectPayload, user: PreRegistrationUserObject, + company: CompanyObjectPayload, account: AccountObjectPayload): + self.name = name + self.taxID = taxID + self.user = user + self.company = company + self.account = account + +class Application: + def __init__(self, name: str, type: str): + self.name = name + self.type = type + + +class TaxId: + def __init__(self, taxID: str, type: str): + self.taxID = taxID + self.type = type + +class PreRegistrationCreate: + def __init__(self, name: str, website: str, taxID: TaxId): + self.name = name + self.taxID = taxID + self.website = website + +class PreRegistration: + def __init__(self, preRegistration: PreRegistrationObjectPayload, user: PreRegistrationUserObject, company: CompanyObjectPayload, account: AccountObjectPayload): + self.preRegistration = preRegistration + self.user = user + self.company = company + account = account + +class PartnerGet: + def __init__(self, preRegistration: PreRegistration): + self.preRegistration = preRegistration + +class PartnerList: + def __init__(self, pageInfo: PageInfo, preRegistrations: List[PreRegistration]): + self.pageInfo = pageInfo + self.preRegistrations = preRegistrations From 0735b2326b48e656afcfbea9707925ab695a648d Mon Sep 17 00:00:00 2001 From: eletroswing Date: Thu, 30 May 2024 11:28:05 -0300 Subject: [PATCH 15/25] fix(partner): adding doc to partner --- openpix/resources/partner.py | 43 +++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/openpix/resources/partner.py b/openpix/resources/partner.py index 1e673e6..5d26ac2 100644 --- a/openpix/resources/partner.py +++ b/openpix/resources/partner.py @@ -13,13 +13,42 @@ class Partner: def __init__(self, HttpClient: HttpClient): self._client = HttpClient + """Get an specific preregistration via taxID param. + Args: + taxID (str): The raw tax ID from the preregistration that you want to get + + [Click here for more info](https://developers.openpix.com.br/api#tag/partner-(request-access)/paths/~1api~1v1~1partner~1company~1%7BtaxID%7D/get) + """ def get(self, taxID: str) -> partner_types.PartnerGet: return self._client.get(path=f'/api/v1/partner/company/{taxID}') - + """Get every preregistration that is managed by you. + Args: + limit (int, optional): itens per page, defaults 10. + skip (int, optional): how many itens are gonna be skipped, default 0. + + [Click here for more info](https://developers.openpix.com.br/api#tag/partner-(request-access)/paths/~1api~1v1~1partner~1company/get) + """ def list(self, limit: int = 10, skip: int = 0) -> partner_types.PartnerList: return self._client.get(path=f'/api/v1/partner/company', query={"limit": limit, "skip": skip}) + """Create a pre registration with a partner reference (your company) + Args: + preRegistration (preRegistration): + - name: str + - website: str + - taxID: + - taxID: str + - type: str + + user (user): + - firstName: str + - lastName: str + - email: str + - phone: str + + [Click here for more info](https://developers.openpix.com.br/api#tag/partner-(request-access)/paths/~1api~1v1~1partner~1company/post) + """ def createPreRegistration(self, preRegistration: partner_types.PreRegistrationCreate, user: partner_types.PreRegistrationUserObject): return self._client.post(path=f'/api/v1/partner/company', data={ "preRegistration": { @@ -38,6 +67,18 @@ def createPreRegistration(self, preRegistration: partner_types.PreRegistrationCr } }) + """Create a new application to some of your preregistration's company. + Args: + application (application): + - name: str + - type: str + + taxID (taxID): + - taxID: str + - type: str + + [Click here for more info](https://developers.openpix.com.br/api#tag/partner-(request-access)/paths/~1api~1v1~1partner~1application/post) + """ def createApplication(self, application: partner_types.Application, taxID: partner_types.TaxId): return self._client.post(path=f'/api/v1/partner/application', data={ "application": { From 1ccb5a3faffc6349b66c2702856ff609d21e09bb Mon Sep 17 00:00:00 2001 From: eletroswing Date: Thu, 30 May 2024 11:28:49 -0300 Subject: [PATCH 16/25] ): adding doc to partner --- openpix/resources/payment.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openpix/resources/payment.py b/openpix/resources/payment.py index a1cf122..e18c394 100644 --- a/openpix/resources/payment.py +++ b/openpix/resources/payment.py @@ -61,5 +61,5 @@ def approve(self, correlationID: str) -> payment_types.PaymentApprove: [Click here for more info](https://developers.openpix.com.br/api#tag/payment-(request-access)/paths/~1api~1v1~1payment/post) """ - def create(self, **kwargs) -> payment_types.PaymentCreate: - return self._client.post(path=f'/api/v1/payment', data=kwargs) \ No newline at end of file + def create(self, payload) -> payment_types.PaymentCreate: + return self._client.post(path=f'/api/v1/payment', data=payload) \ No newline at end of file From 48c10ff29bc1b558fb4add40a77bfcf6e01e34c0 Mon Sep 17 00:00:00 2001 From: eletroswing Date: Thu, 30 May 2024 11:38:49 -0300 Subject: [PATCH 17/25] feat(resource): add pix_qr_code resource --- openpix/resources/pix_qr_code.py | 42 ++++++++++++++++++++++---- openpix/resources/pix_qr_code_types.py | 30 ++++++++++++++++++ 2 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 openpix/resources/pix_qr_code_types.py diff --git a/openpix/resources/pix_qr_code.py b/openpix/resources/pix_qr_code.py index 5fb3e31..e75fc65 100644 --- a/openpix/resources/pix_qr_code.py +++ b/openpix/resources/pix_qr_code.py @@ -2,6 +2,7 @@ Module: pix-qr-code """ from openpix.http import HttpClient +import pix_qr_code_types class PixQrCode(): """ @@ -9,12 +10,41 @@ class PixQrCode(): [Click here for more info](https://developers.woovi.com/api#tag/pixQrCode) # pylint: disable=line-too-long """ + def __init__(self, HttpClient: HttpClient): + self._client = HttpClient - def get(self): - return + """Get one Pix QrCode. + Args: + id (str): pixQrCode ID, correlation ID or emv identifier. + + [Click here for more info](https://developers.openpix.com.br/api#tag/pixQrCode/paths/~1api~1v1~1qrcode-static~1%7Bid%7D/get) + """ + def get(self, id: str) -> pix_qr_code_types.PixQrCodeList: + return self._client.get(path=f'/api/v1/qrcode-static/{id}') - def list(self): - return + """Get a list of Pix QrCodes. + Args: + limit (int, optional): itens per page, defaults 10. + skip (int, optional): how many itens are gonna be skipped, default 0. + + [Click here for more info](https://developers.openpix.com.br/api#tag/pixQrCode/paths/~1api~1v1~1qrcode-static/get) + """ + def list(self, limit: int = 10, skip: int = 0) -> pix_qr_code_types.PixQrCodeList: + return self._client.get(path=f'/api/v1/partner/qrcode-static', query={"limit": limit, "skip": skip}) - def create(self): - return \ No newline at end of file + """Create a new Pix QrCode Static + Args: + name (str): Name of this pix qrcode + correlationID (str): Your correlation ID to keep track of this qrcode + value (int): Value in cents of this qrcode + comment (str): Comment to be added in infoPagador + + [Click here for more info](https://developers.openpix.com.br/api#tag/pixQrCode/paths/~1api~1v1~1qrcode-static/post) + """ + def create(self, name: str, correlationID: str, value: int, comment: str) -> pix_qr_code_types.PixQrCodeCreate: + return self._client.post(path=f'/api/v1/partner/qrcode-static', data={ + "name": name, + "correlationID": correlationID, + "value": value, + "comment": comment + }) \ No newline at end of file diff --git a/openpix/resources/pix_qr_code_types.py b/openpix/resources/pix_qr_code_types.py new file mode 100644 index 0000000..5c4b5ab --- /dev/null +++ b/openpix/resources/pix_qr_code_types.py @@ -0,0 +1,30 @@ +from openpix.types import PageInfo +from typing import List + +class PixQrCode: + def __init__(self, name: str, value: str, comment: str, brCode: str, correlationID: str, + paymentLinkID: str, paymentLinkUrl: str, qrCodeImage: str, createdAt: str, updatedAt: str): + self.name = name + self.value = value + self.comment = comment + self.brCode = brCode + self.correlationID = correlationID + self.paymentLinkID = paymentLinkID + self.paymentLinkUrl = paymentLinkUrl + self.qrCodeImage = qrCodeImage + self.createdAt = createdAt + self.updatedAt = updatedAt + + +class PixQrCodeGet: + def __init__(self, pixQrCode: PixQrCode): + self.pixQrCode = pixQrCode + +class PixQrCodeList: + def __init__(self, pageInfo: PageInfo, pixQrCodes: List[PixQrCode]): + self.pageInfo = pageInfo + self.pixQrCodes = pixQrCodes + +class PixQrCodeCreate: + def __init__(self, pixQrCode: PixQrCode): + self.pixQrCode = pixQrCode From 242462c0543be20d38cfa3bfe9b8eb0a7839c99e Mon Sep 17 00:00:00 2001 From: eletroswing Date: Thu, 30 May 2024 11:41:24 -0300 Subject: [PATCH 18/25] fix(small): small fixes and adding myself as an author --- absurdo.js | 6 ------ pyproject.toml | 1 + 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 absurdo.js diff --git a/absurdo.js b/absurdo.js deleted file mode 100644 index cbc3d94..0000000 --- a/absurdo.js +++ /dev/null @@ -1,6 +0,0 @@ -try { - fetch("some endpoint") -} catch (e) {} -finally { - -} \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 82b4464..2a61def 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,6 +3,7 @@ name = "python-sdk" version = "0.1.0" description = "SDK for integration with the Woovi API" authors = [ + "Ytalo da Silva Batalha ", "Camilo Cunha de Azevedo ", "woovi " ] From e90dff235191abdee7f188c300bef77e15fbbad7 Mon Sep 17 00:00:00 2001 From: eletroswing Date: Thu, 30 May 2024 12:01:49 -0300 Subject: [PATCH 19/25] feat(resource): add subscription resource --- openpix/resources/subscription.py | 54 +++++++++++++++++++++++-- openpix/resources/subscription_types.py | 45 +++++++++++++++++++++ 2 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 openpix/resources/subscription_types.py diff --git a/openpix/resources/subscription.py b/openpix/resources/subscription.py index e9ba1e1..bb7fdcd 100644 --- a/openpix/resources/subscription.py +++ b/openpix/resources/subscription.py @@ -2,6 +2,8 @@ Module: subscription """ from openpix.http import HttpClient +import subscription_types +from typing import List class Subscription: """ @@ -12,8 +14,52 @@ class Subscription: def __init__(self, HttpClient: HttpClient): self._client = HttpClient - def get(self): - return + """Get one subscription + Args: + id (str): The globalID or correlationID of the subscription. + + [Click here for more info](https://developers.openpix.com.br/api#tag/subscription/paths/~1api~1v1~1subscriptions~1%7Bid%7D/get) + """ + def get(self, id: str) -> subscription_types.SubscriptionGet: + return self._client.get(path=f'/api/v1/subscriptions/{id}') - def create(self): - return \ No newline at end of file + """Get one subscription + Args: + customer (customer): + - name: str + - email: str + - phone: str + - taxID: + - taxID: str + - type: str + + value (int): Value in cents of this subscription + comment (str): Comment to be added in infoPagador + additionalInfo (list(additionalInfo)): + [ + - key: str + - value: str + ] + dayGenerateCharge (int): Day of the month that the charges will be generated. Maximum of 31. + chargeType (str): The charge type is used to determine whether charges generated by the subscription will have fines and interests + dayDue (int): Days that the charge will take to expire from the generation day. + correlationID (int): Your correlation ID to keep track of this subscription + + [Click here for more info](https://developers.openpix.com.br/api#tag/subscription/paths/~1api~1v1~1subscriptions/post) + """ + def create(self, customer: subscription_types.Customer, value: int, comment: str, additionalInfo: List[subscription_types.AditionalInfo], dayGenerateCharge: int, chargeType: str, dayDue: str, correlationID: str): + return self._client.post(path=f'/api/v1/subscriptions', data={ + "value": value, + "customer": { + "name": customer.name, + "taxID": customer.taxID.taxID, + "email": customer.email, + "phone": customer.phone, + }, + "dayGenerateCharge": dayGenerateCharge, + "chargeType": chargeType, + "comment": comment, + "additionalInfo": additionalInfo, + "dayDue": dayDue, + "correlationID": correlationID + }) \ No newline at end of file diff --git a/openpix/resources/subscription_types.py b/openpix/resources/subscription_types.py new file mode 100644 index 0000000..1a073dc --- /dev/null +++ b/openpix/resources/subscription_types.py @@ -0,0 +1,45 @@ +class TaxID: + def __init__(self, taxID: str, type: str): + self.taxID = taxID + self.type = type + +class Address: + def __init__(self, zipcode: str, street: str, number: str, neighborhood: str, city: str, state: str, complement: str, country: str): + self.zipcode = zipcode + self.street = street + self.number = number + self.neighborhood = neighborhood + self.city = city + self.state = state + self.complement = complement + self.country = country + +class Customer: + def __init__(self, name: str, email: str, phone: str, taxID: TaxID, address: Address): + self.name = name + self.email = email + self.phone = phone + self.taxID = taxID + self.address = address + +class Subscription: + def __init__(self, globalID: str, value: int, customer: Customer, dayGenerateCharge: int, status: str, correlationID: str): + self.globalID = globalID + self.value = value + self.customer = customer + self.dayGenerateCharge = dayGenerateCharge + self.status = status + self.correlationID = correlationID + +class AditionalInfo: + def __init__(self, key: str, value: str): + self.key = key + self.value = value + +class SubscriptionGet: + def __init__(self, subscription: Subscription): + self.subscription = subscription + +class SubscriptionCreate: + def __init__(self, subscription: Subscription): + self.subscription = subscription From c5daf9ece2f44acb5cb08b9387e7d02c3a6f2da0 Mon Sep 17 00:00:00 2001 From: eletroswing Date: Thu, 30 May 2024 12:11:45 -0300 Subject: [PATCH 20/25] feat(resource): add transaction resource --- openpix/resources/transactions.py | 30 ++++++-- openpix/resources/transactions_type.py | 102 +++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 5 deletions(-) create mode 100644 openpix/resources/transactions_type.py diff --git a/openpix/resources/transactions.py b/openpix/resources/transactions.py index b52d5f7..d8fe9dd 100644 --- a/openpix/resources/transactions.py +++ b/openpix/resources/transactions.py @@ -2,6 +2,7 @@ Module: transactions """ from openpix.http import HttpClient +import transactions_type class Transactions: """ @@ -11,9 +12,28 @@ class Transactions: """ def __init__(self, HttpClient: HttpClient): self._client = HttpClient - - def get(self): - return - def list(self): - return \ No newline at end of file + """Get a Transaction + Args: + id (str): you can use the transaction id from openpix or the endToEndId of transaction from bank + + [Click here for more info](https://developers.openpix.com.br/api#tag/transactions/paths/~1api~1v1~1transaction~1%7Bid%7D/get) + """ + def get(self, id: str) -> transactions_type.TransactionsGet: + return self._client.get(path=f'/api/v1/transaction/{id}') + + """Get a list of transactions + Args: + start (str): Start date used in the query. Complies with RFC 3339. + end (str): End date used in the query. Complies with RFC 3339. + charge (str): You can use the charge ID or correlation ID or transaction ID of charge to get a list of transactions related of this transaction + pixQrCode (str): You can use the QrCode static ID or correlation ID or identifier field of QrCode static to get a list of QrCode related of this transaction + withdrawal (str): You can use the ID or EndToEndId of a withdrawal transaction to get all transactions related to the withdrawal + + limit (int, optional): itens per page, defaults 10. + skip (int, optional): how many itens are gonna be skipped, default 0. + + [Click here for more info](https://developers.openpix.com.br/api#tag/transactions/paths/~1api~1v1~1transaction/get) + """ + def list(self, start: str, end: str, charge: str, pixQrCode: str, withdrawal: str, limit: int = 10, skip: int = 0) -> transactions_type.TransactionsList: + return self._client.get(path=f'/api/v1/transaction', query={"start": start, "end": end, "charge": charge, "pixQrCode": pixQrCode, "withdrawal": withdrawal, "limit": limit, "skip": skip}) diff --git a/openpix/resources/transactions_type.py b/openpix/resources/transactions_type.py new file mode 100644 index 0000000..b3e5110 --- /dev/null +++ b/openpix/resources/transactions_type.py @@ -0,0 +1,102 @@ +from openpix.types import PageInfo +from typing import List + +class TaxID: + def __init__(self, taxID: str, type: str): + self.taxID = taxID + self.type = type + +class Address: + def __init__(self, zipcode: str, street: str, number: str, neighborhood: str, city: str, state: str, complement: str, country: str): + self.zipcode = zipcode + self.street = street + self.number = number + self.neighborhood = neighborhood + self.city = city + self.state = state + self.complement = complement + self.country = country + +class Customer: + def __init__(self, name: str, email: str, phone: str, taxID: TaxID, address: Address): + self.name = name + self.email = email + self.phone = phone + self.taxID = taxID + self.address = address + +class AdditionalInfo: + def __init__(self, key: str, value: str): + self.key = key + self.value = value + +class PixQrCode: + def __init__(self, name: str, value: str, comment: str, brCode: str, correlationID: str, + paymentLinkID: str, paymentLinkUrl: str, qrCodeImage: str, createdAt: str, updatedAt: str): + self.name = name + self.value = value + self.comment = comment + self.brCode = brCode + self.correlationID = correlationID + self.paymentLinkID = paymentLinkID + self.paymentLinkUrl = paymentLinkUrl + self.qrCodeImage = qrCodeImage + self.createdAt = createdAt + self.updatedAt = updatedAt + +class Charge: + def __init__(self, value: int, customer: Customer, type: str, comment: str, brCode: str, status: str, correlationID: str, + paymentLinkID: str, paymentLinkUrl: str, globalID: str, transactionID: str, identifier: str, qrCodeImage: str, + additionalInfo: list, pixKey: str, createdAt: str, updatedAt: str, expiresIn: str): + self.value = value + self.customer = customer + self.type = type + self.comment = comment + self.brCode = brCode + self.status = status + self.correlationID = correlationID + self.paymentLinkID = paymentLinkID + self.paymentLinkUrl = paymentLinkUrl + self.globalID = globalID + self.transactionID = transactionID + self.identifier = identifier + self.qrCodeImage = qrCodeImage + self.additionalInfo = additionalInfo + self.pixKey = pixKey + self.createdAt = createdAt + self.updatedAt = updatedAt + self.expiresIn = expiresIn + +class Subscription: + def __init__(self, globalID: str, value: int, customer: Customer, dayGenerateCharge: int, status: str, correlationID: str): + self.globalID = globalID + self.value = value + self.customer = customer + self.dayGenerateCharge = dayGenerateCharge + self.status = status + self.correlationID = correlationID + +class Transaction: + def __init__(self, charge: Charge, value: int, time: str, endToEndID: str, transactionID: str, infoPagador: str, + customer: Customer, withdraw: dict, payer: Customer, type: str, globalID: str, pixQrCode: PixQrCode): + self.charge = charge + self.value = value + self.time = time + self.endToEndID = endToEndID + self.transactionID = transactionID + self.infoPagador = infoPagador + self.customer = customer + self.withdraw = withdraw + self.payer = payer + self.type = type + self.globalID = globalID + self.pixQrCode = pixQrCode + +class TransactionsGet: + def __init__(self, transaction: Transaction): + self.transaction = transaction + +class TransactionsList: + def __init__(self, pageInfo: PageInfo, transactions: List[Transaction]): + self.pageInfo = pageInfo + self.transactions = transactions From 77e6e46dc7d243ed3b30badaaf6111e70a230552 Mon Sep 17 00:00:00 2001 From: eletroswing Date: Thu, 30 May 2024 12:16:04 -0300 Subject: [PATCH 21/25] feat(pagination): add a pagination object --- openpix/resources/account.py | 5 +++-- openpix/resources/charge.py | 7 ++++--- openpix/resources/charge_refund.py | 5 +++-- openpix/resources/customer.py | 6 +++--- openpix/resources/partner.py | 5 +++-- openpix/resources/payment.py | 5 +++-- openpix/resources/pix_qr_code.py | 5 +++-- openpix/resources/refund.py | 5 +++-- openpix/resources/transactions.py | 5 +++-- openpix/types.py | 4 ++++ 10 files changed, 32 insertions(+), 20 deletions(-) diff --git a/openpix/resources/account.py b/openpix/resources/account.py index b5eb569..5e3273f 100644 --- a/openpix/resources/account.py +++ b/openpix/resources/account.py @@ -3,6 +3,7 @@ """ from openpix.http import HttpClient import account_types +from openpix.types import PagePayload class Account: """ @@ -27,8 +28,8 @@ def get(self, accountId: str) -> account_types.AccountInfo: skip (int): number of how many contents will be ignored [Click here for more info](https://developers.woovi.com/api#tag/account/paths/~1api~1v1~1account~1/get) """ - def list(self, limit: int = 10, skip: int = 0) -> account_types.AccountList: - return self._client.get(path=f'/api/v1/account', query={"limit": limit, "skip": skip}) + def list(self, page: PagePayload = PagePayload()) -> account_types.AccountList: + return self._client.get(path=f'/api/v1/account', query={"limit": page.limit, "skip": page.skip}) """Make a withdraw. Args: diff --git a/openpix/resources/charge.py b/openpix/resources/charge.py index 75079e6..7507729 100644 --- a/openpix/resources/charge.py +++ b/openpix/resources/charge.py @@ -3,7 +3,8 @@ """ from openpix.http import HttpClient import charge_types -from typing import List, Union, Optional +from typing import List, Optional +from openpix.types import PagePayload class Charge: """ @@ -32,8 +33,8 @@ def get(self, id: str) -> charge_types.ChargeGet: skip (int): number of how many contents will be ignored [Click here for more info](https://developers.woovi.com/api#tag/charge/paths/~1api~1v1~1charge/get) """ - def list(self, start: str = None, end: str = None, status: str = None, customer: str = None, limit: int = 10, skip: int = 0) -> charge_types.ChargeList: - return self._client.get(path=f'/api/v1/charge/', query={"limit": limit, "skip": skip, start: start, end: end, status: status, customer: customer}) + def list(self, start: str = None, end: str = None, status: str = None, customer: str = None, page: PagePayload = PagePayload()) -> charge_types.ChargeList: + return self._client.get(path=f'/api/v1/charge/', query={"limit": page.limit, "skip": page.skip, start: start, end: end, status: status, customer: customer}) """Delete one charge request Args: diff --git a/openpix/resources/charge_refund.py b/openpix/resources/charge_refund.py index 7f79a4b..90950d1 100644 --- a/openpix/resources/charge_refund.py +++ b/openpix/resources/charge_refund.py @@ -3,6 +3,7 @@ """ from openpix.http import HttpClient import charge_refund_types +from openpix.types import PagePayload class ChargeRefund: """ @@ -20,8 +21,8 @@ def __init__(self, HttpClient: HttpClient): skip (int): number of how many contents will be ignored [Click here for more info](https://developers.woovi.com/api#tag/charge-refund/paths/~1api~1v1~1charge~1%7Bid%7D~1refund/get) """ - def list(self, id: str, limit: int = 10, skip: int = 0) -> charge_refund_types.ChargeRefundList: - return self._client.get(path=f'/api/v1/charge/{id}/refund', query={"limit": limit, "skip": skip}) + def list(self, id: str, page: PagePayload = PagePayload()) -> charge_refund_types.ChargeRefundList: + return self._client.get(path=f'/api/v1/charge/{id}/refund', query={"limit": page.limit, "skip": page.skip}) """Create a new refund for a charge Args: diff --git a/openpix/resources/customer.py b/openpix/resources/customer.py index 6554537..105f7cb 100644 --- a/openpix/resources/customer.py +++ b/openpix/resources/customer.py @@ -2,7 +2,7 @@ Module: customer """ from openpix.http import HttpClient - +from openpix.types import PagePayload import charge_types class Customer: @@ -30,8 +30,8 @@ def get(self, id: str) -> charge_types.CustomerGet: [Click here for more info](https://developers.openpix.com.br/api#tag/customer/paths/~1api~1v1~1customer~1%7Bid%7D/get) """ - def list(self, limit: int = 10, skip: int = 0) -> charge_types.ChargeList: - return self._client.get(path=f'/api/v1/customer', query={"limit": limit, "skip": skip}) + def list(self, page: PagePayload = PagePayload()) -> charge_types.ChargeList: + return self._client.get(path=f'/api/v1/customer', query={"limit": page.limit, "skip": page.skip}) """create a customer Args: diff --git a/openpix/resources/partner.py b/openpix/resources/partner.py index 5d26ac2..36dfc48 100644 --- a/openpix/resources/partner.py +++ b/openpix/resources/partner.py @@ -3,6 +3,7 @@ """ from openpix.http import HttpClient import partner_types +from openpix.types import PagePayload class Partner: """ @@ -29,8 +30,8 @@ def get(self, taxID: str) -> partner_types.PartnerGet: [Click here for more info](https://developers.openpix.com.br/api#tag/partner-(request-access)/paths/~1api~1v1~1partner~1company/get) """ - def list(self, limit: int = 10, skip: int = 0) -> partner_types.PartnerList: - return self._client.get(path=f'/api/v1/partner/company', query={"limit": limit, "skip": skip}) + def list(self, page: PagePayload = PagePayload()) -> partner_types.PartnerList: + return self._client.get(path=f'/api/v1/partner/company', query={"limit": page.limit, "skip": page.skip}) """Create a pre registration with a partner reference (your company) Args: diff --git a/openpix/resources/payment.py b/openpix/resources/payment.py index e18c394..269e45b 100644 --- a/openpix/resources/payment.py +++ b/openpix/resources/payment.py @@ -3,6 +3,7 @@ """ from openpix.http import HttpClient import payment_types +from openpix.types import PagePayload class Payment: """ @@ -29,8 +30,8 @@ def get(self, id: str) -> payment_types.PaymentGet: [Click here for more info](https://developers.openpix.com.br/api#tag/payment-(request-access)/paths/~1api~1v1~1payment~1%7Bid%7D/get) """ - def list(self, limit: int = 10, skip: int = 0) -> payment_types.PaymentList: - return self._client.get(path=f'/api/v1/payment', query={"limit": limit, "skip": skip}) + def list(self, page: PagePayload = PagePayload()) -> payment_types.PaymentList: + return self._client.get(path=f'/api/v1/payment', query={"limit": page.limit, "skip": page.skip}) """approve a payment Args: diff --git a/openpix/resources/pix_qr_code.py b/openpix/resources/pix_qr_code.py index e75fc65..2e62afe 100644 --- a/openpix/resources/pix_qr_code.py +++ b/openpix/resources/pix_qr_code.py @@ -3,6 +3,7 @@ """ from openpix.http import HttpClient import pix_qr_code_types +from openpix.types import PagePayload class PixQrCode(): """ @@ -29,8 +30,8 @@ def get(self, id: str) -> pix_qr_code_types.PixQrCodeList: [Click here for more info](https://developers.openpix.com.br/api#tag/pixQrCode/paths/~1api~1v1~1qrcode-static/get) """ - def list(self, limit: int = 10, skip: int = 0) -> pix_qr_code_types.PixQrCodeList: - return self._client.get(path=f'/api/v1/partner/qrcode-static', query={"limit": limit, "skip": skip}) + def list(self, page: PagePayload = PagePayload()) -> pix_qr_code_types.PixQrCodeList: + return self._client.get(path=f'/api/v1/partner/qrcode-static', query={"limit": page.limit, "skip": page.skip}) """Create a new Pix QrCode Static Args: diff --git a/openpix/resources/refund.py b/openpix/resources/refund.py index a6194e2..45c046c 100644 --- a/openpix/resources/refund.py +++ b/openpix/resources/refund.py @@ -3,6 +3,7 @@ """ from openpix.http import HttpClient import refund_types +from openpix.types import PagePayload class Refund: """ @@ -29,8 +30,8 @@ def get(self, id: str) -> refund_types.RefundGet: [Click here for more info](https://developers.openpix.com.br/api#tag/refund/paths/~1api~1v1~1refund/get) """ - def list(self, limit: int = 10, skip: int = 0) -> refund_types.RefundList: - return self._client.get(path=f'/api/v1/refund', query={"limit": limit, "skip": skip}) + def list(self, page: PagePayload = PagePayload()) -> refund_types.RefundList: + return self._client.get(path=f'/api/v1/refund', query={"limit": page.limit, "skip": page.skip}) """create a refund Args: diff --git a/openpix/resources/transactions.py b/openpix/resources/transactions.py index d8fe9dd..3e460aa 100644 --- a/openpix/resources/transactions.py +++ b/openpix/resources/transactions.py @@ -3,6 +3,7 @@ """ from openpix.http import HttpClient import transactions_type +from openpix.types import PagePayload class Transactions: """ @@ -35,5 +36,5 @@ def get(self, id: str) -> transactions_type.TransactionsGet: [Click here for more info](https://developers.openpix.com.br/api#tag/transactions/paths/~1api~1v1~1transaction/get) """ - def list(self, start: str, end: str, charge: str, pixQrCode: str, withdrawal: str, limit: int = 10, skip: int = 0) -> transactions_type.TransactionsList: - return self._client.get(path=f'/api/v1/transaction', query={"start": start, "end": end, "charge": charge, "pixQrCode": pixQrCode, "withdrawal": withdrawal, "limit": limit, "skip": skip}) + def list(self, start: str, end: str, charge: str, pixQrCode: str, withdrawal: str, page: PagePayload = PagePayload()) -> transactions_type.TransactionsList: + return self._client.get(path=f'/api/v1/transaction', query={"start": start, "end": end, "charge": charge, "pixQrCode": pixQrCode, "withdrawal": withdrawal, "limit": page.limit, "skip": page.skip}) diff --git a/openpix/types.py b/openpix/types.py index 158d8d2..6b035f1 100644 --- a/openpix/types.py +++ b/openpix/types.py @@ -6,3 +6,7 @@ def __init__(self, skip: int, limit: int, totalCount: int, hasPreviousPage: bool self.hasPreviousPage = hasPreviousPage self.hasNextPage = hasNextPage +class PagePayload: + def __init__(self, page: PagePayload = PagePayload()): + self.limit = limit + self.skip = skip \ No newline at end of file From 364c2c538e10e1268ca6756628b7f2d11000ccec Mon Sep 17 00:00:00 2001 From: eletroswing Date: Thu, 30 May 2024 15:09:13 -0300 Subject: [PATCH 22/25] feat(resource): webhook resource --- openpix/resources/customer.py | 3 +- openpix/resources/partner.py | 3 +- openpix/resources/payment.py | 3 +- openpix/resources/pix_qr_code.py | 3 +- openpix/resources/refund.py | 3 +- openpix/resources/transactions.py | 3 +- openpix/resources/webhook.py | 56 ++++++++++++++++++++++++++---- openpix/resources/webhook_types.py | 30 ++++++++++++++++ 8 files changed, 85 insertions(+), 19 deletions(-) create mode 100644 openpix/resources/webhook_types.py diff --git a/openpix/resources/customer.py b/openpix/resources/customer.py index 105f7cb..a4e4501 100644 --- a/openpix/resources/customer.py +++ b/openpix/resources/customer.py @@ -25,8 +25,7 @@ def get(self, id: str) -> charge_types.CustomerGet: """list customers Args: - limit (int, optional): itens per page, defaults 10. - skip (int, optional): how many itens are gonna be skipped, default 0. + page (PageInfo): A class for page info object containing limit and skip [Click here for more info](https://developers.openpix.com.br/api#tag/customer/paths/~1api~1v1~1customer~1%7Bid%7D/get) """ diff --git a/openpix/resources/partner.py b/openpix/resources/partner.py index 36dfc48..14af47a 100644 --- a/openpix/resources/partner.py +++ b/openpix/resources/partner.py @@ -25,8 +25,7 @@ def get(self, taxID: str) -> partner_types.PartnerGet: """Get every preregistration that is managed by you. Args: - limit (int, optional): itens per page, defaults 10. - skip (int, optional): how many itens are gonna be skipped, default 0. + page (PageInfo): A class for page info object containing limit and skip [Click here for more info](https://developers.openpix.com.br/api#tag/partner-(request-access)/paths/~1api~1v1~1partner~1company/get) """ diff --git a/openpix/resources/payment.py b/openpix/resources/payment.py index 269e45b..1896c7e 100644 --- a/openpix/resources/payment.py +++ b/openpix/resources/payment.py @@ -25,8 +25,7 @@ def get(self, id: str) -> payment_types.PaymentGet: """list payments Args: - limit (int, optional): itens per page, defaults 10. - skip (int, optional): how many itens are gonna be skipped, default 0. + page (PageInfo): A class for page info object containing limit and skip [Click here for more info](https://developers.openpix.com.br/api#tag/payment-(request-access)/paths/~1api~1v1~1payment~1%7Bid%7D/get) """ diff --git a/openpix/resources/pix_qr_code.py b/openpix/resources/pix_qr_code.py index 2e62afe..c4c9b37 100644 --- a/openpix/resources/pix_qr_code.py +++ b/openpix/resources/pix_qr_code.py @@ -25,8 +25,7 @@ def get(self, id: str) -> pix_qr_code_types.PixQrCodeList: """Get a list of Pix QrCodes. Args: - limit (int, optional): itens per page, defaults 10. - skip (int, optional): how many itens are gonna be skipped, default 0. + page (PageInfo): A class for page info object containing limit and skip [Click here for more info](https://developers.openpix.com.br/api#tag/pixQrCode/paths/~1api~1v1~1qrcode-static/get) """ diff --git a/openpix/resources/refund.py b/openpix/resources/refund.py index 45c046c..9188ebe 100644 --- a/openpix/resources/refund.py +++ b/openpix/resources/refund.py @@ -25,8 +25,7 @@ def get(self, id: str) -> refund_types.RefundGet: """list refunds Args: - limit (int, optional): itens per page, defaults 10. - skip (int, optional): how many itens are gonna be skipped, default 0. + page (PageInfo): A class for page info object containing limit and skip [Click here for more info](https://developers.openpix.com.br/api#tag/refund/paths/~1api~1v1~1refund/get) """ diff --git a/openpix/resources/transactions.py b/openpix/resources/transactions.py index 3e460aa..4887f26 100644 --- a/openpix/resources/transactions.py +++ b/openpix/resources/transactions.py @@ -31,8 +31,7 @@ def get(self, id: str) -> transactions_type.TransactionsGet: pixQrCode (str): You can use the QrCode static ID or correlation ID or identifier field of QrCode static to get a list of QrCode related of this transaction withdrawal (str): You can use the ID or EndToEndId of a withdrawal transaction to get all transactions related to the withdrawal - limit (int, optional): itens per page, defaults 10. - skip (int, optional): how many itens are gonna be skipped, default 0. + page (PageInfo): A class for page info object containing limit and skip [Click here for more info](https://developers.openpix.com.br/api#tag/transactions/paths/~1api~1v1~1transaction/get) """ diff --git a/openpix/resources/webhook.py b/openpix/resources/webhook.py index e185372..d5d4f32 100644 --- a/openpix/resources/webhook.py +++ b/openpix/resources/webhook.py @@ -2,6 +2,8 @@ Module: webhook """ from openpix.http import HttpClient +import webhook_types +from openpix.types import PagePayload class Webhook: """ @@ -11,12 +13,52 @@ class Webhook: """ def __init__(self, HttpClient: HttpClient): self._client = HttpClient - - def list(self): - return - def delete(self): - return + """Get a list of webhook IPs + Args: + page (PageInfo): A class for page info object containing limit and skip + + [Click here for more info](https://developers.openpix.com.br/api#tag/webhook/paths/~1api~1v1~1webhook~1ips/get) + """ + def list_ips(self, page: PagePayload = PagePayload()) -> webhook_types.WebhookListIps: + return self._client.get(path=f'/api/v1/webhook/ips', query={"limit": page.limit, "skip": page.skip}) + + """Get a list of webhooks + Args: + page (PageInfo): A class for page info object containing limit and skip + + [Click here for more info](https://developers.openpix.com.br/api#tag/webhook/paths/~1api~1v1~1webhook/get) + """ + def list(self, page: PagePayload = PagePayload()) -> webhook_types.WebhookList: + return self._client.get(path=f'/api/v1/webhook', query={"limit": page.limit, "skip": page.skip}) - def create(self): - return \ No newline at end of file + """Delete a Webhook + Args: + id (str): A class for page info object containing limit and skip + + [Click here for more info](https://developers.openpix.com.br/api#tag/webhook/paths/~1api~1v1~1webhook~1%7Bid%7D/delete) + """ + def delete(self, id: str) -> webhook_types.WebhookDelete: + return self._client.delete(path=f'/api/v1/webhook/{id}') + + """Create a new Webhook + Args: + id (str): identifier of the webhook + name (str): the name of the webhook + event (str): Available events to register a webhook to listen to. If no one selected anyone the default event will be OPENPIX:TRANSACTION_RECEIVED. + url (str): webhook endpoint to be called + isActive (bool): if the endpoint is active + authorization (str): authorization to your endpoint + + [Click here for more info](https://developers.openpix.com.br/api#tag/webhook/paths/~1api~1v1~1webhook/post) + """ + def create(self, name: str, event: str, url: str, authorization: str, isActive: bool) -> webhook_types.WebhookCreate: + return self._client.post(path=f'/api/v1/webhook', data={ + "webhook": { + "name": name, + "event": event, + "url": url, + "isActive": isActive, + "authorization": "authorization" + } + }) diff --git a/openpix/resources/webhook_types.py b/openpix/resources/webhook_types.py new file mode 100644 index 0000000..dbed091 --- /dev/null +++ b/openpix/resources/webhook_types.py @@ -0,0 +1,30 @@ +from openpix.types import PageInfo +from typing import List + +class Webhook: + def __init__(self, id: str, name: str, event: str, url: str, authorization: str, isActive: bool, createdAt: str, updatedAt: str): + self.id = id + self.name = name + self.event = event + self.url = url + self.authorization = authorization + self.isActive = isActive + self.createdAt = createdAt + self.updatedAt = updatedAt + +class WebhookListIps: + def __init__(self, ips: List[str]): + self.ips = ips + +class WebhookList: + def __init__(self, pageInfo: PageInfo, webhooks: List[Webhook]): + self.pageInfo = pageInfo + self.webhooks = webhooks + +class WebhookDelete: + def __init__(self, status: str): + self.status = status + +class WebhookCreate: + def __init__(self, webhook: Webhook): + self.webhook = webhook From 3572d35a4a222fc959001ede1bb1b15ef9f53343 Mon Sep 17 00:00:00 2001 From: eletroswing Date: Thu, 30 May 2024 17:53:36 -0300 Subject: [PATCH 23/25] feat(resource): subaccount resource --- openpix/resources/sub_account.py | 69 ++++++++++++++++++++++---- openpix/resources/sub_account_types.py | 56 +++++++++++++++++++++ 2 files changed, 116 insertions(+), 9 deletions(-) create mode 100644 openpix/resources/sub_account_types.py diff --git a/openpix/resources/sub_account.py b/openpix/resources/sub_account.py index cac38af..e7f8009 100644 --- a/openpix/resources/sub_account.py +++ b/openpix/resources/sub_account.py @@ -2,6 +2,8 @@ Module: sub-account """ from openpix.http import HttpClient +import sub_account_types +from openpix.types import PagePayload class SubAccount(): """ @@ -12,14 +14,63 @@ class SubAccount(): def __init__(self, HttpClient: HttpClient): self._client = HttpClient - def get(self): - return + """Get subaccount details + Args: + id (str): pix key registered to the subaccount + + [Click here for more info](https://developers.openpix.com.br/api#tag/sub-account-(request-access)/paths/~1api~1v1~1subaccount~1%7Bid%7D/get) + """ + def get(self, id: str) -> sub_account_types.SubAccountGet: + return self._client.get(path=f'/api/v1/subaccount/{id}') + + """Get a list of subaccounts + Args: + page (PageInfo): A class for page info object containing limit and skip + + [Click here for more info](https://developers.openpix.com.br/api#tag/sub-account-(request-access)/paths/~1api~1v1~1subaccount/get) + """ + def list(self, page: PagePayload = PagePayload()) -> sub_account_types.SubAccountList: + return self._client.get(path=f'/api/v1/subaccount', query={"limit": page.limit, "skip": page.skip}) - def list(self): - return + """Create a subaccount + Args: + id (str): pix key registered to the subaccount + + [Click here for more info](https://developers.openpix.com.br/api#tag/sub-account-(request-access)/paths/~1api~1v1~1subaccount~1%7Bid%7D~1withdraw/post) + """ + def withdraw(self, id: str) -> sub_account_types.WithdrawCreate: + return self._client.post(path=f'/api/v1/subaccount/{id}/withdraw') - def withdraw(self): - return - - def create(self): - return \ No newline at end of file + """Create a subaccount + Args: + pixKey (str): The pix key for the sub account + name (str): Name of the sub account + + [Click here for more info](https://developers.openpix.com.br/api#tag/sub-account-(request-access)/paths/~1api~1v1~1subaccount/post) + """ + def create(self, pixKey: str, name: str) -> sub_account_types.SubAccountCreate: + return self._client.post(path=f'/api/v1/subaccount', data={ + "pixKey": pixKey, + "name": name + }) + + """Transfer between subaccounts + Args: + value (int): The value of the transfer in cents + fromPixKey (str): The transfer origin pix key + fromPixKeyType (str): The transfer origin pix key type. Enum: "CPF" "CNPJ" "EMAIL" "PHONE" "RANDOM" + toPixKey (str): The transfer destination pix key + toPixKeyType (str): The transfer destination pix key type. Enum: "CPF" "CNPJ" "EMAIL" "PHONE" "RANDOM" + correlationID (str): Your correlation ID to keep track of this transfer + + [Click here for more info](https://developers.openpix.com.br/api#tag/sub-account-(request-access)/paths/~1api~1v1~1subaccount~1transfer/post) + """ + def transfer(self, value: int, fromPixKey: str, fromPixKeyType: str, toPixKey: str, toPixKeyType: str, correlationID: str) -> sub_account_types.TransferCreate: + return self._client.post(path=f'/api/v1/subaccount/transfer', data={ + "value": value, + "fromPixKey": fromPixKey, + "fromPixKeyType": fromPixKeyType, + "toPixKey": toPixKey, + "toPixKeyType": toPixKeyType, + "correlationID": correlationID, + }) \ No newline at end of file diff --git a/openpix/resources/sub_account_types.py b/openpix/resources/sub_account_types.py new file mode 100644 index 0000000..2af9ef5 --- /dev/null +++ b/openpix/resources/sub_account_types.py @@ -0,0 +1,56 @@ +from openpix.types import PageInfo +from typing import List + +class SubAccount: + def __init__(self, name: str, pixKey: str, balance: int): + self.name = name + self.pixKey = pixKey + self.balance = balance + +class Transaction: + def __init__(self, status: str, value: int, correlationID: str, destinationAlias: str, comment: str): + self.status = status + self.value = value + self.correlationID = correlationID + self.destinationAlias = destinationAlias + self.comment = comment + +class SubAccountCreate: + def __init__(self, name: str, pixKey: str): + self.name = name + self.pixKey = pixKey + +class DestinationSubaccount: + def __init__(self, name: str, pixKey: str, value: int): + self.name = name + self.pixKey = pixKey + self.value = value + +class OriginSubaccount: + def __init__(self, name: str, pixKey: str, value: int): + self.name = name + self.pixKey = pixKey + self.value = value + +class SubAccountGet: + def __init__(self, SubAccount: SubAccount): + self.SubAccount = SubAccount + +class SubAccountList: + def __init__(self, pageInfo: PageInfo, subAccounts: List[SubAccount]): + self.pageInfo = pageInfo + self.subAccounts = subAccounts + +class WithdrawCreate: + def __init__(self, transaction: Transaction): + self.transaction = transaction + +class SubAccountCreate: + def __init__(self, SubAccount: SubAccountCreate): + self.SubAccount = SubAccount + +class TransferCreate: + def __init__(self, value: int, destinationSubaccount: DestinationSubaccount, originSubaccount: OriginSubaccount): + self.value = value + self.destinationSubaccount = destinationSubaccount + self.originSubaccount = originSubaccount From b5ef161e787bc6ece96222d3e96eba598fa4df5d Mon Sep 17 00:00:00 2001 From: eletroswing Date: Thu, 30 May 2024 18:07:07 -0300 Subject: [PATCH 24/25] fix(type): import type error --- openpix/resources/account.py | 2 +- openpix/resources/cashback_fidelity.py | 2 +- openpix/resources/charge.py | 2 +- openpix/resources/charge_refund.py | 2 +- openpix/resources/customer.py | 2 +- openpix/resources/partner.py | 2 +- openpix/resources/payment.py | 2 +- openpix/resources/pix_qr_code.py | 2 +- openpix/resources/refund.py | 2 +- openpix/resources/sub_account.py | 2 +- openpix/resources/subscription.py | 2 +- openpix/resources/transfer.py | 2 +- openpix/resources/webhook.py | 2 +- tests/test_account.py | 50 ++++++++++++++++++++++++++ tests/webhook.py | 0 15 files changed, 63 insertions(+), 13 deletions(-) delete mode 100644 tests/webhook.py diff --git a/openpix/resources/account.py b/openpix/resources/account.py index 5e3273f..9b0fbea 100644 --- a/openpix/resources/account.py +++ b/openpix/resources/account.py @@ -2,7 +2,7 @@ Module: account """ from openpix.http import HttpClient -import account_types +openpix.resources. from openpix.types import PagePayload class Account: diff --git a/openpix/resources/cashback_fidelity.py b/openpix/resources/cashback_fidelity.py index 72578aa..539d6ef 100644 --- a/openpix/resources/cashback_fidelity.py +++ b/openpix/resources/cashback_fidelity.py @@ -2,7 +2,7 @@ Module: cashback_fidelity """ from openpix.http import HttpClient -import cashback_fidelity_types +openpix.resources. class CashbackFidelity: """ diff --git a/openpix/resources/charge.py b/openpix/resources/charge.py index 7507729..86e21ce 100644 --- a/openpix/resources/charge.py +++ b/openpix/resources/charge.py @@ -2,7 +2,7 @@ Module: charge """ from openpix.http import HttpClient -import charge_types +openpix.resources. from typing import List, Optional from openpix.types import PagePayload diff --git a/openpix/resources/charge_refund.py b/openpix/resources/charge_refund.py index 90950d1..3ceaceb 100644 --- a/openpix/resources/charge_refund.py +++ b/openpix/resources/charge_refund.py @@ -2,7 +2,7 @@ Module: charge_refund """ from openpix.http import HttpClient -import charge_refund_types +openpix.resources. from openpix.types import PagePayload class ChargeRefund: diff --git a/openpix/resources/customer.py b/openpix/resources/customer.py index a4e4501..3e50c6c 100644 --- a/openpix/resources/customer.py +++ b/openpix/resources/customer.py @@ -3,7 +3,7 @@ """ from openpix.http import HttpClient from openpix.types import PagePayload -import charge_types +openpix.resources. class Customer: """ diff --git a/openpix/resources/partner.py b/openpix/resources/partner.py index 14af47a..1b2cc92 100644 --- a/openpix/resources/partner.py +++ b/openpix/resources/partner.py @@ -2,7 +2,7 @@ Module: partner """ from openpix.http import HttpClient -import partner_types +openpix.resources. from openpix.types import PagePayload class Partner: diff --git a/openpix/resources/payment.py b/openpix/resources/payment.py index 1896c7e..a0c4228 100644 --- a/openpix/resources/payment.py +++ b/openpix/resources/payment.py @@ -2,7 +2,7 @@ Module: payment """ from openpix.http import HttpClient -import payment_types +openpix.resources. from openpix.types import PagePayload class Payment: diff --git a/openpix/resources/pix_qr_code.py b/openpix/resources/pix_qr_code.py index c4c9b37..af8fb0f 100644 --- a/openpix/resources/pix_qr_code.py +++ b/openpix/resources/pix_qr_code.py @@ -2,7 +2,7 @@ Module: pix-qr-code """ from openpix.http import HttpClient -import pix_qr_code_types +openpix.resources. from openpix.types import PagePayload class PixQrCode(): diff --git a/openpix/resources/refund.py b/openpix/resources/refund.py index 9188ebe..e7b5c72 100644 --- a/openpix/resources/refund.py +++ b/openpix/resources/refund.py @@ -2,7 +2,7 @@ Module: refund """ from openpix.http import HttpClient -import refund_types +openpix.resources. from openpix.types import PagePayload class Refund: diff --git a/openpix/resources/sub_account.py b/openpix/resources/sub_account.py index e7f8009..1456ee7 100644 --- a/openpix/resources/sub_account.py +++ b/openpix/resources/sub_account.py @@ -2,7 +2,7 @@ Module: sub-account """ from openpix.http import HttpClient -import sub_account_types +openpix.resources. from openpix.types import PagePayload class SubAccount(): diff --git a/openpix/resources/subscription.py b/openpix/resources/subscription.py index bb7fdcd..e602dba 100644 --- a/openpix/resources/subscription.py +++ b/openpix/resources/subscription.py @@ -2,7 +2,7 @@ Module: subscription """ from openpix.http import HttpClient -import subscription_types +openpix.resources. from typing import List class Subscription: diff --git a/openpix/resources/transfer.py b/openpix/resources/transfer.py index 8d8f2fc..0732aa8 100644 --- a/openpix/resources/transfer.py +++ b/openpix/resources/transfer.py @@ -2,7 +2,7 @@ Module: transfer """ from openpix.http import HttpClient -import transfer_types +openpix.resources. class Transfer: """ diff --git a/openpix/resources/webhook.py b/openpix/resources/webhook.py index d5d4f32..66d6cdb 100644 --- a/openpix/resources/webhook.py +++ b/openpix/resources/webhook.py @@ -2,7 +2,7 @@ Module: webhook """ from openpix.http import HttpClient -import webhook_types +openpix.resources. from openpix.types import PagePayload class Webhook: diff --git a/tests/test_account.py b/tests/test_account.py index e69de29..8bd7585 100644 --- a/tests/test_account.py +++ b/tests/test_account.py @@ -0,0 +1,50 @@ +# test_get.py +import pytest +import responses +from openpix.http import HttpClient +import openpix.resources.account as app + +@pytest.fixture +def client(): + return HttpClient(app_id='123') + +@pytest.fixture +def resource(client): + return app(client) + +@responses.activate +def test_should_get_error(resource): + responses.add( + responses.GET, + 'https://api.openpix.com.br/api/v1/account/some-id', + json={'error': 'not exists'}, + status=400 + ) + + with pytest.raises(Exception) as excinfo: + resource({'id': 'some_id'}) + assert excinfo.value.args[0] == {'error': 'not exists'} + +@responses.activate +def test_should_have_success(resource): + account = { + 'account': { + 'accountId': '6290ccfd42831958a405debc', + 'isDefault': True, + 'balance': { + 'total': 129430, + 'blocked': 0, + 'available': 129430, + }, + }, + } + + responses.add( + responses.GET, + 'https://api.openpix.com.br/api/v1/account/some-id', + json={'account': account}, + status=200 + ) + + response = resource({'id': 'some_id'}) + assert response == {'account': account} diff --git a/tests/webhook.py b/tests/webhook.py deleted file mode 100644 index e69de29..0000000 From fffeda62ba494ef8e4b4ff735d734626e4d2288e Mon Sep 17 00:00:00 2001 From: eletroswing Date: Thu, 30 May 2024 18:46:07 -0300 Subject: [PATCH 25/25] fix(usable): already to use? --- openpix/http/http_client.py | 12 +++---- openpix/resources/account.py | 2 +- openpix/resources/cashback_fidelity.py | 2 +- openpix/resources/charge.py | 2 +- openpix/resources/charge_refund.py | 2 +- openpix/resources/customer.py | 10 +++--- openpix/resources/partner.py | 2 +- openpix/resources/payment.py | 2 +- openpix/resources/pix_qr_code.py | 2 +- openpix/resources/refund.py | 2 +- openpix/resources/sub_account.py | 2 +- openpix/resources/subscription.py | 2 +- openpix/resources/transactions.py | 2 +- openpix/resources/transfer.py | 2 +- openpix/resources/webhook.py | 2 +- openpix/types.py | 2 +- tests/test_account.py | 50 -------------------------- 17 files changed, 23 insertions(+), 77 deletions(-) diff --git a/openpix/http/http_client.py b/openpix/http/http_client.py index 7d02c16..36e662a 100644 --- a/openpix/http/http_client.py +++ b/openpix/http/http_client.py @@ -10,7 +10,7 @@ class HttpClient: def __init__(self, app_id): self._app_id = app_id - self.base_url = "https://api.woovi.com" + self.base_url = "https://api.openpix.com.br" def request(self, method, path, query, maxretries=None, data = None, **kwargs): """Makes a call to the API. @@ -40,13 +40,9 @@ def request(self, method, path, query, maxretries=None, data = None, **kwargs): with http as session: api_result = session.request(method, url, data=data,**kwargs) - response = { - "status": api_result.status_code, - "response": api_result.json() - } - - if response["status"] > 299: - raise ValueError(response["response"]) + response = api_result.json() + if api_result.status_code > 299: + raise ValueError(response) return response diff --git a/openpix/resources/account.py b/openpix/resources/account.py index 9b0fbea..1f9a985 100644 --- a/openpix/resources/account.py +++ b/openpix/resources/account.py @@ -2,7 +2,7 @@ Module: account """ from openpix.http import HttpClient -openpix.resources. +import openpix.resources.account_types as account_types from openpix.types import PagePayload class Account: diff --git a/openpix/resources/cashback_fidelity.py b/openpix/resources/cashback_fidelity.py index 539d6ef..597ad5b 100644 --- a/openpix/resources/cashback_fidelity.py +++ b/openpix/resources/cashback_fidelity.py @@ -2,7 +2,7 @@ Module: cashback_fidelity """ from openpix.http import HttpClient -openpix.resources. +import openpix.resources.cashback_fidelity_types as cashback_fidelity_types class CashbackFidelity: """ diff --git a/openpix/resources/charge.py b/openpix/resources/charge.py index 86e21ce..5569f8a 100644 --- a/openpix/resources/charge.py +++ b/openpix/resources/charge.py @@ -2,7 +2,7 @@ Module: charge """ from openpix.http import HttpClient -openpix.resources. +import openpix.resources.charge_types as charge_types from typing import List, Optional from openpix.types import PagePayload diff --git a/openpix/resources/charge_refund.py b/openpix/resources/charge_refund.py index 3ceaceb..7ac330b 100644 --- a/openpix/resources/charge_refund.py +++ b/openpix/resources/charge_refund.py @@ -2,7 +2,7 @@ Module: charge_refund """ from openpix.http import HttpClient -openpix.resources. +import openpix.resources.charge_refund_types as charge_refund_types from openpix.types import PagePayload class ChargeRefund: diff --git a/openpix/resources/customer.py b/openpix/resources/customer.py index 3e50c6c..e222d9d 100644 --- a/openpix/resources/customer.py +++ b/openpix/resources/customer.py @@ -3,7 +3,7 @@ """ from openpix.http import HttpClient from openpix.types import PagePayload -openpix.resources. +import openpix.resources.customer_types as customer_types class Customer: """ @@ -20,7 +20,7 @@ def __init__(self, HttpClient: HttpClient): [Click here for more info](https://developers.openpix.com.br/api#tag/customer/paths/~1api~1v1~1customer~1%7Bid%7D/get) """ - def get(self, id: str) -> charge_types.CustomerGet: + def get(self, id: str) -> customer_types.CustomerGet: return self._client.get(path=f'/api/v1/customer/{id}') """list customers @@ -29,7 +29,7 @@ def get(self, id: str) -> charge_types.CustomerGet: [Click here for more info](https://developers.openpix.com.br/api#tag/customer/paths/~1api~1v1~1customer~1%7Bid%7D/get) """ - def list(self, page: PagePayload = PagePayload()) -> charge_types.ChargeList: + def list(self, page: PagePayload = PagePayload()) -> customer_types.CustomerList: return self._client.get(path=f'/api/v1/customer', query={"limit": page.limit, "skip": page.skip}) """create a customer @@ -51,7 +51,7 @@ def list(self, page: PagePayload = PagePayload()) -> charge_types.ChargeList: [Click here for more info](https://developers.openpix.com.br/api#tag/customer/paths/~1api~1v1~1customer/post) """ - def create(self, name: str, email: str, phone: str, taxID: str, address: charge_types.Address) -> charge_types.CustomerCreate: + def create(self, name: str, email: str, phone: str, taxID: str, address: customer_types.Address) -> customer_types.CustomerCreate: return self._client.post(path=f'/api/v1/customer', data={ 'name': name, 'phone': phone, @@ -88,7 +88,7 @@ def create(self, name: str, email: str, phone: str, taxID: str, address: charge_ [Click here for more info](https://developers.openpix.com.br/api#tag/customer/paths/~1api~1v1~1customer/post) """ - def update(self, correlationID: str, name: str, email: str, phone: str, taxID: str, address: charge_types.Address) -> charge_types.CustomerUpdate: + def update(self, correlationID: str, name: str, email: str, phone: str, taxID: str, address: customer_types.Address) -> customer_types.CustomerUpdate: return self._client.patch(path=f'/api/v1/customer/{correlationID}', data={ 'name': name, 'phone': phone, diff --git a/openpix/resources/partner.py b/openpix/resources/partner.py index 1b2cc92..73cefb8 100644 --- a/openpix/resources/partner.py +++ b/openpix/resources/partner.py @@ -2,7 +2,7 @@ Module: partner """ from openpix.http import HttpClient -openpix.resources. +import openpix.resources.partner_types as partner_types from openpix.types import PagePayload class Partner: diff --git a/openpix/resources/payment.py b/openpix/resources/payment.py index a0c4228..d764765 100644 --- a/openpix/resources/payment.py +++ b/openpix/resources/payment.py @@ -2,7 +2,7 @@ Module: payment """ from openpix.http import HttpClient -openpix.resources. +import openpix.resources.payment_types as payment_types from openpix.types import PagePayload class Payment: diff --git a/openpix/resources/pix_qr_code.py b/openpix/resources/pix_qr_code.py index af8fb0f..ea8df78 100644 --- a/openpix/resources/pix_qr_code.py +++ b/openpix/resources/pix_qr_code.py @@ -2,7 +2,7 @@ Module: pix-qr-code """ from openpix.http import HttpClient -openpix.resources. +import openpix.resources.pix_qr_code_types as pix_qr_code_types from openpix.types import PagePayload class PixQrCode(): diff --git a/openpix/resources/refund.py b/openpix/resources/refund.py index e7b5c72..4be66b0 100644 --- a/openpix/resources/refund.py +++ b/openpix/resources/refund.py @@ -2,7 +2,7 @@ Module: refund """ from openpix.http import HttpClient -openpix.resources. +import openpix.resources.refund_types as refund_types from openpix.types import PagePayload class Refund: diff --git a/openpix/resources/sub_account.py b/openpix/resources/sub_account.py index 1456ee7..2b3daea 100644 --- a/openpix/resources/sub_account.py +++ b/openpix/resources/sub_account.py @@ -2,7 +2,7 @@ Module: sub-account """ from openpix.http import HttpClient -openpix.resources. +import openpix.resources.sub_account_types as sub_account_types from openpix.types import PagePayload class SubAccount(): diff --git a/openpix/resources/subscription.py b/openpix/resources/subscription.py index e602dba..852b3f2 100644 --- a/openpix/resources/subscription.py +++ b/openpix/resources/subscription.py @@ -2,7 +2,7 @@ Module: subscription """ from openpix.http import HttpClient -openpix.resources. +import openpix.resources.subscription_types as subscription_types from typing import List class Subscription: diff --git a/openpix/resources/transactions.py b/openpix/resources/transactions.py index 4887f26..dbcdf8b 100644 --- a/openpix/resources/transactions.py +++ b/openpix/resources/transactions.py @@ -2,7 +2,7 @@ Module: transactions """ from openpix.http import HttpClient -import transactions_type +import openpix.resources.transactions_type as transactions_type from openpix.types import PagePayload class Transactions: diff --git a/openpix/resources/transfer.py b/openpix/resources/transfer.py index 0732aa8..410ad10 100644 --- a/openpix/resources/transfer.py +++ b/openpix/resources/transfer.py @@ -2,7 +2,7 @@ Module: transfer """ from openpix.http import HttpClient -openpix.resources. +import openpix.resources.transfer_types as transfer_types class Transfer: """ diff --git a/openpix/resources/webhook.py b/openpix/resources/webhook.py index 66d6cdb..ff871b7 100644 --- a/openpix/resources/webhook.py +++ b/openpix/resources/webhook.py @@ -2,7 +2,7 @@ Module: webhook """ from openpix.http import HttpClient -openpix.resources. +import openpix.resources.webhook_types as webhook_types from openpix.types import PagePayload class Webhook: diff --git a/openpix/types.py b/openpix/types.py index 6b035f1..a8f3083 100644 --- a/openpix/types.py +++ b/openpix/types.py @@ -7,6 +7,6 @@ def __init__(self, skip: int, limit: int, totalCount: int, hasPreviousPage: bool self.hasNextPage = hasNextPage class PagePayload: - def __init__(self, page: PagePayload = PagePayload()): + def __init__(self, limit: int = 10, skip:int = 0): self.limit = limit self.skip = skip \ No newline at end of file diff --git a/tests/test_account.py b/tests/test_account.py index 8bd7585..e69de29 100644 --- a/tests/test_account.py +++ b/tests/test_account.py @@ -1,50 +0,0 @@ -# test_get.py -import pytest -import responses -from openpix.http import HttpClient -import openpix.resources.account as app - -@pytest.fixture -def client(): - return HttpClient(app_id='123') - -@pytest.fixture -def resource(client): - return app(client) - -@responses.activate -def test_should_get_error(resource): - responses.add( - responses.GET, - 'https://api.openpix.com.br/api/v1/account/some-id', - json={'error': 'not exists'}, - status=400 - ) - - with pytest.raises(Exception) as excinfo: - resource({'id': 'some_id'}) - assert excinfo.value.args[0] == {'error': 'not exists'} - -@responses.activate -def test_should_have_success(resource): - account = { - 'account': { - 'accountId': '6290ccfd42831958a405debc', - 'isDefault': True, - 'balance': { - 'total': 129430, - 'blocked': 0, - 'available': 129430, - }, - }, - } - - responses.add( - responses.GET, - 'https://api.openpix.com.br/api/v1/account/some-id', - json={'account': account}, - status=200 - ) - - response = resource({'id': 'some_id'}) - assert response == {'account': account}