Skip to content

Commit

Permalink
Add Split and SplitReceiver resources
Browse files Browse the repository at this point in the history
  • Loading branch information
wendel-stark committed Oct 26, 2023
1 parent b1fe9c5 commit 075021c
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
110 changes: 110 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
28 changes: 16 additions & 12 deletions starkbank/split/__split.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand All @@ -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):
Expand All @@ -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:
Expand All @@ -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.
Expand All @@ -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:
Expand All @@ -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,
)
3 changes: 1 addition & 2 deletions starkbank/splitreceiver/__splitreceiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 075021c

Please sign in to comment.