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