#talmor_code
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can 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/1259763525169971200
๐ Have more to share? Add details, code, screenshots, videos, etc. below.
https://docs.stripe.com/billing/subscriptions/usage-based/implementation-guide have you gone through this guide to set up usage-based billing ?
So this is my code currently.
Checkout.vue
<template>
<div>
<button @click="subscribe">Subscribe</button>
</div>
</template>
<script>
import { getAuth } from 'firebase/auth';
import { projectFirestore } from '../firebase/config';
import { token } from '@/stores/token';
export default {
setup() {
const auth = getAuth();
const store = token()
const subscribe = async () => {
const user = auth.currentUser;
if (!user) {
console.error('No authenticated user found.');
return;
}
const userId = user.uid;
const email = user.email; // Assuming email is part of the user object
const organisationId = store.organisationId; // Replace with actual organisation ID
console.log(`User ID: ${userId}, Email: ${email}`);
try {
const response = await fetch('https://us-central1-rostering-app-eaa7d.cloudfunctions.net/createCheckoutSession', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
userId: userId,
email: email,
organisationId: organisationId,
priceId: 'price_1Pa9msDjvFIuC9oVI4RKNHQu' // Replace with your actual metered price ID
}),
});
const session = await response.json();
if (session.error) {
console.error('Error creating checkout session:', session.error);
return;
}
const stripe = Stripe('pk_test_518MrCbDjvFIuC9oVCCKUZOXpzzvhAQ3Jh8cWyOHFheaRxt70FVnj8ZBQd7606Mrdu8IbvXSTC5i2A3iDIHEL3ym700kOGyr5YA'); // Replace with your Stripe publishable key
const { error } = await stripe.redirectToCheckout({ sessionId: session.id });
if (error) {
console.error('Stripe checkout error:', error);
}
} catch (error) {
console.error('Error creating checkout session:', error);
}
};
return { subscribe };
},
};
</script>
At the moment for the product I am trying to use a recurring, usage-based, Monthly item and the Meter is set to Sum.
I also originally had two products setup, the first was the initial charge to a user followed by the subscription.
Discord is a public place and you just leaked your private key, please roll your API key as soon as possible.
And I don't see any meter API use in your code. I'd highly recommend you go through the doc that I sent earlier to start your integration https://docs.stripe.com/billing/subscriptions/usage-based/implementation-guide?dashboard-or-api=api