subscription updates

localization_aamir
Mirza.Shafique@cloudsolutions.com.sa 2 years ago
parent 689460a78d
commit d5745847bf

@ -100,7 +100,7 @@ class ApiConsts {
static String vehicleDetailsMaster = "${baseUrlServices}api/Master";
static String vehicleAdsDurationGet = "${baseUrlServices}api/Advertisement/AdsDuration_Get";
static String vehicleAdsSpecialServicesGet = "${baseUrlServices}api/Common/SpecialService_Get";
static String vehicleAdsSingleStepCreate = "${baseUrlServices}api/Advertisement/AdsSingleStep_Create";
static String vehicleAdsSingleStepCreate = "${baseUrlServices}api/Advertisement/AdsSingl`eStep_Create";
static String vehicleAdsGet = "${baseUrlServices}api/Advertisement/Ads_Get";
static String myAdsReserveGet = "${baseUrlServices}api/Advertisement/AdsReserve_Get";
static String reserveAdsBankDetailsGet = "${baseUrlServices}api/Advertisement/MCBankAccountAd_Get";
@ -113,7 +113,12 @@ class ApiConsts {
static String adsReserveCreate = "${baseUrlServices}api/Advertisement/AdsReserve_Create";
//Subscription
static String getMySubscriptions = "${baseUrlServices}api/ServiceProviders/ProviderSubscription_Get";
static String getAllSubscriptions = "${baseUrlServices}api/Common/Subscription_Get";
static String getSubscriptionBySP = "${baseUrlServices}api/Common/SubscriptionBySP_Get";
static String calculationUpgradePrice = "${baseUrlServices}api/ServiceProviders/CalculationUpgradePrice";
static String payFortOrder_ProviderSubscription_Create = "${baseUrlServices}api/Payment/PayFortOrder_ProviderSubscription_Create";
static String getSPBranchUser_Get = "${baseUrlServices}api/ServiceProviders/SPBranchUser_Get";
// Payment
static String paymentWebViewUrl = "https://ms.hmg.com/pay/PaymentHome";
@ -124,7 +129,6 @@ class ApiConsts {
static String duplicateItems = "${baseUrlServices}api/ServiceProviders/ServiceItemCopy_Create";
//Branch Users
static String getAllProviderDealers = "${baseUrlServices}api/ServiceProviders/DealershipUserBranchWise_Get";
// /api/ServiceProviders/BranchUser_Get

@ -5,18 +5,18 @@ import 'package:mc_common_app/theme/colors.dart';
import 'package:mc_common_app/utils/enums.dart';
extension EmailValidator on String {
Widget toText(
{Color? color,
bool isBold = false,
double? fontSize,
bool isUnderLine = false,
bool isItalic = false,
TextDecoration? textDecoration,
double letterSpacing = -0.4,
TextAlign? textAlign,
FontWeight? fontWeight,
double? height,
int? maxLines}) =>
Widget toText({Color? color,
bool isBold = false,
double? fontSize,
bool isUnderLine = false,
bool isItalic = false,
TextDecoration? textDecoration,
double letterSpacing = -0.4,
TextAlign? textAlign,
FontWeight? fontWeight,
double? height,
Color? decorationColor,
int? maxLines}) =>
AutoSizeText(
this,
textAlign: textAlign,
@ -24,7 +24,10 @@ extension EmailValidator on String {
style: TextStyle(
fontStyle: isItalic ? FontStyle.italic : null,
height: height,
decoration: isUnderLine ? TextDecoration.underline : textDecoration ?? TextDecoration.none,
decoration: isUnderLine ? TextDecoration.underline : textDecoration ??
TextDecoration.none,
decorationColor
: decorationColor,
fontSize: fontSize ?? 10,
fontWeight: isBold ? FontWeight.bold : fontWeight ?? FontWeight.w600,
color: color ?? MyColors.darkTextColor,
@ -33,7 +36,9 @@ extension EmailValidator on String {
);
bool isValidEmail() {
return RegExp(r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$').hasMatch(this);
return RegExp(
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$')
.hasMatch(this);
}
bool isNum() {
@ -141,7 +146,9 @@ extension FormatDate on String {
String date = split("T")[0];
String time = split("T")[1];
var dates = date.split("-");
return "${dates[2]} ${getMonth(int.parse(dates[1]))} ${dates[0]} ${DateFormat('hh:mm a', "en_US").format(DateFormat('hh:mm:ss', "en_US").parse(time))}";
return "${dates[2]} ${getMonth(
int.parse(dates[1]))} ${dates[0]} ${DateFormat('hh:mm a', "en_US")
.format(DateFormat('hh:mm:ss', "en_US").parse(time))}";
}
String toFormattedDateWithoutTime() {
@ -757,3 +764,48 @@ extension ChatTypeEnumToInt on ChatTypeEnum {
}
}
}
extension SubscriptionTypeEnumExt on int {
SubscriptionTypeEnum toSubscriptionTypeEnum() {
if (this == 2) {
return SubscriptionTypeEnum.upgrade;
} else if (this == 3) {
return SubscriptionTypeEnum.downgrade;
}
return SubscriptionTypeEnum.current;
}
}
extension SubscriptionTypeEnumToInt on SubscriptionTypeEnum {
int getIdSubscriptionTypeEnum() {
switch (this) {
case SubscriptionTypeEnum.current:
return 1;
case SubscriptionTypeEnum.upgrade:
return 2;
case SubscriptionTypeEnum.downgrade:
return 3;
default:
return 1;
}
}
}
extension SubscriptionTypeEnumToString on SubscriptionTypeEnum {
String getStringSubscriptionTypeEnum() {
switch (this) {
case SubscriptionTypeEnum.current:
return "Current";
case SubscriptionTypeEnum.upgrade:
return "Upgrade";
case SubscriptionTypeEnum.downgrade:
return "Downgrade";
default:
return "Current";
}
}
}

@ -65,7 +65,7 @@ class BranchDetailModel {
distanceKm: json["distanceKM"]?.toDouble(),
openTime: json["openTime"],
closeTime: json["closeTime"],
branchStatus: (json['branchStatus'] as int).toBranchStatusEnum(),
branchStatus: json.containsKey("branchStatus")?(json['branchStatus'] as int).toBranchStatusEnum():null,
statusId: json["branchStatus"],
statusText: json["statusText"],
branchServices: json["serviceProviderServices"] == null ? [] : List<

@ -0,0 +1,32 @@
class BranchSelectionModel {
int branchId;
String branchName;
bool isSelected;
bool isOpend;
List<UserSelectionModel> usersList;
BranchSelectionModel
({
required
this
.
branchId,
required this.branchName,
required this.isSelected,
this.isOpend = false,
required this.usersList,
});
}
class UserSelectionModel {
int userId;
String userName;
bool isSelected;
UserSelectionModel(
{required this.userId, required this.userName, required this.isSelected});
}

@ -4,7 +4,12 @@
import 'dart:convert';
Subscription subscriptionFromJson(String str) => Subscription.fromJson(json.decode(str));
import 'package:mc_common_app/extensions/string_extensions.dart';
import '../../utils/enums.dart';
Subscription subscriptionFromJson(String str) =>
Subscription.fromJson(json.decode(str));
String subscriptionToJson(Subscription data) => json.encode(data.toJson());
@ -21,19 +26,25 @@ class SubscriptionModel {
List<Subscription>? data;
String? message;
factory SubscriptionModel.fromJson(Map<String, dynamic> json) => SubscriptionModel(
messageStatus: json["messageStatus"],
totalItemsCount: json["totalItemsCount"],
data: json["data"] == null ? [] : List<Subscription>.from(json["data"]!.map((x) => Subscription.fromJson(x))),
message: json["message"],
);
factory SubscriptionModel.fromJson(Map<String, dynamic> json) =>
SubscriptionModel(
messageStatus: json["messageStatus"],
totalItemsCount: json["totalItemsCount"],
data: json["data"] == null
? []
: List<Subscription>.from(
json["data"]!.map((x) => Subscription.fromJson(x))),
message: json["message"],
);
Map<String, dynamic> toJson() => {
"messageStatus": messageStatus,
"totalItemsCount": totalItemsCount,
"data": data == null ? [] : List<dynamic>.from(data!.map((x) => x.toJson())),
"message": message,
};
"messageStatus": messageStatus,
"totalItemsCount": totalItemsCount,
"data": data == null
? []
: List<dynamic>.from(data!.map((x) => x.toJson())),
"message": message,
};
}
class Subscription {
@ -57,6 +68,7 @@ class Subscription {
this.dateEnd,
this.isExpired,
this.isActive,
this.subscriptionTypeEnum,
});
int? id;
@ -78,48 +90,53 @@ class Subscription {
DateTime? dateEnd;
bool? isExpired;
bool? isActive;
SubscriptionTypeEnum? subscriptionTypeEnum;
factory Subscription.fromJson(Map<String, dynamic> json) => Subscription(
id: json["id"],
name: json["name"],
description: json["description"],
durationName: json["durationName"],
durationDays: json["durationDays"],
price: json["price"]?.toDouble(),
currency: json["currency"],
numberOfBranches: json["numberOfBranches"],
numberOfSubUsers: json["numberOfSubUsers"],
numberOfAds: json["numberOfAds"],
countryId: json["countryID"],
countryName: json["countryName"]!,
isSubscribed: json["isSubscribed"],
subscriptionAppliedId: json["subscriptionAppliedID"],
serviceProviderId: json["serviceProviderID"],
dateStart: json["dateStart"] == null ? null : DateTime.parse(json["dateStart"]),
dateEnd: json["dateEnd"] == null ? null : DateTime.parse(json["dateEnd"]),
isExpired: json["isExpired"],
isActive: json["isActive"],
);
id: json["id"],
name: json["name"],
description: json["description"],
durationName: json["durationName"],
durationDays: json["durationDays"],
price: json["price"]?.toDouble(),
currency: json["currency"],
numberOfBranches: json["numberOfBranches"],
numberOfSubUsers: json["numberOfSubUsers"],
numberOfAds: json["numberOfAds"],
countryId: json["countryID"],
countryName: json["countryName"],
isSubscribed: json["isSubscribed"],
subscriptionAppliedId: json["subscriptionAppliedID"],
serviceProviderId:
json["serviceProviderID"],
dateStart:
json["dateStart"] == null ? null : DateTime.parse(json["dateStart"]),
dateEnd: json["dateEnd"] == null ? null : DateTime.parse(json["dateEnd"]),
isExpired: json["isExpired"],
isActive: json["isActive"],
subscriptionTypeEnum: json["subscriptionType"] == null
? null
: ((json['subscriptionType']) as int).toSubscriptionTypeEnum());
Map<String, dynamic> toJson() => {
"id": id,
"name": name,
"description": description,
"durationName": durationName,
"durationDays": durationDays,
"price": price,
"currency": currency,
"numberOfBranches": numberOfBranches,
"numberOfSubUsers": numberOfSubUsers,
"numberOfAds": numberOfAds,
"countryID": countryId,
"countryName": countryName,
"isSubscribed": isSubscribed,
"subscriptionAppliedID": subscriptionAppliedId,
"serviceProviderID": serviceProviderId,
"dateStart": dateStart?.toIso8601String(),
"dateEnd": dateEnd?.toIso8601String(),
"isExpired": isExpired,
"isActive": isActive,
};
"id": id,
"name": name,
"description": description,
"durationName": durationName,
"durationDays": durationDays,
"price": price,
"currency": currency,
"numberOfBranches": numberOfBranches,
"numberOfSubUsers": numberOfSubUsers,
"numberOfAds": numberOfAds,
"countryID": countryId,
"countryName": countryName,
"isSubscribed": isSubscribed,
"subscriptionAppliedID": subscriptionAppliedId,
"serviceProviderID": serviceProviderId,
"dateStart": dateStart?.toIso8601String(),
"dateEnd": dateEnd?.toIso8601String(),
"isExpired": isExpired,
"isActive": isActive,
};
}

@ -3,11 +3,12 @@ class BranchUser {
String? userId;
int? serviceProviderId;
int? dealershipUserID;
String firstName;
String lastName;
String mobileNo;
String email;
bool isBranchUser;
String? firstName;
String? lastName;
String? mobileNo;
String? email;
bool? isBranchUser;
int? serviceProviderBranchID;
BranchUser({
required this.id,
@ -19,19 +20,27 @@ class BranchUser {
required this.mobileNo,
required this.email,
required this.isBranchUser,
this.serviceProviderBranchID,
});
factory BranchUser.fromJson(Map<String, dynamic> json) =>
BranchUser(
factory BranchUser.fromJson(Map<String, dynamic> json) => BranchUser(
id: json["id"],
userId: json.containsKey("userID") ? json["userID"] : null,
serviceProviderId: json.containsKey("serviceProviderID") ? json["serviceProviderID"] : null,
dealershipUserID: json.containsKey("dealershipUserID") ? json["dealershipUserID"] : null,
firstName: json["firstName"],
lastName: json["lastName"],
mobileNo: json["mobileNo"],
email: json["email"],
isBranchUser: json.containsKey("isBranchUser") ? json["isBranchUser"] : false,
serviceProviderId: json.containsKey("serviceProviderID")
? json["serviceProviderID"]
: null,
dealershipUserID: json.containsKey("dealershipUserID")
? json["dealershipUserID"]
: null,
firstName: json.containsKey("firstName") ? json["firstName"] : null,
lastName: json.containsKey("lastName") ? json["lastName"] : null,
mobileNo: json.containsKey("mobileNo") ? json["mobileNo"] : null,
email: json.containsKey("email") ? json["email"] : null,
isBranchUser:
json.containsKey("isBranchUser") ? json["isBranchUser"] : false,
serviceProviderBranchID: json.containsKey("serviceProviderBranchID")
? json["serviceProviderBranchID"]
: null,
);
Map<String, dynamic> toJson() =>

@ -0,0 +1,165 @@
import 'package:mc_common_app/api/api_client.dart';
import 'package:mc_common_app/classes/app_state.dart';
import 'package:mc_common_app/classes/consts.dart';
import 'package:mc_common_app/config/dependencies.dart';
import 'package:mc_common_app/models/general_models/generic_resp_model.dart';
import 'package:mc_common_app/models/general_models/m_response.dart';
import 'package:mc_common_app/models/provider_branches_models/branch_detail_model.dart';
import 'package:mc_common_app/models/subscriptions_models/branch_user_selection_model.dart';
import 'package:mc_common_app/models/subscriptions_models/subscription_model.dart';
import 'package:mc_common_app/models/user_models/branch_user.dart';
abstract class SubscriptionRepo {
Future<SubscriptionModel> getAllSubscriptions(String? serviceProviderID);
Future<SubscriptionModel> getMySubscriptions(String? serviceProviderID);
Future<SubscriptionModel> getSubscriptionBySP(
String? serviceProviderID, bool isRenew);
Future<MResponse> calculationUpgradePrice(
String? serviceProviderID, String? newSubscription);
Future<MResponse> payForProviderSubscription(Map<String, dynamic> map);
Future<List<BranchSelectionModel>> getSPBranchUser_Get(
Map<String, String> map);
}
class SubscriptionRepoImp extends SubscriptionRepo {
@override
Future<SubscriptionModel> getAllSubscriptions(
String? serviceProviderID) async {
String t = AppState().getUser.data!.accessToken ?? "";
Map<String, String> queryParameters = {};
if (serviceProviderID != null) {
queryParameters = {
"ID": serviceProviderID,
};
}
return await injector.get<ApiClient>().getJsonForObject(
(json) => SubscriptionModel.fromJson(json),
ApiConsts.getAllSubscriptions,
token: t,
queryParameters: queryParameters);
}
@override
Future<SubscriptionModel> getSubscriptionBySP(
String? serviceProviderID, bool isRenew) async {
String t = AppState().getUser.data!.accessToken ?? "";
Map<String, String> queryParameters = {};
if (serviceProviderID != null) {
queryParameters = {
"ProviderID": serviceProviderID,
"IsRenew": isRenew.toString(),
};
}
return await injector.get<ApiClient>().getJsonForObject(
(json) => SubscriptionModel.fromJson(json),
ApiConsts.getSubscriptionBySP,
token: t,
queryParameters: queryParameters,
);
}
@override
Future<MResponse> calculationUpgradePrice(
String? serviceProviderID, String? newSubscription) async {
String t = AppState().getUser.data!.accessToken ?? "";
Map<String, String> queryParameters = {};
if (serviceProviderID != null) {
queryParameters = {
"ServiceProviderID": serviceProviderID,
"NewSubscription": newSubscription!,
};
}
return await injector.get<ApiClient>().getJsonForObject(
(json) => MResponse.fromJson(json),
ApiConsts.calculationUpgradePrice,
token: t,
queryParameters: queryParameters,
);
}
@override
Future<MResponse> payForProviderSubscription(Map<String, dynamic> map) async {
String t = AppState().getUser.data!.accessToken ?? "";
return await injector.get<ApiClient>().postJsonForObject(
(json) => MResponse.fromJson(json),
ApiConsts.payFortOrder_ProviderSubscription_Create,
map,
token: t,
);
}
@override
Future<List<BranchSelectionModel>> getSPBranchUser_Get(
Map<String, String> map) async {
String t = AppState().getUser.data!.accessToken ?? "";
GenericRespModel genericRespModel =
await injector.get<ApiClient>().getJsonForObject(
(json) => GenericRespModel.fromJson(json),
ApiConsts.getSPBranchUser_Get,
token: t,
queryParameters: map,
);
List<BranchSelectionModel> branchList = [];
if (genericRespModel.data != null) {
List<BranchDetailModel> branches = [];
List<BranchUser> branchUsers = [];
// List<BranchUsersDatum>.from(json["data"]!.map((x) => BranchUsersDatum.fromJson(x))
branches = List<BranchDetailModel>.from(genericRespModel.data["branches"]
["data"]!
.map((x) => BranchDetailModel.fromJson(x)));
branchUsers = List<BranchUser>.from(genericRespModel.data["branchUsers"]
["data"]!
.map((x) => BranchUser.fromJson(x)));
for (int i = 0; i < branches.length; i++) {
List<UserSelectionModel> availableUsers = [];
for (int j = 0; j < branchUsers.length; j++) {
if (branches[i].id == branchUsers[j].serviceProviderBranchID) {
availableUsers.add(UserSelectionModel(
userId: branchUsers[j].id,
userName:
("${branchUsers[j].firstName ?? ""} ${branchUsers[j].lastName}"),
isSelected: false));
}
}
branchList.add(BranchSelectionModel(
branchId: branches[i].id ?? 0,
branchName: branches[i].branchName ?? "",
isSelected: false,
usersList: availableUsers));
}
}
return branchList;
}
@override
Future<SubscriptionModel> getMySubscriptions(
String? serviceProviderID) async {
String t = AppState().getUser.data!.accessToken ?? "";
Map<String, String> queryParameters = {};
if (serviceProviderID != null) {
queryParameters = {
"ID": serviceProviderID,
};
}
return await injector.get<ApiClient>().getJsonForObject(
(json) => SubscriptionModel.fromJson(json),
ApiConsts.getAllSubscriptions,
token: t,
queryParameters: queryParameters);
}
}

@ -193,3 +193,9 @@ enum ChatTypeEnum {
ads,
requestOffer,
}
enum SubscriptionTypeEnum {
current,
upgrade,
downgrade,
}

@ -9,6 +9,10 @@ import 'package:mc_common_app/services/payments_service.dart';
import 'package:mc_common_app/utils/enums.dart';
import 'package:mc_common_app/utils/navigator.dart';
import 'package:mc_common_app/utils/utils.dart';
import 'package:mc_common_app/view_models/subscriptions_view_model.dart';
import 'package:provider/provider.dart';
import '../classes/app_state.dart';
class PaymentVM extends ChangeNotifier {
final PaymentService paymentService;
@ -49,6 +53,8 @@ class PaymentVM extends ChangeNotifier {
}
Future<void> onContinuePressed(BuildContext context, {required PaymentTypes paymentType}) async {
switch (selectedPaymentMethod) {
case PaymentMethods.mada:
// TODO: Handle this case.
@ -163,6 +169,7 @@ class PaymentVM extends ChangeNotifier {
// TOD0: we have to take payment confirmation methods from Backend team and make success callbacks like onAdsPaymentSuccess
switch (paymentTypeEnum) {
case PaymentTypes.subscription:
onSubscriptionSuccess(context);
break;
case PaymentTypes.appointment:
log("Appointment Payment has been Succeeded");
@ -182,6 +189,20 @@ class PaymentVM extends ChangeNotifier {
);
}
onSubscriptionSuccess(BuildContext context){
pop(context);
pop(context);
pop(context);
context.read<SubscriptionsVM>().getMySubscriptions(
AppState()
.getUser
.data
?.userInfo
?.providerId
.toString() ??
"");
}
Future<void> onVisaCardSelected(BuildContext context, PaymentTypes paymentType) async {
currentPaymentType = paymentType;
switch (currentPaymentType) {

@ -0,0 +1,182 @@
import 'dart:convert';
import 'package:mc_common_app/classes/app_state.dart';
import 'package:mc_common_app/models/general_models/m_response.dart';
import 'package:mc_common_app/models/subscriptions_models/branch_user_selection_model.dart';
import 'package:mc_common_app/models/subscriptions_models/subscription_model.dart';
import 'package:mc_common_app/utils/enums.dart';
import 'package:mc_common_app/view_models/base_view_model.dart';
import 'package:mc_common_app/widgets/dropdown/dropdow_field.dart';
import '../repositories/subscription_repo.dart';
class SubscriptionsVM extends BaseVM {
final SubscriptionRepo subscriptionRepo;
SubscriptionsVM({required this.subscriptionRepo});
//All Subscriptions
int selectedIndex = 0;
late DropValue selectedMothlyTab;
List<DropValue> monthlyTabs = [];
late SubscriptionModel allSubscriptions;
List<Subscription> tempSubscriptions = [];
//My Subscriptions
//All Subscriptions
getAllAvailableSubscriptions(String? serviceProviderID) async {
selectedIndex = 0;
setState(ViewState.busy);
allSubscriptions =
await subscriptionRepo.getAllSubscriptions(serviceProviderID);
if (allSubscriptions.messageStatus == 1) {
monthlyTabs.clear();
var idSet = <int>{};
for (var d in allSubscriptions.data ?? []) {
if (idSet.add(d.durationDays ?? 0)) {
monthlyTabs.add(DropValue(
d.durationDays, _convertDaysToMonths(d.durationDays ?? 0), ""));
}
}
monthlyTabs.sort((a, b) => a.value.compareTo(b.value));
selectedMothlyTab = monthlyTabs.first;
filterSubscriptions();
setState(ViewState.idle);
} else {
setState(ViewState.error);
}
}
getSubscriptionBySP(String serviceProviderID, bool isRenew) async {
selectedIndex = 0;
setState(ViewState.busy);
allSubscriptions =
await subscriptionRepo.getSubscriptionBySP(serviceProviderID, isRenew);
if (allSubscriptions.messageStatus == 1) {
monthlyTabs.clear();
var idSet = <int>{};
for (var d in allSubscriptions.data ?? []) {
if (idSet.add(d.durationDays ?? 0)) {
monthlyTabs.add(DropValue(
d.durationDays, _convertDaysToMonths(d.durationDays ?? 0), ""));
}
}
monthlyTabs.sort((a, b) => a.value.compareTo(b.value));
selectedMothlyTab = monthlyTabs.first;
filterSubscriptions();
setState(ViewState.idle);
} else {
setState(ViewState.error);
}
}
String newPrice = "";
calculationUpgradePrice(
String? serviceProviderID, String? newSubscription) async {
setState(ViewState.busy);
MResponse mResponse = await subscriptionRepo.calculationUpgradePrice(
serviceProviderID, newSubscription);
if (mResponse.messageStatus == 1) {
setState(ViewState.idle);
newPrice = mResponse.data.toString();
} else {
setState(ViewState.error);
}
}
Future<MResponse> payForSubscription(
int subscriptionId, bool isStartNow, bool isReview, String amount,
{bool isDegrade = false,
List<int>? listOfBranches,
List<int>? listOfUsers}) async {
Map<String, dynamic> map;
if (isDegrade) {
map = {
// "id": subscription.id.toString(),
// "payFortOrderID": 0,
"providerID":
AppState().getUser.data?.userInfo?.providerId.toString() ?? "",
"subscriptionID": subscriptionId.toString(),
"isStartNow": isStartNow.toString(),
"subscriptionAmount": amount,
"isRenew": isReview.toString(),
"listOfBranches": listOfBranches,
"listOfUsers": listOfUsers
};
} else {
map = {
// "id": subscription.id.toString(),
// "payFortOrderID": 0,
"providerID":
AppState().getUser.data?.userInfo?.providerId.toString() ?? "",
"subscriptionID": subscriptionId.toString(),
"isStartNow": isStartNow.toString(),
"subscriptionAmount": amount,
"isRenew": isReview.toString()
// "listOfBranches": [],
// "listOfUsers": []
};
}
MResponse mResponse =
await subscriptionRepo.payForProviderSubscription(map);
return mResponse;
}
List<BranchSelectionModel>? branchSelectionList;
getSPBranchUser_Get() async {
branchSelectionList = null;
Map<String, String> map = {
// "id": subscription.id.toString(),
// "payFortOrderID": 0,
"providerID":
AppState().getUser.data?.userInfo?.providerId.toString() ?? "",
// "listOfBranches": [],
// "listOfUsers": []
};
branchSelectionList = await subscriptionRepo.getSPBranchUser_Get(map);
if (branchSelectionList!.isNotEmpty) {
branchSelectionList!.first.isOpend = true;
}
setState(ViewState.idle);
}
String _convertDaysToMonths(int days) {
final int months = days ~/ 30;
final int remainingDays = days % 30;
String _result = months > 0
? '$months Month${months > 1 ? 's' : ''}${remainingDays > 0 ? ' & ' : ''}'
: '';
_result += remainingDays > 0
? '$remainingDays Day${remainingDays > 1 ? 's' : ''}'
: '';
return _result;
}
filterSubscriptions() {
tempSubscriptions.clear();
for (var element in allSubscriptions.data!) {
if (selectedMothlyTab.id == element.durationDays) {
tempSubscriptions.add(element);
}
}
}
//My Subscriptions
getMySubscriptions(String? serviceProviderID) async {
selectedIndex = 0;
setState(ViewState.busy);
// allSubscriptions = await subscriptionRepo.getAllSubscriptions(serviceProviderID);
allSubscriptions = await subscriptionRepo.getMySubscriptions(serviceProviderID);
if (allSubscriptions.messageStatus == 1) {
// allSubscriptions.data!.sort((a, b) => a.value.compareTo(b.value));
setState(ViewState.idle);
} else {
setState(ViewState.error);
}
}
}

@ -12,8 +12,11 @@ import 'package:provider/provider.dart';
class PaymentMethodsView extends StatelessWidget {
final PaymentTypes paymentType;
final Function? onTempContinue;
const PaymentMethodsView({Key? key, required this.paymentType}) : super(key: key);
const PaymentMethodsView(
{Key? key, required this.paymentType, this.onTempContinue})
: super(key: key);
@override
Widget build(BuildContext context) {
@ -69,8 +72,17 @@ class PaymentMethodsView extends StatelessWidget {
child: ShowFillButton(
maxHeight: 55,
title: "Continue",
onPressed: () {
context.read<PaymentVM>().onContinuePressed(context, paymentType: paymentType);
onPressed: () async {
bool isNeedToCallPayment = true;
if (onTempContinue != null) {
isNeedToCallPayment = await onTempContinue!();
}
if (isNeedToCallPayment) {
context.read<PaymentVM>().onContinuePressed(
context,
paymentType: paymentType,
);
}
},
backgroundColor: MyColors.darkPrimaryColor,
),

Loading…
Cancel
Save