forked from go-packages/paypal
Merge pull request #84 from tungquach/master
Update order api endpoints, remove unsupported order do void api
This commit is contained in:
commit
17ba889ca0
|
@ -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**
|
* GET /v2/payments/sale/**ID**
|
||||||
* POST /v2/payments/sale/**ID**/refund
|
* POST /v2/payments/sale/**ID**/refund
|
||||||
* GET /v2/payments/refund/**ID**
|
* GET /v2/payments/refund/**ID**
|
||||||
* GET /v2/payments/orders/**ID**
|
* GET /v2/checkout/orders/**ID**
|
||||||
* POST /v2/payments/orders/**ID**/authorize
|
* POST /v2/checkout/orders/**ID**/authorize
|
||||||
* POST /v2/payments/orders/**ID**/capture
|
* POST /v2/checkout/orders/**ID**/capture
|
||||||
* POST /v2/payments/orders/**ID**/do-void
|
|
||||||
* POST /v2/payments/billing-plans
|
* POST /v2/payments/billing-plans
|
||||||
* PATCH /v2/payments/billing-plans/***ID***
|
* PATCH /v2/payments/billing-plans/***ID***
|
||||||
* POST /v2/payments/billing-agreements
|
* POST /v2/payments/billing-agreements
|
||||||
|
|
|
@ -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) {
|
func TestCreateSinglePayout(t *testing.T) {
|
||||||
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
|
c, _ := NewClient(testClientID, testSecret, APIBaseSandBox)
|
||||||
c.GetAccessToken()
|
c.GetAccessToken()
|
||||||
|
|
30
order.go
30
order.go
|
@ -3,11 +3,11 @@ package paypalsdk
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
// GetOrder retrieves order by ID
|
// 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) {
|
func (c *Client) GetOrder(orderID string) (*Order, error) {
|
||||||
order := &Order{}
|
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 {
|
if err != nil {
|
||||||
return order, err
|
return order, err
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func (c *Client) GetOrder(orderID string) (*Order, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuthorizeOrder - Use this call to authorize an order.
|
// 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) {
|
func (c *Client) AuthorizeOrder(orderID string, amount *Amount) (*Authorization, error) {
|
||||||
type authRequest struct {
|
type authRequest struct {
|
||||||
Amount *Amount `json:"amount"`
|
Amount *Amount `json:"amount"`
|
||||||
|
@ -28,7 +28,7 @@ func (c *Client) AuthorizeOrder(orderID string, amount *Amount) (*Authorization,
|
||||||
|
|
||||||
auth := &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 {
|
if err != nil {
|
||||||
return auth, err
|
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.
|
// 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) {
|
func (c *Client) CaptureOrder(orderID string, amount *Amount, isFinalCapture bool, currency *Currency) (*Capture, error) {
|
||||||
type captureRequest struct {
|
type captureRequest struct {
|
||||||
Amount *Amount `json:"amount"`
|
Amount *Amount `json:"amount"`
|
||||||
|
@ -51,7 +51,7 @@ func (c *Client) CaptureOrder(orderID string, amount *Amount, isFinalCapture boo
|
||||||
|
|
||||||
capture := &Capture{}
|
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 {
|
if err != nil {
|
||||||
return capture, err
|
return capture, err
|
||||||
}
|
}
|
||||||
|
@ -62,21 +62,3 @@ func (c *Client) CaptureOrder(orderID string, amount *Amount, isFinalCapture boo
|
||||||
|
|
||||||
return capture, nil
|
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
|
|
||||||
}
|
|
||||||
|
|
27
types.go
27
types.go
|
@ -313,6 +313,18 @@ type (
|
||||||
Enctype string `json:"enctype,omitempty"`
|
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
|
||||||
MerchantPreferences struct {
|
MerchantPreferences struct {
|
||||||
SetupFee *AmountPayout `json:"setup_fee,omitempty"`
|
SetupFee *AmountPayout `json:"setup_fee,omitempty"`
|
||||||
|
@ -325,14 +337,13 @@ type (
|
||||||
|
|
||||||
// Order struct
|
// Order struct
|
||||||
Order struct {
|
Order struct {
|
||||||
ID string `json:"id,omitempty"`
|
ID string `json:"id,omitempty"`
|
||||||
CreateTime *time.Time `json:"create_time,omitempty"`
|
Status string `json:"status,omitempty"`
|
||||||
UpdateTime *time.Time `json:"update_time,omitempty"`
|
Intent string `json:"intent,omitempty"`
|
||||||
State string `json:"state,omitempty"`
|
PurchaseUnits []PurchaseUnit `json:"purchase_units,omitempty"`
|
||||||
Amount *Amount `json:"amount,omitempty"`
|
Links []Link `json:"links,omitempty"`
|
||||||
PendingReason string `json:"pending_reason,omitempty"`
|
CreateTime *time.Time `json:"create_time,omitempty"`
|
||||||
ParentPayment string `json:"parent_payment,omitempty"`
|
UpdateTime *time.Time `json:"update_time,omitempty"`
|
||||||
Links []Link `json:"links,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Payer struct
|
// Payer struct
|
||||||
|
|
Loading…
Reference in New Issue
Block a user