#Killbotbda-form_input
1 messages · Page 1 of 1 (latest)
hello! have you tried searching online for guidance? i took a quick look and found : https://www.w3schools.com/php/php_forms.asp
yeah I've tried that but the data is empty when it gets to the checkout page
can you elaborate more on what you mean that data is empty when it gets to the checkout page? where are you expecting to see it in - can you provide a screenshot?
did you see the code I pasted?
i saw it but i'm afraid i don't quite understand your explanation
if I use this
<form action="purchase-checkout.php?MFLID=12345" method="POST">
it has a hardcoded value of 12345 on MFLID to pass through to the stripe checkout
and that works fine - the value is passed and maintained all the way to the success page
but I don't want that value to be hardcoded - I want that value that gets passed through to be a user entry
They enter the value here - you hit the purchase now and I want that "333" number to pass through the URL string on that form
i think my first question here is why do you want that value e.g. 333 to be in the URL string on that form?
because there's an automated script that will setup their "league" on the backend based on the entry they put in
the site I use is an addon service for another site
so the "333" or whatever they put in is essentially their space on a different site that I can link on my site
so I'll collect that date, get them to pay and setup the DB as a new entry for them using that value they provided
if you want to retrieve format the URL to contain the data, you're probably going to need to use JS to retrieve the data from the input field then format the URL and make a separate POST request https://stackoverflow.com/questions/42050298/get-value-without-submitting-it
Really though, you should just retrieve the data using $_POST in your server instead. When you click on submit, the values in the input fields will be available when you access $_POST (as this shows https://www.w3schools.com/php/php_forms.asp)
I'll try the first, but for your second point the form action sends goes to stripes server, so it doesn't pass the data unless I put it in the URL string
for the second point, i think the request should be to your own server that has an endpoint to create the Checkout Session
well I do have that
but the checkout session page goes towards stripe
my form calls this page on my server
so in that endpoint, couldn't you write to the backend before creating the Checkout Session?
<?php
require 'vendor/autoload.php';
// This is your test secret API key.
\Stripe\Stripe::setApiKey('#');
header('Content-Type: application/json');
$MFLID = htmlspecialchars($_GET['MFLID']);
$YOUR_DOMAIN = 'http://mflhistory';
$checkout_session = \Stripe\Checkout\Session::create([
'line_items' => [[
# Provide the exact Price ID (e.g. pr_1234) of the product you want to sell
'price' => 'price_#',
'quantity' => 1,
]],
'mode' => 'payment',
'success_url' => $YOUR_DOMAIN . '/new-purchase-success.php?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => $YOUR_DOMAIN . '/cancel.html',
"metadata" => ["MyFantasyLeagueID" => $MFLID],
'automatic_tax' => [
'enabled' => false,
],
]);
header("HTTP/1.1 303 See Other");
header("Location: " . $checkout_session->url);
no because I need the payment to go through first
so it has to be done on success
then you should be listening to webhooks i.e. the checkout.session.completed event
upon receipt of that event, write the metadata to your DB
you shouldn't solely depend on the redirect because the customer could close the page before the redirect completes
I saw that but installing Stripe CLI on my webhost has been a pain
they don't have homebrew or any of those installers
umm, if you have a webhost, and you have a publicly accessible URL, then you don't need the Stripe CLI
the Stripe CLI is mainly to help with localhost development
the checkout fulfull orders link you sent me detailed installing stripe cli ....
the guides are for development, it's not possible to share or cover every single option
so follow the guide ... but don't really follow the guide...
webhooks are sent as a POST request to the endpoint URL defined
if you're doing local development, Stripe wouldn't be able to access your localhost server
however, because you're talking about your webhost - i'm assuming this means that you are deploying the code to your webhost, and hence you have an endpoint URL that is publicly accessible to anyone on the internet
so you don't need to do any workarounds to get the events sent to your server (that has a publicly accessible URL). You would simply configure the webhook endpoint either via the Dashboard in https://dashboard.stripe.com/test/webhooks or via the API : https://stripe.com/docs/api/webhook_endpoints/create
I have a webhook setup and it's getting a 301 err
301 is a redirect error. Stripe doesn't support redirects for webhooks -
The way to resolve this is usually just to replace the URL in your dashboard webhook settings with the one that your site is redirecting Stripe to currently.
can you direct me to the page to generate the webhook script in case it's incorrect?