-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcapture.go
64 lines (54 loc) · 1.94 KB
/
capture.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
57
58
59
60
61
62
63
64
package zooz
import (
"context"
"encoding/json"
"fmt"
)
// CaptureClient is a client for work with Capture entity.
// https://developers.paymentsos.com/docs/api#/reference/captures
type CaptureClient struct {
Caller Caller
}
// Capture is a model of entity.
type Capture struct {
CaptureParams
ID string `json:"id"`
Result Result `json:"result"`
Created json.Number `json:"created"`
ProviderData ProviderData `json:"provider_data"`
}
// CaptureParams is a set of params for creating entity.
type CaptureParams struct {
ReconciliationID string `json:"reconciliation_id,omitempty"`
Amount int64 `json:"amount,omitempty"`
}
// New creates new Capture entity.
func (c *CaptureClient) New(ctx context.Context, idempotencyKey string, paymentID string, params *CaptureParams) (*Capture, error) {
capture := &Capture{}
if err := c.Caller.Call(ctx, "POST", c.capturesPath(paymentID), map[string]string{headerIdempotencyKey: idempotencyKey}, params, capture); err != nil {
return nil, err
}
return capture, nil
}
// Get returns Capture entity.
func (c *CaptureClient) Get(ctx context.Context, paymentID string, captureID string) (*Capture, error) {
capture := &Capture{}
if err := c.Caller.Call(ctx, "GET", c.capturePath(paymentID, captureID), nil, nil, capture); err != nil {
return nil, err
}
return capture, nil
}
// GetList returns list of Captures for given payment ID.
func (c *CaptureClient) GetList(ctx context.Context, paymentID string) ([]Capture, error) {
var captures []Capture
if err := c.Caller.Call(ctx, "GET", c.capturesPath(paymentID), nil, nil, &captures); err != nil {
return nil, err
}
return captures, nil
}
func (c *CaptureClient) capturesPath(paymentID string) string {
return fmt.Sprintf("%s/%s/captures", paymentsPath, paymentID)
}
func (c *CaptureClient) capturePath(paymentID string, captureID string) string {
return fmt.Sprintf("%s/%s", c.capturesPath(paymentID), captureID)
}