#andres-payment-incomplete

1 messages ยท Page 1 of 1 (latest)

modern mirageBOT
ancient compass
#

Hey @vagrant valve what's your question about that API?

vagrant valve
#

my php code

ancient compass
#

You just leaked your real Live Secret API key to anyone

vagrant valve
#

{
"id": "pi_3NYAhVHtgq5cKnHj1iJACOn1",
"object": "payment_intent",
"last_payment_error": null,
"livemode": true,
"next_action": null,
"status": "requires_payment_method",

ancient compass
#

Then please share your code without any API key

vagrant valve
#

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');
?>

ancient compass
#

Please confirm you rolled the API key, anyone could have seen it and be using it

vagrant valve
#

ok i change it ?

ancient compass
#

andres-payment-incomplete

modern mirageBOT
vagrant valve
#

i have an error 500

#

just copy paste your code

dense pebble
#

๐Ÿ‘‹ hopping in here since koopajah had to head out

vagrant valve
#

no problem

dense pebble
#

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

vagrant valve
#

<?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');

dense pebble
#

๐Ÿ‘ glad you figured it out

vagrant valve
#

<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 ?

dense pebble
#

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 ๐Ÿ™‚

vagrant valve
#

i have a success reponse

dense pebble
#

๐Ÿ‘

modern mirageBOT
vagrant valve
#

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" }

jovial pumice
#

What exactly are you trying to do?

#

And whats not working as you expect?

vagrant valve
#

i want just ANDRESb3670b

jovial pumice
#

Ok, but it looks like you're getting that reference value back

#

do you mean to what the value string without the key?

#

You can look that up from the metadata json/hash if thats what you need

#

$session->metadata->reference or similar, i would expect