-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathrefund.go
More file actions
75 lines (59 loc) · 1.85 KB
/
Copy pathrefund.go
File metadata and controls
75 lines (59 loc) · 1.85 KB
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
69
70
71
72
73
74
75
package cryptomus
import (
"encoding/json"
"errors"
)
const (
refundEndpoint = "/payment/refund"
blockedAddressRefundEndpoint = "/wallet/blocked-address-refund"
)
type RefundRequest struct {
Address string `json:"address"`
IsSubtract bool `json:"is_subtract"`
PaymentUUID string `json:"uuid,omitempty"`
OrderId string `json:"order_id,omitempty"`
}
type refundRawResponse struct {
Result []string `json:"result,omitempty"`
State int8 `json:"state"`
}
type BlockedAddressRefundRequest struct {
WalletUUID string `json:"uuid,omitempty"`
OrderId string `json:"order_id,omitempty"`
Address string `json:"address"`
}
type BlockedAddressRefundResponse struct {
Commision string `json:"commision"`
Amount string `json:"amount"`
}
type blockedAddressRefundRawResponse struct {
Result *BlockedAddressRefundResponse `json:"result"`
State int8 `json:"state"`
}
func (c *Cryptomus) Refund(refundRequest *RefundRequest) (bool, error) {
res, err := c.fetch("POST", refundEndpoint, refundRequest)
if err != nil {
return false, err
}
defer res.Body.Close()
response := &refundRawResponse{}
if err = json.NewDecoder(res.Body).Decode(response); err != nil {
return false, err
}
return len(response.Result) == 0, nil
}
func (c *Cryptomus) BlockedAddressRefund(refundRequest *BlockedAddressRefundRequest) (*BlockedAddressRefundResponse, error) {
if refundRequest.WalletUUID == "" || refundRequest.OrderId == "" {
return nil, errors.New("you should pass one of required values [WalletUUID, OrderId]")
}
res, err := c.fetch("POST", blockedAddressRefundEndpoint, refundRequest)
if err != nil {
return nil, err
}
defer res.Body.Close()
response := &blockedAddressRefundRawResponse{}
if err = json.NewDecoder(res.Body).Decode(response); err != nil {
return nil, err
}
return response.Result, nil
}