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