#Illes-403

1 messages · Page 1 of 1 (latest)

elder harbor
#

Hi! Can you give me a little context? What Stripe integration are you using? And what what are you trying to achieve?

sudden prawn
#

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

elder harbor
#

Thanks for the info! What are you using the collect the payment information? Checkout Sessions? PaymentIntent with Payment Elements? Something else?

sudden prawn
#

I used this for the integration:

#

Is this appropriate?

elder harbor
#

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?

sudden prawn
#

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

elder harbor
#

Do you know what line of your code is generating this error?

sudden prawn
elder harbor
#

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?

sudden prawn
#

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');

queen glen
#

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

sudden prawn
#

I am not that much familiar with any back end language, I am quite a back end newbie....

#

But thankyou for the suggestion

queen glen
#

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.

sudden prawn
#

Iam redirected to payment_init.php, because of a form with method="POST" action="payment_init.php"

queen glen
#

and where is the code for that ^^?

sudden prawn
#

here

queen glen
#

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

sudden prawn
#

hmm, sure

queen glen
#

so you changed the frontend code then right?

sudden prawn
#

what do u mean?

queen glen
#

like you say you are following a guide but that guide correctly sends JSON to the backend

sudden prawn
#

yep

queen glen
#

that frontend page you just posted is quite different though right?

sudden prawn
#

yep

queen glen
#

like you just copied the code from the guide and pasted it at the bottom of your existing page and expect it to work?

sudden prawn
#

yes

#

no, I have re-written the id-s etc

queen glen
#

I'd suggest you start by getting a self-contained example to work and then work on integrating it to your existing page

sudden prawn
#

sure, thank you