I was trying to convert ruby codes to slim PHP but was stuck with to json thing if you all can help out and shine some light for me will be helpful.
<?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);
{
session: session,
customer: customer
}.to_json
});
?>
This is the main issue that is creating a problem and I think to json is where the problem arise how can I write in PHP slim to send it to front end with json?
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 javascript used to retrieve those codes.
This is the link to ruby codes which I was trying to convert into PHP slim
I tried this also in PHP slim
<?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]);
});
?>