带条纹和付款单的回拨



我正在应用程序中实现Stripe的Paymentsheet方法,但我找不到回调或其他东西来了解付款是否已确认或出现问题。

付款单上有这些信息吗?如果没有,我如何使用stripe-sdk付款并接收呼叫的回调

您需要使用Stripe webhook在付款成功时收到通知。更具体地说,您应该监听payment_intent.succeeded事件。您可以在本文档中了解更多信息。

我尝试了try-and-catch,只是因为使用webhook会占用我们移动UI的一些时间。不过,Webhook是最好的选择。无论我在这里做了什么,都是一段时间的补丁。

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 ?? ''));
}
}
}
}

最新更新