hi I was trying to convert code from ruby to PHP slim and want to send data from PHP slim with help of to JSON
<pre>$app->get('/order-info', function (Request $request, Response $response) {
$session = \Stripe\Checkout\Session::retrieve($request->get('session_id'));
$customer = \Stripe\Customer::retrieve($session->customer);
{
session: session,
customer: customer
}.to_json
});
and in javascript
<pre>document.addEventListener('DOMContentLoaded', async () => {
var urlParams = new URLSearchParams(window.location.search);
var sessionId = urlParams.get('session_id');
if (sessionId) {
const {customer, session} =
await fetch(`order-info?session_id=${sessionId}`)
.then((r) =>
r.json());
}
});
this is the link to ruby codes which i was trying to convert into php slim
What I have tried:
i have tried this maybe you can help me out if there is some mistake or need some changes to succeed
<pre><?php
$app->get('/order-info', function (Request $request, Response $response) {
$session = \Stripe\Checkout\Session::retrieve($request->get('session_id'));
$customer = \Stripe\Customer::retrieve($session->customer);
return $response->withJson([ 'session' => $session->session, 'customer' => $customer->customer]);
});
?>
I do get error slim application error
actually I was learning stripe PHP checkout following stripe php donation page checkout
but in this video they didn’t mention about success page and couldn’t find one in PHP slim, I asked even stripe about this but they were like we will update and its been 1 month no response and one of their representative told docs are not updated so sorry for the inconvenience. so if you guys can help me that will be so helpful to me