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
|
||||||
|
|
52
types.go
52
types.go
|
@ -296,13 +296,14 @@ type (
|
||||||
// Client represents a Paypal REST API Client
|
// Client represents a Paypal REST API Client
|
||||||
Client struct {
|
Client struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
Client *http.Client
|
Client *http.Client
|
||||||
ClientID string
|
ClientID string
|
||||||
Secret string
|
Secret string
|
||||||
APIBase string
|
APIBase string
|
||||||
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,9 +553,18 @@ 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 {
|
||||||
Payments *CapturedPayments `json:"payments,omitempty"`
|
Items []CapturedPurchaseItem `json:"items,omitempty"`
|
||||||
|
Payments *CapturedPayments `json:"payments,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PayerWithNameAndPhone struct
|
// PayerWithNameAndPhone struct
|
||||||
|
@ -895,19 +905,19 @@ type (
|
||||||
VerifyWebhookResponse struct {
|
VerifyWebhookResponse struct {
|
||||||
VerificationStatus string `json:"verification_status,omitempty"`
|
VerificationStatus string `json:"verification_status,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
WebhookEvent struct {
|
WebhookEvent struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
CreateTime time.Time `json:"create_time"`
|
CreateTime time.Time `json:"create_time"`
|
||||||
ResourceType string `json:"resource_type"`
|
ResourceType string `json:"resource_type"`
|
||||||
EventType string `json:"event_type"`
|
EventType string `json:"event_type"`
|
||||||
Summary string `json:"summary,omitempty"`
|
Summary string `json:"summary,omitempty"`
|
||||||
Resource Resource `json:"resource"`
|
Resource Resource `json:"resource"`
|
||||||
Links []Link `json:"links"`
|
Links []Link `json:"links"`
|
||||||
EventVersion string `json:"event_version,omitempty"`
|
EventVersion string `json:"event_version,omitempty"`
|
||||||
ResourceVersion string `json:"resource_version,omitempty"`
|
ResourceVersion string `json:"resource_version,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
Resource struct {
|
Resource struct {
|
||||||
// Payment Resource type
|
// Payment Resource type
|
||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
|
@ -927,7 +937,7 @@ type (
|
||||||
// Common
|
// Common
|
||||||
Links []Link `json:"links,omitempty"`
|
Links []Link `json:"links,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
CaptureSellerBreakdown struct {
|
CaptureSellerBreakdown struct {
|
||||||
GrossAmount PurchaseUnitAmount `json:"gross_amount"`
|
GrossAmount PurchaseUnitAmount `json:"gross_amount"`
|
||||||
PayPalFee PurchaseUnitAmount `json:"paypal_fee"`
|
PayPalFee PurchaseUnitAmount `json:"paypal_fee"`
|
||||||
|
@ -942,7 +952,7 @@ type (
|
||||||
Products []string `json:"products,omitempty"`
|
Products []string `json:"products,omitempty"`
|
||||||
LegalConsents []Consent `json:"legal_consents,omitempty"`
|
LegalConsents []Consent `json:"legal_consents,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
PartnerConfigOverride struct {
|
PartnerConfigOverride struct {
|
||||||
PartnerLogoURL string `json:"partner_logo_url,omitempty"`
|
PartnerLogoURL string `json:"partner_logo_url,omitempty"`
|
||||||
ReturnURL string `json:"return_url,omitempty"`
|
ReturnURL string `json:"return_url,omitempty"`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user