#mikkelvenni_code
1 messages ยท Page 1 of 1 (latest)
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- mikkelvenni_firestore-webhook-urls, 3 days ago, 22 messages
๐ 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/1257445803950342185
๐ Have more to share? Add details, code, screenshots, videos, etc. below.
Hi!
For the live mode request:
req_7EekTnPUcc1AX2
What are you trying to do in this request exactly? I see the request returned an error because your code passed both billing_cycle_anchor and trial_from_plan. trial_from_plan is an older parameter
It was one of many attempts from my side to make sure that the subscription charges the customer immediately
Let's take a step back for a second. You're using Checkout which means that this request, if successful, will return a Checkout Session. You'll need to direct your customer to the Session's URL so they can complete the sign up and pay the first invoice.
Yes, I am already redirecting the user to the Checkout Session URL to complete the sign-up and payment. However, the issue is that on the Stripe payment page, the message displayed to the customer indicates that the first payment will be added to the next invoice rather than being charged immediately e.g. "1.00 dkk added to the next invoice. Then 1.00 kr. per month."
The goal is to ensure that the customer is charged immediately upon subscription creation, not added to the next invoice.
Since you mentioned you're seeing different behavior between live mode and test mode, can you share a live mode and test mode request ID or a live mode and test mode Checkout Session ID so I can compare?
Yes, of course. Hope this helps explain things:
Live mode request ID:
req_7EekTnPUcc1AX2
Test mode request ID:
req_wzpaYTYO2ScBSS
My code initially stayed exactly the same (except the API Key) and given that I in test mode was successfully charging the user immediately and in live mode it didn't work, I then tried adding the "payment_behavior" and "payment_behavior".
So in test mode, this is the code that initially worked with the immediate payment (and in live mode, the same code also works but without the immediate payment):
exports.createStripeCheckoutSession = functions.region('europe-west3').https.onCall(async (data, context) => {
const userId = context.auth.uid;
const priceId = data.priceId;
if (!userId) {
throw new functions.https.HttpsError("failed-precondition", "The function must be called while authenticated.");
}
try {
// Retrieve the user's email from Firestore
const userDoc = await db.collection("users").doc(userId).get();
const userData = userDoc.data();
const userEmail = userData ? userData.email : null;
const docRef = await db.collection("users").doc(userId).collection("checkout_sessions").add({
success_url: "https://www.foundment.com/onboarding",
cancel_url: "https://www.foundment.com/opret-konto",
price: priceId,
});
docRef.onSnapshot((snap) => {
const { error, url } = snap.data();
console.log(url);
if (error) {
alert(An error occured: ${error.message});
}
if (url) {
// We have a Stripe Checkout URL, let's redirect.
return { url: url };
}
});
return { url: session.url };
} catch (error) {
console.error("Error creating Stripe Checkout Session:", error);
throw new functions.https.HttpsError("internal", "Unable to create Stripe Checkout Session", error.message);
}
});
Do you have a live mode request that successfully created a Checkout Session? This returned a 400 error code
I just made a new request (req_J283NWtA3uc11V) in live mode with the code I just shared. And with that code, as you can see, everything works. But the only thing that's not working is that the customer is not charged immediately upon subscription creation, instead, it's added to the next invoice
Maybe it's a stupid mistake from my side, like a setting in Stripe or something like that?
I'm not familiar with trial_from_plan in subscription data but that's the only thing I can think of that might influence this
Can you omit that from your live mode request and try again?
Give me a few minutes, I'm discussing with a teammate as well
Yes sir. I appreciate it.
Trying to see if I can remove the "trial_from_plan" and make a new request in the meantime
I just made a new request (req_uQp6jrrgJqbzfq) and I don't know if I can omit the "trial_from_plan" since I use the built-in Firebase extension. I continue to see the "trial_from_plan" in the request
Hi there ๐ taking over, as my colleague needs to step away
I reproduced the same Checkout Session behavior and it looks like you would need to find a way to remove trial_from_plan
Thank you. Do you know if the trial_from_plan is added automatically from the Stripe extension in Firebase?
I just can't seem to find a way to remove that. Do you know if it should be possible to do that in my code?
I'm not very familiar with Firebase, so I'm not sure. One workaround would be to find where you are creating the Plan object that's being used and ensure it has no trial_period_days set, or set trial_period_days: 0
Thank you. I've now tried adding this:
trial_from_plan: false,
trial_period_days: 0
But it's like the extension overwrites that. But I don't understand why it was working in test mode and not in live mode?
Do you have a Plan ID I can look at that you've updated with the above parameters?
Yes, I think it's this one:
price_1PWIofRwAlhbjCNqTAO2P7UL
That's really odd. And you've used that Price/Plan to create a Checkout Session? Do you have the Request ID for that?
hate to keep sending you back for more info, but I'm not sure what would cause this behavior
No worries, I just really want to get to the bottom of this, because I've tried to get this to work for the last 3 days
Yes I've used the Plan ID (price_1PWIofRwAlhbjCNqTAO2P7UL)
Request ID:
req_VTBePezZ46VANg
Wait... I'm showing that an invoice was created with amount 100: https://dashboard.stripe.com/invoices/in_1PXtQ4RwAlhbjCNqzxVMthJq
That's what you wanted, right? You were trying to have the Invoice charged immediately?
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Yes, that is what I want. But something seems off.
I don't see the payment on my bank account, and in Firestore when I'm in test mode I see a collection called "payments" with its details after a payment/subscription creation. But in live mode (when actually creating a real payment I don't see the "payments" collection. In addition to that, on the checkout Stripe page I continue to see the text "1.00 kr. added to the next invoice. Then 1.00 kr. per month." (Look at attached image to see the page (with Danish text)).
Ah, apologies, I overlooked the obvious amount_paid: 0. I think this has to do with the amount being too small. Look here: https://dashboard.stripe.com/customers/cus_QOgakbMQSJhDLj/balance_transactions
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Can you try again with a larger amount?
Yes, do you know the minimum amount required?
I believe it's 3.00-kr: https://docs.stripe.com/currencies#minimum-and-maximum-charge-amounts