github.com/stripe/stripe-go/v76@v76.25.0/person/client.go (about) 1 // 2 // 3 // File generated from our OpenAPI spec 4 // 5 // 6 7 // Package person provides the /accounts/{account}/persons APIs 8 package person 9 10 import ( 11 "fmt" 12 "net/http" 13 14 stripe "github.com/stripe/stripe-go/v76" 15 "github.com/stripe/stripe-go/v76/form" 16 ) 17 18 // Client is used to invoke /accounts/{account}/persons APIs. 19 type Client struct { 20 B stripe.Backend 21 Key string 22 } 23 24 // New creates a new person. 25 func New(params *stripe.PersonParams) (*stripe.Person, error) { 26 return getC().New(params) 27 } 28 29 // New creates a new person. 30 func (c Client) New(params *stripe.PersonParams) (*stripe.Person, error) { 31 path := stripe.FormatURLPath( 32 "/v1/accounts/%s/persons", 33 stripe.StringValue(params.Account), 34 ) 35 person := &stripe.Person{} 36 err := c.B.Call(http.MethodPost, path, c.Key, params, person) 37 return person, err 38 } 39 40 // Get returns the details of a person. 41 func Get(id string, params *stripe.PersonParams) (*stripe.Person, error) { 42 return getC().Get(id, params) 43 } 44 45 // Get returns the details of a person. 46 func (c Client) Get(id string, params *stripe.PersonParams) (*stripe.Person, error) { 47 if params == nil { 48 return nil, fmt.Errorf( 49 "params cannot be nil, and params.Account must be set", 50 ) 51 } 52 path := stripe.FormatURLPath( 53 "/v1/accounts/%s/persons/%s", 54 stripe.StringValue(params.Account), 55 id, 56 ) 57 person := &stripe.Person{} 58 err := c.B.Call(http.MethodGet, path, c.Key, params, person) 59 return person, err 60 } 61 62 // Update updates a person's properties. 63 func Update(id string, params *stripe.PersonParams) (*stripe.Person, error) { 64 return getC().Update(id, params) 65 } 66 67 // Update updates a person's properties. 68 func (c Client) Update(id string, params *stripe.PersonParams) (*stripe.Person, error) { 69 path := stripe.FormatURLPath( 70 "/v1/accounts/%s/persons/%s", 71 stripe.StringValue(params.Account), 72 id, 73 ) 74 person := &stripe.Person{} 75 err := c.B.Call(http.MethodPost, path, c.Key, params, person) 76 return person, err 77 } 78 79 // Del removes a person. 80 func Del(id string, params *stripe.PersonParams) (*stripe.Person, error) { 81 return getC().Del(id, params) 82 } 83 84 // Del removes a person. 85 func (c Client) Del(id string, params *stripe.PersonParams) (*stripe.Person, error) { 86 path := stripe.FormatURLPath( 87 "/v1/accounts/%s/persons/%s", 88 stripe.StringValue(params.Account), 89 id, 90 ) 91 person := &stripe.Person{} 92 err := c.B.Call(http.MethodDelete, path, c.Key, params, person) 93 return person, err 94 } 95 96 // List returns a list of persons. 97 func List(params *stripe.PersonListParams) *Iter { 98 return getC().List(params) 99 } 100 101 // List returns a list of persons. 102 func (c Client) List(listParams *stripe.PersonListParams) *Iter { 103 path := stripe.FormatURLPath( 104 "/v1/accounts/%s/persons", 105 stripe.StringValue(listParams.Account), 106 ) 107 return &Iter{ 108 Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) { 109 list := &stripe.PersonList{} 110 err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list) 111 112 ret := make([]interface{}, len(list.Data)) 113 for i, v := range list.Data { 114 ret[i] = v 115 } 116 117 return ret, list, err 118 }), 119 } 120 } 121 122 // Iter is an iterator for persons. 123 type Iter struct { 124 *stripe.Iter 125 } 126 127 // Person returns the person which the iterator is currently pointing to. 128 func (i *Iter) Person() *stripe.Person { 129 return i.Current().(*stripe.Person) 130 } 131 132 // PersonList returns the current list object which the iterator is 133 // currently using. List objects will change as new API calls are made to 134 // continue pagination. 135 func (i *Iter) PersonList() *stripe.PersonList { 136 return i.List().(*stripe.PersonList) 137 } 138 139 func getC() Client { 140 return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key} 141 }