From 92efb297d3900f546373daa5f183575b6bab6b0d Mon Sep 17 00:00:00 2001 From: Wendel de Oliveira Silvestre Date: Fri, 6 Oct 2023 18:17:35 -0300 Subject: [PATCH] Added update function to Deposit resource --- CHANGELOG.md | 2 ++ README.md | 15 +++++++++++++++ starkbank/deposit/__deposit.py | 17 +++++++++++++++++ starkbank/deposit/__init__.py | 2 +- tests/sdk/test_deposit.py | 16 ++++++++++++++++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed18594c..df923798 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index c39a30cc..ed1d6f87 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/starkbank/deposit/__deposit.py b/starkbank/deposit/__deposit.py index 2619e1b0..a7ca2466 100644 --- a/starkbank/deposit/__deposit.py +++ b/starkbank/deposit/__deposit.py @@ -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) \ No newline at end of file diff --git a/starkbank/deposit/__init__.py b/starkbank/deposit/__init__.py index df4f8a7c..7c1e9a27 100644 --- a/starkbank/deposit/__init__.py +++ b/starkbank/deposit/__init__.py @@ -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 diff --git a/tests/sdk/test_deposit.py b/tests/sdk/test_deposit.py index 1f805581..998d0690 100644 --- a/tests/sdk/test_deposit.py +++ b/tests/sdk/test_deposit.py @@ -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)