forked from EasyPost/easypost-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefund.go
More file actions
61 lines (52 loc) · 2.31 KB
/
Copy pathrefund.go
File metadata and controls
61 lines (52 loc) · 2.31 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package easypost
import (
"context"
"net/http"
"time"
)
type Refund struct {
ID string `json:"id,omitempty"`
Object string `json:"object,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
TrackingCode string `json:"tracking_code,omitempty"`
ConfirmationNumber string `json:"confirmation_number,omitempty"`
Status string `json:"status,omitempty"`
Carrier string `json:"carrier,omitempty"`
ShipmentID string `json:"shipment_id,omitempty"`
}
type ListRefundResult struct {
Refunds []*Refund `json:"refunds,omitempty"`
HasMore bool `json:"has_more,omitempty"`
}
// CreateRefund submits a refund request and return a list of refunds.
func (c *Client) CreateRefund(in map[string]interface{}) (out []*Refund, err error) {
return c.CreateRefundWithContext(context.Background(), in)
}
// CreateRefundWithContext performs the same operation as CreateRefund, but
// allows specifying a context that can interrupt the request.
func (c *Client) CreateRefundWithContext(ctx context.Context, in map[string]interface{}) (out []*Refund, err error) {
req := map[string]interface{}{"refund": in}
err = c.post(ctx, "refunds", req, &out)
return
}
// ListRefunds provides a paginated result of Refund objects.
func (c *Client) ListRefunds(opts *ListOptions) (out *ListRefundResult, err error) {
return c.ListRefundsWithContext(context.Background(), opts)
}
// ListRefundsWithContext performs the same operation as ListRefunds, but
// allows specifying a context that can interrupt the request.
func (c *Client) ListRefundsWithContext(ctx context.Context, opts *ListOptions) (out *ListRefundResult, err error) {
err = c.do(ctx, http.MethodGet, "refunds", c.convertOptsToURLValues(opts), &out)
return
}
// retrieves a previously-created Refund by its ID.
func (c *Client) GetRefund(refundID string) (out *Refund, err error) {
return c.GetRefundWithContext(context.Background(), refundID)
}
// GetRefundWithContext performs the same operation as GetRefund, but
// allows specifying a context that can interrupt the request.
func (c *Client) GetRefundWithContext(ctx context.Context, refundID string) (out *Refund, err error) {
err = c.get(ctx, "refunds/"+refundID, &out)
return
}