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
This commit is contained in:
Anooj Muttavarapu 2022-03-05 02:15:53 -05:00 committed by GitHub
parent fc3ffe5b60
commit ca6845e257
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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