forked from gotokatsuya/amazon-pay-sdk-go
/
refund.go
56 lines (49 loc) · 1.68 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
package amazonpay
import (
"context"
"fmt"
"net/http"
)
type CreateRefundRequest struct {
ChargeID string `json:"chargeId,omitempty"`
RefundAmount *Price `json:"refundAmount,omitempty"`
SoftDescriptor string `json:"softDescriptor,omitempty"`
}
type RefundResponse struct {
ErrorResponse
RefundID string `json:"refundId,omitempty"`
ChargeID string `json:"chargeId,omitempty"`
RefundAmount *Price `json:"refundAmount,omitempty"`
SoftDescriptor string `json:"softDescriptor,omitempty"`
CreationTimestamp string `json:"creationTimestamp,omitempty"`
StatusDetails *StatusDetails `json:"statusDetails,omitempty"`
ReleaseEnvironment string `json:"releaseEnvironment,omitempty"`
}
type CreateRefundResponse RefundResponse
func (c *Client) CreateRefund(ctx context.Context, req *CreateRefundRequest) (*CreateRefundResponse, *http.Response, error) {
path := fmt.Sprintf("%s/refunds", APIVersion)
httpReq, err := c.NewRequest(http.MethodPost, path, req)
if err != nil {
return nil, nil, err
}
resp := new(CreateRefundResponse)
httpResp, err := c.Do(ctx, httpReq, resp)
if err != nil {
return nil, httpResp, err
}
return resp, httpResp, nil
}
type GetRefundResponse RefundResponse
func (c *Client) GetRefund(ctx context.Context, refundID string) (*GetRefundResponse, *http.Response, error) {
path := fmt.Sprintf("%s/refunds/%s", APIVersion, refundID)
httpReq, err := c.NewRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
resp := new(GetRefundResponse)
httpResp, err := c.Do(ctx, httpReq, resp)
if err != nil {
return nil, httpResp, err
}
return resp, httpResp, nil
}