#surreal_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.
- surreal_api, 22 hours ago, 19 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/1261151148857884682
đ Have more to share? Add details, code, screenshots, videos, etc. below.
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]
);
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?
Not possible unfortunately
You can only have Checkout Session generates a PaymentIntent
Okay that's fine. How do I get the payment intent from the checkout session after I create it?
Yeah you can find it in the webhook event checkout.session.completed, or from the Checkout Session object from Retrieve Checkout Session API
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
mm okay so basically ill only have access to that server-side once the payment intent has succeeded
post-payment
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?
Which Doc are you following? is it the redirect Checkout Session or Embedded Checkout?
Checkout != elements
https://docs.stripe.com/payments/accept-a-payment?platform=web&ui=embedded-form this is the guide for embeded Checkout
// Initialize Checkout
const checkout = await stripe.initEmbeddedCheckout({
fetchClientSecret,
});
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
That's a js code, not PHP
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
its the Stripe JS package with the integration shown here
https://docs.stripe.com/payments/accept-a-payment?platform=web&ui=embedded-form&client=html
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
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,
});
I'd recommend checking the guide here to check how async-await can be used: https://docs.stripe.com/checkout/embedded/quickstart?client=html
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
That sounds right to me
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
where is your await and async?
This is my fetchClientSecret()
So if i don't have any asynchronous functions, do I still need await and async?
stripe.initEmbeddedCheckout is an async function, so async-await is needed