From 2091d46d04b03a5142539a1895b3815d9a0b658f Mon Sep 17 00:00:00 2001 From: kenbolt <54861412+kenbolt@users.noreply.github.com> Date: Wed, 8 Apr 2020 09:51:17 -0700 Subject: [PATCH] Refund from capture endpoint function (#141) * Capture refund API call * . --- order.go | 16 ++++++++++++++++ types.go | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/order.go b/order.go index 30df7ef7..0ae69d33 100644 --- a/order.go +++ b/order.go @@ -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 +} diff --git a/types.go b/types.go index 7146d0db..ea810e65 100644 --- a/types.go +++ b/types.go @@ -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"`