Include the 'items' in the response when capturing orders

This commit is contained in:
Alex Pliutau 2020-01-06 15:27:03 +01:00
parent 89088bee4e
commit 0e7098bda4
3 changed files with 41 additions and 21 deletions

View File

@ -70,6 +70,12 @@ func (c *Client) SetLog(log io.Writer) {
c.Log = log
}
// SetReturnRepresentation enables verbose response
// Verbose response: https://developer.paypal.com/docs/api/orders/v2/#orders-authorize-header-parameters
func (c *Client) SetReturnRepresentation() {
c.returnRepresentation = true
}
// Send makes a request to the API, the response body will be
// unmarshaled into v, or if v is an io.Writer, the response will
// be written to it without decoding
@ -88,6 +94,9 @@ func (c *Client) Send(req *http.Request, v interface{}) error {
if req.Header.Get("Content-type") == "" {
req.Header.Set("Content-type", "application/json")
}
if c.returnRepresentation {
req.Header.Set("Prefer", "return=representation")
}
resp, err = c.Client.Do(req)
c.log(req, resp)

View File

@ -82,6 +82,7 @@ func (c *Client) AuthorizeOrder(orderID string, authorizeOrderRequest AuthorizeO
func (c *Client) CaptureOrder(orderID string, captureOrderRequest CaptureOrderRequest) (*CaptureOrderResponse, error) {
capture := &CaptureOrderResponse{}
c.SetReturnRepresentation()
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/checkout/orders/"+orderID+"/capture"), captureOrderRequest)
if err != nil {
return capture, err

View File

@ -296,13 +296,14 @@ type (
// Client represents a Paypal REST API Client
Client struct {
sync.Mutex
Client *http.Client
ClientID string
Secret string
APIBase string
Log io.Writer // If user set log file name all requests will be logged there
Token *TokenResponse
tokenExpiresAt time.Time
Client *http.Client
ClientID string
Secret string
APIBase string
Log io.Writer // If user set log file name all requests will be logged there
Token *TokenResponse
tokenExpiresAt time.Time
returnRepresentation bool
}
// CreditCard struct
@ -552,9 +553,18 @@ type (
Captures []CaptureAmount `json:"captures,omitempty"`
}
// CapturedPurchaseItem are items for a captured order
CapturedPurchaseItem struct {
Quantity string `json:"quantity"`
Name string `json:"name"`
SKU string `json:"sku,omitempty"`
Description string `json:"description,omitempty"`
}
// CapturedPurchaseUnit are purchase units for a captured order
CapturedPurchaseUnit struct {
Payments *CapturedPayments `json:"payments,omitempty"`
Items []CapturedPurchaseItem `json:"items,omitempty"`
Payments *CapturedPayments `json:"payments,omitempty"`
}
// PayerWithNameAndPhone struct
@ -897,15 +907,15 @@ type (
}
WebhookEvent struct {
ID string `json:"id"`
CreateTime time.Time `json:"create_time"`
ResourceType string `json:"resource_type"`
EventType string `json:"event_type"`
Summary string `json:"summary,omitempty"`
Resource Resource `json:"resource"`
Links []Link `json:"links"`
EventVersion string `json:"event_version,omitempty"`
ResourceVersion string `json:"resource_version,omitempty"`
ID string `json:"id"`
CreateTime time.Time `json:"create_time"`
ResourceType string `json:"resource_type"`
EventType string `json:"event_type"`
Summary string `json:"summary,omitempty"`
Resource Resource `json:"resource"`
Links []Link `json:"links"`
EventVersion string `json:"event_version,omitempty"`
ResourceVersion string `json:"resource_version,omitempty"`
}
Resource struct {