Think adding payments in MAUI is a pain? Think again. A frictionless in-app payment experience isn’t just a nice-to-have — it’s a critical part of modern mobile development. Whether you’re selling subscriptions, physical goods, or digital services, a clunky checkout process can kill conversions instantly. This guide shows you how to integrate secure and smooth payment flows using .NET MAUI, making sure your users pay with confidence and speed.
Why Payment Integration Matters
Mobile commerce is exploding. In-app purchases, subscriptions, and direct product sales are integral to monetizing modern apps. A smooth, secure payment experience:
- Boosts user trust and retention.
- Reduces cart abandonment.
- Enhances the professionalism of your app.
Whether you’re building a subscription-based fitness tracker, an eCommerce storefront, an education platform, or a donation gateway, integrated payments are essential.
Types of Payment Gateways
Not all gateways are created equal. Here’s a quick overview:
- Stripe: Modern APIs, robust documentation, supports subscriptions and one-time payments. Great for custom checkout flows. In this article, we focus primarily on integrating Stripe with .NET MAUI.
- PayPal: Widely recognized, trusted by users, but more rigid in UI customization.
- Square: Strong in POS systems, supports eCommerce, works well with small to medium businesses.
All three offer RESTful APIs and are usable in .NET MAUI with HTTP clients or available SDK wrappers.
Stripe Integration in .NET MAUI
Let’s walk through the integration with a simplified Stripe REST API example.
Installing and Configuring the Payment SDK
Install necessary NuGet packages:
Install-Package Stripe.net
Add config to your MauiProgram.cs
:
builder.Services.Configure<StripeSettings>(builder.Configuration.GetSection("Stripe"));
Create a config class:
public class StripeSettings
{
public string SecretKey { get; set; }
public string PublishableKey { get; set; }
}
Creating the Payment UI
Using MAUI’s layout system:
<VerticalStackLayout>
<Entry x:Name="CardNumberEntry" Placeholder="Card Number" />
<Entry x:Name="ExpEntry" Placeholder="MM/YY" />
<Entry x:Name="CVCEntry" Placeholder="CVC" />
<Button Text="Pay Now" Clicked="OnPayClicked" />
</VerticalStackLayout>
Handling Transactions and Security
In your code-behind:
private async void OnPayClicked(object sender, EventArgs e)
{
var paymentIntent = await CreatePaymentIntent();
if (paymentIntent != null)
{
// Confirm and handle payment
}
}
private async Task<string> CreatePaymentIntent()
{
StripeConfiguration.ApiKey = "YOUR_SECRET_KEY";
var options = new PaymentIntentCreateOptions
{
Amount = 1099, // in cents
Currency = "usd",
PaymentMethodTypes = new List<string>
{
"card",
},
};
var service = new PaymentIntentService();
var paymentIntent = await service.CreateAsync(options);
return paymentIntent.Id;
}
Always use tokenization. Never store card details.
PayPal Integration in .NET MAUI
To use PayPal REST API:
- Register and create a PayPal app to obtain client ID and secret.
- Use basic authentication for server calls.
- Create order and capture payment.
Example call to create an order:
var client = new HttpClient();
var byteArray = Encoding.ASCII.GetBytes("CLIENT_ID:SECRET");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
var content = new StringContent(JsonConvert.SerializeObject(new {
intent = "CAPTURE",
purchase_units = new[] {
new {
amount = new {
currency_code = "USD",
value = "10.00"
}
}
}
}), Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api-m.sandbox.paypal.com/v2/checkout/orders", content);
Use a WebView for PayPal approval URL redirection or implement native SDKs if needed.
Square Integration in .NET MAUI
- Register a Square developer account and obtain an access token.
- Use Square’s API to create payments or invoices.
Example to create a payment:
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "YOUR_ACCESS_TOKEN");
var body = new
{
source_id = "cnon:card-nonce-ok",
idempotency_key = Guid.NewGuid().ToString(),
amount_money = new { amount = 1000, currency = "USD" }
};
var content = new StringContent(JsonConvert.SerializeObject(body), Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://connect.squareup.com/v2/payments", content);
Note: Square provides mobile SDKs for Android and iOS if native components are preferred.
Testing and Debugging Your Integration
Using Sandbox Environments
- Stripe: Use test keys and predefined card numbers like
4242 4242 4242 4242
. - PayPal: Create sandbox merchant and buyer accounts.
- Square: Use sandbox environment and generated card tokens.
Test edge cases: declined cards, expired dates, incorrect CVVs.
Common Issues and How to Fix Them
- Issue: SDK not working on Android.
- Fix: Check
AndroidManifest.xml
permissions and Proguard rules.
- Fix: Check
- Issue: Payments stuck on loading.
- Fix: Ensure async calls aren’t blocking UI thread.
- Issue: Mismatched keys.
- Fix: Double-check secret/public keys per environment.
Going Live and Best Practices
Switching to Production Mode
- Replace test keys with live ones.
- Ensure webhook URLs are publicly accessible.
- Enable logging for production diagnostics.
Compliance and Security Standards
- Use HTTPS for all communications.
- Stay PCI-DSS compliant.
- Encrypt all sensitive data.
Monitoring and Analytics
Use:
- Stripe Dashboard, PayPal Insights, or Square Dashboard for analytics.
- Integrate Application Insights or Firebase Analytics to monitor user behavior.
FAQ: Your Questions About Payments in .NET MAUI Answered
Yes, especially when using REST APIs or cross-platform SDKs. Platform-specific code is only needed for native SDKs.
If you use tokenization, HTTPS, and avoid storing sensitive data locally — yes.
Yes, for most payment flows, especially to store tokens securely and handle webhooks.
Conclusion: Payment Integration in .NET MAUI is Powerful — If Done Right
Implementing a payment system isn’t just a technical task; it’s a trust exercise. By choosing the right gateway, securing your flow, and following best practices, your .NET MAUI app can handle payments like a pro.
Start small. Test everything. And always secure your users’ trust.
What payment gateway have you integrated with .NET MAUI, and what challenges did you face? Share your experiences in the comments below.