https://github.com/aliumairdev/flutter_pay_kit
A unified API for integrating multiple payment processors in Flutter apps.
https://github.com/aliumairdev/flutter_pay_kit
braintree flutter paddle paymetgateway stripe-payments
Last synced: 3 months ago
JSON representation
A unified API for integrating multiple payment processors in Flutter apps.
- Host: GitHub
- URL: https://github.com/aliumairdev/flutter_pay_kit
- Owner: aliumairdev
- License: mit
- Created: 2025-11-13T18:21:12.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-11-13T21:13:41.000Z (9 months ago)
- Last Synced: 2025-11-13T21:21:26.781Z (9 months ago)
- Topics: braintree, flutter, paddle, paymetgateway, stripe-payments
- Language: Dart
- Homepage:
- Size: 88.9 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Flutter Universal Payments
[](https://pub.dev/packages/flutter_universal_payments)
[](https://opensource.org/licenses/MIT)
A unified, production-ready payment API for Flutter that supports multiple payment processors with a single, consistent interface. Switch between payment providers without rewriting your code.
## β¨ Features
- π **Unified API** - One consistent interface for all payment processors
- π³ **6 Payment Processors** - Stripe, Paddle, Braintree, Lemon Squeezy, Totalpay, and Fake (for testing)
- π **Hot-Swappable** - Switch processors at runtime without code changes
- π± **Ready-to-Use Widgets** - Pre-built payment UI components
- π¨ **Highly Customizable** - Customize every aspect to match your brand
- π **Secure by Design** - PCI-compliant patterns, no card data storage
- π§ͺ **Testing Support** - Built-in fake processor for development
- π **Analytics Ready** - Firebase, Sentry, and custom analytics integrations
- π **Smart Caching** - Automatic data caching with secure storage
- π **Production Ready** - Comprehensive error handling and retry logic
- π― **Type Safe** - Full Dart type safety with Freezed models
- β‘ **State Management** - Built-in Riverpod integration
## π¦ Supported Payment Processors
| Processor | Subscriptions | One-time Payments | Plan Swapping | Webhooks | Testing |
|-----------|:-------------:|:-----------------:|:-------------:|:--------:|:-------:|
| **Stripe** | β
| β
| β
| β
| Sandbox |
| **Paddle** | β
| β
| β
| β
| Sandbox |
| **Braintree** | β
| β
| β
| β
| Sandbox |
| **Lemon Squeezy** | β
| β
| β
| β
| Test Mode |
| **Totalpay** | β
| β
| β
| β
| Sandbox |
| **Fake** | β
| β
| β
| β | Built-in |
## π Quick Start
- Unified API across all payment processors
- **Native Google Pay integration for Android**
- **Native Apple Pay integration for iOS** (iOS 13.0+)
- Type-safe payment models using Freezed
- State management with Riverpod
- Comprehensive error handling
- Easy switching between processors
- Built-in retry logic
- Local payment method storage
- Support for one-time and recurring payments
- Production-ready architecture
### Installation
Add to your `pubspec.yaml`:
```yaml
dependencies:
flutter_universal_payments: ^0.1.0
```
Then run:
```bash
flutter pub get
```
### Basic Usage
### Apple Pay Integration (iOS)
```dart
import 'package:flutter_universal_payments/flutter_universal_payments.dart';
// 1. Configure your payment processor
final config = PaymentConfigurationBuilder()
.useStripe(
publishableKey: 'pk_test_...',
secretKey: 'sk_test_...',
webhookSecret: 'whsec_...',
)
.enableLogging()
.build();
// 2. Initialize the payment service
await FlutterUniversalPayments.initialize(
config: config,
storage: storage, // Your Storage implementation
);
// 3. Get the service instance
final paymentService = FlutterUniversalPayments.instance;
// 4. Initialize customer
await paymentService.initialize(
email: 'customer@example.com',
name: 'John Doe',
);
// 5. Create a subscription
final subscription = await paymentService.subscribe(
priceId: 'price_monthly_999',
trialDays: 14,
);
print('Subscription created: ${subscription.id}');
```
### UI Widgets
The package includes ready-to-use payment widgets:
```dart
// Display pricing plans
PricingTable(
plans: [
SubscriptionPlanData(
id: 'basic',
name: 'Basic',
price: Price(
id: 'price_basic',
amount: 999,
currency: 'USD',
interval: BillingInterval.month,
),
features: ['Feature 1', 'Feature 2'],
),
],
onPlanSelected: (plan) async {
await paymentService.subscribe(priceId: plan.price.id);
},
)
// Payment card input
PaymentCardInput(
onCardChanged: (cardData) {
// Handle card data
},
)
// Subscription status display
SubscriptionStatusWidget(
subscription: subscription,
)
```
## π Documentation
- **[Getting Started Guide](doc/getting_started.md)** - Detailed setup for each processor
- **[Widgets Documentation](doc/widgets.md)** - UI components and customization
- **[Advanced Usage](doc/advanced.md)** - Webhooks, custom processors, best practices
- **[API Reference](https://pub.dev/documentation/flutter_universal_payments/latest/)** - Complete API docs
### Processor-Specific Guides
- [Stripe Integration](doc/processors/stripe.md)
- [Paddle Integration](doc/processors/paddle.md)
- [Braintree Integration](doc/processors/braintree.md)
- [Lemon Squeezy Integration](doc/processors/lemon_squeezy.md)
- [Totalpay Integration](doc/processors/totalpay.md)
## π― Core Concepts
### Customer Management
```dart
// Initialize a customer
await paymentService.initialize(
email: 'customer@example.com',
name: 'John Doe',
phone: '+1234567890',
);
// Get current customer
final customer = await paymentService.getCurrentCustomer();
// Refresh customer data
await paymentService.refreshCustomer();
```
### Subscriptions
```dart
// Create subscription with trial
final subscription = await paymentService.subscribe(
priceId: 'price_monthly',
trialDays: 14,
);
// Check subscription status
final hasActive = await paymentService.hasActiveSubscription('product_id');
final isOnTrial = await paymentService.isOnTrial('product_id');
// Change subscription plan
await paymentService.changePlan(
subscriptionId: subscription.id,
newPriceId: 'price_annual',
);
// Cancel subscription
await paymentService.cancelSubscription(
id: subscription.id,
immediate: false, // Grace period until end of billing cycle
);
// Resume canceled subscription
await paymentService.resumeSubscription(id: subscription.id);
```
### Payment Methods
```dart
// Add payment method
await paymentService.setDefaultPaymentMethod(paymentMethodToken);
// Get all payment methods
final methods = await paymentService.getPaymentMethods();
// Remove payment method
await paymentService.removePaymentMethod(methodId);
```
### One-Time Payments
```dart
// Create a one-time charge
final charge = await paymentService.makePayment(
amount: 2999, // $29.99
currency: 'USD',
description: 'Premium upgrade',
paymentMethodToken: token,
// Configure Google Pay
final googlePayConfig = GooglePayConfig(
merchantId: 'your-merchant-id',
merchantName: 'Your Store',
environment: GooglePayEnvironment.production,
);
```
## π Switching Processors
One of the most powerful features is the ability to switch payment processors without changing your code:
```dart
// Start with Stripe
final stripeConfig = PaymentConfigurationBuilder()
.useStripe(publishableKey: '...', secretKey: '...')
.build();
await FlutterUniversalPayments.initialize(config: stripeConfig);
// Later, switch to Paddle
final paddleConfig = PaymentConfigurationBuilder()
.usePaddle(
vendorId: '...',
authCode: '...',
publicKey: '...',
)
.build();
await FlutterUniversalPayments.reinitialize(config: paddleConfig);
// Your app code remains the same!
```
## π¨ Customization
All widgets are highly customizable:
```dart
PricingTable(
plans: plans,
layout: PricingLayout.grid(crossAxisCount: 3),
cardDecoration: BoxDecoration(
gradient: LinearGradient(
colors: [Colors.blue, Colors.purple],
),
borderRadius: BorderRadius.circular(20),
),
selectedPlanColor: Colors.green,
onPlanSelected: (plan) => handlePlanSelection(plan),
headerBuilder: (context) => CustomHeader(),
)
```
## π Analytics & Logging
Built-in support for analytics and logging:
```dart
// Enable logging
PaymentLogger.enable();
PaymentLogger.setLogLevel(LogLevel.debug);
// Add analytics providers
PaymentLogger.registerAnalyticsProvider(
FirebaseAnalyticsProvider(analytics),
);
// Automatic event logging
// - Payment success/failure
// - Subscription created/canceled
// - Plan changes
// - Checkout events
```
## π§ͺ Testing
Use the built-in fake processor for testing:
```dart
final testConfig = PaymentConfigurationBuilder()
.useFake(
simulateDelays: true,
delayDuration: Duration(seconds: 1),
failureRate: 0.1, // 10% failure rate
)
.build();
await FlutterUniversalPayments.initialize(config: testConfig);
```
## ποΈ Architecture
The package follows clean architecture principles:
```
lib/
βββ src/
β βββ models/ # Data models (Customer, Subscription, Charge, etc.)
β βββ processors/ # Payment processor implementations
β βββ services/ # Business logic (PaymentService)
β βββ widgets/ # UI components
β βββ utils/ # Logging, analytics
β βββ exceptions/ # Custom exceptions
βββ flutter_universal_payments.dart # Public API
```
## π Security Best Practices
- Never store sensitive card data locally
- Use tokenization for payment methods
- Implement webhook signature verification
- Enable logging with sensitive data masking
- Use secure storage for customer IDs and tokens
- Always use HTTPS endpoints
- Validate all user inputs
See [Advanced Usage](doc/advanced.md#security-best-practices) for detailed security guidelines.
## π€ Contributing
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
### Development Setup
```bash
# Clone the repository
git clone https://github.com/aliumairdev/flutter_pay_kit.git
cd flutter_pay_kit
# Install dependencies
flutter pub get
# Run code generation
flutter pub run build_runner build
# Run tests
flutter test
# Run example app
cd example
flutter run
```
## π License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## π Support
// Check availability
final isAvailable = await googlePayConfig.isAvailable();
if (isAvailable) {
// Request payment
final token = await googlePayConfig.requestPayment(amount: 2500);
if (token != null) {
// Process the token with your payment processor
print('Payment token: $token');
}
}
```
For detailed Google Pay integration instructions, see [GOOGLE_PAY_INTEGRATION.md](GOOGLE_PAY_INTEGRATION.md).
// Check if Apple Pay is available
final isAvailable = await ApplePayHandler.isAvailable();
if (isAvailable) {
// Request payment
final result = await ApplePayHandler.requestPayment(
amount: 1999, // $19.99 in cents
currency: 'USD',
merchantId: 'merchant.com.yourcompany.yourapp',
countryCode: 'US',
label: 'Premium Subscription',
);
// Process the payment token with your backend
final paymentData = result['paymentData'];
// Send to your payment processor
}
```
For complete Apple Pay setup instructions, see [APPLE_PAY_SETUP.md](APPLE_PAY_SETUP.md).
## Architecture
- **Documentation**: [doc/getting_started.md](doc/getting_started.md)
- **Issues**: [GitHub Issues](https://github.com/aliumairdev/flutter_pay_kit/issues)
- **Discussions**: [GitHub Discussions](https://github.com/aliumairdev/flutter_pay_kit/discussions)
## πΊοΈ Roadmap
- [ ] Apple Pay support
- [ ] Google Pay support
- [ ] PayPal direct integration
- [ ] Cryptocurrency payments
- [ ] Invoice generation
- [ ] Receipt management
- [ ] Multi-currency support
- [ ] Tax calculation integration
- [ ] Fraud detection hooks
## π¦ Requirements
- **Dart SDK**: `>=3.0.0 <4.0.0`
- **Flutter SDK**: `>=3.10.0`
## π Examples
Check out the [example](example/) directory for a complete Flutter app demonstrating all features:
- Customer initialization
- Subscription management
- Payment method handling
- One-time payments
- UI widgets showcase
- Analytics integration
## π Additional Resources
- [Flutter Documentation](https://flutter.dev/docs)
- [Dart Documentation](https://dart.dev/guides)
- [Riverpod Documentation](https://riverpod.dev)
- [Stripe API Documentation](https://stripe.com/docs/api)
- [Paddle API Documentation](https://developer.paddle.com/)
- [Braintree API Documentation](https://developer.paypal.com/braintree/docs)
---
Made with β€οΈ by the Flutter community