alpha_full/admin/extensions/_stripe/stripeCheckOutSession.php
2026-04-06 22:58:51 +02:00

99 lines
3.2 KiB
PHP
Executable File

<?php
$nomFicAppelant = basename(__FILE__);
// -----------------------------------------------------
// Init
// -----------------------------------------------------
if (isset($_SESSION['lg'])) $lg=$_SESSION['lg']; else $lg='FRA';
if ($lg=="FRA") $locale='fr';
if ($lg=="ENG") $locale='en';
if ($lg=="ESP") $locale='es';
if ($lg=="ITA") $locale='it';
if ($lg=="DEU") $locale='de';
require 'vendor/autoload.php';
// -----------------------------------------------------
// Debug
// -----------------------------------------------------
if (isset($debug[1]) && $debug[1] == '1') { $debugMsg .= monDebug (1, [
'privateSecretStripe' => $privateSecretStripe,
'pubSecretPayStripe' => $pubSecretPayStripe,
'SESSSION[custId]' => $_SESSION['custId'],
'customer_email' => $_SESSION['adminMail'],
'successUrl' => $successUrl,
'errorUrl' => $errorUrl,
'priceId' => $priceId,
'locale' => $locale,
'host' => $host
],'stripeCheckOutSession.php');
}
// -----------------------------------------------------
// On demande et recupere le token
// -----------------------------------------------------
\Stripe\Stripe::setApiKey($privateSecretStripe);
// -----------------------------------------------------
// On prepare le post
// -----------------------------------------------------
if (isset($_SESSION['custId'])) $custID = $_SESSION['custId']; else $custID='';
try {
$checkout_session = \Stripe\Checkout\Session::create([
'success_url' =>$successUrl,
'cancel_url' => $errorUrl,
'payment_method_types' => ["card"],
'mode' => 'subscription',
'client_reference_id' => $_SESSION['custId'],
'customer_email' => $_SESSION['adminMail'],
// 'customer' => $custID,
'line_items' => [
['price' => $priceId,'quantity' => 1],
],
'locale' => $locale,
]);
// -----------------------------------------------------
// On envoi le post
// -----------------------------------------------------
header("Location: " .$checkout_session->url);
exit();
}
catch(\Stripe\Exception\CardException $e) {
echo 'Status is:' .$e->getHttpStatus() . "\n";
echo 'Type is:' .$e->getError()->type . "\n";
echo 'Code is:' .$e->getError()->code . "\n";
// param is '' in this case
echo 'Param is:' .$e->getError()->param . "\n";
echo 'Message is:' .$e->getError()->message . "\n";
}
catch (\Stripe\Exception\RateLimitException $e) {
echo ' Too many requests made to the API too quickly';
}
catch (\Stripe\Exception\InvalidRequestException $e) {
echo ' Invalid parameters were supplied to Stripe API (stripeCheckOutSession)'. "\n";
echo 'Param is:' .$e->getError()->param . "\n";
echo 'Message is:' .$e->getError()->message . "\n";
}
catch (\Stripe\Exception\AuthenticationException $e) {
echo ' Authentication with Stripe API failed ';
echo ' maybe you changed API keys recently';
}
catch (\Stripe\Exception\ApiConnectionException $e) {
echo 'Network communication with Stripe failed';
}
catch (\Stripe\Exception\ApiErrorException $e) {
echo 'Display a very generic error to the user, and maybe send yourself an email';
}
catch (Exception $e) {
echo 'Status is : ' .print_r($e). "\n";
}
// permet d'avor modifié le header
ob_end_flush();
?>