diff --git a/order.go b/order.go index a077728..512a5a5 100644 --- a/order.go +++ b/order.go @@ -2,6 +2,7 @@ package paypal import ( "context" + "encoding/json" "fmt" ) @@ -104,7 +105,7 @@ func (c *Client) AuthorizeOrder(ctx context.Context, orderID string, authorizeOr // CaptureOrder - https://developer.paypal.com/docs/api/orders/v2/#orders_capture // Endpoint: POST /v2/checkout/orders/ID/capture func (c *Client) CaptureOrder(ctx context.Context, orderID string, captureOrderRequest CaptureOrderRequest) (*CaptureOrderResponse, error) { - return c.CaptureOrderWithPaypalRequestId(ctx, orderID, captureOrderRequest, "") + return c.CaptureOrderWithPaypalRequestId(ctx, orderID, captureOrderRequest, "", nil) } // CaptureOrder with idempotency - https://developer.paypal.com/docs/api/orders/v2/#orders_capture @@ -114,6 +115,7 @@ func (c *Client) CaptureOrderWithPaypalRequestId(ctx context.Context, orderID string, captureOrderRequest CaptureOrderRequest, requestID string, + mockResponse *CaptureOrderMockResponse, ) (*CaptureOrderResponse, error) { capture := &CaptureOrderResponse{} @@ -127,6 +129,15 @@ func (c *Client) CaptureOrderWithPaypalRequestId(ctx context.Context, req.Header.Set("PayPal-Request-Id", requestID) } + if mockResponse != nil { + mock, err := json.Marshal(mockResponse) + if err != nil { + return nil, err + } + + req.Header.Set("PayPal-Mock-Response", string(mock)) + } + if err = c.SendWithAuth(req, capture); err != nil { return capture, err } diff --git a/types.go b/types.go index c034c34..9cbd68c 100644 --- a/types.go +++ b/types.go @@ -299,6 +299,11 @@ type ( PaymentSource *PaymentSource `json:"payment_source"` } + // CaptureOrderMockResponse - https://developer.paypal.com/docs/api-basics/sandbox/request-headers/#test-api-error-handling-routines + CaptureOrderMockResponse struct { + MockApplicationCodes string `json:"mock_application_codes"` + } + // RefundOrderRequest - https://developer.paypal.com/docs/api/payments/v2/#captures_refund RefundCaptureRequest struct { Amount *Money `json:"amount,omitempty"`