direct_pay_core 0.0.1
direct_pay_core: ^0.0.1 copied to clipboard
Core payment engine for Direct Pay (S2S) — server-to-server payment SDK for Flutter with SHA-512 hashing, 3D Secure WebView, and structured logging.
example/lib/main.dart
/// Example demonstrating how to use `direct_pay_core` via a branded wrapper.
///
/// In production, merchants use a branded package (e.g., `rd_direct_pay`)
/// which internally depends on `direct_pay_core`. This example shows the
/// core API directly for reference.
library;
import 'package:flutter/material.dart';
import 'package:direct_pay_core/direct_pay_core.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
DirectPayConfig.init(
appId: '<YOUR_APP_ID>',
merchantKey: '<YOUR_MERCHANT_KEY>',
baseUrl: 'https://gateway.example.com',
);
runApp(const CoreExample());
}
class CoreExample extends StatelessWidget {
const CoreExample({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Direct Pay Core Example',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo),
useMaterial3: true,
),
home: const PaymentPage(),
);
}
}
class PaymentPage extends StatefulWidget {
const PaymentPage({super.key});
@override
State<PaymentPage> createState() => _PaymentPageState();
}
class _PaymentPageState extends State<PaymentPage> {
bool _processing = false;
DirectPayResponse? _result;
Future<void> _pay() async {
setState(() => _processing = true);
final request = DirectPayRequest(
orderId: 'ORD_${DateTime.now().millisecondsSinceEpoch}',
amount: '1000',
custName: 'John Doe',
custFirstName: 'John',
custLastName: 'Doe',
custAddress: '123 Main Street',
custCity: 'Dubai',
custState: 'Dubai',
custCountry: 'AE',
custZip: '99999',
custPhone: '9876543210',
custEmail: 'john@example.com',
productDesc: 'Test Payment',
cardNumber: '4111111111111111',
cardExpDt: '122028',
cvv: '123',
);
final response = await DirectPayService.processPayment(context, request);
if (!mounted) return;
setState(() {
_processing = false;
_result = response;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Core Example')),
body: Center(
child: _processing
? const CircularProgressIndicator()
: Column(
mainAxisSize: MainAxisSize.min,
children: [
FilledButton.icon(
onPressed: _pay,
icon: const Icon(Icons.payment),
label: const Text('Pay 10.00'),
),
if (_result != null) ...[
const SizedBox(height: 16),
Text(
_result!.isSuccess ? 'Success' : 'Failed',
style: Theme.of(context).textTheme.titleLarge,
),
Text('Code: ${_result!.responseCode}'),
Text('Message: ${_result!.responseMessage}'),
],
],
),
),
);
}
}