public static async Task <ApiResponse> EncryptWallet(string password) { ApiResponse response = new ApiResponse(); try { var regex = new Regex(@"((?=.*[0-9])(?=.*[a-zA-Z])(?=.*[!@#$%^&*\.])[a-zA-Z0-9!@#$%^&*\._-]+)|((?=.*[0-9])(?=.*[a-zA-Z])[a-zA-Z0-9]+)|((?=.*[0-9])(?=.*[!@#$%^&*\.])[0-9!@#$%^&*\._-]+)|((?=.*[!@#$%^&*\.])(?=.*[a-zA-Z])[a-zA-Z!@#$%^&*\._-]+).{7,30}"); var mathches = regex.Matches(password).Cast <Match>(); var gs = mathches.SelectMany(x => x.Groups.Cast <Group>()); if (!gs.Any(x => x.Value.Equals(password) && x.Value.Length >= 8 && x.Value.Length <= 30)) { throw new ApiCustomException(7000001, "invalid password"); } WalletManagement management = new WalletManagement(); await management.EncryptWallet(password); } catch (ApiCustomException ex) { Logger.Singleton.Error(ex.Message); response.Error = new ApiError(ex.ErrorCode, ex.Message); } catch (Exception ex) { Logger.Singleton.Error(ex.Message); response.Error = new ApiError(ex.HResult, ex.Message); } return(response); }
/// <summary> /// change password /// </summary> /// <param name="oldPassword"></param> /// <param name="newPassword"></param> /// <returns></returns> public static async Task <ApiResponse> WalletPassphraseChange(string oldPassword, string newPassword) { ApiResponse response = new ApiResponse(); try { if (oldPassword == newPassword) { throw new ApiCustomException(3000000, "The old password is not the same as the new password"); } WalletManagement management = new WalletManagement(); await management.WalletPassphraseChange(oldPassword, newPassword); } catch (ApiCustomException ex) { Logger.Singleton.Error(ex.Message); response.Error = new ApiError(ex.ErrorCode, ex.Message); } catch (Exception ex) { Logger.Singleton.Error(ex.Message); response.Error = new ApiError(ex.HResult, ex.Message); } return(response); }
public static async Task <ApiResponse> RestoreWalletBackup(string filePath, string password = null) { ApiResponse response = new ApiResponse(); try { if (Path.GetExtension(filePath) == ".fcdatx" && string.IsNullOrEmpty(password)) { throw new ApiInvalidParametersException("password must not null"); } else { WalletManagement management = new WalletManagement(); await management.RestoreWalletBackup(filePath, password); } } catch (ApiCustomException ex) { Logger.Singleton.Error(ex.Message); response.Error = new ApiError(ex.ErrorCode, ex.Message); } catch (Exception ex) { Logger.Singleton.Error(ex.Message); response.Error = new ApiError(ex.HResult, ex.Message); } return(response); }
public static async Task <ApiResponse> BackupWallet(string filePath) { ApiResponse response = new ApiResponse(); try { WalletManagement management = new WalletManagement(); await management.BackupWallet(filePath); } catch (ApiCustomException ex) { Logger.Singleton.Error(ex.Message); response.Error = new ApiError(ex.ErrorCode, ex.Message); } catch (Exception ex) { Logger.Singleton.Error(ex.Message); response.Error = new ApiError(ex.HResult, ex.Message); } return(response); }
public static async Task <ApiResponse> WalletLock() { ApiResponse response = new ApiResponse(); try { WalletManagement management = new WalletManagement(); await management.WalletLock(); } catch (ApiCustomException ex) { Logger.Singleton.Error(ex.ToString()); response.Error = new ApiError(ex.ErrorCode, ex.ToString()); } catch (Exception ex) { Logger.Singleton.Error(ex.ToString()); response.Error = new ApiError(ex.HResult, ex.ToString()); } return(response); }
public static async Task <ApiResponse> WalletPassphrase(string password) { ApiResponse response = new ApiResponse(); try { WalletManagement management = new WalletManagement(); bool result = await management.WalletPassphrase(password); response.Result = Newtonsoft.Json.Linq.JToken.FromObject(result); } catch (ApiCustomException ex) { Logger.Singleton.Error(ex.Message); response.Error = new ApiError(ex.ErrorCode, ex.Message); } catch (Exception ex) { Logger.Singleton.Error(ex.Message); response.Error = new ApiError(ex.HResult, ex.Message); } return(response); }
public string purchasing(SessionModel session) { WalletManagement wm = new WalletManagement(); LogsRepository logs = new LogsRepository(); TransactionRepository tnx = new TransactionRepository(); AirtimeProvision ap = new AirtimeProvision(); string transactionId = DateTime.Now.ToString("yyyyMMddHs"); string epin_tnx_id = string.Empty; Dictionary <string, string> results_epin; string message = string.Empty; Double comm_fee = 0; Double comm_amount = 0; Double total_amount = 0; string sender_message = string.Empty; string receiver_message = string.Empty; string rollback_tc_message = string.Empty; string rollback_epin_message = string.Empty; try { // Debit the sender Dictionary <string, string> results = wm.pay(session.sender, session.amount, session.pin); //If the status is not 0 we consider this as failed transactions if (!results["status"].Equals("OK")) { logs.Save(session.sender, session.receiver, "Trying to charge the sender on MFS", results["description"]); } return("Ntago ubashije kurangura kubera ikibazo kiri kuri Tigocash"); tnx.Save(session.sender, session.receiver, "TC", results["transactionId"], "", double.Parse(session.amount), 0, 0, true); //comm_fee = CommissionModel.getCommission(); comm_fee = 0; comm_amount = Math.Ceiling((Double.Parse(session.amount) * comm_fee)); total_amount = Double.Parse(session.amount) + comm_amount; results_epin = ap.addStock(session.receiver, total_amount.ToString(), results["transactionId"]); if (!results_epin.ContainsKey("status") || !results_epin["status"].ToLower().Equals("ok")) { //Do rollback Dictionary <string, string> rollback_results = wm.rollback(session.sender, session.amount, results["transactionId"], "ROLLBACK TC"); tnx.Save(session.sender, session.receiver, "ROLLBACK TC", rollback_results["transactionId"], "", double.Parse(session.amount), 0, 0, true); string msg = string.Join(", ", results_epin.Select(m => m.Key + ":" + m.Value).ToArray()); logs.Save(session.sender, session.receiver, "Trying to provision the receiver on PRETUPS", msg); // Send notification rollback_tc_message = "Ntago ubashije kurangura kubera ikibazo kiri kuri Epin usubijwe amafaranga yawe " + session.amount.ToString() + ",Murakoze"; //(new SendNotification()).SendSms(sessionValues.sender, rollback_tc_message); return(rollback_tc_message); } tnx.Save(session.sender, session.receiver, "EPIN", results["transactionId"], "", double.Parse(session.amount), comm_amount, total_amount, true); ////// SEND NOTIFICATIONS ////Sender sender_message = "Amafaranga uranguye angana " + total_amount.ToString() + " yoherejwe neza kuri numero " + session.receiver + ",Murakoze"; //(new SendNotification()).SendSms(session.sender, sender_message); ////Receiver receiver_message = "Wakiriye amafaranga angana " + total_amount.ToString() + " avuye kuri numero " + session.sender + ",Murakoze"; //(new SendNotification()).SendSms(session.receiver, receiver_message); return("Waguze neza Epin ukoresheje Tigocash.You bought successfully Epin using Tigocash"); } catch (Exception ex) { // log and return the error message logs.Save(session.sender, session.receiver, "Trying to provision the receiver on PRETUPS", ex.Message); return(ex.Message); } }
public async Task WalletPassphraseChange() { WalletManagement management = new WalletManagement(); await management.WalletPassphraseChange("P@ssw0rd", "NewP@ssw0rd"); }
public async Task WalletLock() { WalletManagement management = new WalletManagement(); await management.WalletLock(); }
public async Task EncryptWallet() { WalletManagement management = new WalletManagement(); await management.EncryptWallet("P@ssw0rd"); }
public async Task RestoreWalletBackup() { WalletManagement management = new WalletManagement(); await management.RestoreWalletBackup("D:\\wallet.dat"); }
public async Task BackupWallet() { WalletManagement management = new WalletManagement(); await management.BackupWallet("D:\\wallet.dat"); }