adding CityWallet functionality

This commit is contained in:
Prince
2026-06-11 16:33:22 +02:00
parent b10d233428
commit ad79bf2af8
7 changed files with 301 additions and 84 deletions

View File

@@ -1,3 +1,4 @@
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
@@ -54,19 +55,21 @@ class ConfirmController extends ChangeNotifier {
notifyListeners();
// todo: find out if we still need to update these fields
transactionController
transactionController.model.formData = transactionController
.model
.formData = transactionController.model.formData.copyWith(
type: "REQUEST",
trace: transactionController.model.confirmationData['trace'],
id: transactionController.model.confirmationData['id'],
authType: transactionController.model.selectedPaymentProcessor.authType,
);
.formData
.copyWith(
type: "REQUEST",
trace: transactionController.model.confirmationData['trace'],
id: transactionController.model.confirmationData['id'],
authType:
transactionController.model.selectedPaymentProcessor.authType,
);
dynamic workflowResponse = await http.get(
'/public/transaction/request/'
'${transactionController.model.confirmationData['id']}/'
'${transactionController.model.selectedPaymentProcessor.authType}'
'${transactionController.model.confirmationData['id']}/'
'${transactionController.model.selectedPaymentProcessor.authType}',
);
logger.i(workflowResponse.toString());
@@ -82,7 +85,9 @@ class ConfirmController extends ChangeNotifier {
} else {
model.status = response['status'];
model.errorMessage = response['errorMessage'];
return ApiResponse.failure(response['errorMessage'] ?? "Transaction failed");
return ApiResponse.failure(
response['errorMessage'] ?? "Transaction failed",
);
}
} catch (e) {
logger.e(e);
@@ -125,6 +130,50 @@ class ConfirmController extends ChangeNotifier {
return ApiResponse.failure("Polling cancelled");
}
Future<ApiResponse<Map<String, dynamic>>> updateVelocityTransactionOtp(
String id,
Map<String, dynamic> transaction,
) async {
try {
model.isLoading = true;
notifyListeners();
dynamic response = await http.put(
'/public/transaction/$id/velocity-otp',
transaction,
);
model.isLoading = false;
notifyListeners();
if (response['status'] == 'SUCCESS') {
return ApiResponse.success(Map<String, dynamic>.from(response));
} else {
model.errorMessage =
response['errorMessage'] ??
"Problem updating transaction. Please try again or contact support";
return ApiResponse.failure(model.errorMessage!);
}
} on DioException catch (e, s) {
if (kDebugMode) {
logger.e(e);
logger.e(s);
}
model.isLoading = false;
notifyListeners();
return ApiResponse.failure(
"Network error. Please try again or contact support",
);
} catch (e, s) {
logger.e(s);
model.isLoading = false;
notifyListeners();
return ApiResponse.failure(
"Problem updating that transaction. Please try again or contact support",
);
}
}
@override
void dispose() {
// TODO: implement dispose

View File

@@ -78,6 +78,41 @@ class _ConfirmScreenState extends State<ConfirmScreen>
if (!mounted) return;
// Check if the selected payment processor is a wallet (e.g. Velocity)
if (controller
.transactionController
.model
.selectedPaymentProcessor
.label ==
'WALLET') {
final otp = await _showOtpBottomSheet();
if (otp == null) return; // User cancelled or dismissed the bottom sheet
if (!mounted) return;
final transactionId =
controller.transactionController.model.confirmationData['id'];
final otpResponse = await controller.updateVelocityTransactionOtp(
transactionId,
{'verificationCode': otp},
);
if (!otpResponse.isSuccess) {
if (context.mounted) {
AppSnackBar.showError(
context,
controller.model.errorMessage ??
otpResponse.error ??
"OTP verification failed",
);
}
return;
}
if (!mounted) return;
}
// Proceed with normal flow after OTP step (or skip if not WALLET)
if (controller
.transactionController
.model
@@ -99,6 +134,101 @@ class _ConfirmScreenState extends State<ConfirmScreen>
}
}
Future<String?> _showOtpBottomSheet() {
final otpController = TextEditingController();
final formKey = GlobalKey<FormState>();
return showModalBottomSheet<String>(
context: context,
isDismissible: false,
enableDrag: false,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(20)),
),
builder: (context) {
return Padding(
padding: EdgeInsets.only(
left: 24,
right: 24,
top: 24,
bottom: MediaQuery.of(context).viewInsets.bottom + 24,
),
child: Form(
key: formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Container(
width: 40,
height: 4,
decoration: BoxDecoration(
color: Colors.grey.shade300,
borderRadius: BorderRadius.circular(2),
),
),
),
const SizedBox(height: 20),
Text(
'OTP Verification',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.primary,
),
),
const SizedBox(height: 8),
Text(
'Please enter the OTP sent to your mobile/email',
style: TextStyle(fontSize: 14, color: Colors.grey.shade600),
),
const SizedBox(height: 20),
TextFormField(
controller: otpController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Enter OTP',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
),
),
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'Please enter the OTP';
}
return null;
},
),
const SizedBox(height: 20),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () {
if (formKey.currentState!.validate()) {
Navigator.of(context).pop(otpController.text.trim());
}
},
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: const Text(
'Submit OTP',
style: TextStyle(fontSize: 16),
),
),
),
],
),
),
);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(