Skip to content

Commit 5052fd4

Browse files
committed
Fix #271
1 parent 3713084 commit 5052fd4

File tree

2 files changed

+5
-30
lines changed

2 files changed

+5
-30
lines changed

client_test.go

+2-26
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package paypal
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
76
"math/rand"
87
"net/http"
@@ -46,38 +45,15 @@ func createRandomProduct(t *testing.T) Product {
4645
// test the Lock and Unlock methods of the private mutex field
4746
// of Client structure.
4847
func (c *Client) sendWithAuth(req *http.Request, v interface{}) error {
49-
// c.Lock()
5048
c.mu.Lock()
51-
// Note: Here we do not want to `defer c.Unlock()` because we need `c.Send(...)`
52-
// to happen outside of the locked section.
53-
54-
if c.mu.TryLock() {
55-
// if the code is able to acquire a lock
56-
// despite the mutex of c being locked, throw an error
57-
err := errors.New("TryLock succeeded inside sendWithAuth with mutex locked")
58-
return err
59-
}
49+
defer c.mu.Unlock()
50+
6051
if c.Token == nil || (!c.tokenExpiresAt.IsZero() && time.Until(c.tokenExpiresAt) < RequestNewTokenBeforeExpiresIn) {
61-
// c.Token will be updated in GetAccessToken call
6252
if _, err := c.GetAccessToken(req.Context()); err != nil {
63-
// c.Unlock()
64-
c.mu.Unlock()
6553
return err
6654
}
6755
}
6856
req.Header.Set("Authorization", "Bearer "+c.Token.Token)
69-
// Unlock the client mutex before sending the request, this allows multiple requests
70-
// to be in progress at the same time.
71-
// c.Unlock()
72-
c.mu.Unlock()
73-
74-
if !c.mu.TryLock() {
75-
// if the code is unable to acquire a lock
76-
// despite the mutex of c being unlocked, throw an error
77-
err := errors.New("TryLock failed inside sendWithAuth with mutex unlocked")
78-
return err
79-
}
80-
c.mu.Unlock() // undo changes from the previous TryLock
8157

8258
return c.Send(req, v)
8359
}

types.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -483,14 +483,13 @@ type (
483483
Links []Link `json:"links,omitempty"`
484484
}
485485

486-
// AuthorizeOrderResponse .
487486
AuthorizeOrderResponse struct {
488487
CreateTime *time.Time `json:"create_time,omitempty"`
489488
UpdateTime *time.Time `json:"update_time,omitempty"`
490489
ID string `json:"id,omitempty"`
491490
Status string `json:"status,omitempty"`
492491
Intent string `json:"intent,omitempty"`
493-
PurchaseUnits []PurchaseUnitRequest `json:"purchase_units,omitempty"`
492+
PurchaseUnits []PurchaseUnit `json:"purchase_units,omitempty"`
494493
Payer *PayerWithNameAndPhone `json:"payer,omitempty"`
495494
}
496495

@@ -826,7 +825,6 @@ type (
826825
Value string `json:"value"`
827826
}
828827

829-
// PurchaseUnit struct
830828
PurchaseUnit struct {
831829
ReferenceID string `json:"reference_id"`
832830
Amount *PurchaseUnitAmount `json:"amount,omitempty"`
@@ -944,7 +942,8 @@ type (
944942

945943
// CapturedPayments has the amounts for a captured order
946944
CapturedPayments struct {
947-
Captures []CaptureAmount `json:"captures,omitempty"`
945+
Autthorizations []Authorization `json:"authorizations,omitempty"`
946+
Captures []CaptureAmount `json:"captures,omitempty"`
948947
}
949948

950949
// CapturedPurchaseItem are items for a captured order

0 commit comments

Comments
 (0)