Skip to content

Commit

Permalink
Merge pull request #3 from dietdoctor/http-client-interface
Browse files Browse the repository at this point in the history
use interface for http client so that we can use other implementations
  • Loading branch information
lindroth authored Sep 17, 2019
2 parents fdbf52c + 93c6a46 commit 1355537
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions braintree.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ var (
}
)

type httpClient interface {
Do(req *http.Request) (*http.Response, error)
}

// New creates a Braintree client with API Keys.
func New(env Environment, merchId, pubKey, privKey string) *Braintree {
return NewWithHttpClient(env, merchId, pubKey, privKey, defaultClient)
}

// NewWithHttpClient creates a Braintree client with API Keys and a HTTP Client.
func NewWithHttpClient(env Environment, merchantId, publicKey, privateKey string, client *http.Client) *Braintree {
func NewWithHttpClient(env Environment, merchantId, publicKey, privateKey string, client httpClient) *Braintree {
return &Braintree{credentials: newAPIKey(env, merchantId, publicKey, privateKey), HttpClient: client}
}

Expand All @@ -71,7 +75,7 @@ func NewWithAccessToken(accessToken string) (*Braintree, error) {
type Braintree struct {
credentials credentials
Logger *log.Logger
HttpClient *http.Client
HttpClient httpClient
}

// Environment returns the current environment.
Expand Down

0 comments on commit 1355537

Please sign in to comment.