github.com/stripe/stripe-go/v76@v76.25.0/checkout/session/client.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 // Package session provides the /checkout/sessions APIs 8 package session 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 /checkout/sessions APIs. 18 type Client struct { 19 B stripe.Backend 20 Key string 21 } 22 23 // New creates a new checkout session. 24 func New(params *stripe.CheckoutSessionParams) (*stripe.CheckoutSession, error) { 25 return getC().New(params) 26 } 27 28 // New creates a new checkout session. 29 func (c Client) New(params *stripe.CheckoutSessionParams) (*stripe.CheckoutSession, error) { 30 session := &stripe.CheckoutSession{} 31 err := c.B.Call( 32 http.MethodPost, 33 "/v1/checkout/sessions", 34 c.Key, 35 params, 36 session, 37 ) 38 return session, err 39 } 40 41 // Get returns the details of a checkout session. 42 func Get(id string, params *stripe.CheckoutSessionParams) (*stripe.CheckoutSession, error) { 43 return getC().Get(id, params) 44 } 45 46 // Get returns the details of a checkout session. 47 func (c Client) Get(id string, params *stripe.CheckoutSessionParams) (*stripe.CheckoutSession, error) { 48 path := stripe.FormatURLPath("/v1/checkout/sessions/%s", id) 49 session := &stripe.CheckoutSession{} 50 err := c.B.Call(http.MethodGet, path, c.Key, params, session) 51 return session, err 52 } 53 54 // Expire is the method for the `POST /v1/checkout/sessions/{session}/expire` API. 55 func Expire(id string, params *stripe.CheckoutSessionExpireParams) (*stripe.CheckoutSession, error) { 56 return getC().Expire(id, params) 57 } 58 59 // Expire is the method for the `POST /v1/checkout/sessions/{session}/expire` API. 60 func (c Client) Expire(id string, params *stripe.CheckoutSessionExpireParams) (*stripe.CheckoutSession, error) { 61 path := stripe.FormatURLPath("/v1/checkout/sessions/%s/expire", id) 62 session := &stripe.CheckoutSession{} 63 err := c.B.Call(http.MethodPost, path, c.Key, params, session) 64 return session, err 65 } 66 67 // List returns a list of checkout sessions. 68 func List(params *stripe.CheckoutSessionListParams) *Iter { 69 return getC().List(params) 70 } 71 72 // List returns a list of checkout sessions. 73 func (c Client) List(listParams *stripe.CheckoutSessionListParams) *Iter { 74 return &Iter{ 75 Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { 76 list := &stripe.CheckoutSessionList{} 77 err := c.B.CallRaw(http.MethodGet, "/v1/checkout/sessions", 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 checkout sessions. 90 type Iter struct { 91 *stripe.Iter 92 } 93 94 // CheckoutSession returns the checkout session which the iterator is currently pointing to. 95 func (i *Iter) CheckoutSession() *stripe.CheckoutSession { 96 return i.Current().(*stripe.CheckoutSession) 97 } 98 99 // CheckoutSessionList 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) CheckoutSessionList() *stripe.CheckoutSessionList { 103 return i.List().(*stripe.CheckoutSessionList) 104 } 105 106 // ListLineItems is the method for the `GET /v1/checkout/sessions/{session}/line_items` API. 107 func ListLineItems(params *stripe.CheckoutSessionListLineItemsParams) *LineItemIter { 108 return getC().ListLineItems(params) 109 } 110 111 // ListLineItems is the method for the `GET /v1/checkout/sessions/{session}/line_items` API. 112 func (c Client) ListLineItems(listParams *stripe.CheckoutSessionListLineItemsParams) *LineItemIter { 113 path := stripe.FormatURLPath( 114 "/v1/checkout/sessions/%s/line_items", 115 stripe.StringValue(listParams.Session), 116 ) 117 return &LineItemIter{ 118 Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { 119 list := &stripe.LineItemList{} 120 err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list) 121 122 ret := make([]interface{}, len(list.Data)) 123 for i, v := range list.Data { 124 ret[i] = v 125 } 126 127 return ret, list, err 128 }), 129 } 130 } 131 132 // LineItemIter is an iterator for line items. 133 type LineItemIter struct { 134 *stripe.Iter 135 } 136 137 // LineItem returns the line item which the iterator is currently pointing to. 138 func (i *LineItemIter) LineItem() *stripe.LineItem { 139 return i.Current().(*stripe.LineItem) 140 } 141 142 // LineItemList returns the current list object which the iterator is 143 // currently using. List objects will change as new API calls are made to 144 // continue pagination. 145 func (i *LineItemIter) LineItemList() *stripe.LineItemList { 146 return i.List().(*stripe.LineItemList) 147 } 148 149 func getC() Client { 150 return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 151 }