166 lines
5.5 KiB
Dart
166 lines
5.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:qpay/screens/gateway/gateway_controller.dart';
|
|
import 'package:qpay/screens/transaction_controller.dart';
|
|
import 'package:skeletonizer/skeletonizer.dart';
|
|
|
|
import 'integration_controller.dart';
|
|
|
|
class IntegrationScreen extends StatefulWidget {
|
|
const IntegrationScreen({super.key});
|
|
|
|
@override
|
|
State<IntegrationScreen> createState() => _IntegrationScreenState();
|
|
}
|
|
|
|
class _IntegrationScreenState extends State<IntegrationScreen> {
|
|
late IntegrationController controller;
|
|
late TransactionController transactionController;
|
|
late GatewayController gatewayController;
|
|
|
|
bool integrating = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
controller = IntegrationController(context);
|
|
gatewayController = GatewayController(context);
|
|
transactionController = Provider.of<TransactionController>(
|
|
context,
|
|
listen: false,
|
|
);
|
|
|
|
}
|
|
|
|
@override
|
|
void didChangeDependencies() async {
|
|
super.didChangeDependencies();
|
|
|
|
if(integrating) return;
|
|
|
|
String status = Provider.of<TransactionController>(context).model.paymentStatus;
|
|
if(status == 'SUCCESS') {
|
|
setState(() {
|
|
integrating = true;
|
|
});
|
|
await controller.doIntegration();
|
|
}
|
|
}
|
|
|
|
void _showErrorSnackBar(String? message) {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(message.toString()),
|
|
behavior: SnackBarBehavior.floating,
|
|
backgroundColor: Colors.deepOrange,
|
|
),
|
|
);
|
|
});
|
|
}
|
|
|
|
|
|
@override
|
|
void dispose() {
|
|
controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Completing your transaction'),
|
|
),
|
|
body: ListenableBuilder(
|
|
listenable: gatewayController,
|
|
builder: (context, child) {
|
|
return ListenableBuilder(
|
|
listenable: controller,
|
|
builder: (context, child) {
|
|
if (controller.model.status == 'SUCCESS') {
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
context.go('/receipt');
|
|
});
|
|
}
|
|
|
|
return Container(
|
|
padding: EdgeInsets.all(50),
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
SizedBox(height: 75),
|
|
|
|
if(transactionController.model.paymentStatus != 'SUCCESS')
|
|
Column(
|
|
children: [
|
|
Text(
|
|
'We failed to check your payment status',
|
|
style: TextStyle(fontSize: 20),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
SizedBox(height: 50,),
|
|
Skeletonizer(
|
|
enabled: gatewayController.model.isLoading,
|
|
child: OutlinedButton(
|
|
child: Text('Check latest status'),
|
|
onPressed: () {
|
|
gatewayController.poll(transactionController.model.receiptData?['id']);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
|
|
if(transactionController.model.paymentStatus == 'SUCCESS')
|
|
Column(
|
|
children: [
|
|
Text(
|
|
'We\'ve successfully collected your funds. We are now '
|
|
'updating your billing account. This won\'t take long',
|
|
style: TextStyle(fontSize: 20),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
Image.asset('assets/peak-animation.gif', width: 150),
|
|
SizedBox(
|
|
width: 50,
|
|
child: LinearProgressIndicator(),
|
|
),
|
|
SizedBox(height: 50),
|
|
if(controller.model.status == 'FAILED')
|
|
Column(
|
|
children: [
|
|
Text(
|
|
'We failed to update your billing account',
|
|
style: TextStyle(fontSize: 20),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
SizedBox(height: 20,),
|
|
Skeletonizer(
|
|
enabled: controller.model.isLoading,
|
|
child: OutlinedButton(
|
|
child: Text('Retry'),
|
|
onPressed: () {
|
|
controller.doIntegration();
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
),
|
|
);
|
|
}
|
|
}
|