#faizan_webhooks
1 messages ยท Page 1 of 1 (latest)
๐ 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.
๐ happy to help
I'm not sure I understand
would you mind sharing a bit more context?
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
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?
yes
you can just retrieve the subscriptions for a customer https://docs.stripe.com/api/subscriptions/list#list_subscriptions-customer
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
and then if the https://docs.stripe.com/api/subscriptions/object#subscription_object-current_period_end is within the threshhold you calculate then you show the notification
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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>
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..
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
Hey! Taking over for my colleague. Let me catch up.
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 ?
i want a link btw stripe and client(frontend side) which tells the info when ever client run my app
info mean like notification
No Sorry, I still don't understand. you sorry. Can you share a concrete workflow step by step with a concrete example ?
thanks i think i am making wrong logic