mobibox_pay 1.0.6
mobibox_pay: ^1.0.6 copied to clipboard
A Flutter plugin to seamlessly integrate with the Mobibox payment gateway
example/lib/main.dart
import 'package:mobibox_pay/mobi_pay.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MaterialApp(
home: MyApp(),
));
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final MobiPay _mobiPay = MobiPay();
bool _isLoading = false;
@override
void initState() {
super.initState();
_mobiPay.initialize(
checkoutHost: 'xxxxxxxx',
merchantKey: 'xxxxx',
password: 'xxxxxxx',
);
}
void _startPayment() {
setState(() => _isLoading = false);
debugPrint('[Example] Starting payment');
_mobiPay.startPayment(
context: context,
orderNumber: 'order-${DateTime.now().millisecondsSinceEpoch}',
orderAmount: '1.00',
orderCurrency: 'USD',
orderDescription: 'Test Purchase',
cardholderName: 'JOHN DOE',
email: 'test@example.com',
onSubmitResult: (data) {
debugPrint('[Example] ✅ Payment submitted: $data');
},
onTransactionInitiated: (result) {
debugPrint('[Example] 🚀 Transaction initiated:');
debugPrint(' Status: ${result.status}');
debugPrint(' Payment ID: ${result.paymentId}');
debugPrint(' Transaction ID: ${result.transactionId}');
debugPrint(' Order ID: ${result.orderId}');
debugPrint(' Public ID: ${result.publicId}');
},
onTransactionComplete: (result) {
debugPrint('[Example] 💳 Transaction completed:');
debugPrint(' Status: ${result.status}');
debugPrint(' Payment ID: ${result.paymentId}');
debugPrint(' Transaction ID: ${result.transactionId}');
debugPrint(' Order ID: ${result.orderId}');
debugPrint(' Public ID: ${result.publicId}');
debugPrint(' Is Success: ${result.isSuccess}');
debugPrint(' Full result: ${result.toJson()}');
},
onTransactionFailed: (result) {
debugPrint('[Example] ❌ Transaction failed:');
debugPrint(' Status: ${result.status}');
debugPrint(' Payment ID: ${result.paymentId}');
debugPrint(' Transaction ID: ${result.transactionId}');
debugPrint(' Order ID: ${result.orderId}');
debugPrint(' Decline Message: ${result.declineMessage}');
debugPrint(' Full result: ${result.toJson()}');
},
onSuccessRedirect: (url) {
debugPrint('[Example] ✅ Success redirect: $url');
},
onErrorRedirect: (url) {
debugPrint('[Example] 🔥 Error redirect: $url');
},
onError: (e) {
debugPrint('[Example] 🐞 Exception: ${e.toString()}');
},
onPaywallClosed: () {
debugPrint('[Example] 🚪 Paywall closed by user');
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Mobibox Pay SDK'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'Mobibox Pay Sample',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: _isLoading ? null : _startPayment,
child: _isLoading
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Text('Start Payments'),
),
],
),
),
);
}
}