#w_code
1 messages · Page 1 of 1 (latest)
đ Welcome to your new thread!
âČïž We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
â±ïž We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1229763838375624786
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
here is the first part of my code, i need it to grab the client_secret
try {
// Créer un client
$customer = \Stripe\Customer::create([
'name' => 'oo',
'email' => 'oo@gmail.com', // Adresse e-mail du client récupérée à partir du formulaire
]);
// Créer un PaymentIntent
$payment_intent = \Stripe\PaymentIntent::create([
'amount' => 2500, // Ajustez le montant si nécessaire
'currency' => 'eur',
'confirmation_method' => 'automatic', // Définir la méthode de confirmation sur automatique
'customer' => $customer['id'],
]);
// Attach a PaymentMethod to the Customer
$payment_method = 'pm_card_visa'; // Replace with the actual PaymentMethod ID retrieved from your form or Stripe.js
$payment_method = \Stripe\PaymentMethod::retrieve($payment_method);
$payment_method->attach(['customer' => $customer['id']]);
// Return client secret and customer ID
echo json_encode([
'client_secret' => $payment_intent->client_secret,
'customer' => $payment_intent->customer,
]);
} catch (\Stripe\Exception\ApiErrorException $e) {
// Return error response
echo json_encode(['error' => $e->getMessage()]);
}```
then, in an another file, i have this part of code,
try {
// RĂ©cupĂ©rer les donnĂ©es de la requĂȘte
$input = file_get_contents('php://input');
$body = json_decode($input, true);
// RĂ©cupĂ©rer l'ID du moyen de paiement et l'ID du client depuis le corps de la requĂȘte
$payment_method_id = $body['payment_method_id'];
$payment = $body['payment_method'];
$customer_id = $body['customer'];
// Créer un abonnement pour le client
$subscription = \Stripe\Subscription::create([
'customer' => $customer_id,
'items' => [['price' => 'price_1P0LjxEXcR0EgrxwAUpUjNcO']], // Remplacez par l'ID du prix de l'abonnement
]);
// Retourner l'abonnement créé
echo json_encode(['subscription' => $subscription]);
} catch (\Stripe\Exception\ApiErrorException $e) {
// Retourner une réponse d'erreur en cas d'erreur d'API Stripe
echo json_encode(['error' => $e->getMessage()]);
}```
here is the result in my stripe dashboard
I'd like a single payment, which assigns the subscription to the customer, while passing through paymentIntent for the 3dsecure.
hi! hmm why are you doing a separate PaymentIntent?
to be honest, I don't know the stripe api very well, I'm trying to learn as I go, I was trying to make an implementation that accepts 3dsecure
the normal way of doing this is simply you create the Subscription,and then there's a PaymentIntent that is created by that (latest_invoice->payment_intent) and that's all you have to do is confirm that PaymentIntent on the frontend.
well the easiest way would be to use Checkout(https://docs.stripe.com/billing/subscriptions/build-subscriptions?platform=web&ui=stripe-hosted) but otherwise the guide linked above describes the process for building a custom flow
thats a good idea but i need to do some backend completion after the payment
here is a confirmation_method on \Stripe\Subscription ?
i mean, i have to put on "automatic" to get the 3dsecure control, right?
that's not really how it works, it's the PaymentIntent that gets confirmed, to process a payment and present 3D Secure. The Subscription creates a PaymentIntent that you can then use and confirm on the frontend.