mirror of
https://github.com/plutov/paypal.git
synced 2025-02-02 15:10:36 +01:00
Include the 'items' in the response when capturing orders
This commit is contained in:
parent
89088bee4e
commit
0e7098bda4
|
@ -70,6 +70,12 @@ func (c *Client) SetLog(log io.Writer) {
|
||||||
c.Log = log
|
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
|
// 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
|
// unmarshaled into v, or if v is an io.Writer, the response will
|
||||||
// be written to it without decoding
|
// 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") == "" {
|
if req.Header.Get("Content-type") == "" {
|
||||||
req.Header.Set("Content-type", "application/json")
|
req.Header.Set("Content-type", "application/json")
|
||||||
}
|
}
|
||||||
|
if c.returnRepresentation {
|
||||||
|
req.Header.Set("Prefer", "return=representation")
|
||||||
|
}
|
||||||
|
|
||||||
resp, err = c.Client.Do(req)
|
resp, err = c.Client.Do(req)
|
||||||
c.log(req, resp)
|
c.log(req, resp)
|
||||||
|
|
1
order.go
1
order.go
|
@ -82,6 +82,7 @@ func (c *Client) AuthorizeOrder(orderID string, authorizeOrderRequest AuthorizeO
|
||||||
func (c *Client) CaptureOrder(orderID string, captureOrderRequest CaptureOrderRequest) (*CaptureOrderResponse, error) {
|
func (c *Client) CaptureOrder(orderID string, captureOrderRequest CaptureOrderRequest) (*CaptureOrderResponse, error) {
|
||||||
capture := &CaptureOrderResponse{}
|
capture := &CaptureOrderResponse{}
|
||||||
|
|
||||||
|
c.SetReturnRepresentation()
|
||||||
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/checkout/orders/"+orderID+"/capture"), captureOrderRequest)
|
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/checkout/orders/"+orderID+"/capture"), captureOrderRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return capture, err
|
return capture, err
|
||||||
|
|
10
types.go
10
types.go
|
@ -303,6 +303,7 @@ type (
|
||||||
Log io.Writer // If user set log file name all requests will be logged there
|
Log io.Writer // If user set log file name all requests will be logged there
|
||||||
Token *TokenResponse
|
Token *TokenResponse
|
||||||
tokenExpiresAt time.Time
|
tokenExpiresAt time.Time
|
||||||
|
returnRepresentation bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreditCard struct
|
// CreditCard struct
|
||||||
|
@ -552,8 +553,17 @@ type (
|
||||||
Captures []CaptureAmount `json:"captures,omitempty"`
|
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 are purchase units for a captured order
|
||||||
CapturedPurchaseUnit struct {
|
CapturedPurchaseUnit struct {
|
||||||
|
Items []CapturedPurchaseItem `json:"items,omitempty"`
|
||||||
Payments *CapturedPayments `json:"payments,omitempty"`
|
Payments *CapturedPayments `json:"payments,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user