hi i want to take amount, customer name and email on my success page but I am struggling to do.
this is my PHP server side codes which send request to stripe.
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
use SlimHttpRequest;
use SlimHttpResponse;
use StripeStripe;
require 'vendor/autoload.php';
$dotenv = DotenvDotenv::create(__DIR__);
$dotenv->load();
require './config.php';
$app = new SlimApp;
$app->add(function ($request, $response, $next) {
Stripe::setApiKey(getenv('STRIPE_SECRET_KEY'));
return $next($request, $response);
});
$app->get('/', function (Request $request, Response $response, array $args) {
return $response->write(file_get_contents(getenv('STATIC_DIR') . './grid-test.html','/index-copy.html'));
});
$app->post('/checkout_sessions', function(Request $request, Response $response) use ($app) {
$params = json_decode($request->getBody());
$payment_method_types = [
'usd' => ['card'],
'eur' => ['card'],
'cad' => ['card']
];
$products = [
'Private' => 'prod_435646574',
];
$session = StripeCheckoutSession::create([
'success_url' => 'http://localhost:4242/success.html?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => 'http://localhost:4242/?cancel=true',
'mode' => 'payment',
'payment_method_types' => ['card'],
'payment_intent_data' => [
'metadata' => [
'package' => $params->package,
'date' => $params->datepicker,
'no of adults' => $params->adults,
'no of children' => $params->children,
'occupancy' => $params->occupancy,
'tour' => $params->tour,
'location' => $params->location,
]
],
'metadata' => [
'package' => $params->package,
'date' => $params->datepicker,
'no of adults' => $params->adults,
'no of children' => $params->children,
'occupancy' => $params->occupancy,
'tour' => $params->tour,
'location' => $params->location,
],
'submit_type' => 'donate',
'line_items' => [[
'price_data' => [
'currency' => 'aed',
'product' => $products[$params->package],
'unit_amount' => $params->amount,
],
'quantity' => 1,
]],
'phone_number_collection' => [
'enabled' => true,
],
]);
return $response->withJson([
'id' => $session->id
]);
});
$app->run();
this is my success page which I am not able to get checkout session or payment intent details
var params = new URLSearchParams(window.location.search);
var sessionId = params.get('id');
var amount = document.getElementById('amount')
fetch('/get-session?id=' + sessionId)
.then((Response) => Response.json())
.then((session) => {
amount.innerText = session.payment_intent.amount;
})
.catch((error) => {
console.error('Error:', error);
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Thank You For Order</title>
</head>
<body>
<div id="main">
<div id="checkout">
<div id="payment-form">
<h1>Success!</h1>
<p>
Thanks so much for donating <strong id="amount"></strong> to
</p>
<a href="/">Donate More?!</a>
</div>
</div>
</div>
</body>
hi i want to take amount, customer name and email on my success page but I am struggling to do.