-
Notifications
You must be signed in to change notification settings - Fork 390
/
urls.go
43 lines (33 loc) · 1.07 KB
/
urls.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
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package coinpayments
import (
"net/url"
"github.com/zeebo/errs"
)
// ErrNoAuthorizationKey is error that indicates that there is no authorization key.
var ErrNoAuthorizationKey = Error.New("no authorization key")
// GetTransacationKeyFromURL parses provided raw url string
// and extracts authorization key from it. Returns ErrNoAuthorizationKey if
// there is no authorization key and error if rawurl cannot be parsed.
func GetTransacationKeyFromURL(rawurl string) (string, error) {
u, err := url.Parse(rawurl)
if err != nil {
return "", errs.Wrap(err)
}
key := u.Query().Get("key")
if key == "" {
return "", ErrNoAuthorizationKey
}
return key, nil
}
// GetCheckoutURL constructs checkout url from auth key and transaction id.
func GetCheckoutURL(key string, id TransactionID) string {
u, _ := url.Parse("https://coinpayments.net/index.php")
query := u.Query()
query.Add("cmd", "checkout")
query.Add("id", id.String())
query.Add("key", key)
u.RawQuery = query.Encode()
return u.String()
}