Created
January 6, 2024 08:05
-
-
Save jafar260698/43ab0bf7aa41b689663f80411cb29375 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// sign through Eimzo app | |
Future<bool?> callbackEimzo(CustomDocumentResponse data) async { | |
String direct = Platform.isAndroid ? "uz.yt.idcard.eimzo" : "1563416406"; | |
if (Platform.isAndroid || Platform.isIOS) { | |
bool isInstalled = false; | |
if (Platform.isIOS) { | |
isInstalled = true; | |
} else { | |
isInstalled = await DeviceApps.isAppInstalled(direct); | |
} | |
if (isInstalled) { | |
setLoading(true); | |
_successStatus = false; | |
return _openEimzo(data); | |
} else { | |
String url = Platform.isAndroid | |
? "market://details?id=$direct" | |
: "https://apps.apple.com/app/id$direct"; | |
if (await canLaunchUrl(Uri.parse(url))) { | |
await launchUrl(Uri.parse(url)); | |
} else { | |
throw 'Could not launch $url'; | |
} | |
setLoading(false); | |
return null; | |
} | |
} | |
return null; | |
} | |
Future<bool?> _openEimzo(CustomDocumentResponse data) async { | |
final response = await _repositoryEimzo.getEimzoINNData(); | |
if (response is EimzoDataResponse) { | |
return await _crc32Function(response, data); | |
} else { | |
return false; | |
} | |
} | |
Future<bool?> _crc32Function(EimzoDataResponse response, CustomDocumentResponse data) async { | |
CustomDocumentResponse customDataJson = data; | |
documentId = response.documentId; | |
challange = jsonEncode(customDataJson); | |
docBase64 = base64.encode(utf8.encode(challange!)); | |
var siteId = response.siteId; | |
var docHash = GostHash.hashGost(challange!); | |
var code = siteId! + documentId! + docHash; | |
var crc32 = Crc32.calcHex(code); | |
code += crc32; | |
return await _launchURL(code); | |
} | |
Future<bool?> _launchURL(String code) async { | |
var deepLink = 'eimzo://sign?qc=$code'; | |
await canLaunchUrl(Uri.parse(deepLink)) | |
? launchUrl(Uri.parse(deepLink)) | |
: throw Snack.showErrorSnackBar( | |
title: "error".tr, message: 'Could not launch $deepLink'); | |
return await _getStatus(102); | |
} | |
Future<bool?> _getStatus(int i) async { | |
if (!_successStatus) { | |
if (i > 0) { | |
_checkStatus(); | |
Timer(const Duration(seconds: 3), () => {i -= 3, _getStatus(i)}); | |
} else { | |
debugPrint( | |
"Tizimga kirish ma'lumotlari yangilandi. Boshqadan urinib ko'ring", | |
); | |
return false; | |
} | |
} else { | |
i = 0; | |
return await getUserDataByDocumentId(); | |
} | |
return null; | |
} | |
void _checkStatus() async { | |
final response = | |
await _repositoryEimzo.getEimzoStatus(documentId: documentId ?? ''); | |
if (response is EimzoStatus) { | |
if (response.status == 1) { | |
_successStatus = true; | |
} | |
} | |
} | |
Future<bool> getUserDataByDocumentId() async { | |
setLoading(true); | |
AuthInfoRequest authInfoRequest = AuthInfoRequest( | |
documentId: documentId, | |
document: docBase64, | |
); | |
final response = | |
await _repositoryEimzo.getAuthInfo(authInfoRequest: authInfoRequest); | |
if (response is AuthInfoResponse) { | |
String inn = | |
(response.subjectCertificateInfo?.subjectName?.inn?.isNotEmpty ?? | |
false) | |
? (response.subjectCertificateInfo?.subjectName?.inn ?? '') | |
: (response.subjectCertificateInfo?.subjectName?.uID ?? ''); | |
if ((LocalSource.instance.getUserInn().replaceAll(' ', '') == inn)) { | |
debugPrint( | |
"INN to`g`ri: ${LocalSource.instance.getUserInn().replaceAll(' ', '')}"); | |
return await postCustomDoc(response); | |
} else { | |
setLoading(false); | |
Snack.showErrorSnackBar( | |
title: "error".tr, | |
message: | |
"INN xato: ${LocalSource.instance.getUserInn().replaceAll(' ', '')}"); | |
return false; | |
} | |
} else { | |
return false; | |
} | |
} | |
Future<bool> postCustomDoc(AuthInfoResponse authResponse) async { | |
String sign = authResponse.pkcs7Attached ?? ''; | |
NewCreateDocumentRequest newCustomDocRequest = NewCreateDocumentRequest( | |
status: '', | |
sign: sign, | |
tin: LocalSource.instance.getUserInn().replaceAll(' ', '')); | |
final response = | |
await _repository.postNewCustomDocument(newCustomDocRequest); | |
if (response is NewCreateDocumentResponse) { | |
debugPrint('success123'); | |
Navigator.pushNamedAndRemoveUntil( | |
AppConstants.navigatorKey.currentContext!, | |
AppRoutes.main, | |
(Route<dynamic> route) => false, | |
); | |
setLoading(false); | |
Snack.showOrderSuccess( | |
statusTitle: 'document_created', backColor: AppColors.green22C); | |
emit(state.copyWith(fileLink: '')); | |
return true; | |
} else { | |
setLoading(false); | |
Snack.showErrorSnackBar(title: "error".tr, message: response); | |
return false; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomDocumentResponse { | |
DocumentDoc? documentDoc; | |
Contract? contract; | |
String? documentId; | |
Owner? owner; | |
Owner? partner; | |
String? info; | |
String? file; | |
CustomDocumentResponse( | |
{this.documentDoc, | |
this.contract, | |
this.documentId, | |
this.owner, | |
this.partner, | |
this.info, | |
this.file}); | |
CustomDocumentResponse.fromJson(Map<String, dynamic> json) { | |
documentDoc = json['DocumentDoc'] != null | |
? DocumentDoc.fromJson(json['DocumentDoc']) | |
: null; | |
contract = | |
json['Contract'] != null ? Contract.fromJson(json['Contract']) : null; | |
documentId = json['DocumentId']; | |
owner = json['Owner'] != null ? Owner.fromJson(json['Owner']) : null; | |
partner = json['Partner'] != null ? Owner.fromJson(json['Partner']) : null; | |
info = json['Info']; | |
file = json['File']; | |
} | |
Map<String, dynamic> toJson() { | |
final Map<String, dynamic> data = Map<String, dynamic>(); | |
if (documentDoc != null) { | |
data['DocumentDoc'] = documentDoc!.toJson(); | |
} | |
if (contract != null) { | |
data['Contract'] = contract!.toJson(); | |
} | |
data['DocumentId'] = documentId; | |
if (owner != null) { | |
data['Owner'] = owner!.toJson(); | |
} | |
if (partner != null) { | |
data['Partner'] = partner!.toJson(); | |
} | |
data['Info'] = info; | |
data['File'] = file; | |
return data; | |
} | |
} | |
class DocumentDoc { | |
String? documentNo; | |
String? documentDate; | |
String? documentName; | |
DocumentDoc({this.documentNo, this.documentDate, this.documentName}); | |
DocumentDoc.fromJson(Map<String, dynamic> json) { | |
documentNo = json['DocumentNo']; | |
documentDate = json['DocumentDate']; | |
documentName = json['DocumentName']; | |
} | |
Map<String, dynamic> toJson() { | |
final Map<String, dynamic> data = Map<String, dynamic>(); | |
data['DocumentNo'] = documentNo; | |
data['DocumentDate'] = documentDate; | |
data['DocumentName'] = documentName; | |
return data; | |
} | |
} | |
class Contract { | |
String? contractNo; | |
String? contractDate; | |
Contract({this.contractNo, this.contractDate}); | |
Contract.fromJson(Map<String, dynamic> json) { | |
contractNo = json['ContractNo']; | |
contractDate = json['ContractDate']; | |
} | |
Map<String, dynamic> toJson() { | |
final Map<String, dynamic> data = Map<String, dynamic>(); | |
data['ContractNo'] = contractNo; | |
data['ContractDate'] = contractDate; | |
return data; | |
} | |
} | |
class Owner { | |
String? inn; | |
String? name; | |
String? location; | |
Owner({ | |
this.inn, | |
this.name, | |
this.location, | |
}); | |
Owner.fromJson(Map<String, dynamic> json) { | |
inn = json['Inn']; | |
name = json['Name']; | |
location = json['Location']; | |
} | |
Map<String, dynamic> toJson() { | |
final Map<String, dynamic> data = Map<String, dynamic>(); | |
data['Inn'] = inn; | |
data['Name'] = name; | |
data['Location'] = location; | |
return data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment