From 075021cf25ae191326afa4c7e11f9aa6505e0887 Mon Sep 17 00:00:00 2001 From: Wendel de Oliveira Silvestre Date: Thu, 26 Oct 2023 17:15:48 -0300 Subject: [PATCH] Add Split and SplitReceiver resources --- CHANGELOG.md | 5 + README.md | 110 +++++++++++++++++++++ starkbank/split/__split.py | 28 +++--- starkbank/splitreceiver/__splitreceiver.py | 3 +- 4 files changed, 132 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed18594..59fe8bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,11 @@ Given a version number MAJOR.MINOR.PATCH, increment: ## [Unreleased] +### Added +- Split resource +- SplitLog resource +- SplitReceiver resource +- SplitReceiverLog resource ## [2.22.0] - 2023-09-18 ### Removed diff --git a/README.md b/README.md index c39a30c..586a4de 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,8 @@ is as easy as sending a text message to your client! - [CorporateBalance](#get-your-corporatebalance): View your corporate balance - [CorporateTransactions](#query-corporatetransactions): View the transactions that have affected your corporate balance - [CorporateEnums](#corporate-enums): Query enums related to the corporate purchases, such as merchant categories, countries and card purchase methods + - [Split](#query-a-split): Split invoices + - [SplitReceiver](#query-a-split-receiver): Receiver of an invoice split - [Webhooks](#create-a-webhook-subscription): Configure your webhook endpoints and subscriptions - [WebhookEvents](#process-webhook-events): Manage webhook events - [WebhookEventAttempts](#query-failed-webhook-event-delivery-attempts-information): Query failed webhook event deliveries @@ -2167,6 +2169,114 @@ for method in methods: print(method) ``` +## Split + +Split an invoice to different receivers + +## Query a Split + +You can get a list of created splits given some filters. + +```python +import starkbank + +splits = starkbank.split.query(limit=10) + +for split in splits: + print(split) +``` + +## Get a Split + +To get a single Split by its id, run: + +```python +import starkbank + +split = starkbank.split.get("5155165527080960") + +print(split) +``` + +## Query split logs + +You can query split logs to check additional information + +```python +import starkbank + +logs = starkbank.split.log.query( + split_ids=["5155165527080960", "76551659167801921"], +) + +for log in logs: + print(log) +``` + +## Get a split log + +You can also get a split log by specifying its id. + +```python +import starkbank + +log = starkbank.split.log.get("5155165527080960") + +print(log) +``` + +## Query a split receiver + +To take a look at the receivers created to your workspace, just run the following: + +```python +import starkbank + +receivers = starkbank.splitreceiver.query(limit=10) + +for receiver in receivers: + print(receiver) +``` + +## Get a split receiver + +To get a single Receiver by its id, run: + +```python +import starkbank + +receiver = starkbank.splitreceiver.get("5155165527080960") + +print(receiver) +``` + +## Query a split receiver logs + +You can query split receiver logs to check additional information + +```python +import starkbank + +logs = starkbank.splitreceiver.log.query( + receiver_ids =["5155165527080960", "76551659167801921"], +) + +for log in logs: + print(log) +``` + +## Get a split receiver log + +You can also get a split receiver log by specifying its id. + +```python +import starkbank + +log = starkbank.splitreceiver.log.get("5155165527080960") + +print(log) +``` + ## Create a webhook subscription To create a webhook subscription and be notified whenever an event occurs, run: diff --git a/starkbank/split/__split.py b/starkbank/split/__split.py index 8ffb642..38ee689 100644 --- a/starkbank/split/__split.py +++ b/starkbank/split/__split.py @@ -10,32 +10,32 @@ class Split(Resource): created in the Stark Bank API. The 'create' function sends the objects to the Stark Bank API and returns the list of created objects. ## Parameters (required): - - amount [int]: - - receiver_id [string]: + - amount [int]: value to send to receivers. ex: 1000 (= R$ 10.00) + - receiver_id [string]: split receiver unique id. ex: "5656565656565656" ## Attributes (return-only): - id [string]: unique id returned when split is created. ex: "5656565656565656" - source [string]: source receivable which generated this split object. ex: "5656565656565656" - external_id [string]: unique id, generated by the system, to avoid duplicated splits. ex: "invoice/1234/receiver/5678" - - tags [list of strings, default []]: list of strings for tagging + - tags [list of strings, default None]: list of strings for tagging - scheduled [datetime.date, datetime.datetime or string, default now]: payment scheduled date or datetime. ex: datetime.datetime(2020, 3, 10, 15, 17, 3) - status [string]: current payment status. ex: "success" or "failed" - created [datetime.datetime]: creation datetime for the payment. ex: datetime.datetime(2020, 3, 10, 10, 30, 0, 0) - updated [datetime.datetime]: update datetime for the payment. ex: datetime.datetime(2020, 3, 10, 10, 30, 0, 0) """ - def __init__(self, amount, receiver_id, scheduled=None, tags=None, id=None, - status=None, updated=None, created=None, external_id=None, source=None): + def __init__(self, amount, receiver_id, id=None, source=None, external_id=None, + tags=None, scheduled=None, status=None, created=None, updated=None): Resource.__init__(self, id=id) self.amount = amount - self.scheduled = check_datetime(scheduled) - self.tags = tags - self.status = status + self.receiver_id = receiver_id self.source = source self.external_id = external_id - self.receiver_id = receiver_id - self.updated = check_datetime(updated) + self.tags = tags + self.scheduled = check_datetime(scheduled) + self.status = status self.created = check_datetime(created) + self.updated = check_datetime(updated) _resource = {"class": Split, "name": "Split"} @@ -54,7 +54,7 @@ def get(id, user=None): return rest.get_id(resource=_resource, id=id, user=user) -def query(limit=None, after=None, before=None, tags=None, ids=None, status=None, user=None): +def query(limit=None, after=None, before=None, tags=None, ids=None, receiver_ids=None, status=None, user=None): """# Retrieve Splits Receive a generator of Split objects previously created in the Stark Bank API ## Parameters (optional): @@ -63,6 +63,7 @@ def query(limit=None, after=None, before=None, tags=None, ids=None, status=None, - before [datetime.date or string, default None] date filter for objects created only before specified date. ex: datetime.date(2020, 3, 10) - tags [list of strings, default None]: tags to filter retrieved objects. ex: ["tony", "stark"] - ids [list of strings, default None]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - receiver_ids [list of strings, default None]: list of receiver ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] - status [string, default None]: filter for status of retrieved objects. ex: "success" - user [Organization/Project object, default None]: Organization or Project object. Not necessary if starkbank.user was set before function call ## Return: @@ -75,12 +76,13 @@ def query(limit=None, after=None, before=None, tags=None, ids=None, status=None, before=check_date(before), tags=tags, ids=ids, + receiver_ids=receiver_ids, status=status, user=user, ) -def page(cursor=None, after=None, before=None, tags=None, ids=None, status=None, limit=None, user=None): +def page(cursor=None, after=None, before=None, tags=None, ids=None, receiver_ids=None, status=None, limit=None, user=None): """# Retrieve paged Splits Receive a list of up to 100 Split objects previously created in the Stark Bank API and the cursor to the next page. Use this function instead of query if you want to manually page your requests. @@ -91,6 +93,7 @@ def page(cursor=None, after=None, before=None, tags=None, ids=None, status=None, - before [datetime.date or string, default None] date filter for objects created only before specified date. ex: datetime.date(2020, 3, 10) - tags [list of strings, default None]: tags to filter retrieved objects. ex: ["tony", "stark"] - ids [list of strings, default None]: list of ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] + - receiver_ids [list of strings, default None]: list of receiver ids to filter retrieved objects. ex: ["5656565656565656", "4545454545454545"] - status [string, default None]: filter for status of retrieved objects. ex: "success" - user [Organization/Project object, default None]: Organization or Project object. Not necessary if starkbank.user was set before function call ## Return: @@ -105,6 +108,7 @@ def page(cursor=None, after=None, before=None, tags=None, ids=None, status=None, before=check_date(before), tags=tags, ids=ids, + receiver_ids=receiver_ids, status=status, user=user, ) diff --git a/starkbank/splitreceiver/__splitreceiver.py b/starkbank/splitreceiver/__splitreceiver.py index f1fec58..62d6e29 100644 --- a/starkbank/splitreceiver/__splitreceiver.py +++ b/starkbank/splitreceiver/__splitreceiver.py @@ -25,8 +25,7 @@ class SplitReceiver(Resource): """ def __init__(self, name, tax_id, bank_code, branch_code, account_number, account_type, - tags=None, status=None, id=None, created=None, updated=None - ): + tags=None, id=None, status=None, created=None, updated=None): Resource.__init__(self, id=id) self.name = name