Stripe PaymentIntent with 3D Secure in Xamarin Forms

Stripe PaymentIntent with 3D Secure in Xamarin Forms

In this tutorial, we see how we can integrate Stripe into our Xamarin Forms application. In particular, we will see how to use create a PaymentIntent and manage 3D Secure for payment validation.

Create a PaymentIntent in the backend
PaymentIntent can be generated directly within the App, but for greater process security, it is recommended to generate it on your backend API server.

We then create a method that allows the app to request the creation of a PaymentItent and return the ClientSecret generated by Stripe:

Here you can find the complete code and also the version in Python

Request the ClientSecret from the App

Once we have created our method on the backend server we can recall it from our app and obtain the ClientSecret that we will need later

Proceed to payment Once the ClientSecret is obtained, we can proceed with the confirmation of the PaymentIntent, also providing the credit card and customer data:
Integrate 3D Secure

To allow confirmation of payments we must inform the PaymentIntent to enable 3D Secure, and since Stripe Elements are not available for Xamarin, we must manually manage the request.

First we create a return method on our server that displays an html page with the outcome of the payment

Next we need to extend our Pay method on the application in order to provide the ReturnUrl parameter that shows a modal with a WebView to manage the payment validation

Now, if our credit card requires 3D Secure validation, a modal will be shown with its WebView where the next steps for verification will be displayed. Upon verification, we will be redirected back to our server.

You can find the complete example with a backend server in GO and Python on GitHub.