92 lines
3.0 KiB
PHP
Executable File
92 lines
3.0 KiB
PHP
Executable File
<?php
|
|
// -----------------------------------------------------
|
|
// Init
|
|
//
|
|
if (!isset($lg) || empty($lg) ) {
|
|
if (isset($_SESSION['lg']) && empty($_SESSION['lg'])) {$lg=$_SESSION['lg'];}
|
|
else {$lg='FRA';$_SESSION['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') {
|
|
echo "\n". 'privateSecretStripe = ' .$privateSecretStripe;
|
|
echo "\n". 'pubSecretPayStripe = ' .$pubSecretPayStripe;
|
|
echo "\n". 'SESSSION[custId] = ' .$_SESSION['custId'];
|
|
echo "\n". 'successUrl = ' .$successUrl;
|
|
echo "\n". 'errorUrl = ' .$errorUrl;
|
|
echo "\n". 'priceId = ' .$priceId;
|
|
echo "\n". 'locale = ' .$locale;
|
|
}
|
|
|
|
// -----------------------------------------------------
|
|
// On demande et recupere le token
|
|
// -----------------------------------------------------
|
|
\Stripe\Stripe::setApiKey($privateSecretStripe);
|
|
|
|
// -----------------------------------------------------
|
|
// On prepare le post
|
|
// -----------------------------------------------------
|
|
try {
|
|
$checkout_session = \Stripe\Checkout\Session::create([
|
|
'success_url' =>$successUrl,
|
|
'cancel_url' => $errorUrl,
|
|
'payment_method_types' => ["card"],
|
|
'mode' => 'payment',
|
|
'client_reference_id' => $_SESSION['custId'],
|
|
'customer' => $_SESSION['custId'],
|
|
'line_items' => [
|
|
[ 'price' => $priceId,'quantity' => 1, ],
|
|
],
|
|
'locale' => $locale,
|
|
]);
|
|
|
|
// -----------------------------------------------------
|
|
// On envoi le post
|
|
// -----------------------------------------------------
|
|
header("Location: " .$checkout_session->url);
|
|
}
|
|
|
|
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 (checkOutSessionAchatUnique.php)';
|
|
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";
|
|
}
|
|
?>
|