-
Notifications
You must be signed in to change notification settings - Fork 5
/
void.go
56 lines (48 loc) · 1.58 KB
/
void.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package zooz
import (
"context"
"encoding/json"
"fmt"
)
// VoidClient is a client for work with Void entity.
// https://developers.paymentsos.com/docs/api#/reference/voids
type VoidClient struct {
Caller Caller
}
// Void is an entity model.
type Void struct {
ID string `json:"id"`
Result Result `json:"result"`
Created json.Number `json:"created"`
ProviderData ProviderData `json:"provider_data"`
}
// New create new Void entity.
func (c *VoidClient) New(ctx context.Context, idempotencyKey string, paymentID string) (*Void, error) {
void := &Void{}
if err := c.Caller.Call(ctx, "POST", c.voidsPath(paymentID), map[string]string{headerIdempotencyKey: idempotencyKey}, nil, void); err != nil {
return nil, err
}
return void, nil
}
// Get returns Void entity.
func (c *VoidClient) Get(ctx context.Context, paymentID string, voidID string) (*Void, error) {
void := &Void{}
if err := c.Caller.Call(ctx, "GET", c.voidPath(paymentID, voidID), nil, nil, void); err != nil {
return nil, err
}
return void, nil
}
// GetList returns a list of Void for given payment.
func (c *VoidClient) GetList(ctx context.Context, paymentID string) ([]Void, error) {
var voids []Void
if err := c.Caller.Call(ctx, "GET", c.voidsPath(paymentID), nil, nil, &voids); err != nil {
return nil, err
}
return voids, nil
}
func (c *VoidClient) voidsPath(paymentID string) string {
return fmt.Sprintf("%s/%s/voids", paymentsPath, paymentID)
}
func (c *VoidClient) voidPath(paymentID string, voidID string) string {
return fmt.Sprintf("%s/%s", c.voidsPath(paymentID), voidID)
}