capacitor-community / stripe

Stripe Mobile SDK wrapper for Capacitor
MIT License
185 stars 75 forks source link

Confirm payment always catches event Completed, never Failed #266

Closed AlesDspot closed 1 year ago

AlesDspot commented 1 year ago

Platform

Describe the bug Inputing a test card number which fails (4100000000000019) makes a call to api.stripe.com: https://api.stripe.com/v1/payment_intents/pi_3MdXWFCyDbRyOrdF01urgsUD/confirm

which returns the correct response:

image

But the confirmPaymentFlow always returns Completed. I cannot seem to catch the event for failed.

Also (not sure if it's related), the Postal code input is disabled and cannot be typed in.

Expected behavior Catch the failed response.

Nykz commented 1 year ago

This plugin is not catching the events canceled or failed in "PaymentFlow" upon canceling the process or even if the actual card is declined... Only listening to Completed event... In "PaymentSheet" failed eventt is working... But kindly fix the Payment Flow one...

AlesDspot commented 1 year ago

I tried even with PaymentSheet, and it also doesn't catch Failed, only Completed

rdlabo commented 1 year ago

That's right, because Stripe returns completed:

https://github.com/capacitor-community/stripe/blob/master/ios/Plugin/PaymentSheet/PaymentSheetExecutor.swift#L81-L83

I think the implementation needs to check separately whether the customer's payment has been successfully completed on the back end.

rdlabo commented 1 year ago

This Issue is closed because the information has not been updated. Thank you.

Nykz commented 1 year ago

@rdlabo If thats the case then its a big flaw. If the plugin cannot say whether the transaction is completed or not...not throwing proper errors then how will it be detected anywhere... it should pass at least some parameter to track it down...with payment gateways cant take any chance at all... as it involves money

AlesDspot commented 1 year ago

But that makes it unusable. If the transaction failes, how can you notify the user about this?

filipelle commented 1 month ago

For anyone looking at this in the future, when you call Stripe.confirmPaymentFlow(), you can easily check on your backend if the payment has been completed or errors ([stripe.paymentIntents.retrieve] (https://docs.stripe.com/api/payment_intents/retrieve?lang=node) and check if there are last_payment_error), in my case (as I think in many others) you may also use the endpoint to confirm the payment and put eventual data in your db.