From efe72c1ed4358171f0281841311bd25e38afc9fb Mon Sep 17 00:00:00 2001 From: Eric Lee Date: Sat, 2 May 2020 08:09:58 -0700 Subject: [PATCH] Some updates to refund endpoint (#121) * s/authorization/authorizations in url path * Update authorization object to the paypal v2 version * duplicate field * rename some fields * Update types for refund endpoint * actually, don't do a breaking change * . * pointer Co-authored-by: Alex Pliutau --- sale.go | 9 ++------- types.go | 28 ++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/sale.go b/sale.go index f1e4d9c..79d87a8 100644 --- a/sale.go +++ b/sale.go @@ -23,15 +23,10 @@ func (c *Client) GetSale(saleID string) (*Sale, error) { // RefundSale refunds a completed payment. // Use this call to refund a completed payment. Provide the sale_id in the URI and an empty JSON payload for a full refund. For partial refunds, you can include an amount. -// Endpoint: POST /v1/payments/sale/ID/refund -func (c *Client) RefundSale(saleID string, a *Amount) (*Refund, error) { - type refundRequest struct { - Amount *Amount `json:"amount"` - } - +func (c *Client) RefundSale(saleID string, r RefundRequest) (*Refund, error) { refund := &Refund{} - req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/sale/"+saleID+"/refund"), &refundRequest{Amount: a}) + req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/sale/"+saleID+"/refund"), &r) if err != nil { return refund, err } diff --git a/types.go b/types.go index 24fbc5b..74f2a60 100644 --- a/types.go +++ b/types.go @@ -234,6 +234,12 @@ type ( FinalCapture bool `json:"final_capture,omitempty"` } + RefundRequest struct { + Amount *PurchaseUnitAmount `json:"amount,omitempty"` + InvoiceID string `json:"invoice_id,omitempty"` + NoteToPayer string `json:"note_to_payer,omitempty"` + } + SellerProtection struct { Status string `json:"status,omitempty"` DisputeCategories []string `json:"dispute_categories,omitempty"` @@ -244,6 +250,10 @@ type ( Reason string `json:"reason,omitempty"` } + RefundStatusDetails struct { + Reason string `json:"reason,omitempty"` + } + PaymentCaptureResponse struct { Status string `json:"status,omitempty"` StatusDetails *CaptureStatusDetails `json:"status_details,omitempty"` @@ -776,13 +786,16 @@ type ( // Refund struct Refund struct { - ID string `json:"id,omitempty"` - Amount *Amount `json:"amount,omitempty"` - CreateTime *time.Time `json:"create_time,omitempty"` - State string `json:"state,omitempty"` - CaptureID string `json:"capture_id,omitempty"` - ParentPayment string `json:"parent_payment,omitempty"` - UpdateTime *time.Time `json:"update_time,omitempty"` + ID string `json:"id,omitempty"` + Amount *PurchaseUnitAmount `json:"amount,omitempty"` + Status string `json:"status,omitempty"` + StatusDetails *RefundStatusDetails `json:"status_details,omitempty"` + InvoiceID string `json:"invoice_id,omitempty"` + NoteToPayer string `json:"note_to_payer,omitempty"` + SellerPayableBreakdown *CaptureSellerBreakdown `json:"seller_payable_breakdown,omitempty"` + Links []Link `json:"links"` + CreateTime *time.Time `json:"create_time,omitempty"` + UpdateTime *time.Time `json:"update_time,omitempty"` } // RefundResponse . @@ -983,7 +996,6 @@ type ( Links []Link `json:"links"` } - // WebhookEvent struct WebhookEvent struct { ID string `json:"id"` CreateTime time.Time `json:"create_time"`