Skip to content

Commit

Permalink
Refund from capture endpoint function (#141)
Browse files Browse the repository at this point in the history
* Capture refund API call

* .
  • Loading branch information
kenbolt authored Apr 8, 2020
1 parent 6f0fe4d commit 2091d46
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions order.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,19 @@ func (c *Client) CaptureOrder(orderID string, captureOrderRequest CaptureOrderRe

return capture, nil
}

// RefundCapture - https://developer.paypal.com/docs/api/payments/v2/#captures_refund
// Endpoint: POST /v2/payments/captures/ID/refund
func (c *Client) RefundCapture(captureID string, refundCaptureRequest RefundCaptureRequest) (*RefundResponse, error) {
refund := &RefundResponse{}

req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v2/payments/captures/"+captureID+"/refund"), refundCaptureRequest)
if err != nil {
return refund, err
}

if err = c.SendWithAuth(req, refund); err != nil {
return refund, err
}
return refund, nil
}
7 changes: 7 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ type (
PaymentSource *PaymentSource `json:"payment_source"`
}

// RefundOrderRequest - https://developer.paypal.com/docs/api/payments/v2/#captures_refund
RefundCaptureRequest struct {
Amount *Money `json:"amount,omitempty"`
InvoiceID string `json:"invoice_id,omitempty"`
NoteToPayer string `json:"note_to_payer,omitempty"`
}

// BatchHeader struct
BatchHeader struct {
Amount *AmountPayout `json:"amount,omitempty"`
Expand Down

0 comments on commit 2091d46

Please sign in to comment.