github.com/stripe/stripe-go/v76@v76.25.0/climate/order/client.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 // Package order provides the /climate/orders APIs 8 package order 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 /climate/orders APIs. 18 type Client struct { 19 B stripe.Backend 20 Key string 21 } 22 23 // New creates a new climate order. 24 func New(params *stripe.ClimateOrderParams) (*stripe.ClimateOrder, error) { 25 return getC().New(params) 26 } 27 28 // New creates a new climate order. 29 func (c Client) New(params *stripe.ClimateOrderParams) (*stripe.ClimateOrder, error) { 30 order := &stripe.ClimateOrder{} 31 err := c.B.Call(http.MethodPost, "/v1/climate/orders", c.Key, params, order) 32 return order, err 33 } 34 35 // Get returns the details of a climate order. 36 func Get(id string, params *stripe.ClimateOrderParams) (*stripe.ClimateOrder, error) { 37 return getC().Get(id, params) 38 } 39 40 // Get returns the details of a climate order. 41 func (c Client) Get(id string, params *stripe.ClimateOrderParams) (*stripe.ClimateOrder, error) { 42 path := stripe.FormatURLPath("/v1/climate/orders/%s", id) 43 order := &stripe.ClimateOrder{} 44 err := c.B.Call(http.MethodGet, path, c.Key, params, order) 45 return order, err 46 } 47 48 // Update updates a climate order's properties. 49 func Update(id string, params *stripe.ClimateOrderParams) (*stripe.ClimateOrder, error) { 50 return getC().Update(id, params) 51 } 52 53 // Update updates a climate order's properties. 54 func (c Client) Update(id string, params *stripe.ClimateOrderParams) (*stripe.ClimateOrder, error) { 55 path := stripe.FormatURLPath("/v1/climate/orders/%s", id) 56 order := &stripe.ClimateOrder{} 57 err := c.B.Call(http.MethodPost, path, c.Key, params, order) 58 return order, err 59 } 60 61 // Cancel is the method for the `POST /v1/climate/orders/{order}/cancel` API. 62 func Cancel(id string, params *stripe.ClimateOrderCancelParams) (*stripe.ClimateOrder, error) { 63 return getC().Cancel(id, params) 64 } 65 66 // Cancel is the method for the `POST /v1/climate/orders/{order}/cancel` API. 67 func (c Client) Cancel(id string, params *stripe.ClimateOrderCancelParams) (*stripe.ClimateOrder, error) { 68 path := stripe.FormatURLPath("/v1/climate/orders/%s/cancel", id) 69 order := &stripe.ClimateOrder{} 70 err := c.B.Call(http.MethodPost, path, c.Key, params, order) 71 return order, err 72 } 73 74 // List returns a list of climate orders. 75 func List(params *stripe.ClimateOrderListParams) *Iter { 76 return getC().List(params) 77 } 78 79 // List returns a list of climate orders. 80 func (c Client) List(listParams *stripe.ClimateOrderListParams) *Iter { 81 return &Iter{ 82 Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { 83 list := &stripe.ClimateOrderList{} 84 err := c.B.CallRaw(http.MethodGet, "/v1/climate/orders", 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 climate orders. 97 type Iter struct { 98 *stripe.Iter 99 } 100 101 // ClimateOrder returns the climate order which the iterator is currently pointing to. 102 func (i *Iter) ClimateOrder() *stripe.ClimateOrder { 103 return i.Current().(*stripe.ClimateOrder) 104 } 105 106 // ClimateOrderList 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) ClimateOrderList() *stripe.ClimateOrderList { 110 return i.List().(*stripe.ClimateOrderList) 111 } 112 113 func getC() Client { 114 return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 115 }