使用 Stripe 的 Payment Intent API 接受 Xamarin 表单中的付款 [英] Accepting payments in Xamarin Forms with Stripe's Payment Intent API

查看:39
本文介绍了使用 Stripe 的 Payment Intent API 接受 Xamarin 表单中的付款的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have implemented payment in my back-end using Stripe.net, Now I have a mobile client writen in Xamarin Which I want to approve credit card payments with. But All of the examples I find online use the Charge API. I use the PaymentIntentAPI in my back-end and this returns a client secret as requested.

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

My question is: How do I confirm the payment using the Stripe.net package and the PaymentIntent API ?

这是如何在 android 上使用 java 完成的:

Here is how it is done on android with java:

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

在 dotnet 中使用旧的费用 API,操作方法如下:

Using the old charges API in dotnet, here is how it is done:

 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 服务器端,如本指南中所述:

The approach depends a bit depending on your requirements. If you plan to accept only U.S and Canadian cards then the simplest approach would be to confirm the PaymentIntent server-side as described in this guide here:

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

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

The gist is that you collect the credit card information client-side (preferably by tokenizing the details using one of our client-libraries), then call the PaymentIntents API much like you would the 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);

这里的关键参数是:

  • Confirm:需要设置为true,以便立即处理付款.
  • ErrorOnRequiresAction:需要设置为 true 以防止付款进入需要某种形式身份验证(例如 3D Secure)的状态
  • Confirm: needs to be set to true so that the payment is processed right away.
  • ErrorOnRequiresAction: needs to be set to true to prevent the payment from entering a state where it expects some form of authentication (e.g. 3D Secure)

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

If SCA and global regulatory requirements are a concern. Then you will need to find a way to confirm the payment client-side so users can authenticate a payment if they need to. Right now, the available integration paths are unfortunately quite limited for hybrid mobile technologies like Cordova, React Native, and Xamarin. Generally speaking there are two paths you can take:

在 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/.

This would allow you to use all the methods described here: https://stripe.com/docs/js, and follow our default integration path for accepting payments: https://stripe.com/docs/payments/accept-a-payment. For the Xamarin side of things a good place to start would be the official WebView example: 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/(安卓)

This is a bit more complex than running Stripe.js in a WebView, but would likely be more performant and give a slightly more polished user experience. With this approach you would build a bridge into Stripe's Android and iOS SDKs using the approaches outlined here: https://devblogs.microsoft.com/xamarin/binding-ios-swift-libraries/ (iOS), https://docs.microsoft.com/en-us/xamarin/android/platform/binding-java-library/ (Android)

这篇关于使用 Stripe 的 Payment Intent API 接受 Xamarin 表单中的付款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆