I am trying to get list of all plans that exist in my Stripe account using Stripes's Golang API. As per documentation provided here: https://stripe.com/docs/api/go#list_plans it should return a list of all plans. But its returning me only a single plan details.
Here is my code:
package main
import (
"github.com/gin-gonic/gin"
"github.com/stripe/stripe-go"
"github.com/stripe/stripe-go/plan"
)
func main(){
router := gin.Default()
stripe.Key = "stripe_api_key"
router.GET("/plans", func(c *gin.Context) {
plans := GetAllPlans()
c.JSON(200, gin.H{ "plans": plans, })
})
router.Run(":8080")
}
func GetAllPlans() (plans *stripe.Plan){
plans = &stripe.Plan{}
params := &stripe.PlanListParams{}
it := plan.List(params)
for it.Next() {
plans = it.Plan()
}
return
}
What's interesting I have found is the response example provided in the documentation for Golang is somewhat different from other languages like PHP, Ruby etc. For languages other than Go and .NET its returning an array of plans but for Go and .NET its returning a single plan. So I am not sure it is api's default behaviour or some bug.
Any kind of help will be appreciated.
Thanks!