#rudh_code

1 messages ¡ Page 1 of 1 (latest)

fringe minnowBOT
#

👋 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/1263095466204336160

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

grizzled echoBOT
#

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.

azure flare
#

Above is my front end and back end code for creating the subscription and attempting to intialise the payment sheet

pseudo yacht
#

What's the sub_xxx ID?

azure flare
#

sub_1PdVosCfWIy2jYftUUxG0leT

#

I retrieve it when I create the subscription but I do not actually use it in my payment sheet and I wonder if that is an issue

pseudo yacht
#

Well your code appears to be correct, in that you use the latest_invoice.payment_intent to initialise the Payment Sheet. But what you describe does not align with the state of that intent: pi_3PdVosCfWIy2jYft1ZcoH2PM

#

It's in a requires_payment_method state which implies that payment hasn't even been attempted yet

#

But on success of payment, it does not activate the subscription. It just creates a one off payment.
What does 'success of payment' look like exactly?

#

Also, what is the actual value of clientSecret variable?

azure flare
#

this is what it looks like on the dashbord

pseudo yacht
#

And it is those one-time payments that you're using with the Payment Sheet

#

Do you have a backend route/endpoint that calls paymentIntents.create?

azure flare
#

This is my backend create payment intents api endpoint i seem to call from the front end

#

I have also just console logged the clinet secret and I can see that the client secret I init my payment sheet, is different to the client secret returned from my subscription endpoint call

pseudo yacht
azure flare
#

Ahh ok, so please correct me if I am mistaken,

I am getting a client secret from the /create-payment-intent endpoint that I call when i initialise my payment sheet, and this is wrong (or at least not really what i want). Then I create a subscription, retrieve a client secret (the one I want) but when I then display my payment sheet, I show the payment sheet that was initialised with the previous client secret, that corresponds to a one off payment, and so when I make the payment, i successfully make the one off payment, not the subcription

#

Please let me know if the above is correct or if I have misunderstood anything

pseudo yacht
#

You shouldn't be creating a Payment Intent at all if you're doing Subscriptions. Subscription will take care of that, and you use the intent generated there to automatically transition sub status once its paid

azure flare
#

Ok so please advise me on the correct flow and how to fix this, as I am still a little unclear

  1. create the customer and get their customer id

  2. create a subscription using the customer id

  3. return back the subscription id, the client secret (are there any other necessary fields?)

  4. now initialise the payment sheet with the above client secret?

    const { error } = await initPaymentSheet({
    paymentIntentClientSecret: clientSecret, //THAT WE GET FROM THE SUBSCRIPTION CALL
    returnURL: "your-app-scheme://payment-sheet",
    // allowsDelayedPaymentMethods: true,
    });

  5. present this payment sheet

  6. the user fills in the information and confirms the sbscription payment?

Is the above correct

pseudo yacht
azure flare
#

ok sure thiing, I will have a go again at following the above, and try not to diverge from it at this point

pseudo yacht
#

Yeah you just need not to create a Payment Intent directly. The Subscription creation handles that either via latest_invoice.payment_intent (which you have in your code) or pending_setup_intent if there's no initial payment (i.e. a trial)