BASE: Update Icons & Name Of The App.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import 'dart:convert';
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get/get.dart' hide Trans;
|
||||
import 'package:http/http.dart' as http;
|
||||
import '../../models/onprovider_order_model.dart';
|
||||
import '../models/wallet_transaction_model.dart';
|
||||
@@ -48,7 +48,9 @@ import '../utils/preferences.dart';
|
||||
import 'on_demand_dashboard_controller.dart';
|
||||
|
||||
class OnDemandPaymentController extends GetxController {
|
||||
Rx<OnProviderOrderModel?> onDemandOrderModel = Rx<OnProviderOrderModel?>(null);
|
||||
Rx<OnProviderOrderModel?> onDemandOrderModel = Rx<OnProviderOrderModel?>(
|
||||
null,
|
||||
);
|
||||
RxDouble totalAmount = 0.0.obs;
|
||||
late bool isExtra;
|
||||
|
||||
@@ -76,19 +78,37 @@ class OnDemandPaymentController extends GetxController {
|
||||
ShowToastDialog.showLoader("Please wait...".tr());
|
||||
|
||||
onDemandOrderModel.value?.payment_method = selectedPaymentMethod.value;
|
||||
onDemandOrderModel.value?.paymentStatus = onDemandOrderModel.value?.provider.priceUnit == "Fixed" && selectedPaymentMethod.value == "cod" ? false : true;
|
||||
onDemandOrderModel.value?.paymentStatus =
|
||||
onDemandOrderModel.value?.provider.priceUnit == "Fixed" &&
|
||||
selectedPaymentMethod.value == "cod"
|
||||
? false
|
||||
: true;
|
||||
onDemandOrderModel.value?.extraPaymentStatus = true;
|
||||
|
||||
await FireStoreUtils.onDemandOrderPlace(onDemandOrderModel.value!, totalAmount.value);
|
||||
await FireStoreUtils.onDemandOrderPlace(
|
||||
onDemandOrderModel.value!,
|
||||
totalAmount.value,
|
||||
);
|
||||
|
||||
if (onDemandOrderModel.value?.status == Constant.orderPlaced) {
|
||||
await FireStoreUtils.sendOrderOnDemandServiceEmail(orderModel: onDemandOrderModel.value!);
|
||||
await FireStoreUtils.sendOrderOnDemandServiceEmail(
|
||||
orderModel: onDemandOrderModel.value!,
|
||||
);
|
||||
|
||||
final providerUser = await FireStoreUtils.getUserProfile(onDemandOrderModel.value!.provider.author!);
|
||||
final providerUser = await FireStoreUtils.getUserProfile(
|
||||
onDemandOrderModel.value!.provider.author!,
|
||||
);
|
||||
|
||||
if (providerUser != null) {
|
||||
final payLoad = {"type": 'provider_order', "orderId": onDemandOrderModel.value?.id};
|
||||
await SendNotification.sendFcmMessage(Constant.bookingPlaced, providerUser.fcmToken ?? '', payLoad);
|
||||
final payLoad = {
|
||||
"type": 'provider_order',
|
||||
"orderId": onDemandOrderModel.value?.id,
|
||||
};
|
||||
await SendNotification.sendFcmMessage(
|
||||
Constant.bookingPlaced,
|
||||
providerUser.fcmToken ?? '',
|
||||
payLoad,
|
||||
);
|
||||
}
|
||||
|
||||
ShowToastDialog.showToast("OnDemand Service successfully booked".tr());
|
||||
@@ -107,16 +127,23 @@ class OnDemandPaymentController extends GetxController {
|
||||
paymentStatus: "success".tr(),
|
||||
);
|
||||
|
||||
await FireStoreUtils.setWalletTransaction(transactionModel).then((value) async {
|
||||
await FireStoreUtils.setWalletTransaction(transactionModel).then((
|
||||
value,
|
||||
) async {
|
||||
if (value == true) {
|
||||
await FireStoreUtils.updateUserWallet(amount: "-${totalAmount.value.toString()}", userId: FireStoreUtils.getCurrentUid()).then((value) {});
|
||||
await FireStoreUtils.updateUserWallet(
|
||||
amount: "-${totalAmount.value.toString()}",
|
||||
userId: FireStoreUtils.getCurrentUid(),
|
||||
).then((value) {});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ShowToastDialog.closeLoader();
|
||||
Get.offAll(const OnDemandDashboardScreen());
|
||||
OnDemandDashboardController controller = Get.put(OnDemandDashboardController());
|
||||
OnDemandDashboardController controller = Get.put(
|
||||
OnDemandDashboardController(),
|
||||
);
|
||||
controller.selectedIndex.value = 2;
|
||||
} else {
|
||||
// Extra Charges Flow
|
||||
@@ -137,9 +164,14 @@ class OnDemandPaymentController extends GetxController {
|
||||
paymentStatus: "success".tr(),
|
||||
);
|
||||
|
||||
await FireStoreUtils.setWalletTransaction(transactionModel).then((value) async {
|
||||
await FireStoreUtils.setWalletTransaction(transactionModel).then((
|
||||
value,
|
||||
) async {
|
||||
if (value == true) {
|
||||
await FireStoreUtils.updateUserWallet(amount: "-${totalAmount.value.toString()}", userId: FireStoreUtils.getCurrentUid()).then((value) {});
|
||||
await FireStoreUtils.updateUserWallet(
|
||||
amount: "-${totalAmount.value.toString()}",
|
||||
userId: FireStoreUtils.getCurrentUid(),
|
||||
).then((value) {});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -160,9 +192,14 @@ class OnDemandPaymentController extends GetxController {
|
||||
paymentStatus: "success".tr(),
|
||||
);
|
||||
|
||||
await FireStoreUtils.setWalletTransaction(transactionModel).then((value) async {
|
||||
await FireStoreUtils.setWalletTransaction(transactionModel).then((
|
||||
value,
|
||||
) async {
|
||||
if (value == true) {
|
||||
await FireStoreUtils.updateUserWallet(amount: "-$totalAmount", userId: FireStoreUtils.getCurrentUid());
|
||||
await FireStoreUtils.updateUserWallet(
|
||||
amount: "-$totalAmount",
|
||||
userId: FireStoreUtils.getCurrentUid(),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -171,7 +208,9 @@ class OnDemandPaymentController extends GetxController {
|
||||
|
||||
ShowToastDialog.closeLoader();
|
||||
Get.offAll(const OnDemandDashboardScreen());
|
||||
OnDemandDashboardController controller = Get.put(OnDemandDashboardController());
|
||||
OnDemandDashboardController controller = Get.put(
|
||||
OnDemandDashboardController(),
|
||||
);
|
||||
controller.selectedIndex.value = 2;
|
||||
}
|
||||
}
|
||||
@@ -194,19 +233,45 @@ class OnDemandPaymentController extends GetxController {
|
||||
Future<void> getPaymentSettings() async {
|
||||
isLoading.value = true;
|
||||
await FireStoreUtils.getPaymentSettingsData().then((value) {
|
||||
stripeModel.value = StripeModel.fromJson(jsonDecode(Preferences.getString(Preferences.stripeSettings)));
|
||||
payPalModel.value = PayPalModel.fromJson(jsonDecode(Preferences.getString(Preferences.paypalSettings)));
|
||||
payStackModel.value = PayStackModel.fromJson(jsonDecode(Preferences.getString(Preferences.payStack)));
|
||||
mercadoPagoModel.value = MercadoPagoModel.fromJson(jsonDecode(Preferences.getString(Preferences.mercadoPago)));
|
||||
flutterWaveModel.value = FlutterWaveModel.fromJson(jsonDecode(Preferences.getString(Preferences.flutterWave)));
|
||||
paytmModel.value = PaytmModel.fromJson(jsonDecode(Preferences.getString(Preferences.paytmSettings)));
|
||||
payFastModel.value = PayFastModel.fromJson(jsonDecode(Preferences.getString(Preferences.payFastSettings)));
|
||||
razorPayModel.value = RazorPayModel.fromJson(jsonDecode(Preferences.getString(Preferences.razorpaySettings)));
|
||||
midTransModel.value = MidTrans.fromJson(jsonDecode(Preferences.getString(Preferences.midTransSettings)));
|
||||
orangeMoneyModel.value = OrangeMoney.fromJson(jsonDecode(Preferences.getString(Preferences.orangeMoneySettings)));
|
||||
xenditModel.value = Xendit.fromJson(jsonDecode(Preferences.getString(Preferences.xenditSettings)));
|
||||
walletSettingModel.value = WalletSettingModel.fromJson(jsonDecode(Preferences.getString(Preferences.walletSettings)));
|
||||
cashOnDeliverySettingModel.value = CodSettingModel.fromJson(jsonDecode(Preferences.getString(Preferences.codSettings)));
|
||||
stripeModel.value = StripeModel.fromJson(
|
||||
jsonDecode(Preferences.getString(Preferences.stripeSettings)),
|
||||
);
|
||||
payPalModel.value = PayPalModel.fromJson(
|
||||
jsonDecode(Preferences.getString(Preferences.paypalSettings)),
|
||||
);
|
||||
payStackModel.value = PayStackModel.fromJson(
|
||||
jsonDecode(Preferences.getString(Preferences.payStack)),
|
||||
);
|
||||
mercadoPagoModel.value = MercadoPagoModel.fromJson(
|
||||
jsonDecode(Preferences.getString(Preferences.mercadoPago)),
|
||||
);
|
||||
flutterWaveModel.value = FlutterWaveModel.fromJson(
|
||||
jsonDecode(Preferences.getString(Preferences.flutterWave)),
|
||||
);
|
||||
paytmModel.value = PaytmModel.fromJson(
|
||||
jsonDecode(Preferences.getString(Preferences.paytmSettings)),
|
||||
);
|
||||
payFastModel.value = PayFastModel.fromJson(
|
||||
jsonDecode(Preferences.getString(Preferences.payFastSettings)),
|
||||
);
|
||||
razorPayModel.value = RazorPayModel.fromJson(
|
||||
jsonDecode(Preferences.getString(Preferences.razorpaySettings)),
|
||||
);
|
||||
midTransModel.value = MidTrans.fromJson(
|
||||
jsonDecode(Preferences.getString(Preferences.midTransSettings)),
|
||||
);
|
||||
orangeMoneyModel.value = OrangeMoney.fromJson(
|
||||
jsonDecode(Preferences.getString(Preferences.orangeMoneySettings)),
|
||||
);
|
||||
xenditModel.value = Xendit.fromJson(
|
||||
jsonDecode(Preferences.getString(Preferences.xenditSettings)),
|
||||
);
|
||||
walletSettingModel.value = WalletSettingModel.fromJson(
|
||||
jsonDecode(Preferences.getString(Preferences.walletSettings)),
|
||||
);
|
||||
cashOnDeliverySettingModel.value = CodSettingModel.fromJson(
|
||||
jsonDecode(Preferences.getString(Preferences.codSettings)),
|
||||
);
|
||||
|
||||
if (walletSettingModel.value.isEnabled == true) {
|
||||
selectedPaymentMethod.value = PaymentGateway.wallet.name;
|
||||
@@ -249,20 +314,32 @@ class OnDemandPaymentController extends GetxController {
|
||||
Future<void> stripeMakePayment({required String amount}) async {
|
||||
log(double.parse(amount).toStringAsFixed(0));
|
||||
try {
|
||||
Map<String, dynamic>? paymentIntentData = await createStripeIntent(amount: amount);
|
||||
Map<String, dynamic>? paymentIntentData = await createStripeIntent(
|
||||
amount: amount,
|
||||
);
|
||||
log("stripe Responce====>$paymentIntentData");
|
||||
if (paymentIntentData!.containsKey("error")) {
|
||||
Get.back();
|
||||
ShowToastDialog.showToast("Something went wrong, please contact admin.".tr());
|
||||
ShowToastDialog.showToast(
|
||||
"Something went wrong, please contact admin.".tr(),
|
||||
);
|
||||
} else {
|
||||
await Stripe.instance.initPaymentSheet(
|
||||
paymentSheetParameters: SetupPaymentSheetParameters(
|
||||
paymentIntentClientSecret: paymentIntentData['client_secret'],
|
||||
allowsDelayedPaymentMethods: false,
|
||||
googlePay: const PaymentSheetGooglePay(merchantCountryCode: 'US', testEnv: true, currencyCode: "USD"),
|
||||
googlePay: const PaymentSheetGooglePay(
|
||||
merchantCountryCode: 'US',
|
||||
testEnv: true,
|
||||
currencyCode: "USD",
|
||||
),
|
||||
customFlow: true,
|
||||
style: ThemeMode.system,
|
||||
appearance: PaymentSheetAppearance(colors: PaymentSheetAppearanceColors(primary: AppThemeData.primary300)),
|
||||
appearance: PaymentSheetAppearance(
|
||||
colors: PaymentSheetAppearanceColors(
|
||||
primary: AppThemeData.primary300,
|
||||
),
|
||||
),
|
||||
merchantDisplayName: 'GoRide',
|
||||
),
|
||||
);
|
||||
@@ -308,7 +385,10 @@ class OnDemandPaymentController extends GetxController {
|
||||
var response = await http.post(
|
||||
Uri.parse('https://api.stripe.com/v1/payment_intents'),
|
||||
body: body,
|
||||
headers: {'Authorization': 'Bearer $stripeSecret', 'Content-Type': 'application/x-www-form-urlencoded'},
|
||||
headers: {
|
||||
'Authorization': 'Bearer $stripeSecret',
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
},
|
||||
);
|
||||
|
||||
return jsonDecode(response.body);
|
||||
@@ -318,8 +398,14 @@ class OnDemandPaymentController extends GetxController {
|
||||
}
|
||||
|
||||
//mercadoo
|
||||
Future<Null> mercadoPagoMakePayment({required BuildContext context, required String amount}) async {
|
||||
final headers = {'Authorization': 'Bearer ${mercadoPagoModel.value.accessToken}', 'Content-Type': 'application/json'};
|
||||
Future<Null> mercadoPagoMakePayment({
|
||||
required BuildContext context,
|
||||
required String amount,
|
||||
}) async {
|
||||
final headers = {
|
||||
'Authorization': 'Bearer ${mercadoPagoModel.value.accessToken}',
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
final body = jsonEncode({
|
||||
"items": [
|
||||
@@ -332,12 +418,20 @@ class OnDemandPaymentController extends GetxController {
|
||||
},
|
||||
],
|
||||
"payer": {"email": Constant.userModel?.email},
|
||||
"back_urls": {"failure": "${Constant.globalUrl}payment/failure", "pending": "${Constant.globalUrl}payment/pending", "success": "${Constant.globalUrl}payment/success"},
|
||||
"back_urls": {
|
||||
"failure": "${Constant.globalUrl}payment/failure",
|
||||
"pending": "${Constant.globalUrl}payment/pending",
|
||||
"success": "${Constant.globalUrl}payment/success",
|
||||
},
|
||||
"auto_return": "approved",
|
||||
// Automatically return after payment is approved
|
||||
});
|
||||
|
||||
final response = await http.post(Uri.parse("https://api.mercadopago.com/checkout/preferences"), headers: headers, body: body);
|
||||
final response = await http.post(
|
||||
Uri.parse("https://api.mercadopago.com/checkout/preferences"),
|
||||
headers: headers,
|
||||
body: body,
|
||||
);
|
||||
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
final data = jsonDecode(response.body);
|
||||
@@ -420,15 +514,23 @@ class OnDemandPaymentController extends GetxController {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ShowToastDialog.showToast("Something went wrong, please contact admin.".tr());
|
||||
ShowToastDialog.showToast(
|
||||
"Something went wrong, please contact admin.".tr(),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//flutter wave Payment Method
|
||||
Future<Null> flutterWaveInitiatePayment({required BuildContext context, required String amount}) async {
|
||||
Future<Null> flutterWaveInitiatePayment({
|
||||
required BuildContext context,
|
||||
required String amount,
|
||||
}) async {
|
||||
final url = Uri.parse('https://api.flutterwave.com/v3/payments');
|
||||
final headers = {'Authorization': 'Bearer ${flutterWaveModel.value.secretKey}', 'Content-Type': 'application/json'};
|
||||
final headers = {
|
||||
'Authorization': 'Bearer ${flutterWaveModel.value.secretKey}',
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
|
||||
final body = jsonEncode({
|
||||
"tx_ref": _ref,
|
||||
@@ -436,15 +538,24 @@ class OnDemandPaymentController extends GetxController {
|
||||
"currency": "NGN",
|
||||
"redirect_url": "${Constant.globalUrl}payment/success",
|
||||
"payment_options": "ussd, card, barter, payattitude",
|
||||
"customer": {"email": Constant.userModel?.email.toString(), "phonenumber": Constant.userModel?.phoneNumber, "name": Constant.userModel?.fullName()},
|
||||
"customizations": {"title": "Payment for Services", "description": "Payment for XYZ services"},
|
||||
"customer": {
|
||||
"email": Constant.userModel?.email.toString(),
|
||||
"phonenumber": Constant.userModel?.phoneNumber,
|
||||
"name": Constant.userModel?.fullName(),
|
||||
},
|
||||
"customizations": {
|
||||
"title": "Payment for Services",
|
||||
"description": "Payment for XYZ services",
|
||||
},
|
||||
});
|
||||
|
||||
final response = await http.post(url, headers: headers, body: body);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final data = jsonDecode(response.body);
|
||||
Get.to(MercadoPagoScreen(initialURl: data['data']['link']))!.then((value) {
|
||||
Get.to(MercadoPagoScreen(initialURl: data['data']['link']))!.then((
|
||||
value,
|
||||
) {
|
||||
if (value) {
|
||||
ShowToastDialog.showToast("Payment Successful!!".tr());
|
||||
placeOrder();
|
||||
@@ -473,8 +584,14 @@ class OnDemandPaymentController extends GetxController {
|
||||
|
||||
// payFast
|
||||
void payFastPayment({required BuildContext context, required String amount}) {
|
||||
PayStackURLGen.getPayHTML(payFastSettingData: payFastModel.value, amount: amount.toString(), userModel: Constant.userModel!).then((String? value) async {
|
||||
bool isDone = await Get.to(PayFastScreen(htmlData: value!, payFastSettingData: payFastModel.value));
|
||||
PayStackURLGen.getPayHTML(
|
||||
payFastSettingData: payFastModel.value,
|
||||
amount: amount.toString(),
|
||||
userModel: Constant.userModel!,
|
||||
).then((String? value) async {
|
||||
bool isDone = await Get.to(
|
||||
PayFastScreen(htmlData: value!, payFastSettingData: payFastModel.value),
|
||||
);
|
||||
if (isDone) {
|
||||
Get.back();
|
||||
ShowToastDialog.showToast("Payment successfully".tr());
|
||||
@@ -494,26 +611,50 @@ class OnDemandPaymentController extends GetxController {
|
||||
final response = await http.post(
|
||||
Uri.parse(getChecksum),
|
||||
headers: {},
|
||||
body: {"mid": paytmModel.value.paytmMID.toString(), "order_id": orderId, "key_secret": paytmModel.value.pAYTMMERCHANTKEY.toString()},
|
||||
body: {
|
||||
"mid": paytmModel.value.paytmMID.toString(),
|
||||
"order_id": orderId,
|
||||
"key_secret": paytmModel.value.pAYTMMERCHANTKEY.toString(),
|
||||
},
|
||||
);
|
||||
|
||||
final data = jsonDecode(response.body);
|
||||
await verifyCheckSum(checkSum: data["code"], amount: amount, orderId: orderId).then((value) {
|
||||
await verifyCheckSum(
|
||||
checkSum: data["code"],
|
||||
amount: amount,
|
||||
orderId: orderId,
|
||||
).then((value) {
|
||||
initiatePayment(amount: amount, orderId: orderId).then((value) {
|
||||
String callback = "";
|
||||
if (paytmModel.value.isSandboxEnabled == true) {
|
||||
callback = "${callback}https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=$orderId";
|
||||
callback =
|
||||
"${callback}https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=$orderId";
|
||||
} else {
|
||||
callback = "${callback}https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=$orderId";
|
||||
callback =
|
||||
"${callback}https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=$orderId";
|
||||
}
|
||||
|
||||
GetPaymentTxtTokenModel result = value;
|
||||
startTransaction(context, txnTokenBy: result.body.txnToken ?? '', orderId: orderId, amount: amount, callBackURL: callback, isStaging: paytmModel.value.isSandboxEnabled);
|
||||
startTransaction(
|
||||
context,
|
||||
txnTokenBy: result.body.txnToken ?? '',
|
||||
orderId: orderId,
|
||||
amount: amount,
|
||||
callBackURL: callback,
|
||||
isStaging: paytmModel.value.isSandboxEnabled,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> startTransaction(context, {required String txnTokenBy, required orderId, required double amount, required callBackURL, required isStaging}) async {
|
||||
Future<void> startTransaction(
|
||||
context, {
|
||||
required String txnTokenBy,
|
||||
required orderId,
|
||||
required double amount,
|
||||
required callBackURL,
|
||||
required isStaging,
|
||||
}) async {
|
||||
// try {
|
||||
// var response = AllInOneSdk.startTransaction(
|
||||
// paytmModel.value.paytmMID.toString(),
|
||||
@@ -549,24 +690,38 @@ class OnDemandPaymentController extends GetxController {
|
||||
// }
|
||||
}
|
||||
|
||||
Future verifyCheckSum({required String checkSum, required double amount, required orderId}) async {
|
||||
Future verifyCheckSum({
|
||||
required String checkSum,
|
||||
required double amount,
|
||||
required orderId,
|
||||
}) async {
|
||||
String getChecksum = "${Constant.globalUrl}payments/validatechecksum";
|
||||
final response = await http.post(
|
||||
Uri.parse(getChecksum),
|
||||
headers: {},
|
||||
body: {"mid": paytmModel.value.paytmMID.toString(), "order_id": orderId, "key_secret": paytmModel.value.pAYTMMERCHANTKEY.toString(), "checksum_value": checkSum},
|
||||
body: {
|
||||
"mid": paytmModel.value.paytmMID.toString(),
|
||||
"order_id": orderId,
|
||||
"key_secret": paytmModel.value.pAYTMMERCHANTKEY.toString(),
|
||||
"checksum_value": checkSum,
|
||||
},
|
||||
);
|
||||
final data = jsonDecode(response.body);
|
||||
return data['status'];
|
||||
}
|
||||
|
||||
Future<GetPaymentTxtTokenModel> initiatePayment({required double amount, required orderId}) async {
|
||||
Future<GetPaymentTxtTokenModel> initiatePayment({
|
||||
required double amount,
|
||||
required orderId,
|
||||
}) async {
|
||||
String initiateURL = "${Constant.globalUrl}payments/initiatepaytmpayment";
|
||||
String callback = "";
|
||||
if (paytmModel.value.isSandboxEnabled == true) {
|
||||
callback = "${callback}https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=$orderId";
|
||||
callback =
|
||||
"${callback}https://securegw-stage.paytm.in/theia/paytmCallback?ORDER_ID=$orderId";
|
||||
} else {
|
||||
callback = "${callback}https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=$orderId";
|
||||
callback =
|
||||
"${callback}https://securegw.paytm.in/theia/paytmCallback?ORDER_ID=$orderId";
|
||||
}
|
||||
final response = await http.post(
|
||||
Uri.parse(initiateURL),
|
||||
@@ -584,9 +739,12 @@ class OnDemandPaymentController extends GetxController {
|
||||
);
|
||||
log(response.body);
|
||||
final data = jsonDecode(response.body);
|
||||
if (data["body"]["txnToken"] == null || data["body"]["txnToken"].toString().isEmpty) {
|
||||
if (data["body"]["txnToken"] == null ||
|
||||
data["body"]["txnToken"].toString().isEmpty) {
|
||||
Get.back();
|
||||
ShowToastDialog.showToast("something went wrong, please contact admin.".tr());
|
||||
ShowToastDialog.showToast(
|
||||
"something went wrong, please contact admin.".tr(),
|
||||
);
|
||||
}
|
||||
return GetPaymentTxtTokenModel.fromJson(data);
|
||||
}
|
||||
@@ -604,7 +762,10 @@ class OnDemandPaymentController extends GetxController {
|
||||
'description': 'wallet Topup',
|
||||
'retry': {'enabled': true, 'max_count': 1},
|
||||
'send_sms_hash': true,
|
||||
'prefill': {'contact': Constant.userModel?.phoneNumber, 'email': Constant.userModel?.email},
|
||||
'prefill': {
|
||||
'contact': Constant.userModel?.phoneNumber,
|
||||
'email': Constant.userModel?.email,
|
||||
},
|
||||
'external': {
|
||||
'wallets': ['paytm'],
|
||||
},
|
||||
@@ -639,7 +800,10 @@ class OnDemandPaymentController extends GetxController {
|
||||
}
|
||||
|
||||
//Midtrans payment
|
||||
Future<void> midtransMakePayment({required String amount, required BuildContext context}) async {
|
||||
Future<void> midtransMakePayment({
|
||||
required String amount,
|
||||
required BuildContext context,
|
||||
}) async {
|
||||
await createPaymentLink(amount: amount).then((url) {
|
||||
ShowToastDialog.closeLoader();
|
||||
if (url != '') {
|
||||
@@ -657,15 +821,30 @@ class OnDemandPaymentController extends GetxController {
|
||||
|
||||
Future<String> createPaymentLink({required var amount}) async {
|
||||
var ordersId = const Uuid().v1();
|
||||
final url = Uri.parse(midTransModel.value.isSandbox! ? 'https://api.sandbox.midtrans.com/v1/payment-links' : 'https://api.midtrans.com/v1/payment-links');
|
||||
final url = Uri.parse(
|
||||
midTransModel.value.isSandbox!
|
||||
? 'https://api.sandbox.midtrans.com/v1/payment-links'
|
||||
: 'https://api.midtrans.com/v1/payment-links',
|
||||
);
|
||||
|
||||
final response = await http.post(
|
||||
url,
|
||||
headers: {'Accept': 'application/json', 'Content-Type': 'application/json', 'Authorization': generateBasicAuthHeader(midTransModel.value.serverKey!)},
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': generateBasicAuthHeader(
|
||||
midTransModel.value.serverKey!,
|
||||
),
|
||||
},
|
||||
body: jsonEncode({
|
||||
'transaction_details': {'order_id': ordersId, 'gross_amount': double.parse(amount.toString()).toInt()},
|
||||
'transaction_details': {
|
||||
'order_id': ordersId,
|
||||
'gross_amount': double.parse(amount.toString()).toInt(),
|
||||
},
|
||||
'usage_limit': 2,
|
||||
"callbacks": {"finish": "https://www.google.com?merchant_order_id=$ordersId"},
|
||||
"callbacks": {
|
||||
"finish": "https://www.google.com?merchant_order_id=$ordersId",
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -673,7 +852,9 @@ class OnDemandPaymentController extends GetxController {
|
||||
final responseData = jsonDecode(response.body);
|
||||
return responseData['payment_url'];
|
||||
} else {
|
||||
ShowToastDialog.showToast("something went wrong, please contact admin.".tr());
|
||||
ShowToastDialog.showToast(
|
||||
"something went wrong, please contact admin.".tr(),
|
||||
);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -692,16 +873,33 @@ class OnDemandPaymentController extends GetxController {
|
||||
static String orderId = '';
|
||||
static String amount = '';
|
||||
|
||||
Future<void> orangeMakePayment({required String amount, required BuildContext context}) async {
|
||||
Future<void> orangeMakePayment({
|
||||
required String amount,
|
||||
required BuildContext context,
|
||||
}) async {
|
||||
reset();
|
||||
|
||||
var id = const Uuid().v4();
|
||||
var paymentURL = await fetchToken(context: context, orderId: id, amount: amount, currency: 'USD');
|
||||
var paymentURL = await fetchToken(
|
||||
context: context,
|
||||
orderId: id,
|
||||
amount: amount,
|
||||
currency: 'USD',
|
||||
);
|
||||
|
||||
ShowToastDialog.closeLoader();
|
||||
|
||||
if (paymentURL.toString().isNotEmpty) {
|
||||
Get.to(() => OrangeMoneyScreen(initialURl: paymentURL, accessToken: accessToken, amount: amount, orangePay: orangeMoneyModel.value, orderId: orderId, payToken: payToken))!.then((value) {
|
||||
Get.to(
|
||||
() => OrangeMoneyScreen(
|
||||
initialURl: paymentURL,
|
||||
accessToken: accessToken,
|
||||
amount: amount,
|
||||
orangePay: orangeMoneyModel.value,
|
||||
orderId: orderId,
|
||||
payToken: payToken,
|
||||
),
|
||||
)!.then((value) {
|
||||
if (value == true) {
|
||||
ShowToastDialog.showToast("Payment Successful!!".tr());
|
||||
placeOrder();
|
||||
@@ -712,13 +910,22 @@ class OnDemandPaymentController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> fetchToken({required String orderId, required String currency, required BuildContext context, required String amount}) async {
|
||||
Future<String> fetchToken({
|
||||
required String orderId,
|
||||
required String currency,
|
||||
required BuildContext context,
|
||||
required String amount,
|
||||
}) async {
|
||||
String apiUrl = 'https://api.orange.com/oauth/v3/token';
|
||||
Map<String, String> requestBody = {'grant_type': 'client_credentials'};
|
||||
|
||||
var response = await http.post(
|
||||
Uri.parse(apiUrl),
|
||||
headers: <String, String>{'Authorization': "Basic ${orangeMoneyModel.value.auth ?? ''}", 'Content-Type': 'application/x-www-form-urlencoded', 'Accept': 'application/json'},
|
||||
headers: <String, String>{
|
||||
'Authorization': "Basic ${orangeMoneyModel.value.auth ?? ''}",
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
body: requestBody,
|
||||
);
|
||||
|
||||
@@ -731,21 +938,36 @@ class OnDemandPaymentController extends GetxController {
|
||||
return '';
|
||||
}
|
||||
|
||||
return await webpayment(context: context, amountData: amount, currency: currency, orderIdData: orderId);
|
||||
return await webpayment(
|
||||
context: context,
|
||||
amountData: amount,
|
||||
currency: currency,
|
||||
orderIdData: orderId,
|
||||
);
|
||||
} else {
|
||||
ShowToastDialog.showToast("Something went wrong, please contact admin.".tr());
|
||||
ShowToastDialog.showToast(
|
||||
"Something went wrong, please contact admin.".tr(),
|
||||
);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> webpayment({required String orderIdData, required BuildContext context, required String currency, required String amountData}) async {
|
||||
Future<String> webpayment({
|
||||
required String orderIdData,
|
||||
required BuildContext context,
|
||||
required String currency,
|
||||
required String amountData,
|
||||
}) async {
|
||||
orderId = orderIdData;
|
||||
amount = amountData;
|
||||
|
||||
// ✅ Null-safe handling
|
||||
bool isSandbox = orangeMoneyModel.value.isSandbox ?? false;
|
||||
|
||||
String apiUrl = isSandbox ? 'https://api.orange.com/orange-money-webpay/dev/v1/webpayment' : 'https://api.orange.com/orange-money-webpay/cm/v1/webpayment';
|
||||
String apiUrl =
|
||||
isSandbox
|
||||
? 'https://api.orange.com/orange-money-webpay/dev/v1/webpayment'
|
||||
: 'https://api.orange.com/orange-money-webpay/cm/v1/webpayment';
|
||||
|
||||
Map<String, String> requestBody = {
|
||||
"merchant_key": orangeMoneyModel.value.merchantKey ?? '',
|
||||
@@ -761,7 +983,11 @@ class OnDemandPaymentController extends GetxController {
|
||||
|
||||
var response = await http.post(
|
||||
Uri.parse(apiUrl),
|
||||
headers: <String, String>{'Authorization': 'Bearer $accessToken', 'Content-Type': 'application/json', 'Accept': 'application/json'},
|
||||
headers: <String, String>{
|
||||
'Authorization': 'Bearer $accessToken',
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
},
|
||||
body: json.encode(requestBody),
|
||||
);
|
||||
|
||||
@@ -774,7 +1000,9 @@ class OnDemandPaymentController extends GetxController {
|
||||
return '';
|
||||
}
|
||||
} else {
|
||||
ShowToastDialog.showToast("Something went wrong, please contact admin.".tr());
|
||||
ShowToastDialog.showToast(
|
||||
"Something went wrong, please contact admin.".tr(),
|
||||
);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -888,7 +1116,13 @@ class OnDemandPaymentController extends GetxController {
|
||||
await createXenditInvoice(amount: amount).then((model) {
|
||||
ShowToastDialog.closeLoader();
|
||||
if (model.id != null) {
|
||||
Get.to(() => XenditScreen(initialURl: model.invoiceUrl ?? '', transId: model.id ?? '', apiKey: xenditModel.value.apiKey!.toString()))!.then((value) {
|
||||
Get.to(
|
||||
() => XenditScreen(
|
||||
initialURl: model.invoiceUrl ?? '',
|
||||
transId: model.id ?? '',
|
||||
apiKey: xenditModel.value.apiKey!.toString(),
|
||||
),
|
||||
)!.then((value) {
|
||||
if (value == true) {
|
||||
ShowToastDialog.showToast("Payment Successful!!".tr());
|
||||
placeOrder();
|
||||
@@ -905,7 +1139,9 @@ class OnDemandPaymentController extends GetxController {
|
||||
const url = 'https://api.xendit.co/v2/invoices';
|
||||
var headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': generateBasicAuthHeader(xenditModel.value.apiKey!.toString()),
|
||||
'Authorization': generateBasicAuthHeader(
|
||||
xenditModel.value.apiKey!.toString(),
|
||||
),
|
||||
// 'Cookie': '__cf_bm=yERkrx3xDITyFGiou0bbKY1bi7xEwovHNwxV1vCNbVc-1724155511-1.0.1.1-jekyYQmPCwY6vIJ524K0V6_CEw6O.dAwOmQnHtwmaXO_MfTrdnmZMka0KZvjukQgXu5B.K_6FJm47SGOPeWviQ',
|
||||
};
|
||||
|
||||
@@ -918,7 +1154,11 @@ class OnDemandPaymentController extends GetxController {
|
||||
});
|
||||
|
||||
try {
|
||||
final response = await http.post(Uri.parse(url), headers: headers, body: body);
|
||||
final response = await http.post(
|
||||
Uri.parse(url),
|
||||
headers: headers,
|
||||
body: body,
|
||||
);
|
||||
|
||||
if (response.statusCode == 200 || response.statusCode == 201) {
|
||||
XenditModel model = XenditModel.fromJson(jsonDecode(response.body));
|
||||
|
||||
Reference in New Issue
Block a user