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

51 lines
2.0 KiB
PHP
Executable File

<?php
$nomFicAppelant = basename(__FILE__);
// -----------------------------------------------------
// Init
// -----------------------------------------------------
require 'vendor/autoload.php';
// include ($includePathAdmin. '/psk/psk.php');
//
$trouve=false;
$return_url = $_SESSION['server']. '/admin/frmAdmin.php?affAdmin=17&reglageExtension=1&codeRetourPaiement=2&checkOutSession_id={CHECKOUT_SESSION_ID}';
// -----------------------------------------------------
// Verifier si le client exist
// -----------------------------------------------------
header('Content-Type: application/json');
$stripe = new \Stripe\StripeClient($privateSecretStripe);
$response = $stripe->customers->all($_SESSION['adminMail']);
$trouve=false;
//
for($a=0;$a<count($response->data);$a++) {
if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .='$a=' .$a;
$id=$response->data[$a]->id;
$email=$response->data[$a]->email;
if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .=' id => ' .$id;
if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .=' email => ' .$email;
if (isset($debug[1]) && $debug[1] == '1' ) $debugMsg .=' - - - - - - ';
if ($email==$_SESSION['adminMail'] && $trouve==false) {
$custId=$id;
$trouve=true;
}
}
// -----------------------------------------
// Portal ( on fait un create mais on devrait faire un retrieve ( version2..). Mais pas de header -> location dans retrieve ?)
// -----------------------------------------
\Stripe\Stripe::setApiKey($privateSecretStripe);
// Authenticate your user.
$session = \Stripe\BillingPortal\Session::create([
'customer' => $custId,
'return_url' => $return_url ,
]);
// Redirect to the customer portal.
header("Location: " . $session->url);
exit();
if (isset($debug[2]) && $debug[2] == '1') { $debugMsg .= monDebug(2, ['reqSelect' => $reqSelect], 'stripePortalLink.php');}
if (isset($debug[2]) && $debug[2] == '1') { $debugMsg .= monDebug(2, ['checkOutPortal_id' => $checkOutPortal_id], '');}
?>