forked from go-packages/paypal
#89: Add UpdateOrder
This commit is contained in:
parent
637e1c4b15
commit
224bd1f949
17
README.md
17
README.md
|
@ -36,6 +36,7 @@ Currently supports **v2** only, if you want to use **v1**, use **v1.1.4** git ta
|
||||||
* GET /v2/payments/refund/**ID**
|
* GET /v2/payments/refund/**ID**
|
||||||
* POST /v2/checkout/orders
|
* POST /v2/checkout/orders
|
||||||
* GET /v2/checkout/orders/**ID**
|
* GET /v2/checkout/orders/**ID**
|
||||||
|
* PATCH /v2/checkout/orders/**ID**
|
||||||
* POST /v2/checkout/orders/**ID**/authorize
|
* POST /v2/checkout/orders/**ID**/authorize
|
||||||
* POST /v2/checkout/orders/**ID**/capture
|
* POST /v2/checkout/orders/**ID**/capture
|
||||||
* POST /v2/payments/billing-plans
|
* POST /v2/payments/billing-plans
|
||||||
|
@ -115,22 +116,22 @@ order, err := c.GetOrder("O-4J082351X3132253H")
|
||||||
order, err := c.CreateOrder(paypalsdk.OrderIntentCapture, []paypalsdk.PurchaseUnitRequest{paypalsdk.PurchaseUnitRequest{ReferenceID: "ref-id", Amount: paypalsdk.Amount{Total: "7.00", Currency: "USD"}}})
|
order, err := c.CreateOrder(paypalsdk.OrderIntentCapture, []paypalsdk.PurchaseUnitRequest{paypalsdk.PurchaseUnitRequest{ReferenceID: "ref-id", Amount: paypalsdk.Amount{Total: "7.00", Currency: "USD"}}})
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Update Order by ID
|
||||||
|
|
||||||
|
```go
|
||||||
|
order, err := c.UpdateOrder("O-4J082351X3132253H", []paypalsdk.PurchaseUnitRequest{})
|
||||||
|
```
|
||||||
|
|
||||||
### Authorize Order
|
### Authorize Order
|
||||||
|
|
||||||
```go
|
```go
|
||||||
auth, err := c.AuthorizeOrder(orderID, paypalsdk.PaymentSource{})
|
auth, err := c.AuthorizeOrder(orderID, paypalsdk.AuthorizeOrderRequest{})
|
||||||
```
|
```
|
||||||
|
|
||||||
### Capture Order
|
### Capture Order
|
||||||
|
|
||||||
```go
|
```go
|
||||||
capture, err := c.CaptureOrder(orderID, paypalsdk.PaymentSource{})
|
capture, err := c.CaptureOrder(orderID, paypalsdk.CaptureOrderRequest{})
|
||||||
```
|
|
||||||
|
|
||||||
### Void Order
|
|
||||||
|
|
||||||
```go
|
|
||||||
order, err := c.VoidOrder(orderID)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Identity
|
### Identity
|
||||||
|
|
29
order.go
29
order.go
|
@ -40,12 +40,29 @@ func (c *Client) CreateOrder(intent string, purchaseUnits []PurchaseUnitRequest,
|
||||||
return order, nil
|
return order, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuthorizeOrder - Use this call to authorize an order.
|
// UpdateOrder updates the order by ID
|
||||||
|
// Endpoint: PATCH /v2/checkout/orders/ID
|
||||||
|
func (c *Client) UpdateOrder(orderID string, purchaseUnits []PurchaseUnitRequest) (*Order, error) {
|
||||||
|
order := &Order{}
|
||||||
|
|
||||||
|
req, err := c.NewRequest("PATCH", fmt.Sprintf("%s%s%s", c.APIBase, "/v2/checkout/orders/", orderID), purchaseUnits)
|
||||||
|
if err != nil {
|
||||||
|
return order, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = c.SendWithAuth(req, order); err != nil {
|
||||||
|
return order, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return order, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthorizeOrder - https://developer.paypal.com/docs/api/orders/v2/#orders_authorize
|
||||||
// Endpoint: POST /v2/checkout/orders/ID/authorize
|
// Endpoint: POST /v2/checkout/orders/ID/authorize
|
||||||
func (c *Client) AuthorizeOrder(orderID string, paymentSource PaymentSource) (*Authorization, error) {
|
func (c *Client) AuthorizeOrder(orderID string, authorizeOrderRequest AuthorizeOrderRequest) (*Authorization, error) {
|
||||||
auth := &Authorization{}
|
auth := &Authorization{}
|
||||||
|
|
||||||
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/checkout/orders/"+orderID+"/authorize"), paymentSource)
|
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/checkout/orders/"+orderID+"/authorize"), authorizeOrderRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return auth, err
|
return auth, err
|
||||||
}
|
}
|
||||||
|
@ -57,12 +74,12 @@ func (c *Client) AuthorizeOrder(orderID string, paymentSource PaymentSource) (*A
|
||||||
return auth, nil
|
return auth, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CaptureOrder - Use this call to capture a payment on an order.
|
// CaptureOrder - https://developer.paypal.com/docs/api/orders/v2/#orders_capture
|
||||||
// Endpoint: POST /v2/checkout/orders/ID/capture
|
// Endpoint: POST /v2/checkout/orders/ID/capture
|
||||||
func (c *Client) CaptureOrder(orderID string, paymentSource PaymentSource) (*Capture, error) {
|
func (c *Client) CaptureOrder(orderID string, captureOrderRequest CaptureOrderRequest) (*Capture, error) {
|
||||||
capture := &Capture{}
|
capture := &Capture{}
|
||||||
|
|
||||||
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/checkout/orders/"+orderID+"/capture"), paymentSource)
|
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/checkout/orders/"+orderID+"/capture"), captureOrderRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return capture, err
|
return capture, err
|
||||||
}
|
}
|
||||||
|
|
11
types.go
11
types.go
|
@ -126,6 +126,17 @@ type (
|
||||||
ProtectionEligibilityType string `json:"protection_eligibility_type,omitempty"`
|
ProtectionEligibilityType string `json:"protection_eligibility_type,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AuthorizeOrderRequest - https://developer.paypal.com/docs/api/orders/v2/#orders_authorize
|
||||||
|
AuthorizeOrderRequest struct {
|
||||||
|
PaymentSource *PaymentSource `json:"payment_source"`
|
||||||
|
VaultOnCapture bool `json:"vault_on_capture"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CaptureOrderRequest - https://developer.paypal.com/docs/api/orders/v2/#orders_capture
|
||||||
|
CaptureOrderRequest struct {
|
||||||
|
PaymentSource *PaymentSource `json:"payment_source"`
|
||||||
|
}
|
||||||
|
|
||||||
// BatchHeader struct
|
// BatchHeader struct
|
||||||
BatchHeader struct {
|
BatchHeader struct {
|
||||||
Amount *AmountPayout `json:"amount,omitempty"`
|
Amount *AmountPayout `json:"amount,omitempty"`
|
||||||
|
|
Loading…
Reference in New Issue
Block a user