mobibox_pay 1.2.3
mobibox_pay: ^1.2.3 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';
// ignore: unused_import
import 'package:mobibox_pay/mobi_pay_apple_pay_config.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: 'xxxxx-xxxxxx-xxxxxx',
merchantKey: 'xxxxx-xxxxxx-xxxxxx',
password: 'xxxxx-xxxxxx-xxxxxx',
// Optional: shows a native Apple Pay button above the card fields
// (iOS only). Requires an Apple Pay Merchant Identifier + certs set
// up in Apple Developer + the Mobibox admin "Wallets" tab, the
// com.apple.developer.in-app-payments entitlement enabled in Xcode,
// and your S2S CARD SALE endpoint (POST /post) from your Mobibox
// account manager. Leave this out entirely to keep card-only checkout.
// applePayConfig: const MobiPayApplePayConfig(
// merchantIdentifier: 'merchant.com.yourcompany.app',
// paymentApiUrl: 'https://test.apiurl.com/post',
// merchantDisplayName: 'Your Company',
// countryCode: 'US',
// ),
);
}
void _startPayment() {
setState(() => _isLoading = false);
_mobiPay.startPayment(
context: context,
orderNumber: 'order-${DateTime.now().millisecondsSinceEpoch}',
orderAmount: '1.00',
orderCurrency: 'USD',
orderDescription: 'Test Purchase',
cardholderName: 'JOHN DOE',
email: 'test@example.com',
// Optional: Recurring payment parameters
// recurringInit: true,
// scheduleId: 'xxxxx-xxxx-xxxx-xxx',
// reqToken: true,
// cardToken: ['token_abc', 'token_def'],
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'),
),
],
),
),
);
}
}