Adding a capture auth idempotent function (#142)

* Adding a capture auth idempotent function

* refactoring

* better name

Co-Authored-By: Roopak Venkatakrishnan <roopak.v@gmail.com>

* what's in a name

Co-authored-by: Roopak Venkatakrishnan <roopak.v@gmail.com>
This commit is contained in:
kenbolt 2020-04-20 12:49:30 -07:00 committed by GitHub
parent 1fb8e0b1fa
commit 907cf40be1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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()
@ -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
}