Skip to content

Commit 930ad92

Browse files
committed
Added update function to Deposit resource
1 parent 16de372 commit 930ad92

File tree

4 files changed

+86
-0
lines changed

4 files changed

+86
-0
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Given a version number MAJOR.MINOR.PATCH, increment:
1313

1414

1515
## [Unreleased]
16+
### Added
17+
- update function to Deposit resource
1618

1719
## [0.4.1] - 2023-09-18
1820
### Removed

README.md

+33
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,39 @@ func main() {
14451445

14461446
```
14471447

1448+
## Update a Deposit
1449+
1450+
Update a deposit by passing its id to be partially or fully reversed.
1451+
1452+
```golang
1453+
package main
1454+
1455+
import (
1456+
"fmt"
1457+
"github.com/starkbank/sdk-go/starkbank"
1458+
Deposit "github.com/starkbank/sdk-go/starkbank/deposit"
1459+
"github.com/starkbank/sdk-go/tests/utils"
1460+
)
1461+
1462+
func main() {
1463+
1464+
starkbank.User = utils.ExampleProject
1465+
1466+
var patchData = map[string]interface{}{}
1467+
patchData["amount"] = 0
1468+
1469+
deposit, err := Deposit.Update("5155165527080960", patchData, nil)
1470+
if err.Errors != nil {
1471+
for _, e := range err.Errors {
1472+
panic(fmt.Sprintf("code: %s, message: %s", e.Code, e.Message))
1473+
}
1474+
}
1475+
1476+
fmt.Println(deposit)
1477+
}
1478+
1479+
```
1480+
14481481
## Query deposit logs
14491482

14501483
Logs are pretty important to understand the life cycle of a deposit.

starkbank/deposit/deposit.go

+24
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,27 @@ func Page(params map[string]interface{}, user user.User) ([]Deposit, string, Err
134134
}
135135
return objects, cursor, err
136136
}
137+
138+
func Update(id string, patchData map[string]interface{}, user user.User) (Deposit, Error.StarkErrors) {
139+
// Update Deposit entity
140+
//
141+
// Update the Deposit by passing its id to be partially or fully reversed.
142+
//
143+
// Parameters (required):
144+
// - patchData [map[string]interface{}]: map containing the attributes to be updated. ex: map[string]interface{}{"amount": 9090}
145+
// Parameters (optional):
146+
// - amount [string]: The new amount of the Deposit. If the amount = 0 the Deposit will be fully reversed
147+
//
148+
// Parameters (optional):
149+
// - user [Organization/Project struct, default nil]: Organization or Project struct. Not necessary if starkbank.User was set before function call
150+
//
151+
// Return:
152+
// - Target Deposit with updated attributes
153+
update, err := utils.Patch(resource, id, patchData, user)
154+
unmarshalError := json.Unmarshal(update, &object)
155+
if unmarshalError != nil {
156+
return object, err
157+
}
158+
return object, err
159+
}
160+

tests/sdk/deposit_test.go

+27
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,33 @@ func TestDepositQuery(t *testing.T) {
5050
assert.Equal(t, 201, i)
5151
}
5252

53+
func TestDepositUpdate(t *testing.T) {
54+
55+
starkbank.User = Utils.ExampleProject
56+
57+
var depositList []Deposit.Deposit
58+
var params = map[string]interface{}{}
59+
params["limit"] = 1
60+
params["status"] = "created"
61+
62+
deposits := Deposit.Query(params, nil)
63+
for deposit := range deposits {
64+
depositList = append(depositList, deposit)
65+
}
66+
67+
var patchData = map[string]interface{}{}
68+
patchData["amount"] = 0
69+
70+
updated, err := Deposit.Update(depositList[rand.Intn(len(depositList))].Id, patchData, nil)
71+
if err.Errors != nil {
72+
for _, e := range err.Errors {
73+
panic(fmt.Sprintf("code: %s, message: %s", e.Code, e.Message))
74+
}
75+
}
76+
77+
assert.Equal(t, updated.Amount, patchData["amount"])
78+
}
79+
5380
func TestDepositPage(t *testing.T) {
5481

5582
starkbank.User = Utils.ExampleProject

0 commit comments

Comments
 (0)