-
Notifications
You must be signed in to change notification settings - Fork 1
/
api_get_refund_history.go
51 lines (43 loc) · 1.36 KB
/
api_get_refund_history.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
package appstoreserverapi
import (
"net/http"
"sort"
"strings"
)
// ApiGetRefundHistory 获取退款历史
// Get Refund History
// doc: https://developer.apple.com/documentation/appstoreserverapi/get_refund_history
// desc: true then signedTransactions order by webOrderLineItemId desc
func (c *client) ApiGetRefundHistory(transactionId string, desc bool) (*RefundLookupResponse, error) {
reqUrl := c.apiGetRefundHistoryUrl + transactionId
r, err := c.doRequest(http.MethodGet, reqUrl, nil)
if err != nil {
return nil, err
}
result := &RefundLookupResponse{
raw: r.String(),
}
signedTransactions := make([]JWSTransactionDecodedPayload, 0)
for _, item := range r.Get("signedTransactions").Array() {
signedTransaction := JWSTransactionDecodedPayload{}
Parse(item.String(), &signedTransaction)
signedTransactions = append(signedTransactions, signedTransaction)
}
if desc {
sort.SliceStable(signedTransactions, func(i, j int) bool {
if strings.Compare(signedTransactions[i].WebOrderLineItemId, signedTransactions[j].WebOrderLineItemId) == 1 {
return true
}
return false
})
}
result.SignedTransactions = signedTransactions
return result, nil
}
type RefundLookupResponse struct {
raw string
SignedTransactions []JWSTransactionDecodedPayload `json:"signedTransactions"`
}
func (r *RefundLookupResponse) Raw() string {
return r.raw
}