145 lines
5.0 KiB
PHP
Executable File
145 lines
5.0 KiB
PHP
Executable File
<?php
|
|
$nomFicAppelant = basename(__FILE__);
|
|
require 'vendor/autoload.php';
|
|
$continue=true;
|
|
|
|
// ---------------------------------------------------
|
|
// On récupère les clés
|
|
// ---------------------------------------------------
|
|
$bdd= $_POST['bdd'];
|
|
if ( (isset($bdd) && $bdd=='demo') || $_SESSION['bdd']=='demo' || $_SESSION['isDemo']==1) {
|
|
// ---------------------------------------------------
|
|
// Mon identifiant Stripe
|
|
include ('./admin/adminInclude/psk.test.php');
|
|
}
|
|
else {
|
|
// ---------------------------------------------------
|
|
// DB identifiant
|
|
$stripeConfigFile = __DIR__ . '/stripe_config';
|
|
if (file_exists($stripeConfigFile)) {
|
|
$config = file(__DIR__ . '/stripe_config', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
$privateSecretStripe = trim($config[0]);
|
|
$pubSecretPayStripe = trim($config[1]);
|
|
}
|
|
else {
|
|
// Fichier introuvable
|
|
$continue=false;
|
|
throw new Exception('Fichier de conf stripe introuvable.');
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------
|
|
// On récupère le reste
|
|
// ---------------------------------------------------
|
|
if ( $continue===true) {
|
|
$montant= $_POST['montant'];
|
|
$idMail= $_POST['idMail'];
|
|
$nomSite= $_POST['nomSite'];
|
|
$server= $_POST['server'];
|
|
$success_url= $_POST['success_url'];
|
|
$cancel_url= $_POST['cancel_url'];
|
|
if(!isset($server)) $server = $_SESSION['server'];
|
|
$locale= $_POST['locale'];
|
|
|
|
// debug
|
|
//pas en prod
|
|
// if (isset($debug[1]) && $debug[1] == '1') { $debugMsg .= monDebug(1, ['privateSecretStripe' => $privateSecretStripe, 'pubSecretPayStripe' => $pubSecretPayStripe, 'montant' => $montant, 'idMail' => $idMail, 'nomSite' => $nomSite, 'locale' => $locale, 'server' => $server ], 'stripeCheckout.appel.php'); }
|
|
|
|
// ---------------------------------------------------
|
|
// Test des montant et clePrivée
|
|
// ---------------------------------------------------
|
|
if (!empty($montant)) {
|
|
if (!empty($privateSecretStripe)) {
|
|
|
|
// ---------------------------------------------------
|
|
// Appel API
|
|
// ---------------------------------------------------
|
|
try {
|
|
// on demande et recupere le token
|
|
\Stripe\Stripe::setApiKey($privateSecretStripe);
|
|
|
|
// on crée la session stripe
|
|
// flag edt quantity = 1 ?
|
|
$checkout_session = \Stripe\Checkout\Session::create([
|
|
'success_url' => $success_url,
|
|
'cancel_url' => $cancel_url,
|
|
'payment_method_types' => ["card"],
|
|
'mode' => 'payment',
|
|
'client_reference_id' => $idMail,
|
|
'customer_email' => $idMail,
|
|
'line_items' => [[
|
|
'price_data' => [
|
|
'currency' => 'eur',
|
|
'product_data' => [ 'name' => 'Votre commande sur ' .$nomSite ],
|
|
'unit_amount' => $montant
|
|
],
|
|
'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';
|
|
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\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';
|
|
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";
|
|
// var_dump ($e);
|
|
}
|
|
|
|
catch (\Stripe\Exception\ApiErrorException $e) {
|
|
echo ' Display a very generic error to the user, and maybe send yourself an email';
|
|
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 (Exception $e) {
|
|
echo ' Status is:' . $e . '\n';
|
|
}
|
|
}
|
|
else echo '<br>Clé API vide pour stripe stripeCheckout!';
|
|
}
|
|
else echo '<br>Montant session vide!';
|
|
}
|
|
else {
|
|
echo 'Problème Stripe config';
|
|
}
|
|
?>
|