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());
}
});
Checkout 101: Build a custom order confirmation page with Checkout (Ruby) - YouTube[^][
^]
this is the link for reference what am I doing
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]);
});
?>