2015-12-17 08:50:25 +01:00
|
|
|
package paypalsdk
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
2016-12-22 06:06:00 +01:00
|
|
|
// GetOrder retrieves order by ID
|
2019-03-27 09:27:53 +01:00
|
|
|
// Endpoint: GET /v2/payments/orders/ID
|
2015-12-17 08:50:25 +01:00
|
|
|
func (c *Client) GetOrder(orderID string) (*Order, error) {
|
|
|
|
order := &Order{}
|
|
|
|
|
2019-03-27 09:27:53 +01:00
|
|
|
req, err := c.NewRequest("GET", fmt.Sprintf("%s%s%s", c.APIBase, "/v2/payments/orders/", orderID), nil)
|
2015-12-17 08:50:25 +01:00
|
|
|
if err != nil {
|
|
|
|
return order, err
|
|
|
|
}
|
|
|
|
|
2017-11-23 03:15:11 +01:00
|
|
|
if err = c.SendWithAuth(req, order); err != nil {
|
2015-12-17 08:50:25 +01:00
|
|
|
return order, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return order, nil
|
|
|
|
}
|
|
|
|
|
2015-12-29 10:21:11 +01:00
|
|
|
// AuthorizeOrder - Use this call to authorize an order.
|
2019-03-27 09:27:53 +01:00
|
|
|
// Endpoint: POST /v2/payments/orders/ID/authorize
|
2015-12-17 08:50:25 +01:00
|
|
|
func (c *Client) AuthorizeOrder(orderID string, amount *Amount) (*Authorization, error) {
|
|
|
|
type authRequest struct {
|
|
|
|
Amount *Amount `json:"amount"`
|
|
|
|
}
|
|
|
|
|
|
|
|
auth := &Authorization{}
|
|
|
|
|
2019-03-27 09:27:53 +01:00
|
|
|
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/orders/"+orderID+"/authorize"), authRequest{Amount: amount})
|
2015-12-17 08:50:25 +01:00
|
|
|
if err != nil {
|
|
|
|
return auth, err
|
|
|
|
}
|
|
|
|
|
2017-11-23 03:15:11 +01:00
|
|
|
if err = c.SendWithAuth(req, auth); err != nil {
|
2015-12-17 08:50:25 +01:00
|
|
|
return auth, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return auth, nil
|
|
|
|
}
|
|
|
|
|
2015-12-29 10:21:11 +01:00
|
|
|
// 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.
|
2019-03-27 09:27:53 +01:00
|
|
|
// Endpoint: POST /v2/payments/orders/ID/capture
|
2015-12-17 08:50:25 +01:00
|
|
|
func (c *Client) CaptureOrder(orderID string, amount *Amount, isFinalCapture bool, currency *Currency) (*Capture, error) {
|
|
|
|
type captureRequest struct {
|
|
|
|
Amount *Amount `json:"amount"`
|
|
|
|
IsFinalCapture bool `json:"is_final_capture"`
|
|
|
|
Currency *Currency `json:"transaction_fee"`
|
|
|
|
}
|
|
|
|
|
|
|
|
capture := &Capture{}
|
|
|
|
|
2019-03-27 09:27:53 +01:00
|
|
|
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/orders/"+orderID+"/capture"), captureRequest{Amount: amount, IsFinalCapture: isFinalCapture, Currency: currency})
|
2015-12-17 08:50:25 +01:00
|
|
|
if err != nil {
|
|
|
|
return capture, err
|
|
|
|
}
|
|
|
|
|
2017-11-23 03:15:11 +01:00
|
|
|
if err = c.SendWithAuth(req, capture); err != nil {
|
2015-12-17 08:50:25 +01:00
|
|
|
return capture, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return capture, nil
|
|
|
|
}
|
|
|
|
|
2015-12-29 10:21:11 +01:00
|
|
|
// VoidOrder - Use this call to void an existing order.
|
|
|
|
// Note: An order cannot be voided if payment has already been partially or fully captured.
|
2019-03-27 09:27:53 +01:00
|
|
|
// Endpoint: POST /v2/payments/orders/ID/do-void
|
2015-12-17 08:50:25 +01:00
|
|
|
func (c *Client) VoidOrder(orderID string) (*Order, error) {
|
|
|
|
order := &Order{}
|
|
|
|
|
2019-03-27 09:27:53 +01:00
|
|
|
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/orders/"+orderID+"/do-void"), nil)
|
2015-12-17 08:50:25 +01:00
|
|
|
if err != nil {
|
|
|
|
return order, err
|
|
|
|
}
|
|
|
|
|
2017-11-23 03:15:11 +01:00
|
|
|
if err = c.SendWithAuth(req, order); err != nil {
|
2015-12-17 08:50:25 +01:00
|
|
|
return order, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return order, nil
|
|
|
|
}
|