Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Updates #1352

Merged
merged 5 commits into from Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions customer.go
Expand Up @@ -114,6 +114,13 @@ type CustomerListParams struct {
Email *string `form:"email"`
}

// Returns a list of PaymentMethods for a given Customer
type CustomerListPaymentMethodsParams struct {
ListParams `form:"*"`
Customer *string `form:"-"` // Included in URL
Type *string `form:"type"`
}

// The customer's location as identified by Stripe Tax.
type CustomerTaxLocation struct {
Country string `json:"country"`
Expand Down
43 changes: 43 additions & 0 deletions customer/client.go
Expand Up @@ -110,6 +110,49 @@ func (i *Iter) CustomerList() *stripe.CustomerList {
return i.List().(*stripe.CustomerList)
}

// ListPaymentMethods is the method for the `GET /v1/customers/{customer}/payment_methods` API.
func ListPaymentMethods(params *stripe.CustomerListPaymentMethodsParams) *PaymentMethodIter {
return getC().ListPaymentMethods(params)
}

// ListPaymentMethods is the method for the `GET /v1/customers/{customer}/payment_methods` API.
func (c Client) ListPaymentMethods(listParams *stripe.CustomerListPaymentMethodsParams) *PaymentMethodIter {
path := stripe.FormatURLPath(
"/v1/customers/%s/payment_methods",
stripe.StringValue(listParams.Customer),
)
return &PaymentMethodIter{
Iter: stripe.GetIter(listParams, func(p *stripe.Params, b *form.Values) ([]interface{}, stripe.ListContainer, error) {
list := &stripe.PaymentMethodList{}
err := c.B.CallRaw(http.MethodGet, path, c.Key, b, p, list)

ret := make([]interface{}, len(list.Data))
for i, v := range list.Data {
ret[i] = v
}

return ret, list, err
}),
}
}

// PaymentMethodIter is an iterator for payment methods.
type PaymentMethodIter struct {
*stripe.Iter
}

// PaymentMethod returns the payment method which the iterator is currently pointing to.
func (i *PaymentMethodIter) PaymentMethod() *stripe.PaymentMethod {
return i.Current().(*stripe.PaymentMethod)
}

// PaymentMethodList returns the current list object which the iterator is
// currently using. List objects will change as new API calls are made to
// continue pagination.
func (i *PaymentMethodIter) PaymentMethodList() *stripe.PaymentMethodList {
return i.List().(*stripe.PaymentMethodList)
}

func getC() Client {
return Client{stripe.GetBackend(stripe.APIBackend), stripe.Key}
}