This commit is contained in:
Hamza Aleghwairyeen
2024-04-16 10:22:01 +03:00
parent a2d4cd845c
commit 24b3804045
18 changed files with 457 additions and 226 deletions

View File

@@ -190,6 +190,33 @@ class CRUD {
}
}
Future<dynamic> postPayMob({
required String link,
Map<String, dynamic>? payload,
}) async {
// String? basicAuthCredentials =
// await storage.read(key: BoxName.basicAuthCredentials);
var url = Uri.parse(
link,
);
var response = await http.post(url,
body: payload, headers: {'Content-Type': 'application/json'});
print(response.request);
print(payload);
var jsonData = jsonDecode(response.body);
// print(jsonData);
if (response.statusCode == 200) {
if (jsonData['status'] == 'success') {
return response.body;
} else {
return (jsonData['status']);
}
} else {
return response.statusCode;
}
}
sendEmail(
String link,
Map<String, String>? payload,

View File

@@ -248,19 +248,22 @@ class HomeCaptainController extends GetxController {
}
getKazanPercent() async {
var res = await CRUD().get(link: AppLink.getKazanPercent);
var res = await CRUD().get(
link: AppLink.getKazanPercent,
payload: {'country': box.read(BoxName.countryCode).toString()},
);
if (res != 'failure') {
kazan = double.parse(jsonDecode(res)['message'][0]['kazan']);
naturePrice = double.parse(jsonDecode(res)['message'][0]['naturePrice']);
heavyPrice = double.parse(jsonDecode(res)['message'][0]['heavyPrice']);
latePrice = double.parse(jsonDecode(res)['message'][0]['latePrice']);
comfortPrice =
double.parse(jsonDecode(res)['message'][0]['comfortPrice']);
speedPrice = double.parse(jsonDecode(res)['message'][0]['speedPrice']);
deliveryPrice =
double.parse(jsonDecode(res)['message'][0]['deliveryPrice']);
mashwariPrice = double.parse(jsonDecode(res)['message'][0]['freePrice']);
fuelPrice = double.parse(jsonDecode(res)['message'][0]['fuelPrice']);
var json = jsonDecode(res);
kazan = double.parse(json['message'][0]['kazan']);
naturePrice = double.parse(json['message'][0]['naturePrice']);
heavyPrice = double.parse(json['message'][0]['heavyPrice']);
latePrice = double.parse(json['message'][0]['latePrice']);
comfortPrice = double.parse(json['message'][0]['comfortPrice']);
speedPrice = double.parse(json['message'][0]['speedPrice']);
deliveryPrice = double.parse(json['message'][0]['deliveryPrice']);
mashwariPrice = double.parse(json['message'][0]['freePrice']);
fuelPrice = double.parse(json['message'][0]['fuelPrice']);
print(json);
}
}

View File

@@ -2489,17 +2489,16 @@ class MapPassengerController extends GetxController {
);
if (res != 'failure') {
// print(jsonDecode(res));
kazan = double.parse(jsonDecode(res)['message'][0]['kazan']);
naturePrice = double.parse(jsonDecode(res)['message'][0]['naturePrice']);
heavyPrice = double.parse(jsonDecode(res)['message'][0]['heavyPrice']);
latePrice = double.parse(jsonDecode(res)['message'][0]['latePrice']);
fuelPrice = double.parse(jsonDecode(res)['message'][0]['fuelPrice']);
comfortPrice =
double.parse(jsonDecode(res)['message'][0]['comfortPrice']);
speedPrice = double.parse(jsonDecode(res)['message'][0]['speedPrice']);
mashwariPrice = double.parse(jsonDecode(res)['message'][0]['freePrice']);
deliveryPrice =
double.parse(jsonDecode(res)['message'][0]['deliveryPrice']);
var json = jsonDecode(res);
kazan = double.parse(json['message'][0]['kazan']);
naturePrice = double.parse(json['message'][0]['naturePrice']);
heavyPrice = double.parse(json['message'][0]['heavyPrice']);
latePrice = double.parse(json['message'][0]['latePrice']);
comfortPrice = double.parse(json['message'][0]['comfortPrice']);
speedPrice = double.parse(json['message'][0]['speedPrice']);
deliveryPrice = double.parse(json['message'][0]['deliveryPrice']);
mashwariPrice = double.parse(json['message'][0]['freePrice']);
fuelPrice = double.parse(json['message'][0]['fuelPrice']);
}
}

View File

@@ -7,6 +7,7 @@ import 'package:flutter_stripe/flutter_stripe.dart';
import 'package:get/get.dart';
import 'package:local_auth/local_auth.dart';
import 'package:SEFER/controller/home/map_passenger_controller.dart';
import 'package:paymob_payment/paymob_payment.dart';
import '../../constant/box_name.dart';
import '../../constant/colors.dart';
@@ -457,6 +458,42 @@ class PaymentController extends GetxController {
}
}
Future<void> payWithPayMob(
BuildContext context, String amount, currency) async {
try {
final PaymobResponse? response = await PaymobPayment.instance.pay(
context: context,
currency: currency, //"EGP",
amountInCents: amount, // 19.00 EGP
onPayment: (PaymobResponse response) {
print('Success: ${response.success}');
print('Transaction ID: ${response.transactionID}');
print('Response Code: ${response.responseCode}');
// print('Message: ${response.message}');
},
);
if (response!.responseCode == 'APPROVED') {
Get.defaultDialog(
title: 'Payment Successful',
content: const Text('The payment was approved.'),
);
} else {
Get.defaultDialog(
title: 'Payment Failed',
content:
const Text('The payment was not approved. Please try again.'),
);
}
} catch (e) {
Get.defaultDialog(
title: 'Error',
content: const Text('An error occurred during the payment process.'),
);
rethrow;
}
}
@override
void onInit() {
timestamp = now.millisecondsSinceEpoch;

View File

@@ -0,0 +1,129 @@
import 'package:SEFER/constant/box_name.dart';
import 'package:dio/dio.dart' as dio;
import 'package:dio/dio.dart';
import 'package:get/get.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../constant/api_key.dart';
import '../../main.dart';
class PaymobManager extends GetxController {
String authanticationToken1 = "";
String orderId1 = "";
Future<String> getPaymentKey(int amount, String currency) async {
try {
String authanticationToken = await _getAuthanticationToken();
int orderId = await _getOrderId(
authanticationToken: authanticationToken,
amount: (100 * amount).toString(),
currency: currency,
);
String paymentKey = await _getPaymentKey(
authanticationToken: authanticationToken,
amount: (100 * amount).toString(),
currency: currency,
orderId: orderId.toString(),
);
authanticationToken1 = authanticationToken.toString();
orderId1 = orderId.toString();
update();
return paymentKey;
} catch (e) {
print("Exc==========================================");
print(e.toString());
throw Exception();
}
}
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'),
);
// String paymentStatus = await _getStatusAfterPaid();
}
Future<String> _getStatusAfterPaid() async {
print(authanticationToken1);
print(orderId1);
final dio.Response response = await Dio().post(
"https://accept.paymob.com/api/ecommerce/orders/transaction_inquiry",
data: {
"auth_token": authanticationToken1,
"merchant_order_id": "970960",
"order_id": orderId1
});
print(response.data);
print(response.data['success']);
return response.data["success"];
}
Future<String> _getAuthanticationToken() async {
final dio.Response response =
await Dio().post("https://accept.paymob.com/api/auth/tokens", data: {
"api_key": AK.payMobApikey,
'username': AK.usernamePayMob,
"password": AK.passwordPayMob,
});
return response.data["token"];
}
Future<int> _getOrderId({
required String authanticationToken,
required String amount,
required String currency,
}) async {
final dio.Response response = await Dio()
.post("https://accept.paymob.com/api/ecommerce/orders", data: {
"auth_token": authanticationToken,
"amount_cents": amount,
"currency": currency,
"delivery_needed": "false",
"items": [],
});
print('id is');
print(response.data["id"]);
return response.data["id"];
}
Future<String> _getPaymentKey({
required String authanticationToken,
required String orderId,
required String amount,
required String currency,
}) async {
final dio.Response response = await Dio()
.post("https://accept.paymob.com/api/acceptance/payment_keys", data: {
"expiration": 200,
"auth_token": authanticationToken.toString(),
"order_id": orderId.toString(),
"integration_id": int.parse(AK.integrationIdPayMob),
"lock_order_when_paid": "false",
"amount_cents": amount,
"currency": currency,
"billing_data": {
"first_name": box.read(BoxName.nameDriver) ?? box.read(BoxName.name),
"last_name": box.read(BoxName.lastNameDriver) ?? box.read(BoxName.name),
"email": box.read(BoxName.emailDriver) ?? box.read(BoxName.email),
"phone_number":
box.read(BoxName.phoneDriver) ?? box.read(BoxName.phone),
"apartment": "NA",
"floor": "NA",
"street": "NA",
"building": "NA",
"shipping_method": "NA",
"postal_code": "NA",
"city": "NA",
"country": box.read(BoxName.countryCode),
"state": "NA"
},
});
return response.data["token"];
}
}