#SenorKarlos-pagination

1 messages ยท Page 1 of 1 (latest)

brazen leaf
#

๐Ÿ‘‹ Happy to help

red wagon
#

heya! thanks ๐Ÿ˜„ still wrapping my brain around some of the finer points of this programming nonsense ๐Ÿ˜‚

brazen leaf
#

Am I right to understand that you want to iterate the customer.list(..) until the end when has_more is false?

red wagon
#

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

brazen leaf
red wagon
#

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

brazen leaf
#

Auto pagination allows iterating the list of customers without keep tracking the has_more. In the sample video, it provides both options:

  1. while loop with has_more flag check (manual)
  2. 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

red wagon
#

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

brazen leaf
#

SenorKarlos-pagination

red wagon
#

my code uses plan.id alot, but I know it can now be found at items.data[0].somethin eh lol

brazen leaf
#

Can you share a little bit more what you want to achieve?

red wagon
#

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

brazen leaf
#

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.

red wagon
#

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)

#

๐Ÿ˜‚

brazen leaf
red wagon
#

I think I've been following that, hence the new checkout and cx portal

brazen leaf
#

Yup, let me know if you have more question

red wagon
#

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)

brazen leaf
#

Does your existing/old subscription have subscription.items?

red wagon
#

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?

brazen leaf
#

Yup, I'd suggest checking what you have now and work on that.

red wagon
#

awesome! thanks very much ๐Ÿ˜„ lots to chew on there!

brazen leaf
#

No problem! Happy to help ๐Ÿ™‚

red wagon
#

๐Ÿ˜… 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

brazen leaf
#

the list function is a async function. can you try:

let list = await stripe.customer.list();
red wagon
#

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
brazen leaf
#

the func inside ontime is not set to async. can you make the ontime function into async?

async function(ot) ...
red wagon
#

I seem to recall no, but will try. my idea just failed the same way lol

brazen leaf
#

i'm not sure how ontime works, but can you try without using ontime and call stripe methods directly with async-await?

red wagon
#

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

brazen leaf
#

awesome! happy that it works out for you!

red wagon
#

thanks ๐Ÿ˜„ sometimes just talkin it out helps eh (and finding stupid typos lol)

brazen leaf
#

yes! that's what we are here for!

red wagon
#

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!

brazen leaf
#

No problem! Happy to help ๐Ÿ™‚