Skip to content

Commit

Permalink
Added update function to Deposit resource
Browse files Browse the repository at this point in the history
  • Loading branch information
wendel-stark committed Oct 6, 2023
1 parent 58314d5 commit 92efb29
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
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
15 changes: 15 additions & 0 deletions 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
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]: 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
16 changes: 16 additions & 0 deletions tests/sdk/test_deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,19 @@ def test_success(self):

if __name__ == '__main__':
main()


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)
print(deposit)
updated_deposit = starkbank.deposit.update(
deposit.id,
amount=deposit_amount,
)
print(updated_deposit)
self.assertEqual(updated_deposit.amount, deposit_amount)

0 comments on commit 92efb29

Please sign in to comment.