github.com/stripe/stripe-go/v76@v76.25.0/price/client.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 // Package price provides the /prices APIs 8 package price 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 /prices APIs. 18 type Client struct { 19 B stripe.Backend 20 Key string 21 } 22 23 // New creates a new price. 24 func New(params *stripe.PriceParams) (*stripe.Price, error) { 25 return getC().New(params) 26 } 27 28 // New creates a new price. 29 func (c Client) New(params *stripe.PriceParams) (*stripe.Price, error) { 30 price := &stripe.Price{} 31 err := c.B.Call(http.MethodPost, "/v1/prices", c.Key, params, price) 32 return price, err 33 } 34 35 // Get returns the details of a price. 36 func Get(id string, params *stripe.PriceParams) (*stripe.Price, error) { 37 return getC().Get(id, params) 38 } 39 40 // Get returns the details of a price. 41 func (c Client) Get(id string, params *stripe.PriceParams) (*stripe.Price, error) { 42 path := stripe.FormatURLPath("/v1/prices/%s", id) 43 price := &stripe.Price{} 44 err := c.B.Call(http.MethodGet, path, c.Key, params, price) 45 return price, err 46 } 47 48 // Update updates a price's properties. 49 func Update(id string, params *stripe.PriceParams) (*stripe.Price, error) { 50 return getC().Update(id, params) 51 } 52 53 // Update updates a price's properties. 54 func (c Client) Update(id string, params *stripe.PriceParams) (*stripe.Price, error) { 55 path := stripe.FormatURLPath("/v1/prices/%s", id) 56 price := &stripe.Price{} 57 err := c.B.Call(http.MethodPost, path, c.Key, params, price) 58 return price, err 59 } 60 61 // List returns a list of prices. 62 func List(params *stripe.PriceListParams) *Iter { 63 return getC().List(params) 64 } 65 66 // List returns a list of prices. 67 func (c Client) List(listParams *stripe.PriceListParams) *Iter { 68 return &Iter{ 69 Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { 70 list := &stripe.PriceList{} 71 err := c.B.CallRaw(http.MethodGet, "/v1/prices", c.Key, b, p, list) 72 73 ret := make([]interface{}, len(list.Data)) 74 for i, v := range list.Data { 75 ret[i] = v 76 } 77 78 return ret, list, err 79 }), 80 } 81 } 82 83 // Iter is an iterator for prices. 84 type Iter struct { 85 *stripe.Iter 86 } 87 88 // Price returns the price which the iterator is currently pointing to. 89 func (i *Iter) Price() *stripe.Price { 90 return i.Current().(*stripe.Price) 91 } 92 93 // PriceList returns the current list object which the iterator is 94 // currently using. List objects will change as new API calls are made to 95 // continue pagination. 96 func (i *Iter) PriceList() *stripe.PriceList { 97 return i.List().(*stripe.PriceList) 98 } 99 100 // Search returns a search result containing prices. 101 func Search(params *stripe.PriceSearchParams) *SearchIter { 102 return getC().Search(params) 103 } 104 105 // Search returns a search result containing prices. 106 func (c Client) Search(params *stripe.PriceSearchParams) *SearchIter { 107 return &SearchIter{ 108 SearchIter: stripe.GetSearchIter(params, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.SearchContainer, error) { 109 list := &stripe.PriceSearchResult{} 110 err := c.B.CallRaw(http.MethodGet, "/v1/prices/search", c.Key, b, p, list) 111 112 ret := make([]interface{}, len(list.Data)) 113 for i, v := range list.Data { 114 ret[i] = v 115 } 116 117 return ret, list, err 118 }), 119 } 120 } 121 122 // SearchIter is an iterator for prices. 123 type SearchIter struct { 124 *stripe.SearchIter 125 } 126 127 // Price returns the price which the iterator is currently pointing to. 128 func (i *SearchIter) Price() *stripe.Price { 129 return i.Current().(*stripe.Price) 130 } 131 132 // PriceSearchResult returns the current list object which the iterator is 133 // currently using. List objects will change as new API calls are made to 134 // continue pagination. 135 func (i *SearchIter) PriceSearchResult() *stripe.PriceSearchResult { 136 return i.SearchResult().(*stripe.PriceSearchResult) 137 } 138 139 func getC() Client { 140 return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 141 }