-
Notifications
You must be signed in to change notification settings - Fork 0
/
refund.go
64 lines (47 loc) · 1.31 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
62
63
64
package gogojudo
import (
"bytes"
"encoding/json"
"net/http"
"net/url"
"path"
)
type RefundModel struct {
// Payment identification
ReceiptID string `json:"receiptId"`
YourPaymentReference string `json:"yourPaymentReference"`
// Information relating to the transaction
PaymentMetaData string `json:"yourPaymentMetaData"`
ClientDetails map[string]interface{} `json:"clientDetails"`
// Finantial information
Amount float64 `json:"amount"`
Currency string `json:"currency"`
// Since it needs to be included
JudoID string `json:"judoId"`
}
func (jp *JudoPay) Refund(rcp RefundModel) (ret PaymentReceiptModel, err error) {
var requestURL url.URL = *jp.APIUrl
rcp.JudoID = jp.JudopayID
requestBody, err := json.Marshal(rcp)
if err != nil {
return ret, err
}
requestURL.Path = path.Join(requestURL.Path, "refunds")
request, err := http.NewRequest(http.MethodPost, requestURL.String(), bytes.NewBuffer(requestBody))
jp.SetHeaders(request)
if err != nil {
return ret, err
}
resp, err := jp.HttpClient.Do(request)
if err != nil {
return ret, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
var jerror = &JudoError{}
json.NewDecoder(resp.Body).Decode(&jerror)
return ret, jerror.GetError()
}
json.NewDecoder(resp.Body).Decode(&ret)
return ret, nil
}