-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrefund.go
88 lines (69 loc) · 2.01 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package mobilepay
import (
"context"
"net/http"
)
const refundsBasePath = "v1/refunds"
type RefundService interface {
List(ctx context.Context, opt *RefundsListOptions) (*RefundsRoot, error)
Create(ctx context.Context, createRequest *RefundParams) (*Refund, error)
}
type RefundParams struct {
IdempotencyKey string `json:"idempotencyKey"`
PaymentId string `json:"paymentId"`
Amount int `json:"amount"`
Reference string `json:"reference"`
Description string `json:"description"`
}
type Refund struct {
RefundId string `json:"refundId"`
PaymentId string `json:"paymentId"`
Amount int `json:"amount"`
RemainingAmount int `json:"remainingAmount,omitempty"`
Description string `json:"description"`
Reference string `json:"reference"`
CreatedOn string `json:"createdOn"`
}
type RefundsRoot struct {
Refunds []Refund `json:"refunds"`
PageSize int `json:"pageSize"`
NextPageNumber int `json:"nextPageNumber"`
}
type RefundServiceOp struct {
client *Client
}
var _ RefundService = &RefundServiceOp{}
func (rs *RefundServiceOp) Create(ctx context.Context, refundParams *RefundParams) (*Refund, error) {
if refundParams == nil {
rs.client.Logger.Errorf("refundParams cannot be nil")
return nil, newArgError("refundParams", "cannot be nil")
}
path := refundsBasePath
req, err := rs.client.NewRequest(ctx, http.MethodPost, path, refundParams)
if err != nil {
return nil, err
}
root := new(Refund)
_, err = rs.client.Do(ctx, req, root)
if err != nil {
return nil, err
}
return root, err
}
func (rs RefundServiceOp) List(ctx context.Context, opts *RefundsListOptions) (*RefundsRoot, error) {
path := refundsBasePath
path, err := addOptions(path, opts)
if err != nil {
return nil, err
}
req, err := rs.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, err
}
root := new(RefundsRoot)
_, err = rs.client.Do(ctx, req, root)
if err != nil {
return nil, err
}
return root, err
}