-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
111 lines (97 loc) · 3.01 KB
/
client.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
package pinpayments
import (
"net/http"
"net/url"
"runtime"
"strings"
)
const (
BaseURL string = "https://api.pinpayments.com/1/"
BaseURLTest string = "https://test-api.pinpayments.com/1/"
RequestContentType string = "application/json"
RequestAccept string = "application/json"
Connection string = "keep-alive"
AuthHeader string = "Authorization"
TokenType string = "Basic"
APIEnvSecret string = "API_SECRET"
APIEnvKey string = "API_KEY"
)
type Client struct {
BaseURL *url.URL
config *Config
userAgent string
client *http.Client
common service
secretKey string
publishableKey string
Charges *ChagresService
Customers *CustomersService
Refunds *RefundsService
Cards *CardsService
Recipients *RecipientsService
Transfers *TransfersService
Balance *BalanceService
BankAccount *BankAccountService
Events *EventsService
WebhookEndpoints *WebhookEndpointsService
Webhooks *WebhooksService
Plans *PlansService
Subscription *SubscriptionService
Merchant *MerchantsService
}
type service struct {
client *Client
}
func (c *Client) WithAuthenticationValue(k string, p string) error {
if k == "" {
return errEmptyApiKey
}
if p == "" {
return errEmptyApiPublishable
}
c.secretKey = strings.TrimSpace(k)
c.publishableKey = strings.TrimSpace(p)
return nil
}
func NewClient(baseClient *http.Client, c *Config) (pinpayments *Client, err error) {
if baseClient == nil {
baseClient = http.DefaultClient
}
var host string
if c.testing {
host = BaseURLTest
} else {
host = BaseURL
}
u, _ := url.Parse(host)
pinpayments = &Client{
BaseURL: u,
config: c,
client: baseClient,
}
pinpayments.common.client = pinpayments
// here is all services begin
pinpayments.Charges = (*ChagresService)(&pinpayments.common)
pinpayments.Customers = (*CustomersService)(&pinpayments.common)
pinpayments.Refunds = (*RefundsService)(&pinpayments.common)
pinpayments.Cards = (*CardsService)(&pinpayments.common)
pinpayments.Recipients = (*RecipientsService)(&pinpayments.common)
pinpayments.Transfers = (*TransfersService)(&pinpayments.common)
pinpayments.Balance = (*BalanceService)(&pinpayments.common)
pinpayments.BankAccount = (*BankAccountService)(&pinpayments.common)
pinpayments.Events = (*EventsService)(&pinpayments.common)
pinpayments.WebhookEndpoints = (*WebhookEndpointsService)(&pinpayments.common)
pinpayments.Webhooks = (*WebhooksService)(&pinpayments.common)
pinpayments.Plans = (*PlansService)(&pinpayments.common)
pinpayments.Subscription = (*SubscriptionService)(&pinpayments.common)
pinpayments.Merchant = (*MerchantsService)(&pinpayments.common)
// here is all services end
pinpayments.publishableKey = c.publishableKey
pinpayments.secretKey = c.secretKey
pinpayments.userAgent = strings.Join([]string{
runtime.GOOS,
runtime.GOARCH,
runtime.Version(),
}, ";")
return
}