#Jonastex

1 messages · Page 1 of 1 (latest)

swift atlasBOT
#

Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

timid stream
#

Hi there, the error message said that you specified a PaymentIntent client secret.

You should pass a SetupIntent client secret instead

stuck marlin
#

Okay, but i use the PaymentIntent for a one-time payment and when i look the doc of SetupIntent i don't see when i can add the price ... I will share you the code I think it will be better to understand the context : ```php
try {
$id_customer = get_id_stripe_by_mail("test25@gmail.com");
$makeSinglePayment = true; // Mettez cette variable à true ou false en fonction de votre logique

// Créez une méthode de paiement pour le client
$paymentMethod = $stripe->paymentMethods->create([
    'type' => 'card',
    'card' => [
        'token' => 'tok_visa', // Utilisez le token de test approprié
    ],
]);

// Attachez la méthode de paiement au client
$stripe->paymentMethods->attach(
    $paymentMethod->id,
    ['customer' => $id_customer]
);

// Définissez la méthode de paiement attachée comme la méthode de paiement par défaut
$stripe->customers->update(
    $id_customer,
    ['invoice_settings' => ['default_payment_method' => $paymentMethod->id]]
);

$items = [['price' => '...', 'quantity' => 1]];

$subscription = $stripe->subscriptions->create([
    'customer' => $id_customer,
    'items' => $items,
]);

$clientSecret = $subscription->latest_invoice->payment_intent->client_secret;

$output = [
    'clientSecret' => $clientSecret,
];

if ($makeSinglePayment) {
    // Effectuer le paiement ponctuel en plus de l'abonnement
    $intent = $stripe->paymentIntents->create([
        'amount' => 1000,  // Montant en cents pour le paiement ponctuel
        'currency' => 'eur',
        'customer' => $id_customer,
    ]);

    $singlePaymentClientSecret = $intent->client_secret;

    $output = [
        'clientSecret' => $singlePaymentClientSecret,
    ];
}

echo json_encode($output);

} catch (Error $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}```

timid stream
#

Why do you want to set a price on a SetupIntent object?

stuck marlin
#

Because in paymentIntents i set price but if i must to use the SetupIntent where I can set the price ?

timid stream
#

No there's no param to set a price to SetupIntent, and I still don't understand why you want to do that.

#

Can you tell me the business problem that you are trying to solve with Stripe API, so that I can propose a solution for you?

stuck marlin
timid stream
stuck marlin
#

Yes thanks but i have same error : shared-79b9cea000d0cafa71248114be079370.js:1 Uncaught (in promise) FetchError: Error fetching https://r.stripe.com/b: Failed to fetch at shared-79b9cea000d0cafa71248114be079370.js:1:144595 (anonyme) @ shared-79b9cea000d0cafa71248114be079370.js:1 checkout.js:76 Uncaught (in promise) IntegrationError: Invalid value for stripe.confirmCardSetup intent secret: value should be a SetupIntent client secret. You specified: a PaymentIntent client secret. at S (v3/:1:491594) at ne (v3/:1:184847) at re (v3/:1:185102) at p (v3/:1:486412) at v3/:1:357928 at v3/:1:158969 at e.<anonymous> (v3/:1:390691) at e.confirmCardSetup (v3/:1:92194) at HTMLFormElement.handleSubmit (checkout.js:63:34))
I have replace php $intent = $stripe->paymentIntents->create([ 'amount' => 1000, // Montant en cents pour le paiement ponctuel 'currency' => 'eur', 'customer' => $id_customer, ]);
to php $intent = \Stripe\PaymentIntent::create([ 'customer' => $id_customer, 'setup_future_usage' => 'off_session', 'amount' => 1099, 'currency' => 'eur', // In the latest version of the API, specifying the `automatic_payment_methods` parameter is optional because Stripe enables its functionality by default. 'automatic_payment_methods' => [ 'enabled' => 'true', ], ]);

The function js is this : ```js
async function handleSubmit(e) {
e.preventDefault();

// Define the setLoading function
function setLoading(isLoading) {
if (isLoading) {
document.querySelector("#submit").disabled = true;
document.querySelector("#spinner").classList.remove("hidden");
document.querySelector("#button-text").classList.add("hidden");
} else {
document.querySelector("#submit").disabled = false;
document.querySelector("#spinner").classList.add("hidden");
document.querySelector("#button-text").classList.remove("hidden");
}
}

setLoading(true);

const { error, paymentMethod } = await stripe.confirmCardSetup(clientSecret, {
payment_method: {
card: elements.getElement("card"),
},
});

if (error) {
showMessage(error.message);
}

setLoading(false);
}```

timid stream
#

Why you are still using stripe.confirmCardSetup ? Did you get a chance to look at the doc that I shared earlier?