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 // UpdateOrder updates the order by ID
// Endpoint: PATCH /v2/checkout/orders/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{} 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 { if err != nil {
return order, err return err
} }
if err = c.SendWithAuth(req, order); err != nil { if err = c.SendWithAuth(req, order); err != nil {
return order, err return err
} }
return nil
return order, nil
} }
// AuthorizeOrder - https://developer.paypal.com/docs/api/orders/v2/#orders_authorize // 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 // CapturedDetail - https://developer.paypal.com/docs/api/payments/v2/#captures_get
// Endpoint: GET /v2/payments/captures/ID // 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{} response := &CaptureDetailsResponse{}
req, err := c.NewRequest(ctx, "GET", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/captures/"+captureID), nil) req, err := c.NewRequest(ctx, "GET", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/captures/"+captureID), nil)