Skip to content

Commit

Permalink
Feature update function to Deposit resource
Browse files Browse the repository at this point in the history
  • Loading branch information
wendel-stark committed Nov 17, 2023
1 parent 58314d5 commit 112a6e8
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Given a version number MAJOR.MINOR.PATCH, increment:


## [Unreleased]
### Added
- update function to Deposit resource

## [2.22.0] - 2023-09-18
### Removed
Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,21 @@ deposit = starkbank.deposit.get("5155165527080960")
print(deposit)
```

## Update a deposit

Update a deposit by passing its id to be partially or fully reversed.

```python
import starkbank

deposit = starkbank.deposit.update(
"5155165527080960",
amount=0,
)

print(deposit)
```

## Query deposit logs

Logs are pretty important to understand the life cycle of a deposit.
Expand Down Expand Up @@ -2306,7 +2321,7 @@ With this function, you can manually set events retrieved from the API as
```python
import starkbank

event = starkbank.event.update(id="129837198237192", is_delivered=True)
event = starkbank.event.update("129837198237192", is_delivered=True)

print(event)
```
Expand Down
17 changes: 17 additions & 0 deletions starkbank/deposit/__deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,20 @@ def page(cursor=None, limit=None, after=None, before=None, status=None, sort=Non
ids=ids,
user=user,
)


def update(id, amount=None, user=None):
"""# Update Deposit entity
Update the Deposit by passing its id to be partially or fully reversed.
## Parameters (required):
- id [string]: Deposit id. ex: "5656565656565656"
## Parameters (optional):
- amount [string, default None]: The new amount of the Deposit. If the amount = 0 the Deposit will be fully reversed
- user [Organization/Project object, default None]: Organization or Project object. Not necessary if starkbank.user was set before function call
## Return:
- target Deposit with updated attributes
"""
payload = {
"amount": amount,
}
return rest.patch_id(resource=_resource, id=id, user=user, payload=payload)
2 changes: 1 addition & 1 deletion starkbank/deposit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .__deposit import get, query, page
from .__deposit import get, query, page, update
from .log.__log import Log
from . import log
1 change: 1 addition & 0 deletions tests/sdk/test_boleto.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ def test_success(self):
booklet_pdf = starkbank.boleto.pdf(boleto_id, layout="booklet", hidden_fields=["customerAddress"])
self.assertGreater(len(booklet_pdf), 1000)


if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion tests/sdk/test_corporate_card.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import starkbank
from unittest import TestCase, main
from datetime import date, timedelta
from tests.utils.holder import generateExampleHoldersJson
from tests.utils.user import exampleProject
from tests.utils.card import generateExampleCardJson
from tests.utils.holder import generateExampleHoldersJson

starkbank.user = exampleProject

Expand Down
16 changes: 16 additions & 0 deletions tests/sdk/test_deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,21 @@ def test_success(self):
print(deposit)


class TestDepositInfoPatch(TestCase):

def test_success_amount(self):
deposits = starkbank.deposit.query(status="created", limit=1)
deposit_amount = 0
for deposit in deposits:
self.assertIsNotNone(deposit.id)
updated_deposit = starkbank.deposit.update(
deposit.id,
amount=deposit_amount,
)
print(updated_deposit)
self.assertEqual(updated_deposit.amount, deposit_amount)


if __name__ == '__main__':
main()

4 changes: 2 additions & 2 deletions tests/sdk/test_transfer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import starkbank
from datetime import timedelta, date
from unittest import TestCase, main
from tests.utils.transfer import generateExampleTransfersJson
from datetime import timedelta, date
from tests.utils.user import exampleProject
from tests.utils.transfer import generateExampleTransfersJson


starkbank.user = exampleProject
Expand Down

0 comments on commit 112a6e8

Please sign in to comment.