From ca6845e257c15977fee3d03ad0d82b707dd64234 Mon Sep 17 00:00:00 2001 From: Anooj Muttavarapu <95250761+anooj-bolt@users.noreply.github.com> Date: Sat, 5 Mar 2022 02:15:53 -0500 Subject: [PATCH] Fixes updaterequest (#236) * Fixes updaterequest Fixes update request to support the patch request body format. https://developer.paypal.com/api/orders/v2/#definition-patch * Change return type Return type should only be error. * Add nil return Add nil return --- order.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/order.go b/order.go index 5e2a6b6..a077728 100644 --- a/order.go +++ b/order.go @@ -64,19 +64,24 @@ func (c *Client) CreateOrderWithPaypalRequestID(ctx context.Context, // UpdateOrder updates the order by ID // Endpoint: PATCH /v2/checkout/orders/ID -func (c *Client) UpdateOrder(ctx context.Context, orderID string, purchaseUnits []PurchaseUnitRequest) (*Order, error) { +func (c *Client) UpdateOrder(ctx context.Context, orderID string, op string, path string, value map[string]string) error { + + type patchRequest struct { + Op string `json:"op"` + Path string `json:"path"` + Value map[string]string `json:"value"` + } order := &Order{} - req, err := c.NewRequest(ctx, "PATCH", fmt.Sprintf("%s%s%s", c.APIBase, "/v2/checkout/orders/", orderID), purchaseUnits) + req, err := c.NewRequest(ctx, "PATCH", fmt.Sprintf("%s%s%s", c.APIBase, "/v2/checkout/orders/", orderID), patchRequest{Op: op, Path: path, Value: value}) if err != nil { - return order, err + return err } if err = c.SendWithAuth(req, order); err != nil { - return order, err + return err } - - return order, nil + return nil } // AuthorizeOrder - https://developer.paypal.com/docs/api/orders/v2/#orders_authorize @@ -161,7 +166,7 @@ func (c *Client) RefundCaptureWithPaypalRequestId(ctx context.Context, // CapturedDetail - https://developer.paypal.com/docs/api/payments/v2/#captures_get // Endpoint: GET /v2/payments/captures/ID -func (c *Client) CapturedDetail(ctx context.Context, captureID string ) (*CaptureDetailsResponse, error) { +func (c *Client) CapturedDetail(ctx context.Context, captureID string) (*CaptureDetailsResponse, error) { response := &CaptureDetailsResponse{} req, err := c.NewRequest(ctx, "GET", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/captures/"+captureID), nil) @@ -173,4 +178,4 @@ func (c *Client) CapturedDetail(ctx context.Context, captureID string ) (*Captur return response, err } return response, nil -} \ No newline at end of file +}