forked from go-pay/gopay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrefund.go
34 lines (31 loc) · 915 Bytes
/
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
package apple
import (
"context"
"encoding/json"
"fmt"
"net/http"
"github.com/go-pay/gopay"
)
// GetRefundHistory Get Refund History
// Doc: https://developer.apple.com/documentation/appstoreserverapi/get_refund_history
func (c *Client) GetRefundHistory(ctx context.Context, transactionId, revision string) (rsp *RefundHistoryRsp, err error) {
path := fmt.Sprintf(getRefundHistory, transactionId)
if revision != "" {
path = fmt.Sprintf(getRefundHistory, transactionId) + "?revision=" + revision
}
res, bs, err := c.doRequestGet(ctx, path)
if err != nil {
return nil, err
}
rsp = &RefundHistoryRsp{}
if err = json.Unmarshal(bs, rsp); err != nil {
return nil, fmt.Errorf("[%w]: %v, bytes: %s", gopay.UnmarshalErr, err, string(bs))
}
if res.StatusCode == http.StatusOK {
return rsp, nil
}
if err = statusCodeErrCheck(rsp.StatusCodeErr); err != nil {
return rsp, err
}
return rsp, nil
}