#faizan_webhooks

1 messages ยท Page 1 of 1 (latest)

signal nestBOT
#

๐Ÿ‘‹ 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/1234439804213792780

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

thin vault
#

๐Ÿ‘‹ happy to help

#

I'm not sure I understand

#

would you mind sharing a bit more context?

spice reef
#

i want notification on client side regarding subscription expire

#

but i have no link to client and stripe directly...manualy i am handly using hardcode ids in test case senario

thin vault
#

do you mean you want to be able to let your customer know that their subscription is about to expire?

#

on your application's frontend?

spice reef
#

yes

thin vault
spice reef
#

here is my javascript code i am giving hardcoded ids i want code picks ids dynamicly how ?....<script>

    function retrieveCustomerSubscription(customerId) {
        return fetch('https://api.stripe.com/v1/subscriptions?customer=' + customerId, {
            method: 'GET',
            headers: {
                'Authorization': 'Bearer sk_test_51P9PdRGSVAelLEOgaiLoLQDoR7z89w5jW0UKT7iuciOyiWSNpq7P9I8AL2wTNrd3mqRyuRvzAPU1SjUyhyBX7OpS00rHGZoFqX', // Use the publishable key directly
            }
        })
            .then(response => response.json())
            .catch(error => console.error('Error:', error));
    }

    function checkSubscriptionExpiry(customerId) {
        retrieveCustomerSubscription(customerId)
            .then(data => {
                var subscriptions = data.data;
                var currentTimestamp = Math.floor(Date.now() / 1000);

                subscriptions.forEach(subscription => {
                    var trialEnd = subscription.trial_end;
                    var currentPeriodEnd = subscription.current_period_end;

                    if (trialEnd < currentTimestamp && currentTimestamp < currentPeriodEnd) {
                        // Subscription is expiring soon, send notification
                        var daysUntilExpiry = Math.ceil((currentPeriodEnd - currentTimestamp) / (60 * 60 * 24));
                        alert("Your subscription is expiring in " + daysUntilExpiry + " days. Please renew to continue enjoying our service.");
                    }
                });
            });
    }
    window.addEventListener('load', function () {
        var customerId = "cus_PzQOy40UT2lDnT"; // Replace with actual customer ID
        checkSubscriptionExpiry(customerId);
    });

</script>
thin vault
#

you should not be using your secret key on the frontend

#

instead you should have a backend server that you call from your frontend

#

and that uses the secret key to retrieve the subscriptions etc..

spice reef
#

i understand but my question is how i can get ids if a client is using my product or how i retrieve ids on frontend side.... in my code i am giving hardcoded ids copied from stripe desktop but in real senario i dont want hardcoded ids...hope you get it

signal nestBOT
muted coral
#

Hey! Taking over for my colleague. Let me catch up.

spice reef
#

๐Ÿ˜“

#

did you get it?

muted coral
#

No sorry,

here is my javascript code i am giving hardcoded ids i want code picks ids dynamicly how ?
From where you want to pick the ids you mean ?

spice reef
#

i want a link btw stripe and client(frontend side) which tells the info when ever client run my app

#

info mean like notification

muted coral
#

No Sorry, I still don't understand. you sorry. Can you share a concrete workflow step by step with a concrete example ?

spice reef
#

thanks i think i am making wrong logic