-
Notifications
You must be signed in to change notification settings - Fork 0
/
refund.go
61 lines (49 loc) · 1.74 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
package pawapay
import (
"fmt"
"net/http"
)
// RequestRefund provides the functionality of requesting a refund for an initiated deposit
// See docs https://docs.pawapay.co.uk/#operation/depositWebhook for more details
func (s *Service) RequestRefund(refundId, depositId string, amount Amount) (InitiateRefundResponse, error) {
resource := "refunds"
payload := s.newRefundRequest(refundId, depositId, amount)
var response InitiateRefundResponse
annotation, err := s.makeRequest(http.MethodPost, resource, payload, &response)
if err != nil {
return InitiateRefundResponse{}, err
}
response.Annotation = annotation
return response, nil
}
// GetRefund provides the functionality of retrieving an initiated refund
// See docs https://docs.pawapay.co.uk/#operation/getRefund for more details
func (s *Service) GetRefund(refundId string) (Refund, error) {
resource := fmt.Sprintf("refunds/%s", refundId)
var (
response []Refund
result Refund
)
annotation, err := s.makeRequest(http.MethodGet, resource, nil, &response)
if err != nil {
return Refund{}, err
}
if len(response) > 0 {
result = response[0]
}
result.Annotation = annotation
return result, nil
}
// ResendRefundCallback provides the functionality of resending a callback (webhook)
// See docs https://docs.pawapay.co.uk/#operation/refundsResendCallback for more details
func (s *Service) ResendRefundCallback(refundId string) (RefundStatusResponse, error) {
resource := "refunds/resend-callback"
payload := ResendCallbackRequest{RefundId: refundId}
var response RefundStatusResponse
annotation, err := s.makeRequest(http.MethodPost, resource, payload, &response)
if err != nil {
return RefundStatusResponse{}, err
}
response.Annotation = annotation
return response, nil
}