Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: paypal client with proxy url option #371

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion paypal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ type Client struct {
baseUrlSandbox string
}

type Option func(*Client)

// NewClient 初始化PayPal支付客户端
func NewClient(clientid, secret string, isProd bool) (client *Client, err error) {
func NewClient(clientid, secret string, isProd bool, options ...Option) (client *Client, err error) {
if clientid == util.NULL || secret == util.NULL {
return nil, gopay.MissPayPalInitParamErr
}
Expand All @@ -38,6 +40,9 @@ func NewClient(clientid, secret string, isProd bool) (client *Client, err error)
baseUrlProd: baseUrlProd,
baseUrlSandbox: baseUrlSandbox,
}
for _, option := range options {
option(client)
}
_, err = client.GetAccessToken()
if err != nil {
return nil, err
Expand All @@ -47,6 +52,14 @@ func NewClient(clientid, secret string, isProd bool) (client *Client, err error)
return client, nil
}

// WithProxyUrl 设置代理 Url
func WithProxyUrl(proxyUrlProd, proxyUrlSandbox string) Option {
return func(c *Client) {
c.baseUrlProd = proxyUrlProd
c.baseUrlSandbox = proxyUrlSandbox
}
}

// SetBodySize 设置http response body size(MB)
func (c *Client) SetBodySize(sizeMB int) {
if sizeMB > 0 {
Expand Down