mirror of
https://github.com/plutov/paypal.git
synced 2025-01-23 10:21:03 +01:00
SendWithAuth
This commit is contained in:
parent
5043557577
commit
ba0fb56eea
|
@ -87,6 +87,15 @@ func (c *Client) Send(req *http.Request, v interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// SendWithAuth makes a request to the API and apply OAuth2 header automatically.
|
||||
// If the access token soon to be expired, it will try to get a new one before
|
||||
// making the main request
|
||||
func (c *Client) SendWithAuth(req *http.Request, v interface{}) error {
|
||||
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
|
||||
|
||||
return c.Send(req, v)
|
||||
}
|
||||
|
||||
func (c *Client) log(request *http.Request, response *http.Response) {
|
||||
if c.LogFile != "" {
|
||||
os.OpenFile(c.LogFile, os.O_CREATE, 0755)
|
||||
|
|
|
@ -22,7 +22,7 @@ func (c *Client) CreateDirectPaypalPayment(amount Amount, redirectURI string) (*
|
|||
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
|
||||
|
||||
p := PaymentResponse{}
|
||||
err = c.Send(req, &p)
|
||||
err = c.SendWithAuth(req, &p)
|
||||
|
||||
if p.ID == "" {
|
||||
return &p, errors.New("Unable to create payment with this access token")
|
||||
|
@ -43,7 +43,7 @@ func (c *Client) ExecuteApprovedPayment(paymentID string, payerID string) (*Exec
|
|||
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
|
||||
|
||||
e := ExecuteResponse{}
|
||||
err = c.Send(req, &e)
|
||||
err = c.SendWithAuth(req, &e)
|
||||
|
||||
if e.ID == "" {
|
||||
return &e, errors.New("Unable to execute payment with paymentID=" + paymentID)
|
||||
|
|
Loading…
Reference in New Issue
Block a user