github.com/stripe/stripe-go/v76@v76.25.0/refund/client.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 // Package refund provides the /refunds APIs 8 package refund 9 10 import ( 11 "net/http" 12 13 stripe "github.com/stripe/stripe-go/v76" 14 "github.com/stripe/stripe-go/v76/form" 15 ) 16 17 // Client is used to invoke /refunds APIs. 18 type Client struct { 19 B stripe.Backend 20 Key string 21 } 22 23 // New creates a new refund. 24 func New(params *stripe.RefundParams) (*stripe.Refund, error) { 25 return getC().New(params) 26 } 27 28 // New creates a new refund. 29 func (c Client) New(params *stripe.RefundParams) (*stripe.Refund, error) { 30 refund := &stripe.Refund{} 31 err := c.B.Call(http.MethodPost, "/v1/refunds", c.Key, params, refund) 32 return refund, err 33 } 34 35 // Get returns the details of a refund. 36 func Get(id string, params *stripe.RefundParams) (*stripe.Refund, error) { 37 return getC().Get(id, params) 38 } 39 40 // Get returns the details of a refund. 41 func (c Client) Get(id string, params *stripe.RefundParams) (*stripe.Refund, error) { 42 path := stripe.FormatURLPath("/v1/refunds/%s", id) 43 refund := &stripe.Refund{} 44 err := c.B.Call(http.MethodGet, path, c.Key, params, refund) 45 return refund, err 46 } 47 48 // Update updates a refund's properties. 49 func Update(id string, params *stripe.RefundParams) (*stripe.Refund, error) { 50 return getC().Update(id, params) 51 } 52 53 // Update updates a refund's properties. 54 func (c Client) Update(id string, params *stripe.RefundParams) (*stripe.Refund, error) { 55 path := stripe.FormatURLPath("/v1/refunds/%s", id) 56 refund := &stripe.Refund{} 57 err := c.B.Call(http.MethodPost, path, c.Key, params, refund) 58 return refund, err 59 } 60 61 // Cancel is the method for the `POST /v1/refunds/{refund}/cancel` API. 62 func Cancel(id string, params *stripe.RefundCancelParams) (*stripe.Refund, error) { 63 return getC().Cancel(id, params) 64 } 65 66 // Cancel is the method for the `POST /v1/refunds/{refund}/cancel` API. 67 func (c Client) Cancel(id string, params *stripe.RefundCancelParams) (*stripe.Refund, error) { 68 path := stripe.FormatURLPath("/v1/refunds/%s/cancel", id) 69 refund := &stripe.Refund{} 70 err := c.B.Call(http.MethodPost, path, c.Key, params, refund) 71 return refund, err 72 } 73 74 // List returns a list of refunds. 75 func List(params *stripe.RefundListParams) *Iter { 76 return getC().List(params) 77 } 78 79 // List returns a list of refunds. 80 func (c Client) List(listParams *stripe.RefundListParams) *Iter { 81 return &Iter{ 82 Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { 83 list := &stripe.RefundList{} 84 err := c.B.CallRaw(http.MethodGet, "/v1/refunds", c.Key, b, p, list) 85 86 ret := make([]interface{}, len(list.Data)) 87 for i, v := range list.Data { 88 ret[i] = v 89 } 90 91 return ret, list, err 92 }), 93 } 94 } 95 96 // Iter is an iterator for refunds. 97 type Iter struct { 98 *stripe.Iter 99 } 100 101 // Refund returns the refund which the iterator is currently pointing to. 102 func (i *Iter) Refund() *stripe.Refund { 103 return i.Current().(*stripe.Refund) 104 } 105 106 // RefundList returns the current list object which the iterator is 107 // currently using. List objects will change as new API calls are made to 108 // continue pagination. 109 func (i *Iter) RefundList() *stripe.RefundList { 110 return i.List().(*stripe.RefundList) 111 } 112 113 func getC() Client { 114 return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 115 }