payments/refund

This commit is contained in:
Aliaksandr Pliutau 2015-12-17 11:28:26 +07:00
parent 27411f215f
commit 7913ad67ae
4 changed files with 42 additions and 0 deletions

View File

@ -13,6 +13,7 @@
* POST /v1/payments/authorization/**ID**/reauthorize * POST /v1/payments/authorization/**ID**/reauthorize
* GET /v1/payments/sale/**ID** * GET /v1/payments/sale/**ID**
* POST /v1/payments/sale/**ID**/refund * POST /v1/payments/sale/**ID**/refund
* GET /v1/payments/refund/**ID**
#### Create client #### Create client
@ -146,3 +147,9 @@ refund, err := c.RefundSale("1", nil)
// Partial // Partial
refund, err := c.RefundSale("1", &paypalsdk.Amount{Total: "100", Currency: "USD"}) refund, err := c.RefundSale("1", &paypalsdk.Amount{Total: "100", Currency: "USD"})
``` ```
#### Get Refund by ID
```go
refund, err := c.GetRefund("1")
```

View File

@ -83,4 +83,12 @@ func main() {
fmt.Println("ERROR: " + err.Error()) fmt.Println("ERROR: " + err.Error())
} }
fmt.Println("OK") 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")
} }

17
sale.go
View File

@ -40,3 +40,20 @@ func (c *Client) RefundSale(saleID string, a *Amount) (*Refund, error) {
return refund, nil 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
}

View File

@ -26,3 +26,13 @@ func TestRefundSale(t *testing.T) {
t.Errorf("RefundSale must be failed") 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")
}
}