我已经使用Stripe.net在后端实现了付款,现在我有一个用Xamarin编写的移动客户端,我想通过该客户端批准信用卡付款。 但是我在网上找到的所有示例都使用Charge API。 我在后端使用了PaymentIntentAPI,并按要求返回了客户密码。
我的问题是:如何使用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);
答案 0 :(得分:2)
该方法取决于您的要求。如果您打算仅接受美国和加拿大卡,那么最简单的方法就是按照本指南中的说明确认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/(Android)