Introduce Stripe for .NET MAUI

Introduce Stripe for .NET MAUI

Steps to integrate Stripe SDK in your .NET MAUI app.


Stripe is a very well known payment service to let your end users pay easily and beautifully for your product/service(s) within your mobile apps and websites.

This article will guide you steps to integrate Stripe SDK into a newly created .NET MAUI app step by step.


  • .NET 8

  • Java SDK 17

  • Visual Studio on Windows or Visual Studio for Mac, alternatively

    • JetBrains Rider alternatively

    • Visual Studio Code with .NET MAUI extension

  • .NET workloads for .NET MAUI

  • Download the get-started source code


0/ Open the downloaded solution dotnet-maui-stripe-get-started.sln

0.a/ Create file by making a copy of

    |-- QuickStart.Dotnet.StripeHost
        |-- Shared.cs
        |--        <------      YOUR_FILE_HERE

0.b/ Replace placeholders with your secrets

partial class ClientHelper
    public const string API_KEY = "YOUR_API_KEY";

HINTS: You can copy these secrets quickly from the official quick start by Stripe.

0.c/ Run the API host

cd your-path-to-source-code/src/QuickStart.Dotnet.StripeHost
dotnet run -c debug

0.d/ Expose your API endpoint with ngrok

ngrok http http://localhost:4242

NOTE: ngrok is a tool that allows us to expose a development endpoint publicly via the network with ease.

0.e/ Amend with the generated URL

partial class ClientHelper
    public const string BACKEND_URL= "";

1/ Create a new .NET MAUI app from Visual Studio

NOTE: Follow step by step with all default options

2/ Install Stripe SDK for .NET MAUI

2.a/ Upgrade all .NET MAUI packages before installing Stripe.MAUI package

2.b/ Search for Stripe.Maui package and install


  • Before going next

    • Close the solution

    • Remove bin/obj folders of the .NET MAUI project

    • Reopen the solution

  • IMPORTANT!!! If you faced any issues of project loading failed, please repeat these steps :D

3/ Enable Stripe in MauiProgram.cs

3.a/ Add shared files to the .NET MAUI project

NOTE: We will add these files as links to share code across projects.

3.b/ Add Stripe to MauiAppBuilder


4/ Inject IPaymentSheet into MainPage.xaml.cs

public partial class MainPage : ContentPage
    private readonly IPaymentSheet paymentSheet;

    public MainPage(IPaymentSheet paymentSheet)
        this.paymentSheet = paymentSheet;

NOTE: To get the DI to work, we need to register MainPage as a scoped dependency through MauiAppBuilder.

// In MauiProgram.cs

5/ Try paying with payment intent

5.a/ Override MainPage.xaml file with the below content

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns=""
            Text="Pay now"
            SemanticProperties.Hint="Pay with Stripe"
            HorizontalOptions="Fill" />

5.b/ Fetch payment intent client secret from the above API endpoint

private string paymentIntentClientSecret;
protected override async void OnAppearing()

    // The helper method comes from the downloaded source code
    await QuickStart.Dotnet.Stripe.ClientHelper.FetchPaymentIntent()
        .ContinueWith(t =>
            var (ok, msg) = t.Result;
            if (!ok)
                MainThread.BeginInvokeOnMainThread(() => DisplayAlert("API Error", msg, "OK"));

            paymentIntentClientSecret = msg;

            MainThread.BeginInvokeOnMainThread(() => PayNowButton.IsEnabled = true);


  • By default, Pay now button is disabled

  • It will only be enabled if we can fetch the client secret successfully from the API

5.c/ Add OnPayNow handler

    private async void OnPayNow(object sender, EventArgs e)
        var configuration = new Configuration(" Co.Ltd.");

        var (result, msg) = await paymentSheet.PresentWithPaymentIntentAsync(paymentIntentClientSecret, configuration)
            .ContinueWith(t =>
                if (t.IsCompletedSuccessfully) return (t.Result, null);

                return (PaymentSheetResult.Canceled, "Cannot pay for a reason...");

            case PaymentSheetResult.Completed:
                await DisplayAlert("Payment Result", "Payment completed successfully!", "OK");
            case PaymentSheetResult.Canceled:
                if (!string.IsNullOrWhiteSpace(msg))
                    await DisplayAlert("Payment Result", "Payment completed failed!", "Try again");

        Debug.WriteLine("Payment complete.");

6/ Run up and check out

Till now, you're ready to check out the result on both Android and iOS.

  • Android: You can try either on a emulator or on a real device by plugging it in directly to your PC

  • iOS:

    • If you have an Apple paid developer account, you can plug your iPhone directly to your PC and try out

    • Otherwise, you will need a MacOS device to run the simulator


I just guided you on how to integrate Stripe SDK into a newly created .NET MAUI project. You can follow these steps to add it to your project(s) easily.

Documents from Stripe are also very helpful, please always take a look to understand a feature you desire to add to your app.

If you want to check out the source code of the binding libraries, you can check it here. If you want to check out the source code of the .NET MAUI library (along with a sample app), you can check it here.

Happy Coding!!!