#nikivi_api

1 messages ¡ Page 1 of 1 (latest)

radiant pantherBOT
#

👋 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/1282944076525867058

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

vagrant lake
wintry wren
#

this is sk_test i see

#

do i change this to live value right

#

as i want to get things from production stripe

vagrant lake
#

Sure you can do that

wintry wren
#

is it this publishable key?

vagrant lake
#

No, you should use the private API key to retrieve subscriptions

wintry wren
#

so secret key?

#

ok adding

vagrant lake
#

i.e., sk_live_xxx

wintry wren
#

can i not have limit

#

i want to get all

#

oh its optional

vagrant lake
wintry wren
#
import Stripe from "stripe"

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!)

async function getStripePayingUsers() {
    const subscriptions = await stripe.subscriptions.list()

    const payingCustomers = []
    for (const subscription of subscriptions.data) {
        if (subscription.status === "active") {
            const customer = await stripe.customers.retrieve(subscription.customer as string)
            payingCustomers.push(customer)
        }
    }
    console.log(payingCustomers, "paying customers")
    console.log(subscriptions, "subs")
}
#

yea we have more than 100

#

a ok will try paginate

#

trying to get how to get the customer associated as the return is quite messy

#

from subscriptions

#

like there is req status there too

#

i just want to get the data out

#

is it possible to get return from stripe without that request details

#

just the data

#

i.e.

async function getStripePayingUsers() {
    const subscriptions = await stripe.subscriptions.list()

    const payingCustomers = []
    for (const subscription of subscriptions.data) {
        if (subscription.status === "active") {
            const customer = await stripe.customers.retrieve(subscription.customer as string)
            payingCustomers.push(customer)
        }
    }
    console.log(payingCustomers, "paying customers")
}
#

if i log this, its hard to see what is even being returned

vagrant lake
#

What do you mean by "without that request details" ?

#

I think you can just use a map function to filter out the data

wintry wren
#

i get all this stuff

#

im looking at returned customer object

#

how do i know they are paying sub

#

none of this helps me know if they are paying or not cat_think

#

maybe balance

vagrant lake
#

Any invoice payment failures, or past-due invoices associated with the customer will set delinquent to true.

wintry wren
#

trying to figure out types now

#

ok i failed to add types

#

@vagrant lake but check this

#
async function getStripePayingUsers() {
    const subscriptions = await stripe.subscriptions.list()

    const payingCustomers = []
    for (const subscription of subscriptions.data) {
        if (subscription.status === "active") {
            const customer = await stripe.customers.retrieve(subscription.customer as string)
            // @ts-ignore
            if (!customer.delinquent) {
                payingCustomers.push(customer)
            }
        }
    }
    console.log(
        // @ts-ignore
        payingCustomers.map(c => ({ id: c.id, name: c.name, email: c.email })),
        "non-delinquent customers"
    )
}
#

this returns too little users

#

it returns 8

#

but i have more than 100 paying users

#

100%

#

i have feeling its due to pagination

#

but i don't get how to get pagination over 1000 elements

vagrant lake
wintry wren
#

that worked, thank you @vagrant lake