Joh*_*ode 7 c# stripe-payments xamarin.forms
我已经使用 Stripe.net 在后端实现了付款,现在我有一个用 Xamarin 编写的移动客户端,我想用它批准信用卡付款。但我在网上找到的所有示例都使用 Charge API。我在后端使用 PaymentIntentAPI,这会根据请求返回客户端密钥。
我的问题是:如何使用 Stripe.net 包和 PaymentIntent API 确认付款?
下面是在 android 上用 java 完成的方法:
stripe = new Stripe(
context,
PaymentConfiguration.getInstance(context).getPublishableKey()
);
stripe.confirmPayment(this, confirmParams);
Run Code Online (Sandbox Code Playgroud)
使用 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);
Run Code Online (Sandbox Code Playgroud)
小智 3
该方法有点取决于您的要求。如果您计划仅接受美国和加拿大卡,那么最简单的方法是确认 PaymentIntent 服务器端,如本指南中所述:
https://stripe.com/docs/ payments/without-card-authentication
要点是您在客户端收集信用卡信息(最好使用我们的客户端库之一对详细信息进行标记),然后调用 PaymentIntents API,就像调用 Charges 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);
Run Code Online (Sandbox Code Playgroud)
这里的关键参数是:
Confirm:需要设置为true以便立即处理付款。ErrorOnRequiresAction:需要设置true为防止付款进入需要某种形式的身份验证(例如 3D Secure)的状态如果 SCA 和全球监管要求是一个问题。然后,您需要找到一种方法来确认付款客户端,以便用户可以在需要时验证付款。不幸的是,目前,对于 Cordova、React Native 和 Xamarin 等混合移动技术来说,可用的集成路径非常有限。一般来说,您可以采取两条路径:
在 WebView 中运行 Stripe.js
这将允许您使用此处描述的所有方法: https: //stripe.com/docs/js,并遵循我们接受付款的默认集成路径:https ://stripe.com/docs/ payments/accept-a-支付。对于 Xamarin 方面,官方 WebView 示例是一个不错的起点: https: //learn.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://learn。 microsoft.com/en-us/xamarin/android/platform/binding-java-library/(Android)
| 归档时间: |
|
| 查看次数: |
3313 次 |
| 最近记录: |