Skip to content

Commit

Permalink
Adding a capture auth idempotent function (#142)
Browse files Browse the repository at this point in the history
* Adding a capture auth idempotent function

* refactoring

* better name

Co-Authored-By: Roopak Venkatakrishnan <[email protected]>

* what's in a name

Co-authored-by: Roopak Venkatakrishnan <[email protected]>
  • Loading branch information
kenbolt and roopakv authored Apr 20, 2020
1 parent 1fb8e0b commit 907cf40
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions order.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ func (c *Client) AuthorizeOrder(orderID string, authorizeOrderRequest AuthorizeO
// CaptureOrder - https://developer.paypal.com/docs/api/orders/v2/#orders_capture
// Endpoint: POST /v2/checkout/orders/ID/capture
func (c *Client) CaptureOrder(orderID string, captureOrderRequest CaptureOrderRequest) (*CaptureOrderResponse, error) {
return c.CaptureOrderWithPaypalRequestId(orderID, captureOrderRequest, "")
}

// CaptureOrder with idempotency - https://developer.paypal.com/docs/api/orders/v2/#orders_capture
// Endpoint: POST /v2/checkout/orders/ID/capture
// https://developer.paypal.com/docs/api/reference/api-requests/#http-request-headers
func (c *Client) CaptureOrderWithPaypalRequestId(
orderID string,
captureOrderRequest CaptureOrderRequest,
requestID string,
) (*CaptureOrderResponse, error) {
capture := &CaptureOrderResponse{}

c.SetReturnRepresentation()
Expand All @@ -88,6 +99,10 @@ func (c *Client) CaptureOrder(orderID string, captureOrderRequest CaptureOrderRe
return capture, err
}

if requestID != "" {
req.Header.Set("PayPal-Request-Id", requestID)
}

if err = c.SendWithAuth(req, capture); err != nil {
return capture, err
}
Expand Down

0 comments on commit 907cf40

Please sign in to comment.