Skip to content

Generation-One/G1.Stripe.Maui

Repository files navigation

G1.Stripe.Maui

G1.Stripe.Maui nuget downloads
G1.Stripe.Android.Bindings nuget downloads
G1.Stripe.iOS.Bindings nuget downloads

A .NET MAUI library providing Stripe payment integration for cross-platform mobile applications.

Contribition

Maintaining this on our own isn’t feasible, so we’re turning it into a community-driven project. Right now it provides a minimal, working iOS API, but we need contributors to flesh it out and improve its reliability. We’ve seen many developers struggle with these same issues, so we’re making everything public in hopes that the community can help build a robust, well-documented solution together.

Stripe SDK Versions

This library uses the following Stripe SDK versions for each platform:

  • Stripe Android SDK: 21.18.0
  • Stripe iOS SDK: 24.16.1

Long path error

You can face issue with long paths, similar to that:

Could not find a part of the path 'c:\packages\g1.stripe.ios.bindings\0.0.3-beta\lib\net9.0-ios18.0\G1.Stripe.iOS.Bindings.resources\Stripe.Swift.Proxy.xcframework\ios-arm64_x86_64-simulator\Stripe_Swift_Proxy.framework\Modules\Stripe_Swift_Proxy.swiftmodule\arm64-apple-ios-simulator.private.swiftinterface'.

to handle that need to enable long paths support and install package via CLI

dotnet add package G1.Stripe.Maui --prerelease

Installation

In your MAUI project’s MauiProgram.cs, wire up the Payment Sheet under the G1.Stripe.Maui namespace:

using G1.Stripe.Maui;

public static MauiApp CreateMauiApp()
{
    var builder = MauiApp.CreateBuilder();
    builder
        .UseMauiApp<App>()
        .UseStripePaymentSheet();

    return builder.Build();
}

Usage

1. Initialize the SDK

Initialize with your Stripe publishable key:

var paymentSheet = App.Current.Services.GetRequiredService<IPaymentSheet>();
paymentSheet.Initialize("pk_test_XXXXXXXXXXXXXXXXXXXXXXXX");

2. Present the Payment Sheet

Build your options and open the sheet:

var options = new PaymentSheetOptions
{
    ClientSecret = paymentIntentClientSecret,
    MerchantDisplayName = "My Store, Inc.",

    // Optional :
    Customer = new PaymentSheetCustomerOptions(ephemeralKey, customerId),
    AllowsDelayedPaymentMethods = true,
    BillingDetails = new Options.PaymentSheetBillingDetailsCollectionOptions
    {
        Name = Options.BillingDetailsCollectionMode.Always,
        Phone = Options.BillingDetailsCollectionMode.Always,
        Email = Options.BillingDetailsCollectionMode.Always,
        Address = Options.AddressCollectionMode.Full,
        AttachDefaultsToPaymentMethod = false
    },

#if IOS
    ApplePayConfiguration = new TSPSApplePayConfiguration("your.merchant.id", "us", PassKit.PKPaymentButtonType.Checkout, null, null)
#elif ANDROID
    GooglePay = new Com.Stripe.Android.Paymentsheet.PaymentSheet.GooglePayConfiguration(Com.Stripe.Android.Paymentsheet.PaymentSheet.GooglePayConfiguration.Environment.Test!, "us")
#endif
};

var result = await paymentSheet.Open(options, cancellationToken);

3. Handle the Result

switch (result)
{
    case PaymentSheetResult.Completed:
        // Payment successful
        break;
    case PaymentSheetResult.Canceled:
        // User canceled the sheet
        break;
    case PaymentSheetResult.Failed failure:
        // An error occurred
        break;
}

Important

If it doesn’t fit your needs:

Register Yourself

Register AndroidPaymentSheet and iOSPaymentSheet. Make sure you call
AndroidPaymentSheet.CaptureActivity(..) — Stripe requires an activity that is not yet started.

Or Use Bindings Directly

Reference G1.Stripe.Android.Bindings and G1.Stripe.iOS.Bindings and consume the API from there.

Android

Android provides almost all APIs from Stripe.

iOS

For iOS, we have a very small set of APIs since Stripe doesn’t expose them via Objective-C (-objc). We need to wrap the necessary methods and then expose them to enable interop. I need help to expose more APIs. Details here: stripe/stripe-ios#3377

About

A .NET MAUI library providing Stripe payment integration for cross-platform mobile applications.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •  

Languages