#SenorKarlos-pagination
1 messages ยท Page 1 of 1 (latest)
heya! thanks ๐ still wrapping my brain around some of the finer points of this programming nonsense ๐
Am I right to understand that you want to iterate the customer.list(..) until the end when has_more is false?
I think that's the proper way to say it lol. In the end I want a list array of all the customers to send into parse instead of doing it mid function like how it was written
In this case, I'd recommend using auto pagination provided by library, so that you don't have to keep track of the pages that you're in: https://stripe.com/docs/api/pagination/auto
Other helpful docs and videos:
ok I can take a look at that and see if I can figure it out ๐ that's the problem I was having when I started writing some lines, I'd either have variables writing over themselves and not know when to finish or an if chain with a capacity limit where you quit lol
Auto pagination allows iterating the list of customers without keep tracking the has_more. In the sample video, it provides both options:
- while loop with has_more flag check (manual)
- use auto-pagination provides by the library, so that you don't have to handle pagination manually (auto)
If you want to use manually, the video is a good start and it describes how you can do it
something else has been buggin me all weekend, had a chat with a fellow dev about it but would like to know what the heck from you guys ๐ while i got ya
subsciptions.plan .... it's not in the API reference for subscription object, there is a 'plans' reference, but the 'prices' reference seems to be the replacement and the subscription.items be used, I'm just not sure about using it properly or if plan will suddenly vanish from the object
SenorKarlos-pagination
my code uses plan.id alot, but I know it can now be found at items.data[0].somethin eh lol
Can you share a little bit more what you want to achieve?
heh summary
- why subscriptions.plan isn't mentioned and if it will go away? does it take updates?
- more information about items if it will be necessary. I never plan to have users on multiple prices under one subscription if that matters or helps
well i guess the second point I can go read up, more if I have to lol
why subscriptions.plan isn't mentioned and if it will go away, does it take updates?
To obtain the items that a customer subscribes, subscription.items should be used. Plan is legacy, and it's no longer recommended. If the subscription item has been changed, it'll reflect the updated one.
more information about items if it will be necessary. I never plan to have users on multiple prices under one subscription if that matters or help
Items are just basically the list of items that customer subscribes in a subscription. The number items under a subscription depends how you create a subscription.
alright that's kind of what I thought, I'll take the time now to remove the legacy references. I'm surprised though that there isn't a legacy warning or mention of it, would avoid confusion like this. I'm surprised to see it at all, I upgraded my API to latest, and created all new test data and only made customers with new calls, latest stripe_js dependency, and purchases/subs on the checkout/portal
basically if I'm getting it in the response object, the reference should mention it
ohyea!! ๐ it's been a busy weekend, can I hit ya for one more ๐ ๐
I think I'm understanding things correctly, hence the update part of that question (kind of related still actually)
๐
I'd recommend to reference this for the latest subscription integration: https://stripe.com/docs/billing/subscriptions/build-subscriptions
I think I've been following that, hence the new checkout and cx portal
Yup, let me know if you have more question
yeah I see your thumbs up there now ๐
so I have a ton of customers, using an old naming scheme from the original code, if I understand correctly I can programmatically update them to the new scheme (they have common elements to use), but at the same time can I put them on new price plans with just a subscription update?
(using items instead of plans as we just discussed lol)
Does your existing/old subscription have subscription.items?
They were made with legacy methods but created in the Dashboard as Products with Prices, so I presume so. Haven't run any trace code in live mode and my old bot is now offline
I'm being 'the bot' until i finish this rewrite ๐ kill me bahahaha
I guess step one there is make a lil mini script to pull a cx list and log it to see what I'm dealing with eh? but presumably I could update them that way?
Yup, I'd suggest checking what you have now and work on that.
In any case, this is the migration doc from Plan to Price: https://stripe.com/docs/billing/migration/migrating-prices
awesome! thanks very much ๐ lots to chew on there!
No problem! Happy to help ๐
๐
well I thought I figured out the pagination based on all that, but I think Node's tendency to rush on is gonna make me think outside my poor synchronous brain here lol
wall.js (main script)
ontime({
cycle: config.sync.stripe
}, function(ot) {
console.info("["+bot.getTime("stamp")+"] [wall.js] Starting Stripe Customer Synchronization.");
let list = stripe.customer.list();
stripe.customer.parse(list);
ot.done();
return;
});
stripe.js
const config = require("../files/config.json");
const stripe_js = require('stripe')(config.stripe.live_sk);
const stripe = {
customer: {
list: async function() {
let list = [];
for await (const customer of stripe_js.customers.list({limit: 100, expand: ['data.subscriptions']})) {
list.push(customer);
} return list;
},
parse: (...)
}
}
}
Error throws in the parse function as list is empty going in ๐ sad thing is that if this was in like old Java I'd probably be done already (but have a 3 million line program that runs at windows 95 speed)
(yeah that's more of a how to code thing than a stripe thing lol)
hrm.... return stripe.customers.parse(list); maybe.. make the function end in the next function?
is that a thing ๐ bahaha
the list function is a async function. can you try:
let list = await stripe.customer.list();
oyea ontime didn't like that at all, bot wouldn't start, that was my first thought
let list = await stripe.customer.list();
^^^^^
SyntaxError: await is only valid in async function
the func inside ontime is not set to async. can you make the ontime function into async?
async function(ot) ...
I seem to recall no, but will try. my idea just failed the same way lol
i'm not sure how ontime works, but can you try without using ontime and call stripe methods directly with async-await?
my skill level and what works already kind of limit my scope ๐ I'm also trying to wrap my brain around the errors returned on my idea there. Trying the ot change in a moment
๐คฆโโ๏ธ one letter can make an entire test invalid lol, figured that error out
HA! my idea did work (I am almost 99% sure ontime can't be async) I had put customers instead of customer in my parse object call ๐คฆโโ๏ธ you can see it in my message up there
awesome! happy that it works out for you!
thanks ๐ sometimes just talkin it out helps eh (and finding stupid typos lol)
yes! that's what we are here for!
that and knowing stripe and its docs extremely well ๐ my poor browser right now
welcome to dev ops eh ๐
a million references and google/stack searches
anywho ty again!
No problem! Happy to help ๐