gpt4 book ai didi

c# - 使用 Stripe 的 Payment Intent API 接受 Xamarin 表单中的付款

转载 作者:行者123 更新时间:2023-12-03 23:47:14 25 4
gpt4 key购买 nike

我已经使用 Stripe.net 在我的后端实现了付款,现在我有一个用 Xamarin 编写的移动客户端,我想用它来批准信用卡付款。
但是我在网上找到的所有示例都使用 Charge API。
我在后端使用 PaymentIntentAPI,这会根据请求返回客户端 secret 。

我的问题是:如何使用 Stripe.net 包和 PaymentIntent API 确认付款?

这是在 android 上使用 java 完成的方法:

 stripe = new Stripe(
context,
PaymentConfiguration.getInstance(context).getPublishableKey()
);
stripe.confirmPayment(this, confirmParams);

在 dotnet 中使用旧的费用 API,这是如何完成的:
 StripeConfiguration.SetApiKey("pk_test_xxxxxxxxxxxxxxxxx");

var tokenOptions = new StripeTokenCreateOptions()
{
Card = new StripeCreditCardOptions()
{
Number = cardNumber,
ExpirationYear = cardExpYear,
ExpirationMonth = cardExpMonth,
Cvc = cardCVC
}
};

var tokenService = new StripeTokenService();
StripeToken stripeToken = tokenService.Create(tokenOptions);

最佳答案

该方法取决于您的要求。如果您打算接受 仅限美国和加拿大卡 那么最简单的方法是确认 PaymentIntent 服务器端,如本指南中所述:

https://stripe.com/docs/payments/without-card-authentication

要点是您在客户端收集信用卡信息(最好使用我们的一个客户端库对详细信息进行标记),然后像调用 Charges API 一样调用 PaymentIntents API:

            var options = new PaymentIntentCreateOptions
{
Amount = 1099,
Currency = "usd",
PaymentMethodId = request.PaymentMethodId,

// A PaymentIntent can be confirmed some time after creation,
// but here we want to confirm (collect payment) immediately.
Confirm = true,

// If the payment requires any follow-up actions from the
// customer, like two-factor authentication, Stripe will error
// and you will need to prompt them for a new payment method.
ErrorOnRequiresAction = true,
};

paymentIntent = service.Create(options);

这里的关键参数是:
  • Confirm : 需要设置为 true以便立即处理付款。
  • ErrorOnRequiresAction : 需要设置为 true防止付款进入需要某种形式的身份验证(例如 3D 安全)的状态

  • 如果 SCA 和全局监管要求是一个问题。然后,您需要找到一种方法来确认付款客户端,以便用户可以在需要时验证付款。目前,遗憾的是,对于 Cordova、React Native 和 Xamarin 等混合移动技术,可用的集成路径非常有限。一般来说,你可以走两条路:

    在 WebView 中运行 Stripe.js

    这将允许您使用此处描述的所有方法: https://stripe.com/docs/js ,并遵循我们接受付款的默认集成路径: https://stripe.com/docs/payments/accept-a-payment .对于 Xamarin 方面的事情,一个好的起点是官方 WebView 示例: https://docs.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/workingwithwebview/ .

    为 Stripe 的原生 iOS 和 Android SDK 搭建桥梁

    这比在 WebView 中运行 Stripe.js 稍微复杂一些,但可能会更高效,并提供稍微更精致的用户体验。通过这种方法,您可以使用此处概述的方法在 Stripe 的 Android 和 iOS SDK 中建立桥梁: https://devblogs.microsoft.com/xamarin/binding-ios-swift-libraries/ (iOS), https://docs.microsoft.com/en-us/xamarin/android/platform/binding-java-library/ (安卓)

    关于c# - 使用 Stripe 的 Payment Intent API 接受 Xamarin 表单中的付款,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61924620/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com