From 907cf40be1ae5ec3bcb2cab58c1e0a5a2aafc3c0 Mon Sep 17 00:00:00 2001 From: kenbolt <54861412+kenbolt@users.noreply.github.com> Date: Mon, 20 Apr 2020 12:49:30 -0700 Subject: [PATCH] Adding a capture auth idempotent function (#142) * Adding a capture auth idempotent function * refactoring * better name Co-Authored-By: Roopak Venkatakrishnan * what's in a name Co-authored-by: Roopak Venkatakrishnan --- order.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/order.go b/order.go index 0ae69d3..b901269 100644 --- a/order.go +++ b/order.go @@ -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 }