#CheckoutList
1 messages ยท Page 1 of 1 (latest)
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Should be this parameter
That's an object ID, not a date.
Sorry, I want to filter them based on a date range, ideally.
ahh
Umm I see. Unfortunately our API seem doesn't support it yet
You can list all then implement your own filter though
Yep! Thanks mate. Just trying to get pagination working. I assume the API always lists the latest CheckoutSessions first?
So if I do sessions := session.List(params) I'll always get the latest sessions?
Hmm. I actually can't find a date/time attribute for a CheckoutSession object.
Right, I am looking at the object
A bit surprised to me too, but yes the Checkout object doesn't have the date/time
There's a timestamp on the payment for a particular session, when viewed in the console. I wonder if I have to get the Payment object?
session.PaymentIntent.Created?
I think so yes. Payment Intent should be treated as transactions
Awesome. I'll take it from there and see how far I get - thanks, @tough cedar
Good luck!
๐
for sessions.Next() {
session := sessions.CheckoutSession()
if session.Status != "complete" {
continue
}
if session.PaymentIntent.Created < notBefore {
continue
}
if session.Customer == nil {
continue
}
allSessions = append(allSessions, session)
}```
This did it.
Ahh filter directly with the Payment Intent inside
Sort of. I had to do params.AddExpand("data.payment_intent") and then I can access .PaymentIntent.Created, which is a UNIX timestamp.
Go lang, right?
Aye
This part
if session.PaymentIntent.Created < notBefore {
continue
}
If you have 100 sessions, the notBefore happens at 60th. You will loop 60 times with appending and 40 times without appending
If you break instead of continue, you will only loop 60 times and exit
Just my guts when imaging the pagination logic
I see what you mean - you're suggesting I short-circuit the loop once I hit an invalid date? That's a great suggestion, thank you, but it comes back to my original question above: in what order do the checkout session objects come back from the API? ๐
What if the order is random?
I could stop on the first invalid date, at sessions[10], break from the loop and miss out on 30-40 checkout sessions, no?
Right, fair point. To confirm your original intention is to filter out "after some created date", correct?
and using auto pagination hmm
Yep! So I want to run a cronjob based worker every few minutes, find new CheckoutSessions that were created in the last 72 hours, determine if I've never seen the item before (based on the customer's email), and then create a new customer account in a DB if I've never seen that email.
I want to avoid using web hooks as I find them fragile. If I'm reaching out to the API on a periodic basis, there will be a slight delay for the customer of a few minutes, but it's easier for me to maintain and it scales to infinity. Also, I don't have to worry about missing customer payments during a deployment of anything, as a service that's down cannot receive a web hook.
I totally understand the concern as of a dev, but I would say Webhook still save you from more troubles, like you could end up with higher chance hitting rate limit for the polling strategy, or your cron job could error/down on network connect just like if your webhook endpoint is down via a deployment
๐ I will need to step down for the day. If you have other questions feel free to ask in the channel and my colleagues would be happy to assist
For above code, I think if you control the pagination yourself by starting_after and limit to load batch of 100 sessions for example, you can control the order and short-circuit, but yes a full loop using auto-pagination shouldn't have much impact over performance ๐