Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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

PHP
<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]);

  });
?>
Posted
Updated 21-Sep-22 6:44am
Comments
Richard MacCutchan 21-Sep-22 11:25am    
What is the actual code that you are using, and what happens when you run it?
MSameer Asif 21-Sep-22 12:34pm    
$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]);

});

this the code which I tried and it give error saying slim application error
MSameer Asif 21-Sep-22 12:38pm    
https://www.youtube.com/watch?v=FOLRATK4pVA
i used this to create stripe PHP checkout but now I want to try success page but tutorial is in ruby and I want to make this possible in PHP I even asked stripe to provide on tutorial but no response from them infact they even said that some of the doc are not updated so kind of stuck

1 solution

You will probably get a quicker answer from the Slim forum at Slim Framework[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900