Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

## [0.4.2] - 2023-12-15
### Changed
Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,39 @@ func main() {

```

## Update a Deposit

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

```golang
package main

import (
"fmt"
"github.com/starkbank/sdk-go/starkbank"
Deposit "github.com/starkbank/sdk-go/starkbank/deposit"
"github.com/starkbank/sdk-go/tests/utils"
)

func main() {

starkbank.User = utils.ExampleProject

var patchData = map[string]interface{}{}
patchData["amount"] = 0

deposit, err := Deposit.Update("5155165527080960", patchData, nil)
if err.Errors != nil {
for _, e := range err.Errors {
panic(fmt.Sprintf("code: %s, message: %s", e.Code, e.Message))
}
}

fmt.Println(deposit)
}

```

## Query deposit logs

Logs are pretty important to understand the life cycle of a deposit.
Expand Down
24 changes: 24 additions & 0 deletions starkbank/deposit/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,27 @@ func Page(params map[string]interface{}, user user.User) ([]Deposit, string, Err
}
return deposit, cursor, err
}

func Update(id string, patchData map[string]interface{}, user user.User) (Deposit, Error.StarkErrors) {
// Update Deposit entity
//
// Update the Deposit by passing its id to be partially or fully reversed.
//
// Parameters (required):
// - patchData [map[string]interface{}]: map containing the attributes to be updated. ex: map[string]interface{}{"amount": 9090}
// Parameters (optional):
// - amount [string]: The new amount of the Deposit. If the amount = 0 the Deposit will be fully reversed
//
// Parameters (optional):
// - user [Organization/Project struct, default nil]: Organization or Project struct. Not necessary if starkbank.User was set before function call
//
// Return:
// - Target Deposit with updated attributes
update, err := utils.Patch(resource, id, patchData, user)
unmarshalError := json.Unmarshal(update, &object)
if unmarshalError != nil {
return object, err
}
return object, err
}

27 changes: 27 additions & 0 deletions tests/sdk/deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,33 @@ func TestDepositQuery(t *testing.T) {
assert.Equal(t, 201, i)
}

func TestDepositUpdate(t *testing.T) {

starkbank.User = Utils.ExampleProject

var depositList []Deposit.Deposit
var params = map[string]interface{}{}
params["limit"] = 1
params["status"] = "created"

deposits := Deposit.Query(params, nil)
for deposit := range deposits {
depositList = append(depositList, deposit)
}

var patchData = map[string]interface{}{}
patchData["amount"] = 0

updated, err := Deposit.Update(depositList[rand.Intn(len(depositList))].Id, patchData, nil)
if err.Errors != nil {
for _, e := range err.Errors {
panic(fmt.Sprintf("code: %s, message: %s", e.Code, e.Message))
}
}

assert.Equal(t, updated.Amount, patchData["amount"])
}

func TestDepositPage(t *testing.T) {

starkbank.User = Utils.ExampleProject
Expand Down