diff --git a/README.md b/README.md index 184d577..45b7da7 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ * POST /v1/payments/authorization/**ID**/reauthorize * GET /v1/payments/sale/**ID** * POST /v1/payments/sale/**ID**/refund + * GET /v1/payments/refund/**ID** #### Create client @@ -146,3 +147,9 @@ refund, err := c.RefundSale("1", nil) // Partial refund, err := c.RefundSale("1", &paypalsdk.Amount{Total: "100", Currency: "USD"}) ``` + +#### Get Refund by ID + +```go +refund, err := c.GetRefund("1") +``` diff --git a/examples/main.go b/examples/main.go index 9763f41..c0e6b15 100644 --- a/examples/main.go +++ b/examples/main.go @@ -83,4 +83,12 @@ func main() { fmt.Println("ERROR: " + err.Error()) } fmt.Println("OK") + + refund, err = client.GetRefund("1") + if err == nil { + fmt.Println("DEBUG: RefundID=" + refund.ID) + } else { + fmt.Println("ERROR: " + err.Error()) + } + fmt.Println("OK") } diff --git a/sale.go b/sale.go index 0dfb4a1..c16f114 100644 --- a/sale.go +++ b/sale.go @@ -40,3 +40,20 @@ func (c *Client) RefundSale(saleID string, a *Amount) (*Refund, error) { return refund, nil } + +// GetRefund by ID +func (c *Client) GetRefund(refundID string) (*Refund, error) { + refund := &Refund{} + + req, err := c.NewRequest("GET", fmt.Sprintf("%s%s", c.APIBase, "/v1/payments/refund/"+refundID), nil) + if err != nil { + return refund, err + } + + err = c.SendWithAuth(req, refund) + if err != nil { + return refund, err + } + + return refund, nil +} diff --git a/sale_test.go b/sale_test.go index ab29981..6d7c7fb 100644 --- a/sale_test.go +++ b/sale_test.go @@ -26,3 +26,13 @@ func TestRefundSale(t *testing.T) { t.Errorf("RefundSale must be failed") } } + +func TestGetRefund(t *testing.T) { + c, _ := NewClient("clid", "secret", APIBaseSandBox) + c.GetAccessToken() + + _, err := c.GetRefund("1") + if err == nil { + t.Errorf("GetRefund must be failed") + } +}