-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrefund.go
66 lines (56 loc) · 1.99 KB
/
refund.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
65
66
package zooz
import (
"context"
"encoding/json"
"fmt"
)
// RefundClient is a client for work with Refund entity.
// https://developers.paymentsos.com/docs/api#/reference/refunds
type RefundClient struct {
Caller Caller
}
// Refund is a entity model.
type Refund struct {
RefundParams
ID string `json:"id"`
Result Result `json:"result"`
Created json.Number `json:"created"`
ProviderData ProviderData `json:"provider_data"`
}
// RefundParams is a set of params for creating entity.
type RefundParams struct {
ReconciliationID string `json:"reconciliation_id,omitempty"`
Amount int64 `json:"amount,omitempty"`
CaptureID string `json:"capture_id,omitempty"`
Reason string `json:"reason,omitempty"`
}
// New creates new Refund entity.
func (c *RefundClient) New(ctx context.Context, idempotencyKey string, paymentID string, params *RefundParams) (*Refund, error) {
refund := &Refund{}
if err := c.Caller.Call(ctx, "POST", c.refundsPath(paymentID), map[string]string{headerIdempotencyKey: idempotencyKey}, params, refund); err != nil {
return nil, err
}
return refund, nil
}
// Get returns Refund entity.
func (c *RefundClient) Get(ctx context.Context, paymentID string, refundID string) (*Refund, error) {
refund := &Refund{}
if err := c.Caller.Call(ctx, "GET", c.refundPath(paymentID, refundID), nil, nil, refund); err != nil {
return nil, err
}
return refund, nil
}
// GetList returns a list of Refunds for given payment.
func (c *RefundClient) GetList(ctx context.Context, paymentID string) ([]Refund, error) {
var refunds []Refund
if err := c.Caller.Call(ctx, "GET", c.refundsPath(paymentID), nil, nil, &refunds); err != nil {
return nil, err
}
return refunds, nil
}
func (c *RefundClient) refundsPath(paymentID string) string {
return fmt.Sprintf("%s/%s/refunds", paymentsPath, paymentID)
}
func (c *RefundClient) refundPath(paymentID string, refundID string) string {
return fmt.Sprintf("%s/%s", c.refundsPath(paymentID), refundID)
}