YardPay Pro Flutter SDK
Flutter plugin for accepting payments on iOS and Android with native performance.
Installation
Add the dependency to your pubspec.yaml:
dependencies:
quickpay_flutter: ^1.0.0Then run:
flutter pub getConfiguration
Initialize the SDK before using any payment features, typically in your main() function.
import 'package:quickpay_flutter/quickpay_flutter.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await QuickPay.configure(
publishableKey: 'pk_live_your_publishable_key',
);
runApp(const MyApp());
}Hosted Checkout (presentCheckout)
The quickest integration path. Presents YardPay's hosted checkout in an in-app browser.
import 'package:quickpay_flutter/quickpay_flutter.dart';
class CheckoutScreen extends StatelessWidget {
final String clientSecret;
const CheckoutScreen({super.key, required this.clientSecret});
Future<void> _handleCheckout(BuildContext context) async {
final result = await QuickPay.presentCheckout(
clientSecret: clientSecret,
returnUrl: 'myapp://payment-complete',
);
switch (result) {
case CheckoutResult.completed:
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Payment successful!')),
);
break;
case CheckoutResult.cancelled:
// User dismissed
break;
case CheckoutResult.failed:
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Payment failed: ${result.error}')),
);
break;
}
}
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: () => _handleCheckout(context),
child: const Text('Checkout'),
);
}
}QPCardField Widget
A native card input widget that renders platform-specific UI for collecting card details.
import 'package:quickpay_flutter/quickpay_flutter.dart';
class CardFormScreen extends StatefulWidget {
final String clientSecret;
const CardFormScreen({super.key, required this.clientSecret});
@override
State<CardFormScreen> createState() => _CardFormScreenState();
}
class _CardFormScreenState extends State<CardFormScreen> {
final _cardFieldController = QPCardFieldController();
bool _isComplete = false;
bool _isProcessing = false;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
QPCardField(
controller: _cardFieldController,
style: QPCardFieldStyle(
textColor: Colors.black87,
placeholderColor: Colors.grey,
borderColor: Colors.grey.shade300,
borderWidth: 1,
borderRadius: 8,
fontSize: 16,
),
onCardChanged: (details) {
setState(() => _isComplete = details.isComplete);
},
),
const SizedBox(height: 16),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: _isComplete && !_isProcessing ? _handlePay : null,
child: Text(_isProcessing ? 'Processing...' : 'Pay'),
),
),
],
),
);
}
Future<void> _handlePay() async {
setState(() => _isProcessing = true);
// See confirmPayment() below
}
}QPClickToPayButton Widget
A widget that renders the Click to Pay button and handles SRC enrollment and authentication.
import 'package:quickpay_flutter/quickpay_flutter.dart';
class PaymentOptions extends StatelessWidget {
final String clientSecret;
const PaymentOptions({super.key, required this.clientSecret});
@override
Widget build(BuildContext context) {
return Column(
children: [
QPClickToPayButton(
clientSecret: clientSecret,
height: 48,
onSuccess: (result) {
// result.token — tokenized card
// result.cardBrand — 'visa' | 'mastercard'
// result.lastFour — '1234'
debugPrint('Tokenized: ${result.token.id}');
},
onError: (error) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error: ${error.message}')),
);
},
),
],
);
}
}confirmPayment()
Submit the payment using collected card details. Handles 3DS challenges automatically.
import 'package:quickpay_flutter/quickpay_flutter.dart';
Future<void> confirmPayment({
required String clientSecret,
required QPCardFieldController cardController,
}) async {
final result = await QuickPay.confirmPayment(
clientSecret: clientSecret,
cardDetails: cardController.cardDetails,
billingDetails: const BillingDetails(
name: 'Jane Doe',
email: '[email protected]',
),
returnUrl: 'myapp://payment-complete',
);
switch (result.status) {
case PaymentStatus.succeeded:
debugPrint('Payment successful: ${result.paymentId}');
break;
case PaymentStatus.requiresAction:
// 3DS handled automatically via in-app browser
debugPrint('Awaiting 3DS authentication...');
break;
case PaymentStatus.processing:
debugPrint('Payment is processing');
break;
case PaymentStatus.failed:
debugPrint('Payment failed: ${result.error?.message}');
break;
}
}Platform requirements
- Flutter 3.10+
- Dart 3.0+
- iOS 15.0+
- Android API 24+
Android setup
Ensure your android/app/build.gradle has minSdkVersion 24 or higher, and that kotlin_version is 1.8.0 or higher in your project-level build file.