generated from mythrnr/template-lib-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_refund.go
68 lines (57 loc) · 1.51 KB
/
api_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
package paypayopa
import (
"context"
"time"
)
type RefundPaymentPayload struct {
MerchantRefundID string `json:"merchantRefundId"`
PaymentID string `json:"paymentId"`
Amount *MoneyAmount `json:"amount"`
RequestedAt int64 `json:"requestedAt"`
Reason string `json:"reason"`
}
type RefundResponse struct {
Status string `json:"status"`
AcceptedAt int64 `json:"acceptedAt"`
MerchantRefundID string `json:"merchantRefundId"`
PaymentID string `json:"paymentId"`
Amount *MoneyAmount `json:"amount"`
RequestedAt int64 `json:"requestedAt"`
Reason string `json:"reason"`
AssumeMerchant string `json:"assumeMerchant"`
}
func refundPayment(
ctx context.Context,
client *opaClient,
req *RefundPaymentPayload,
) (*RefundResponse, *ResultInfo, error) {
const timeout = 30 * time.Second
res := &RefundResponse{}
info, err := client.POST(
ctxWithTimeout(ctx, timeout),
"/v2/refunds",
res,
req,
)
if err != nil || !info.Success() {
return nil, info, err
}
return res, info, nil
}
func getRefundDetails(
ctx context.Context,
client *opaClient,
merchantRefundID string,
) (*RefundResponse, *ResultInfo, error) {
const timeout = 15 * time.Second
res := &RefundResponse{}
info, err := client.GET(
ctxWithTimeout(ctx, timeout),
"/v2/refunds/"+merchantRefundID,
res,
)
if err != nil || !info.Success() {
return nil, info, err
}
return res, info, nil
}