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