-
Notifications
You must be signed in to change notification settings - Fork 0
/
pairClient.go
55 lines (47 loc) · 1.3 KB
/
pairClient.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
package ptcpayclient
import (
"encoding/json"
"net/http"
)
//***********************************************
//* Copyright (c) 2021 Ulbora Labs LLC
//* Copyright (c) 2021 Ken Williamson
//***********************************************
//Token Token
func (a *BTCPayClient) Token(req *TokenRequest) *TokenResponse {
var rtn TokenResponse
var url = a.host + "/tokens"
a.log.Debug("url: ", url)
aJSON, err := json.Marshal(req)
if err == nil {
var headers Headers
req := a.buildRequest(http.MethodPost, url, headers, aJSON)
suc, stat := a.proxy.Do(req, &rtn)
a.log.Debug("suc: ", suc)
a.log.Debug("stat: ", stat)
rtn.Code = int64(stat)
if !suc || stat != http.StatusOK {
a.log.Debug("proxy call failed to : ", url)
}
}
a.log.Debug("rtn: ", rtn)
if len(rtn.Data) > 0 {
a.tokens = rtn.Data[0]
}
return &rtn
}
//PairClient PairClient
func (a *BTCPayClient) PairClient(code string) *TokenResponse {
a.log.Debug("pairing with code: ", code)
var tkr TokenRequest
tkr.ID = a.clientID
tkr.PairingCode = code
a.log.Debug("PairClient req: ", tkr)
return a.Token(&tkr)
}
//GetPairingCodeRequest GetPairingCodeRequest
func (a *BTCPayClient) GetPairingCodeRequest(code string) string {
var url = a.host + "/api-access-request?pairingCode=" + code
a.log.Debug("pair request url: ", url)
return url
}