mirror of
https://github.com/plutov/paypal.git
synced 2025-01-23 02:11:02 +01:00
fix update order patchrequest (#240)
Co-authored-by: andy <xxxandyfenxxx@xxx.com>
This commit is contained in:
parent
c9ae5c4190
commit
7dc1f997d6
11
order.go
11
order.go
|
@ -72,14 +72,19 @@ func (c *Client) UpdateOrder(ctx context.Context, orderID string, op string, pat
|
|||
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), patchRequest{Op: op, Path: path, Value: value})
|
||||
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 err
|
||||
}
|
||||
|
||||
if err = c.SendWithAuth(req, order); err != nil {
|
||||
if err = c.SendWithAuth(req, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
|
66
order_test.go
Normal file
66
order_test.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
package paypal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var testClientID = "AXy9orp-CDaHhBZ9C78QHW2BKZpACgroqo85_NIOa9mIfJ9QnSVKzY-X_rivR_fTUUr6aLjcJsj6sDur"
|
||||
var testSecret = "EBoIiUSkCKeSk49hHSgTem1qnjzzJgRQHDEHvGpzlLEf_nIoJd91xu8rPOBDCdR_UYNKVxJE-UgS2iCw"
|
||||
|
||||
func TestUpdateOrder(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
|
||||
_, _ = c.GetAccessToken(ctx)
|
||||
|
||||
orderResponse, err := c.CreateOrder(
|
||||
ctx,
|
||||
OrderIntentCapture,
|
||||
[]PurchaseUnitRequest{
|
||||
{
|
||||
Amount: &PurchaseUnitAmount{
|
||||
Value: "7.00",
|
||||
Currency: "USD",
|
||||
},
|
||||
},
|
||||
},
|
||||
&CreateOrderPayer{},
|
||||
&ApplicationContext{},
|
||||
)
|
||||
if err != nil {
|
||||
t.Errorf("Not expected error for CreateOrder(), got %s", err.Error())
|
||||
}
|
||||
|
||||
order, err := c.GetOrder(ctx, orderResponse.ID)
|
||||
if err != nil {
|
||||
t.Errorf("Not expected error for GetOrder(), got %s", err.Error())
|
||||
}
|
||||
|
||||
if order.PurchaseUnits[0].Amount.Value != "7.00" {
|
||||
t.Errorf("CreateOrder amount incorrect")
|
||||
}
|
||||
|
||||
err = c.UpdateOrder(
|
||||
ctx,
|
||||
orderResponse.ID,
|
||||
"replace",
|
||||
"/purchase_units/@reference_id=='default'/amount",
|
||||
map[string]string{
|
||||
"currency_code": "USD",
|
||||
"value": "2.00",
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
t.Errorf("Not expected error for UpdateOrder(), got %s", err.Error())
|
||||
}
|
||||
|
||||
order, err = c.GetOrder(ctx, orderResponse.ID)
|
||||
if err != nil {
|
||||
t.Errorf("Not expected error for GetOrder(), got %s", err.Error())
|
||||
}
|
||||
|
||||
if order.PurchaseUnits[0].Amount.Value != "2.00" {
|
||||
t.Errorf("CreateOrder after update amount incorrect")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user