#conor_23723
1 messages ยท Page 1 of 1 (latest)
Hello! We'll be with you shortly. 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.
- conor-embedded-checkout-java, 1 hour ago, 29 messages
What's the issue exactly?
I am trying to render a checkout, however I am not even getting an error. Just a black screen with the client secret showing i.e. my javascript is not working. I checked the elements and source and the script doesn't show up there either in my jsp
Here is my servlet code:
This is the javascript I am trying to use to show the checkout
And this is what is being rendered on the JSP. the script is not present in the elements, so I dont know whats wrong
please delete that code snippet and re-post without your secret key
that's considered sensitive data even in test mode
No problem
Servlet code:
Checkout JSP: <%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Pay Now</title>
<script src="https://js.stripe.com/v3/"></script>
</head>
<body>
<div id="checkout">
<!-- form auto inserts from js method -->
</div>
<script>
const stripe = Stripe('pk_test_');
initialize();
// Fetch the Checkout Session to get the clientSecret
async function initialize() {
const response = await fetch("<%=request.getContextPath()%>/pay-now", {
method: "POST",
});
const { clientSecret } = await response.json();
const checkout = await stripe.initEmbeddedCheckout({
clientSecret,
});
// Mount Checkout
checkout.mount('#checkout');
}
</script>
</body>
</html>
Its also not showing up in my logs on the stripe dashboard
What have you tried? That's a big wall of code that's really hard to understand out of context
Have you used a debugger? Anything?
Its for stripe connect - I was originally trying to make the checkout using the checkout session id, but was getting an error saying session id is not a parameter. Then I spoke to a developer here in a thread an hour ago and he said that I must use the client secret for the stripe initialise checkout method. He sent me the following link for help: https://stripe.com/docs/checkout/embedded/quickstart
So I have written servlets for onboarding which work - I can create a connected account and I am redirected back to my website, and the stripe account ID is stored in my database. Then using the above document, I wrote the code that I sent you to try and get the client secret and pass it to a parameter so I can call it using JS on the checkout JSP.
The servlet I sent gets the client secret and sets it to the attribute clientSecret. Then on the JSP I am trying to initialise the stripe connect checkout using javascript with that clientSecret.
I have no errors in the console, and it calls my servlet perfectly. The client secret is passed properly, as it is being rendered on a screen when my servlet is called. However, the checkout is not initialised - it is just a black screen with the client secret displayed
This is the JSP (checkout page) with the api key removed.
Ah ok
Have you tried using your developer tools in the browser to inspect and click elements on the page? Is an iframe being rendered or something at least even though it's blank?
I checked and no iFrame is being rendered
Ok and you're saying the script isn't even rendered?
Yes
How is the client secret being passed though? Looks like that's where you render it. In the script
A completely black screen with the following text is rendered - I will change the client key: {"clientSecret":"cs_test_.........."}
But where are you passing client secret? To me it only looks like it's within the script tag
So wouldn't the script have to be there?
Yes that is true actually - so do you know why the actual checkout isnt being shown?
Can you share screenshot of the browser window?
Also is /pay-now being hit on your server?
Yes it is
So the script has to be running then, yeah?
Yes actually the script must be running if the client secret is shown. But why am I shown a black screen instead of the checkout being initialised do you know?
Looking into it
I have a custom branded checkout created on stripe connect, so trying to show that
Can you console.log the clientSecret variable right after it's set
And paste what it shows
I did that and nothing showed up in the console
I'm quite confused
I said this: const { clientSecret } = await response.json();
console.log(clientSecret);
and the console is completely blank
Tried this too: console.log("Client Secret" + clientSecret); - and its still blank. So this line of code must not be running I think?
Can you see if there's another script running?
Feel like something else is interfering here
I don't see the checkout div at all
Like click the scripts tab
Will do
There are no scripts available to see in the sources tab
Are you sure the page that's being rendered is from the same code you shared? I don't see how it could be honestly
Yes it definitely is
let me try mess around with my servlet and see if I can try do some debugging and I will come back to you in 2 mins
Ok I changed my servlet and now its sending me to a blank white screen but an iframe is showing in the source code
Hi there ๐ taking over, as my colleague needs to step away
Give me a few minutes to get caught up.
I can briefly explain
So I am having an error rendering the checkout for stripe connect on my JSP
I just changed around the servlet to direct me to a jsp which has the client secret, and im trying to use that to render the checkout
After just changing it I'm now getting a JSON error in the console for the checkout jsp
Uncaught (in promise) SyntaxError: Unexpected token '<', "
<!DOCTYPE "... is not valid JSON
await (async)
(anonymous) @ pay-now:18
for this jsp
Gotcha. That doesn't sound like a Stripe error, so I'm not sure we can really assist with that. You'll need to step through your code and figure out why raw HTML is being parsed instead of the JSON the function is expecting
There is a stripe error too
The checkout session is not being created in my stripe account logs
I'd recommend figuring out the JSON error first. You can't easily debug API errors with an application that's erroring/halting at compile time.