Zypay Flutter SDK
A comprehensive Flutter SDK for blockchain payment processing with support for multiple blockchains including TON and BSC.
Features
- π Multi-blockchain support - TON, BSC, and more
- π³ Payment processing - Secure transaction handling
- π¨ Modern UI components - Beautiful, responsive payment interface
- π Security first - Built with security best practices
- π± Mobile responsive - Works seamlessly on all devices
- π Type safety - Full Dart type safety
- β‘ Real-time updates - Live payment status updates via WebSocket
- π― Easy integration - Simple Flutter provider API
Installation
Add this to your package's pubspec.yaml file:
dependencies:
zypay_flutter_sdk: ^1.0.2
Then run:
flutter pub get
Quick Start
1. Wrap your app with ZypayProvider
import 'package:flutter/material.dart';
import 'package:zypay_flutter_sdk/zypay_flutter_sdk.dart';
void main() {
runApp(
ZypayProvider(
config: ZypayConfig(
token: 'your-api-token',
hostUrl: 'https://api.zypay.app',
debug: DebugConfig(
enabled: true,
level: DebugLevel.info,
),
),
child: MyApp(),
),
);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Zypay Demo',
home: HomePage(),
);
}
}
2. Initialize and use the payment widget
import 'package:flutter/material.dart';
import 'package:zypay_flutter_sdk/zypay_flutter_sdk.dart';
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final zypay = ZypayProvider.of(context);
return Scaffold(
appBar: AppBar(title: Text('Zypay Payment')),
body: Center(
child: ElevatedButton(
onPressed: () async {
await zypay.initializePayment(
userId: 'user-123',
onPaymentComplete: () {
print('Payment completed successfully!');
},
onPaymentFailed: (error) {
print('Payment failed: ${error.message}');
},
onPaymentCancelled: () {
print('Payment cancelled');
},
);
},
child: Text('Make Payment'),
),
),
);
}
}
3. Display the payment widget
The payment modal will automatically appear when you call initializePayment. You can also manually show it:
// Access payment state
final paymentState = zypay.state;
// Show payment widget manually
if (paymentState.isOpen) {
return PaymentWidget();
}
Configuration
Basic Configuration
ZypayConfig(
token: 'your-api-token',
hostUrl: 'https://api.zypay.app',
timeout: Duration(seconds: 30),
retryAttempts: 3,
debug: DebugConfig(
enabled: true,
level: DebugLevel.info,
logNetwork: true,
logState: true,
logPerformance: false,
),
)
Debug Configuration
The SDK includes comprehensive debug logging capabilities:
DebugConfig(
enabled: true, // Enable debug logging
level: DebugLevel.debug, // Log level: error, warn, info, debug
timestamps: true, // Include timestamps in logs
includeComponent: true, // Include component names in logs
logNetwork: true, // Log network requests and responses
logState: true, // Log state changes
logPerformance: true, // Log performance metrics
customLogger: (level, message, data) {
// Custom logger function
print('[$level] $message');
},
)
API Reference
ZypayProvider
The main provider for integrating Zypay payments into your Flutter application.
Methods
initializePayment({required String userId, ...})- Initialize payment for a userdisconnect()- Disconnect from the payment servicereconnect()- Reconnect to the payment servicegetHealth()- Check service health status
State
Access the current payment state:
final zypay = ZypayProvider.of(context);
final state = zypay.state;
// Check payment status
if (state.status == PaymentStatus.confirmed) {
print('Payment confirmed!');
}
Payment States
The SDK manages various payment states:
idle- Initial stateloading- Loading payment optionsselecting- User selecting payment optionsprocessing- Payment being processedpending- Payment pending confirmationconfirmed- Payment confirmedexpired- Payment expiredfailed- Payment failedcancelled- Payment cancelled
Error Handling
await zypay.initializePayment(
userId: 'user-123',
onPaymentFailed: (error) {
// Handle payment error
print('Error: ${error.message}');
print('Code: ${error.code}');
print('Retryable: ${error.retryable}');
},
);
Supported Blockchains
- TON - The Open Network
- BSC - Binance Smart Chain
- More blockchains coming soon!
UI Widgets
PaymentWidget
The main payment interface widget that handles the complete payment flow.
PaymentWidget(
onClose: () {
// Handle modal close
},
)
Custom Styling
You can customize the appearance of the payment widgets:
ZypayTheme(
primaryColor: Colors.blue,
accentColor: Colors.blueAccent,
errorColor: Colors.red,
backgroundColor: Colors.white,
textColor: Colors.black,
cardRadius: 12.0,
child: PaymentWidget(),
)
Examples
Check out the example directory for complete working examples:
- Basic payment integration
- Custom styling
- Error handling
- State management
Development
Prerequisites
- Flutter SDK 3.0.0 or higher
- Dart SDK 3.0.0 or higher
Setup
git clone https://github.com/zypay-dev/flutter-sdk.git
cd flutter-sdk
flutter pub get
Run Example
cd example
flutter run
Testing
flutter test
Linting
flutter analyze
Security
The Zypay Flutter SDK is built with security in mind:
- All API communications are encrypted
- Tokens are securely handled
- No sensitive data is stored locally
- Regular security audits and updates
Contributing
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- π§ Email: support@zypay.app
- π¬ Discord: Join our community
- π Documentation: docs.zypay.app
- π Issues: GitHub Issues
Changelog
See CHANGELOG.md for a list of changes and version history.
Made with β€οΈ by the Zypay Team
Libraries
- examples/basic_usage
- Basic usage example for Zypay Flutter SDK
- zypay_flutter_sdk
- Zypay Flutter SDK - A comprehensive Flutter SDK for blockchain payment processing
- zypay_sdk
- Zypay SDK - A comprehensive Flutter SDK for blockchain payment processing