I am implementing the Paymentsheet method of Stripe in my application, but i can't find a callback or something else to know if the payment has been confirmed or there have been problems.
Is this information available with Paymentsheet? If not, how can i pay using stripe sdk and receive a callback of the call
CodePudding user response:
You need to use Stripe webhooks to be notified when the payment succeeds. More specifically you should listen to the payment_intent.succeeded
event. You can learn more about this in this doc.
CodePudding user response:
I tried with try and catch only because using webhook it tooks some time for our mobile UI. Though, Webhook is the best option. Whatever I did here is some time of patch.
Future<void> _presentPaymentSheet(
BuildContext context, String? clientSecret) async {
try {
await Stripe.instance.presentPaymentSheet();
// ==> Here, I assume payment success
state = NetworkState.success;
} on Exception catch (stripeException) {
if (stripeException is StripeException) {
state = NetworkState.error;
if (stripeException.error.code == FailureCode.Canceled) {
context.showSnackBar(AppStrings.errorFromStripe
(stripeException.error.localizedMessage ?? ''));
context.pop();
} else {
debugLog('Error7: $stripeException');
context.showSnackBar(AppStrings.errorFromStripe
(stripeException.error.localizedMessage ?? ''));
}
}
}
}