$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 '
Clé API vide pour stripe stripeCheckout!';
}
else echo '
Montant session vide!';
}
else {
echo 'Problème Stripe config';
}
?>