#surreal_code

1 messages ¡ Page 1 of 1 (latest)

bitter hareBOT
rose umbraBOT
#

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.

bitter hareBOT
#

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

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

wheat brook
#

You need to close the parameter bracket first

#
$checkout_session = $stripe->checkout->sessions->create([
'ui_mode' => 'embedded',
'line_items' => [
    [
    'price' => $stripePrice->id,
    'quantity' => 1,
    ],
],
//'customer' => $customer,
'mode' => 'payment',
'return_url' => 'https://site.com/validatePayment.php?session_id={CHECKOUT_SESSION_ID}',
'automatic_tax' => [
  'enabled' => true,
],
], // <--- close this before stripe_account
['stripe_account' => $connectedAccountId]
);
rapid coral
#

Ohh, so I had it as a parameter in the first array, but it needs to be specified after that. Okay thank you! I've tested that and it's working. That solves problem #1

#

#2 is How can I get the payment intent associated with a checkout session? Is it possible for me to create a payment intent first, then attach that to the new checkout session?

wheat brook
#

Not possible unfortunately

#

You can only have Checkout Session generates a PaymentIntent

rapid coral
#

Okay that's fine. How do I get the payment intent from the checkout session after I create it?

wheat brook
#

Yeah you can find it in the webhook event checkout.session.completed, or from the Checkout Session object from Retrieve Checkout Session API

rapid coral
#

mm okay so basically ill only have access to that server-side once the payment intent has succeeded

#

post-payment

rapid coral
#

const stripe = Stripe('public key', {
stripeAccount: 'acct_1PahPcRLntYw8p5f' });

const options = {
    clientSecret: 'cs_test_a1llXbp0Ux5JXCZ9TKMBXdvlhvW10FNsMAn6H59bPv6wQIa2uk4sWx99qJ_secret_fidwbEhqYWAnPydgaGdgYWFgYScpJ2lkfGpwcVF8dWAnPyd2bGtiaWBabHFgaCcpJ3dgYWx3YGZxSmtGamh1aWBxbGprJz8nZGlyZHx2JyknZ2RmbmJ3anBrYUZqaWp3Jz8nJjQyND03Myd4JSUl',
    // Fully customizable with appearance API.
    appearance: {/*...*/},
};

I get this JavaScript error:
IntegrationError: Invalid value for elements(): clientSecret should be a client secret of the form ${id}secret${secret}.

It looks like I'm specifying it that way already?

wheat brook
#

Which Doc are you following? is it the redirect Checkout Session or Embedded Checkout?

rapid coral
#

Embedded

#

This is with stripe elements tho

wheat brook
#

Checkout != elements

#
  // Initialize Checkout
  const checkout = await stripe.initEmbeddedCheckout({
    fetchClientSecret,
  });

bitter hareBOT
rapid coral
#

const checkout = stripe.initEmbeddedCheckout(
{"clientSecret":"cs_test_a186sArDMFjekeCWikySJdEhAfWZkghinbznCUBY8VTFAZaXndactqHPn2_secret_fidwbEhqYWAnPydgaGdgYWFgYScpJ2lkfGpwcVF8dWAnPyd2bGtiaWBabHFgaCcpJ3dgYWx3YGZxSmtGamh1aWBxbGprJz8nZGlyZHx2JyknZ2RmbmJ3anBrYUZqaWp3Jz8nJjQyND03Myd4JSUl"} );

// Mount Checkout
checkout.mount('#checkout');

checkoutSession.php:125 Uncaught TypeError: checkout.mount is not a function

wheat brook
#

That's a js code, not PHP

rapid coral
#

That's the JS console output

#

right after initializing the checkout object, i call the mount function. console reports that this function doesn't exist for the checkout object (checkout.mount is not a function)

#

i develop full stack, system admin, network and cloud arch, cybersecurity lol

#

The issue with the checkout session is solved, but the payment form is not loading. That's the issue.
When the payment form attempts to load, this error is thrown in the browser console:
Uncaught TypeError: checkout.mount is not a function

spare rover
#

stripe.initEmbeddedCheckout returns a Promise. A promise can't be mounted. You should use await to get the object. For example,

const checkout = await stripe.initEmbeddedCheckout({
    fetchClientSecret,
  });
rapid coral
#

This is what I'm seeing

const checkout = await stripe.initEmbeddedCheckout({
fetchClientSecret,
});

// Mount Checkout
checkout.mount('#checkout');

And the fetchClientSecret function makes a fetch out to grab the checkout session ID.

I really don't want to make the user send another API call just to grab that if I can avoid it.

#

I guess I just need to pass a different function to that. Write my own fetchClientSecret which basically immediately returns it

spare rover
#

That sounds right to me

rapid coral
#

I think that worked! It's initializing the checkout object and the call to initEmbeddedCheckout() isn't returning any errors.

#

The strange thing is that, somehow
checkout.mount('#checkout')
is still giving the problem

spare rover
#

where is your await and async?

rapid coral
#

This is my fetchClientSecret()

#

So if i don't have any asynchronous functions, do I still need await and async?

ruby junco
#

stripe.initEmbeddedCheckout is an async function, so async-await is needed