Closed wambui-pixel closed 1 month ago
@wambui-pixel The limit
parameter controls the number of elements to return in each page when you make a List call. It doesn't control the total number of results that will be returned.
I can see you are using the Single
option though which asks us for only one page overall in which case if you pass Limit: 3
then we would return only up to 3 results.
I tried code similar to yours and it worked fine for me both on the latest major (v79) and your current major (v75).
I used a Customer that has 10 PaymentMethods right now and I was able to retrieve only the first 3, or the next 3 when passing StartingAfter
and then the iteration stopped. This Customer exists on our default test account so I included its API keys that you can see in the docs while not logged in.
Here's the code I used:
package main
import "fmt"
import "github.com/stripe/stripe-go/v75"
import "github.com/stripe/stripe-go/v75/customer"
func main() {
stripe.Key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
params := &stripe.CustomerListPaymentMethodsParams{
Customer: stripe.String("cus_Qx22bldgw5DCa9"),
}
params.Limit = stripe.Int64(3)
params.ListParams.Single = true
params.StartingAfter = stripe.String("card_1Q57yC2eZvKYlo2C9Noa5cKe")
i := customer.ListPaymentMethods(params)
for i.Next() {
p := i.PaymentMethod()
fmt.Printf("Got: %s\n", p.ID)
}
}
Can you confirm this code works fine for you locally without the context part? If it does, can you then give me a clear end-to-end reproduction script that would help me debug this further?
The code works. Thank you for your assistance.
Describe the bug
I am attempting to list customer payment methods with a limit parameter, but the results continue to return the full list of payment methods. It appears that the limit parameter is not being passed correctly or is not functioning as expected in the request. Below is the implementation of the limit in the code snippet:-
To Reproduce
Expected behavior
The result should have implemented the limit parameter and returned only the specified number of payment methods.
Code snippets
OS
Linux
Go version
Go 1.22.2
stripe-go version
v75.11
API version
2024-06-20
Additional context
No response