From 1f766901f93d0c72e1d931ece0f9b93385813bf6 Mon Sep 17 00:00:00 2001 From: tungquach Date: Sun, 21 Apr 2019 10:08:48 +0700 Subject: [PATCH 1/4] Update order api endpoints --- README.md | 7 +++---- order.go | 30 ++++++------------------------ 2 files changed, 9 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 86079ca..7ce90c0 100644 --- a/README.md +++ b/README.md @@ -34,10 +34,9 @@ Currently supports **v2** only, if you want to use **v1**, use **v1.1.4** git ta * GET /v2/payments/sale/**ID** * POST /v2/payments/sale/**ID**/refund * GET /v2/payments/refund/**ID** - * GET /v2/payments/orders/**ID** - * POST /v2/payments/orders/**ID**/authorize - * POST /v2/payments/orders/**ID**/capture - * POST /v2/payments/orders/**ID**/do-void + * GET /v2/checkout/orders/**ID** + * POST /v2/checkout/orders/**ID**/authorize + * POST /v2/checkout/orders/**ID**/capture * POST /v2/payments/billing-plans * PATCH /v2/payments/billing-plans/***ID*** * POST /v2/payments/billing-agreements diff --git a/order.go b/order.go index 0598894..e07394d 100644 --- a/order.go +++ b/order.go @@ -3,11 +3,11 @@ package paypalsdk import "fmt" // GetOrder retrieves order by ID -// Endpoint: GET /v2/payments/orders/ID +// Endpoint: GET /v2/checkout/orders/ID func (c *Client) GetOrder(orderID string) (*Order, error) { order := &Order{} - req, err := c.NewRequest("GET", fmt.Sprintf("%s%s%s", c.APIBase, "/v2/payments/orders/", orderID), nil) + req, err := c.NewRequest("GET", fmt.Sprintf("%s%s%s", c.APIBase, "/v2/checkout/orders/", orderID), nil) if err != nil { return order, err } @@ -20,7 +20,7 @@ func (c *Client) GetOrder(orderID string) (*Order, error) { } // AuthorizeOrder - Use this call to authorize an order. -// Endpoint: POST /v2/payments/orders/ID/authorize +// Endpoint: POST /v2/checkout/orders/ID/authorize func (c *Client) AuthorizeOrder(orderID string, amount *Amount) (*Authorization, error) { type authRequest struct { Amount *Amount `json:"amount"` @@ -28,7 +28,7 @@ func (c *Client) AuthorizeOrder(orderID string, amount *Amount) (*Authorization, auth := &Authorization{} - req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/orders/"+orderID+"/authorize"), authRequest{Amount: amount}) + req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/checkout/orders/"+orderID+"/authorize"), authRequest{Amount: amount}) if err != nil { return auth, err } @@ -41,7 +41,7 @@ func (c *Client) AuthorizeOrder(orderID string, amount *Amount) (*Authorization, } // CaptureOrder - Use this call to capture a payment on an order. To use this call, an original payment call must specify an intent of order. -// Endpoint: POST /v2/payments/orders/ID/capture +// Endpoint: POST /v2/checkout/orders/ID/capture func (c *Client) CaptureOrder(orderID string, amount *Amount, isFinalCapture bool, currency *Currency) (*Capture, error) { type captureRequest struct { Amount *Amount `json:"amount"` @@ -51,7 +51,7 @@ func (c *Client) CaptureOrder(orderID string, amount *Amount, isFinalCapture boo capture := &Capture{} - req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/orders/"+orderID+"/capture"), captureRequest{Amount: amount, IsFinalCapture: isFinalCapture, Currency: currency}) + req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/checkout/orders/"+orderID+"/capture"), captureRequest{Amount: amount, IsFinalCapture: isFinalCapture, Currency: currency}) if err != nil { return capture, err } @@ -62,21 +62,3 @@ func (c *Client) CaptureOrder(orderID string, amount *Amount, isFinalCapture boo return capture, nil } - -// VoidOrder - Use this call to void an existing order. -// Note: An order cannot be voided if payment has already been partially or fully captured. -// Endpoint: POST /v2/payments/orders/ID/do-void -func (c *Client) VoidOrder(orderID string) (*Order, error) { - order := &Order{} - - req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/orders/"+orderID+"/do-void"), nil) - if err != nil { - return order, err - } - - if err = c.SendWithAuth(req, order); err != nil { - return order, err - } - - return order, nil -} From 3adfc8c315804eeccc5082d88128b7b17328c529 Mon Sep 17 00:00:00 2001 From: tungquach Date: Sun, 21 Apr 2019 10:13:01 +0700 Subject: [PATCH 2/4] update order intergration test --- integration_test.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/integration_test.go b/integration_test.go index 688c438..f78254a 100644 --- a/integration_test.go +++ b/integration_test.go @@ -128,16 +128,6 @@ func TestCaptureOrder(t *testing.T) { } } -func TestVoidOrder(t *testing.T) { - c, _ := NewClient(testClientID, testSecret, APIBaseSandBox) - c.GetAccessToken() - - _, err := c.VoidOrder(testOrderID) - if err == nil { - t.Errorf("Order is expired, 400 error must be returned") - } -} - func TestCreateSinglePayout(t *testing.T) { c, _ := NewClient(testClientID, testSecret, APIBaseSandBox) c.GetAccessToken() From 4557d3e5a78cccc5ece2719050783e3e1fa55578 Mon Sep 17 00:00:00 2001 From: tungquach Date: Sun, 21 Apr 2019 10:44:07 +0700 Subject: [PATCH 3/4] update order struct --- types.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/types.go b/types.go index 9eee27f..c9fcf66 100644 --- a/types.go +++ b/types.go @@ -94,6 +94,12 @@ type ( Value string `json:"value"` } + // GrossTotalAmount struct + GrossTotalAmount struct { + Value string `json:"value"` + Currency string `json:"currency"` + } + // ApplicationContext struct ApplicationContext struct { BrandName string `json:"brand_name"` @@ -325,14 +331,13 @@ type ( // Order struct Order struct { - ID string `json:"id,omitempty"` - CreateTime *time.Time `json:"create_time,omitempty"` - UpdateTime *time.Time `json:"update_time,omitempty"` - State string `json:"state,omitempty"` - Amount *Amount `json:"amount,omitempty"` - PendingReason string `json:"pending_reason,omitempty"` - ParentPayment string `json:"parent_payment,omitempty"` - Links []Link `json:"links,omitempty"` + ID string `json:"id,omitempty"` + Status string `json:"status,omitempty"` + Intent string `json:"intent,omitempty"` + GrossTotalAmount *GrossTotalAmount `json:"gross_total_amount,omitempty"` + Links []Link `json:"links,omitempty"` + CreateTime *time.Time `json:"create_time,omitempty"` + UpdateTime *time.Time `json:"update_time,omitempty"` } // Payer struct From 561690178b516af510311caba2b35c17e1bdb45c Mon Sep 17 00:00:00 2001 From: tungquach Date: Sun, 21 Apr 2019 11:43:53 +0700 Subject: [PATCH 4/4] update order struct, add purchase units --- types.go | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/types.go b/types.go index c9fcf66..345862a 100644 --- a/types.go +++ b/types.go @@ -94,12 +94,6 @@ type ( Value string `json:"value"` } - // GrossTotalAmount struct - GrossTotalAmount struct { - Value string `json:"value"` - Currency string `json:"currency"` - } - // ApplicationContext struct ApplicationContext struct { BrandName string `json:"brand_name"` @@ -319,6 +313,18 @@ type ( Enctype string `json:"enctype,omitempty"` } + // PurchaseUnitAmount struct + PurchaseUnitAmount struct { + Currency string `json:"currency_code"` + Value string `json:"value"` + } + + // PurchaseUnit struct + PurchaseUnit struct { + ReferenceID string `json:"reference_id"` + Amount *PurchaseUnitAmount `json:"amount,omitempty"` + } + // MerchantPreferences struct MerchantPreferences struct { SetupFee *AmountPayout `json:"setup_fee,omitempty"` @@ -331,13 +337,13 @@ type ( // Order struct Order struct { - ID string `json:"id,omitempty"` - Status string `json:"status,omitempty"` - Intent string `json:"intent,omitempty"` - GrossTotalAmount *GrossTotalAmount `json:"gross_total_amount,omitempty"` - Links []Link `json:"links,omitempty"` - CreateTime *time.Time `json:"create_time,omitempty"` - UpdateTime *time.Time `json:"update_time,omitempty"` + ID string `json:"id,omitempty"` + Status string `json:"status,omitempty"` + Intent string `json:"intent,omitempty"` + PurchaseUnits []PurchaseUnit `json:"purchase_units,omitempty"` + Links []Link `json:"links,omitempty"` + CreateTime *time.Time `json:"create_time,omitempty"` + UpdateTime *time.Time `json:"update_time,omitempty"` } // Payer struct