-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpayments.go
163 lines (138 loc) · 4.96 KB
/
payments.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package coinpayments
import "net/url"
//createTransactionResponse is the api response of a "create_transaction" call
type createTransactionResponse struct {
Amount string `json:"amount"`
Address string `json:"address"`
DestTag string `json:"dest_tag"`
TxnId string `json:"txn_id"`
ConfirmsNeeded string `json:"confirms_needed"`
Timeout int `json:"timeout"`
CheckoutURL string `json:"checkout_url"`
StatusURL string `json:"status_url"`
QRCodeURL string `json:"qrcode_url"`
}
//CreateTransaction calls the "create_transaction" command
func (c *Client) CreateTransaction(amount, currency1, currency2, buyerEmail string, optionals ...OptionalValue) (*createTransactionResponse, error) {
values := &url.Values{}
values.Set("amount", amount)
values.Set("currency1", currency1)
values.Set("currency2", currency2)
values.Set("buyer_email", buyerEmail)
addOptionals(optionals, values)
var resp struct {
errResponse
Result *createTransactionResponse `json:"result"`
}
if err := c.call("create_transaction", values, &resp); err != nil {
return nil, err
}
return resp.Result, nil
}
//getCallbackAddressResponse is the api response of a "get_callback_address" call
type getCallbackAddressResponse struct {
Address string `json:"address"`
PubKey string `json:"pubkey"`
DestTag string `json:"dest_tag"`
}
//GetCallbackAddress calls the "get_callback_address" command
func (c *Client) GetCallbackAddress(currency string, optionals ...OptionalValue) (*getCallbackAddressResponse, error) {
values := &url.Values{}
values.Set("currency", currency)
addOptionals(optionals, values)
var resp struct {
errResponse
Result *getCallbackAddressResponse `json:"result"`
}
if err := c.call("get_callback_address", values, &resp); err != nil {
return nil, err
}
return resp.Result, nil
}
//getTxInfoResponse is the api response of a "get_tx_info" call
type getTxInfoResponse struct {
TimeCreated int `json:"time_created"`
TimeExpires int `json:"time_expires"`
Status int `json:"status"`
StatusText string `json:"status_text"`
Type string `json:"type"`
Coin string `json:"coin"`
Amount int `json:"amount"`
Amountf string `json:"amountf"`
Received int `json:"received"`
Receivedf string `json:"receivedf"`
ReceivedConfirms int `json:"recv_confirms"`
PaymentAddress string `json:"payment_address"`
Checkout struct {
Currency string `json:"currency"`
Amount int `json:"amount"`
Test int `json:"test"`
ItemNumber string `json:"item_number"`
ItemName string `json:"item_name"`
Details []interface{} `json:"details"`
Invoice string `json:"invoice"`
Custom string `json:"custom"`
IPNURL string `json:"ipn_url"`
Amountf int `json:"amountf"`
} `json:"checkout,omitempty"`
Shipping []interface{} `json:"shipping,omitempty"`
}
//GetTxInfo calls the "get_tx_info" command
func (c *Client) GetTxInfo(txid string, optionals ...OptionalValue) (*getTxInfoResponse, error) {
values := &url.Values{}
values.Set("txid", txid)
addOptionals(optionals, values)
var resp struct {
errResponse
Result *getTxInfoResponse `json:"result"`
}
if err := c.call("get_tx_info", values, &resp); err != nil {
return nil, err
}
return resp.Result, nil
}
//getTxInfoMultiResponse is the api response of a "get_tx_info_multi" call
type getTxInfoMultiResponse map[string]struct {
Error string `json:"error"`
TimeCreated int `json:"time_created"`
TimeExpires int `json:"time_expires"`
Status int `json:"status"`
StatusText string `json:"status_text"`
Type string `json:"type"`
Coin string `json:"coin"`
Amount int `json:"amount"`
Amountf string `json:"amountf"`
Received int `json:"received"`
Recievedf string `json:"recievedf"`
RecievedConfirms int `json:"recv_confirms"`
PaymentAddress string `json:"payment_address"`
}
//GetTxInfoMulti calls the "get_tx_info_multi" command
func (c *Client) GetTxInfoMulti(txid string, optionals ...OptionalValue) (*getTxInfoMultiResponse, error) {
values := &url.Values{}
values.Set("txid", txid)
addOptionals(optionals, values)
var resp struct {
errResponse
Result *getTxInfoMultiResponse `json:"result"`
}
if err := c.call("get_tx_info_multi", values, &resp); err != nil {
return nil, err
}
return resp.Result, nil
}
//getTxIdsResponse is the api response of a "get_tx_ids" call
type getTxIdsResponse []string
//GetTxIds calls the "get_tx_ids" command
func (c *Client) GetTxIds(optionals ...OptionalValue) (*getTxIdsResponse, error) {
values := &url.Values{}
addOptionals(optionals, values)
var resp struct {
errResponse
Result *getTxIdsResponse `json:"result"`
}
if err := c.call("get_tx_ids", values, &resp); err != nil {
return nil, err
}
return resp.Result, nil
}