#mmunir-cpanel
1 messages · Page 1 of 1 (latest)
Like when i click paynow it dosent redirect
if you open the developer console, do you see any errors there?
I tried putting client files in server folder then its working in cpanel
Maybe its directory issue for checkout.
Got one more question like i have this server files and client file but that is used for one product, to have mutiple stripe checkout on multiple product do i need to have json, env multiple time or one is enough, and how will the server file which fetch stripe checkout work do i need to have separate file or mention some codes in this one
the idea is that you'd have a single endpoint on your server which creates checkout sessions, and that endpoint should accept a parameter which specifies which product to add as a line item to the checkout session
when the client code makes a request to the endpoint, it'd pass the product id as a parameter
Thanks
np
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
use Slim\Http\Request;
use Slim\Http\Response;
use Stripe\Stripe;
require 'vendor/autoload.php';
$dotenv = Dotenv\Dotenv::create(DIR);
$dotenv->load();
require './config.php';
$app = new \Slim\App;
$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') . '/index.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 = [
'cause-a' => 'prod_KP3YP2a3IGYqsb',
'cause-b' => 'prod_KP3iZRGcEjn5W8',
];
$session = \Stripe\Checkout\Session::create([
'success_url' => 'http://localhost:4242/?success=true',
'cancel_url' => 'http://localhost:4242/?cancel=true',
'mode' => 'payment',
'payment_method_types' => $payment_method_types[$params->currency],
'metadata' => [
'cause' => $params->cause,
'currency' => $params->currency,
],
'submit_type' => 'donate',
'line_items' => [[
'price_data' => [
'currency' => $params->currency,
'product' => $products[$params->cause],
'unit_amount' => $params->amount,
],
'quantity' => 1,
]]
]);
return $response->withJson([
'id' => $session->id
]);
});
$app->post('/webhook', function(Request $request, Response $response) {
$params = json_decode($request->getBody(), true);
$event = \Stripe\Event::constructFrom($params);
switch($event->type) {
—-------------------------------------
As this is my server file its mention $response->write(file_get_contents(getenv(static_dir). /index. Html
As you can see it mention only one product page which is index.html,how will i mention index2.html as my secound page is index2. Html