generated from NdoleStudio/go-http-client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
payment_service.go
63 lines (51 loc) · 1.77 KB
/
payment_service.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
package coinpayments
import (
"context"
"encoding/json"
"net/http"
"net/url"
)
// paymentService is the API client Payments on coinpayments.net
type paymentService service
// CreateTransaction creates a payment on coinpayments
//
// API Docs: https://www.coinpayments.net/apidoc-create-transaction
func (service *paymentService) CreateTransaction(ctx context.Context, params *CreatePaymentRequest) (*CreatePaymentResponse, *Response, error) {
payload := url.Values{}
payload.Add("amount", params.Amount)
payload.Add("currency1", params.OriginalCurrency)
payload.Add("currency2", params.SendingCurrency)
request, err := service.client.newRequest(ctx, http.MethodPost, "create_transaction", payload)
if err != nil {
return nil, nil, err
}
response, err := service.client.do(request)
if err != nil {
return nil, response, err
}
createPaymentResponse := new(CreatePaymentResponse)
if err = json.Unmarshal(*response.Body, createPaymentResponse); err != nil {
return nil, response, err
}
return createPaymentResponse, response, nil
}
// GetTransaction fetches information on a transaction
//
// API Docs: https://www.coinpayments.net/apidoc-get-tx-info
func (service *paymentService) GetTransaction(ctx context.Context, transactionID string) (*map[string]interface{}, *Response, error) {
payload := url.Values{}
payload.Add("txid", transactionID)
request, err := service.client.newRequest(ctx, http.MethodPost, "get_tx_info", payload)
if err != nil {
return nil, nil, err
}
response, err := service.client.do(request)
if err != nil {
return nil, response, err
}
createPaymentResponse := new(map[string]interface{})
if err = json.Unmarshal(*response.Body, createPaymentResponse); err != nil {
return nil, response, err
}
return createPaymentResponse, response, nil
}