#mikkelvenni_code

1 messages ยท Page 1 of 1 (latest)

upbeat swanBOT
somber duneBOT
#

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.

upbeat swanBOT
#

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

native sluice
#

Hi there!

#

Do you have a request ID for either the test or live mode request?

frigid kiln
#

Hi!
For the live mode request:
req_7EekTnPUcc1AX2

native sluice
#

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

frigid kiln
#

It was one of many attempts from my side to make sure that the subscription charges the customer immediately

native sluice
#

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.

frigid kiln
#

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.

native sluice
#

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?

frigid kiln
#

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);
}
});

native sluice
frigid kiln
#

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?

native sluice
#

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?

upbeat swanBOT
native sluice
#

Give me a few minutes, I'm discussing with a teammate as well

frigid kiln
#

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

brazen wadi
#

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

frigid kiln
#

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?

brazen wadi
#

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

frigid kiln
#

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?

brazen wadi
#

Do you have a Plan ID I can look at that you've updated with the above parameters?

frigid kiln
#

Yes, I think it's this one:

price_1PWIofRwAlhbjCNqTAO2P7UL

brazen wadi
#

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

frigid kiln
#

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

brazen wadi
frigid kiln
#

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)).

brazen wadi
#

Can you try again with a larger amount?

frigid kiln
#

Yes, do you know the minimum amount required?

brazen wadi
upbeat swanBOT
frigid kiln
#

You are a genius

#

Now it works

#

I can't believe this has been the problem and I feel like a fool for spending so much time on it... Thank you so much!!!