#andres-payment-incomplete
1 messages ยท Page 1 of 1 (latest)
Hey @vagrant valve what's your question about that API?
my php code
You just leaked your real Live Secret API key to anyone
Please immediately roll your API key https://stripe.com/docs/keys#rolling-keys
{
"id": "pi_3NYAhVHtgq5cKnHj1iJACOn1",
"object": "payment_intent",
"last_payment_error": null,
"livemode": true,
"next_action": null,
"status": "requires_payment_method",
Then please share your code without any API key
and the reponse
<?php
require_once('../init.php');
require_once('../../admin/conf.inc.php');
\Stripe\Stripe::setApiKey("sk_live_51L....");
$customer = \Stripe\Customer::create(array(
'name' => $_POST['name'],
'email' => $_POST['stripeEmail'],
'source' => $_POST['stripeToken'],
));
$intent = \Stripe\PaymentIntent::create([
'customer' => $customer->id,
'amount' => $_POST['amount'],
'currency' => 'eur',
'automatic_payment_methods' => [
'enabled' => true,
],
]);
//$sql = "UPDATE abonnements SET statut = 'En attente de validation du paiement' WHERE orderRef = '".$_POST['reference']."'";
//mysqli_query($connexion, $sql);
header('Location: https://www.recrutement-chr.fr/compte-abonnements.php');
?>
Please confirm you rolled the API key, anyone could have seen it and be using it
ok i change it ?
And so what's your question? Your shared many lines of code but not much details. Right now this code creates a Customer, then a PaymentIntent, and that's it. The next step is to collect payment method details client-side. Mostly it'd be following https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements end to end
andres-payment-incomplete
๐ hopping in here since koopajah had to head out
no problem
What code are you copying? In general, with our guides you can't copy-paste and expect them immediately work - you need to make sure you have your server correctly set up, do some debugging to make sure everything works, etc
<?php
require 'vendor/autoload.php';
$stripe = new \Stripe\StripeClient('sk_test_...');
$checkout_session = $stripe->checkout->sessions->create([
'line_items' => [[
'price_data' => [
'currency' => 'usd',
'product_data' => [
'name' => 'T-shirt',
],
'unit_amount' => 2000,
],
'quantity' => 1,
]],
'mode' => 'payment',
'success_url' => 'https://www.recrutement-chr.fr/success.php',
'cancel_url' => 'https://www.recrutement-chr.fr/cancel.php',
]);
header("HTTP/1.1 303 See Other");
header("Location: " . $checkout_session->url);
?>
i find a solution i remplace
require 'vendor/autoload.php';
by
require_once('../init.php');
๐ glad you figured it out
<form action="./stripe/webhook/create-checkout-session.php" method="POST">
<input type="hidden" id="amount" value="'.$abt['montant']1001.2.'">
<input type="hidden" id="formule" value="'.$abt['formule'].'">
<button type="submit">Payer</button>
</form>i can do this ?
I'd suggest just trying it out and seeing how it behaves
Yes, just looking at that block of code it seems fine, but I don't know what the rest of your code is doing and it'll be much faster for you to try these things out rapidly and debug as you go ๐
i have a success reponse
๐
last question and i have finish
in success.php
$checkout_session = $stripe->checkout->sessions->create([
'line_items' => [[
'price_data' => [
'currency' => 'eur',
'product_data' => [
'name' => $_POST['formule'],
],
'unit_amount' => $_POST['amount'],
],
'quantity' => 1,
]],
'metadata' => [
'reference' => $_POST['reference'],
],
'customer_email' => $_POST['email'],
'mode' => 'payment',
'success_url' => 'https://www.recrutement-chr.fr/stripe/webhook/success.php?session_id={CHECKOUT_SESSION_ID}',
'cancel_url' => 'https://www.recrutement-chr.fr/stripe/webhook/cancel.php',
]);
i search to read metadata
try {
$session = $stripe->checkout->sessions->retrieve($_GET['session_id']);
$customer = $stripe->customers->retrieve($session->customer);
echo "<h1>Thanks for your order, $customer->name , $session->metadata->reference !</h1>";
http_response_code(200);
} catch (Error $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}
$session->metadata->reference don't work
$session->metadata['reference']
dont work
$session->metadata
Stripe\StripeObject JSON: { "reference": "ANDRESb3670b" }
i want just ANDRESb3670b