This commit is contained in:
Hamza Aleghwairyeen
2024-04-18 00:53:16 +03:00
parent d450ad0f93
commit 1f333852ac
11 changed files with 493 additions and 255 deletions

View File

@@ -39,15 +39,67 @@ class PaymobManager extends GetxController {
}
Future<void> payWithPayMob(int amount, String currency) async {
String key = await PaymobManager().getPaymentKey(amount, currency);
await launchUrl(
Uri.parse(
'https://accept.paymob.com/api/acceptance/iframes/837992?payment_token=$key'),
);
// 1. Fetch Payment Key (Assuming PaymobManager is a custom class)
String paymentToken;
try {
paymentToken = await PaymobManager().getPaymentKey(amount, currency);
} on Exception catch (e) {
// Handle errors gracefully, e.g., display error message to user
print("Error fetching payment key: $e");
return;
}
// String paymentStatus = await _getStatusAfterPaid();
// 2. Prepare Payment Data Payload
final Map<String, dynamic> data = {
"source": {
"identifier": "01010101010", // Replace with actual source identifier
"subtype": "WALLET",
},
"payment_token": paymentToken,
};
// 3. Make Payment Request using Dio
final dio = Dio();
try {
final response = await dio.post(
'https://accept.paymob.com/api/acceptance/payments/pay',
data: data,
);
// 4. Handle Payment Response
if (response.statusCode == 200) {
// Payment successful: Process response data (e.g., transaction ID)
final paymentData = response.data; // Assuming JSON response
print("Payment successful: $paymentData");
// Navigate to success screen or display success message
} else {
// Payment failed: Handle errors (e.g., display error message)
print("Payment failed: ${response.statusCode} - ${response.data}");
}
} on DioError catch (e) {
// Handle network or Dio-related errors
print("Error making payment request: $e");
}
}
// Future<void> payWithPayMob(int amount, String currency) async {
// String key = await PaymobManager().getPaymentKey(amount, currency);
// await launchUrl(Uri.parse(
// // 'https://accept.paymob.com/api/acceptance/iframes/837992?payment_token=$key'),
// 'https://accept.paymob.com/api/acceptance/payments/pay'));
// print(key);
// final dio.Response response = await Dio()
// .post('https://accept.paymob.com/api/acceptance/payments/pay', data: {
// "source": {
// "identifier": "01010101010",
// "subtype": "WALLET",
// },
// "payment_token": key, // token obtained in step 3
// });
//
// // String paymentStatus = await _getStatusAfterPaid();
// }
Future<String> _getStatusAfterPaid() async {
print(authanticationToken1);
print(orderId1);