forked from leebenson/paypal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sale.go
47 lines (37 loc) · 934 Bytes
/
sale.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package paypal
import (
"fmt"
)
type (
RefundReq struct {
Amount *Amount `json:"amount"`
}
)
// GetSales returns a sale by ID
func (c *Client) GetSale(saleID string) (*Sale, error) {
req, err := NewRequest("GET", fmt.Sprintf("%s/payments/sale/%s", c.APIBase, saleID), nil)
if err != nil {
return nil, err
}
v := &Sale{}
err = c.SendWithAuth(req, v)
if err != nil {
return nil, err
}
return v, nil
}
// RefundSale refunds a completed payment and accepts an optional
// Amount struct. If Amount is provided, a partial refund is requested,
// or else a full refund is made instead
func (c *Client) RefundSale(saleID string, a *Amount) (*Refund, error) {
req, err := NewRequest("POST", fmt.Sprintf("%s/payments/sale/%s/refund", c.APIBase, saleID), &RefundReq{Amount: a})
if err != nil {
return nil, err
}
v := &Refund{}
err = c.SendWithAuth(req, v)
if err != nil {
return nil, err
}
return v, nil
}