#ericrueter_22046
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.
- ericrueter_22046, 1 day ago, 15 messages
- ericrueter_22046, 1 day ago, 41 messages
Hello! A lot of people set up an endpoint on their server that returns the publishable key, then their frontend code fetches it from the server when needed.
How do I do that. I can write PHP end point code, but the Checkout.js doe not invoke PHP.
examples would help, but if you can point me in a direction that would help. I am self taught, work by myself, and therefore do not havesome of the exposure to "things" that others have.
Sorry, maybe I misunderstood. Can you show me the code that you're talking about that goes on your website? The code with the publishable key?
The second const is my first attempt at making a change. This is almost exactly what is offered in the quick start checkout on the Stripe website.
// This is your test publishable API key.
// const stripe = Stripe("pk_test_kDvBG3sFiQ9YyQlC3vqHtzW0");
const stripe = '<?php echo Stripe("$StripePublishKey")?>';
initialize();
// Create a Checkout Session as soon as the page loads
async function initialize() {
const response = await fetch("/SOLEStripeCheckout.php", {
method: "POST",
});
const { clientSecret } = await response.json();
const checkout = await stripe.initEmbeddedCheckout({
clientSecret,
});
// Mount Checkout
checkout.mount('#checkout');
}
Gotcha. Try const stripe = Stripe("<?php echo $StripePublishKey;");
that will not work. This JS is "executed" before php is invoked (best I can tell). So the <php does not work. I just ran it twice, once with the listed php variable (which I do not think is available because there is no way to "post" it. I changed to use a $_Session var, and I still get the message "something went wrong...".
That's not how it works. The PHP is run first when the page is requested from your server. The PHP runs, then the output is sent to the browser.
If you view the source of the page after trying the code I shared above what do you see after const stripe = Stripe("?
// This is your test publishable API key.
// const stripe = Stripe("pk_test_kDvBG3sFiQ9YyQlC3vqHtzW0");
// const stripe = "<?php echo "Stripe('$StripePublishKey')";?>";
// const stripe = Stripe("<?php echo $_SESSION['StripeTestPublishKey'];?>");
// const stripe = Stripe("pk_test_51OXpNcLPFl17ZYBBUpTll20MYePBKuVYvDu7vLqchjyuppNelLPXHd1Ig0RkGCgeQMFH0owrC5gWPDu8y0ZT58Y100AAefE8ph");
// const stripe = Stripe("pk_test_kDvBG3sFiQ9YyQlC3vqHtzW0");
// const stripeapi = document.currentScript.getAttribute('API');
// const stripeapi = env.StripePublishKey;
const stripe = Stripe("<?php echo $_SESSION['StripeTestPublishKey'];");
// alert(stripeapi);
// const stripe = Stripe(stripeapi);
initialize();
// Create a Checkout Session as soon as the page loads
async function initialize() {
const response = await fetch("/SOLEStripeCheckoutTEST.php", {
method: "POST",
});
const { clientSecret } = await response.json();
const checkout = await stripe.initEmbeddedCheckout({
clientSecret,
});
// Mount Checkout
checkout.mount('#checkout');
}
is in the JS window. Let me see if I can find page source ... may take a min or two.
This is the page source ... The page is loaded by the JS. I "think" (I am NOT at all sure), that since it is loaded via JS, there hasn't been any true interaction with the server, so no invoking of PHP.
<!DOCTYPE html>
<html lang="en">
<?php
$APIX = $_SESSION['StripeTestPublishKey'];
error_log($APIX);
?>
<head>
<meta charset="utf-8" />
<title>SOLE Checkout</title>
<meta name="description" content="Payment on Stripe" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<script src="SOLEStripeCheckoutTEST.js" random="<?php echo filemtime('SOLEStripeCheckoutTEST.js'); ?>" defer ></script>
<script src="https://js.stripe.com/v3/"></script>
<!-- (A) PHP VARIABLE -->
<!-- Display a payment form -->
<div id="checkout">
<!-- Checkout will insert the payment form here -->
</div>
</body>
</html>
Excuse the extra stuff,,, it is leftover from my many trips down deadends..
Sorry, not sure I follow. The page with the JS you modify isn't being loaded from your server? Where is it being loaded from?
Heck I don't know. All I know is I invoke the above "page" from a PHP program, and none of the php code on it actually works. Note the PHP at the beginning, it does not execute. The script withe the src for the SOLE...checkout. js does not change the php echo... it appears to try and load the STRIPE embeded page, then returns the something went wrong message. IF I do put use the hardcoded PK, then it works. fine.
Maybe your web server is only set up to run PHP code in files with a .php extension? If you rename the file to checkout.php does the PHP code run as expected?
OK - Thank you. That got me a little closer. Now I have to backout all the different "tries" that were not working. That will take a few minutes. I'll get back on this thread IF I continue to have a problem. I've been at this since a week ago last monday (ten days). The first seven days I was being abused by the non-tech support group. They never thought about saying "Hey have you tried Discord?". Again thank you for your time.
Abused? Non-tech support group? Can you tell me what happened?
I had this problem. I would send them an eMAIL complying with their request, they would wait until around 5:00 in the afternoon and reply with another vague request, "like send us a code snippet", but not say from where. They didn't bother to tell me they only accepted PDFs. They kept telling me that my eMAIL address did not match the account that was having trouble. This went on for more than a week. I was seriously thinking about finding another software company. They were never really rude, but when they start each eMAIL with "Thank you for circling back" and other platitudes, it got to be a bit much. There is more, but this is not your problem. I am very pleased with the support I have received once I found Discord. I started my career in IT over 50 years ago and I have had a LOT of experience with support.