#hazem-elkhalil_api
1 messages · Page 1 of 1 (latest)
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.
- hazem-elkhalil_api, 1 day ago, 5 messages
👋 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/1242834996595654666
📝 Have more to share? Add more details, code, screenshots, videos, etc. below.
const handleSubmit = async (event) => {
event.preventDefault();
if (!stripe || !elements) {
return;
}
const result = await stripe.confirmPayment({
elements,
confirmParams: {
return_url: "http://localhost:3000/bekraftelse",
},
redirect: "if_required", // If i dont add this, it will redirect even if the swish payment is canncled
});
if (result.error) {
//The error is not being catched here <------
return setError(result.error.message!);
} else {
console.log(result);
if (result.paymentIntent.last_payment_error) {
return setError("Något gick fel med din swish betalning, försök igen!"); // Error here that is not being catched in result.error Error ("partner_generic_decline")
}
}
};```
I pasted some code so its easier to understand what is going on
here is an object
{
"id": "pi_3PJFLT0357RGjGIi0UA8NYT2",
"object": "payment_intent",
"amount": 1000,
"amount_details": {
"tip": {}
},
"automatic_payment_methods": null,
"canceled_at": null,
"cancellation_reason": null,
"capture_method": "automatic_async",
"client_secret": "pi_3PJFLT0357RGjGIi0UA8NYT2_secret_L8D4dY5zWXiRA0f03T3CIm3Ch",
"confirmation_method": "automatic",
"created": 1716385003,
"currency": "sek",
"description": null,
"last_payment_error": {
"code": "payment_method_provider_decline",
"decline_code": "partner_generic_decline",
"doc_url": "https://stripe.com/docs/error-codes/payment-method-provider-decline",
"message": "The customer canceled BankID signing.",
"payment_method": {
"id": "pm_1PJFM90357RGjGIiNj4WmSKF",
"object": "payment_method",
"allow_redisplay": "unspecified",
"billing_details": {
"address": {
"city": null,
"country": null,
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"email": null,
"name": null,
"phone": null
},
"created": 1716385045,
"customer": null,
"livemode": true,
"swish": {},
"type": "swish"
},
"type": "card_error"
},
"livemode": true,
"next_action": null,
"payment_method": null,
"payment_method_configuration_details": null,
"payment_method_types": [
"swish"
],
"processing": null,
"receipt_email": null,
"setup_future_usage": null,
"shipping": null,
"source": null,
"status": "requires_payment_method"
}```
even the redirect status is succeeded
for some reason, really confusing
Hello
I think that's intended behavior.
https://docs.stripe.com/payments/swish/accept-a-payment?web-or-mobile=web&payments-ui-type=elements#failed-payments
You'd check for the payment success/failure on the page that you get redirected to afaik
After calling confirmPayment, the customers are redirected to Swish to approve or decline the payment. After the customers authorise the payment, they’re redirected to the Payment Intent’s return_url. Stripe adds payment_intent, payment_intent_client_secret, redirect_pm_type, and redirect_status as URL query parameters (along with any existing query parameters in the return_url).
But thats not how it works with cards, which presents the issue that the user is thrown out of the "booking" page and they have to reenter all their details again if the accidantally cancells, is there no way of handling this better ?
When a payment fails with cards there is an error in result.error, so they are not redirected
Or am i thinking of it in the wrong way ? <.<
I think it's different for card and other PaymentMethods. Swish is a redirect based payment method (which card is not).
We call this out in our docs here: https://docs.stripe.com/js/payment_intents/confirm_payment#confirm_payment_intent-options-redirect
ah i understand,
okey i wil have to solve this somehow
Another question Hanzo, it is a bit irrelevant
How would i modify a paymentintents price, in the situation where the user adds a discount, do i have to create a new payment intent or is there a way to edit one
No, you can update the PaymentIntent server-side by calling the Update API
https://docs.stripe.com/api/payment_intents/update
and then use fetchUpdates() function client-side
https://docs.stripe.com/js/elements_object/fetch_updates
does that help @native crane ?
Yes it does 🙂
Thanks a lot hanzo 🙂
Last question, how would i remove all unused paymentintents ?
those that are uncompleted
You can cancel them via the API https://docs.stripe.com/api/payment_intents/cancel
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
thanks 🙂 !