#Illes-403
1 messages · Page 1 of 1 (latest)
Hi! Can you give me a little context? What Stripe integration are you using? And what what are you trying to achieve?
Sure
thank you
I have a web app
It is a "Mobile Barber" app, the client can select the service and the city where he lives and he will get a price and has to pay 20% of it as an advance. I want to integrate a Stripe card payment method in the app
Thanks for the info! What are you using the collect the payment information? Checkout Sessions? PaymentIntent with Payment Elements? Something else?
I used this for the integration:
Is this appropriate?
I don't know this specific tutorial, but it seems to be using Checkout Sessions which is a great option.
So now that I understand the situation, what exactly is your question?
Look at this code
this is payment_init.php
if (!empty($request->createCheckoutSession)) {...}
checkout session is not create
*created
$response = array(
'status' => 0,
'error' => array(
'message' => 'Invalid Request!'
)
);
I ge this response
*get
'invalid request'
there is a JSON error
echo json_last_error() ---> returns 4
Do you know what line of your code is generating this error?
This doesn't look like an error related to Stripe.
But if json_last_error returns 4, it means JSON_ERROR_SYNTAX. So the issue is probably with this line: json_decode($input). Have you tried to print the value of $input?
not yet
good idea! 🙂
yep
$input is returned as an undefined variable
input = file_get_contents('php://input');
I do not know what this is:
file_get_contents('php://input');
it reads the POST body of the request that is loading the script.
if you're not familiar with this details of PHP I'd suggest using a backend language you are more familiar with
I am not that much familiar with any back end language, I am quite a back end newbie....
But thankyou for the suggestion
so if $input is null, how exactly do you test this script?
like to be clear, simply loading payment_init.php in your browser won't work , since your script expects POST data right? but if you just open the script in a browser, that's a GET request so you'd expect there to be no data and file_get_contents('php://input') will be null.
Iam redirected to payment_init.php, because of a form with method="POST" action="payment_init.php"
and where is the code for that ^^?
also <form>s do not pass JSON, that pass form-encoded data, so if that is the case, it doesn't make sense to json_decode the input
hmm, sure
so you changed the frontend code then right?
what do u mean?
like you say you are following a guide but that guide correctly sends JSON to the backend
yep
that frontend page you just posted is quite different though right?
yep
like you just copied the code from the guide and pasted it at the bottom of your existing page and expect it to work?
I'd suggest you start by getting a self-contained example to work and then work on integrating it to your existing page
sure, thank you