-
Notifications
You must be signed in to change notification settings - Fork 0
/
budpay.go
54 lines (47 loc) · 1.21 KB
/
budpay.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
package budpay
import (
"fmt"
"log/slog"
"net/http"
"net/url"
"os"
"time"
)
type BudPayClient struct {
BaseURL string
apiKey string
encryptionkey []byte
HTTPClient *http.Client
logger *slog.Logger
}
const (
CURRENCY_CODE_NGN string = "NGN"
ACCOUNT_VERIFICATION_UNAVAILABLE string = "account_verification unavailable"
)
func NewBudPayClient(budPayBaseURL, budPayApiKey, budPayEncryptionKey string) *BudPayClient {
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
client := &BudPayClient{
BaseURL: budPayBaseURL,
apiKey: budPayApiKey,
encryptionkey: []byte(budPayEncryptionKey),
HTTPClient: &http.Client{
Timeout: 1 * time.Minute,
},
logger: logger,
}
return client
}
func (bc *BudPayClient) SetupProxy(budpayProxy string) error {
if budpayProxy != "" {
bc.logger.Debug("using proxy for budpay", "proxy", budpayProxy)
proxyUrl, err := url.Parse(fmt.Sprintf("http://%s", budpayProxy))
if err != nil {
bc.logger.Error("error creating proxy url for budpay", "error", err)
return err
}
bc.HTTPClient.Transport = &http.Transport{Proxy: http.ProxyURL(proxyUrl)}
} else {
return fmt.Errorf("proxy cannot be empty")
}
return nil
}