#daan_api
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1365044622518259753
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
It gives me this error
{
"error": {
"message": "Invalid string: {:eq=>\"payout\"}",
"param": "type",
"request_log_url": "https://dashboard.stripe.com/acct_1MmdYhC0QD1kttcN/test/logs/req_qAnKtiyXTVeIG7?t=1745522388",
"type": "invalid_request_error"
}
}
func (o *PaginationOptions) AddPaginationStripeFilters(filters stripe.Filters) stripe.Filters {
for _, filter := range o.FieldFilters {
if _, ok := filter.Value.(string); !ok {
continue
}
filters.AddFilter(filter.Field, filter.Operator.toStripeOperator(), filter.Value.(string))
}
return filters
}
used here
func (s service) GetBalanceTransactionsForOrganization(accountId string, paginationOptions pagination.PaginationOptions) (*pagination.PaginatedResult[*stripe.BalanceTransaction], error) {
params := &stripe.BalanceTransactionListParams{}
params.SetStripeAccount(accountId)
params.Limit = stripe.Int64(int64(paginationOptions.PageSize))
params.EndingBefore = paginationOptions.EndingBefore
params.StartingAfter = paginationOptions.StartingAfter
var filters stripe.Filters
if len(paginationOptions.FieldFilters) > 0 {
filters = paginationOptions.AddPaginationStripeFilters(params.Filters)
}
if paginationOptions.Search != "" {
filters = paginationOptions.AddPaginationStripeSearch(params.Filters, "id")
}
params.Filters = filters
iter := balancetransaction.List(params)
err := iter.Err()
if err != nil {
return nil, err
}
meta := iter.Meta()
data := iter.BalanceTransactionList().Data
return &pagination.PaginatedResult[*stripe.BalanceTransaction]{
MetaData: pagination.PaginationMetaData{
HasNext: meta.HasMore,
HasPrev: paginationOptions.EndingBefore != nil && *paginationOptions.EndingBefore != "",
PageSize: paginationOptions.PageSize,
},
Data: data,
}, nil
}
The AddFilter method is exposed in the SDK
type Filters struct {
f []*filter `form:"-"` // See custom AppendTo implementation
}
// AddFilter adds a new filter with a given key, op and value.
func (f *Filters) AddFilter(key, op, value string) {
filter := &filter{Key: key, Op: op, Val: value}
f.f = append(f.f, filter)
}
Hello, I am not immediately sure what those filters are. I can look into that, but you should be able to filter by passing us the type as a String in the call's parameters like this:
result := balancetransaction.List(params);```
Can I use this with multiple filters?
I'm using this conversion from my own pagination settings by the way
func (o Operator) toStripeOperator() string {
switch o {
case OperatorEqual:
return ":"
case OperatorNotEqual:
return "-"
case OperatorGreaterThan:
return ">"
case OperatorGreaterOrEqual:
return ">="
case OperatorLessThan:
return "<"
case OperatorLessOrEqual:
return "<="
case OperatorIn:
return "~"
default:
return ""
}
}
As listed here https://docs.stripe.com/search?lang=go
Yes, though that is also different than the Go language objects that you are using https://docs.stripe.com/search?lang=go#multiple-filters
Alright, I'll give it a look. Thanks!
The AddFilter method is documented here by the way https://pkg.go.dev/gopkg.in/stripe/stripe-go.v36#Filters.AddFilter, But I've not seen it in the official docs anywhere
I see we show it in our API reference https://docs.stripe.com/api/pagination/auto?lang=go
It looks like if you don't include an op parameter we may just pass it as an argument. I am wondering if this is an older syntax that hasn't been deprecated. Will try digging a bit more
Let me know if using the params the way they are in those two other docs works for you, that may be simpler and get the same job done
I'll give it a try
Cool, that did the trick!
That's all I need right now. Thanks for the help!