private void showStoredData(Data_AppUserWallet wal) { PriceAndText price = wal.CalucateCost(); TitleId.Text = wal.Title; userName.Text = sd.LoggedOnUserName; InfoText.Text = wal.DisplayLinesAsHTML(); CalcInfo.Text = price.Explained; commitTextDiv.Visible = true; CalcInfoDiv.Visible = true; alterStep1DivVisibility(false, null, 0, 0, 0, 0); CalcInfoDiv.Visible = true; CommitDiv.Visible = false; PaymentInstruction.Visible = true; paypalAmount.Text = String.Format("{0:0.00} USD", price.FinalPrice); paypalLink.HRef = String.Format("https://PayPal.me/NiceAPI/{0:0.00}usd", price.FinalPrice); try { BitcoinPrice.BitcoinPriceInfos currentPrice = BitcoinPrice.PriceFromGecko(); btcAmount.Text = String.Format("{0:0.00000} BTC", price.FinalPrice / currentPrice.btc.PriceInUSD); bchAmount.Text = String.Format("{0:0.00000} BCH", price.FinalPrice / currentPrice.bch.PriceInUSD); } catch { } }
public void RetrieveAll(d1_Data_AppUserWallet d, IMyLog log) { foreach (string f1 in Directory.GetFiles(FolderNames.GetFolder(NiceSystemInfo.DEFAULT, MyFolders.ASP_UserWalletFolder_))) { string email = Data_AppUserWalletHandling_File.GetEmailFromFileName(Path.GetFileName(f1)); Data_AppUserWallet w1 = RetrieveOne(email, log); if (w1 != null) { d(w1); } } }
protected void Commit_Click(object sender, EventArgs e) { IMyLog logUpgrade = MyLog.GetLogger("Upgrade"); try { UpdateInfo priceInfo = getHardcodedPriceInfoOrGoBackToPricePage(); int howManyNumbers = 0; int.TryParse(HowManyNumbers.SelectedItem.Value, out howManyNumbers); int howManyMessages = 0; int.TryParse(HowManyMessages.SelectedItem.Value, out howManyMessages); int howManyTopups = 0; int.TryParse(HowManyTopups.SelectedItem.Value, out howManyTopups); int fullpayment = 0; int.TryParse(FullPayment.SelectedItem.Value, out fullpayment); logUpgrade.Info("Commit"); Data_AppUserWallet wal = Data_AppUserWallet.Create( sd.LoggedOnUserEmail, TitleId.Text, priceInfo.Info, priceInfo.Type, new AmountAndPrice(howManyNumbers, GetPrice(priceInfo.Number)), new AmountAndPrice(howManyMessages, GetPrice(priceInfo.Message)), new AmountAndPrice(howManyTopups, GetPrice(priceInfo.Month)), new AmountAndPrice(1, GetPrice(priceInfo.OneTimeSetup)), new AmountAndPrice(fullpayment, GetPrice(priceInfo.FullPayment))); string emailBody = wal.GetEmailBody(sd.LoggedOnUserName, sd.LoggedOnUserEmail); bool alreadyThere; DSSwitch.appWallet().StoreNew(wal, out alreadyThere, logUpgrade); EMail.SendGeneralEmail(sd.LoggedOnUserEmail, true, wal.Title, emailBody, new LogForEmailSend(MyLog.GetLogger("Email"))); showStoredData(wal); } catch (DataUnavailableException) { DSSwitch.OnDataUnavailableException(this); } catch (Exception ex) { logUpgrade.Debug(ex.Message); } }
public static string GetEmailBody(this Data_AppUserWallet appUserWallet, string userName, string userEmail) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("<p>Hi {0}</p>\n", userName); sb.AppendLine("You have committed yourself to the following account upgrade:<br>"); sb.AppendFormat("Please visit <a href=\"{0}\">{0}</a> for payment instructions.<br>\n", "https://niceapi.net/Upgrade"); sb.AppendFormat("Your email is {0}\n", userEmail); sb.AppendLine("<br>"); sb.AppendLine(new UpgradeTextList(appUserWallet.DisplayLines).GetAsEmialText); sb.AppendLine("<br>\n"); sb.AppendLine("<pre>" + appUserWallet.CalucateCost().Explained + "</pre>"); sb.AppendLine("<br>\n"); sb.AppendLine("<p>Your NiceApi.net team.</p>"); return(sb.ToString()); }
public Data_AppUserWallet RetrieveOne(string email, IMyLog log) { string filePath = getWalletFullPath(email); Data_AppUserWallet o = Data_AppUserWallet.CreateBlank(); Stream stream = OpenFile.ForRead(filePath, false, false, log); if (stream == null) { return(null); } using (BinaryReader br = new BinaryReader(stream)) { o.ReadFromStream(br); } return(o); }
protected void Calculate_Click(object sender, EventArgs e) { IMyLog logUpgrade = MyLog.GetLogger("Upgrade"); try { UpdateInfo priceInfo = getHardcodedPriceInfoOrGoBackToPricePage(); int howManyNumbers = 0; int.TryParse(HowManyNumbers.SelectedItem.Value, out howManyNumbers); int howManyMessages = 0; int.TryParse(HowManyMessages.SelectedItem.Value, out howManyMessages); int howManyTopups = 0; int.TryParse(HowManyTopups.SelectedItem.Value, out howManyTopups); int fullpayment = 0; int.TryParse(FullPayment.SelectedItem.Value, out fullpayment); Data_AppUserWallet wal = new Data_AppUserWallet( priceInfo.Type, new AmountAndPrice(howManyNumbers, GetPrice(priceInfo.Number)), new AmountAndPrice(howManyMessages, GetPrice(priceInfo.Message)), new AmountAndPrice(howManyTopups, GetPrice(priceInfo.Month)), new AmountAndPrice(1, GetPrice(priceInfo.OneTimeSetup)), new AmountAndPrice(fullpayment, GetPrice(priceInfo.FullPayment))); CalcInfo.Text = wal.CalucateCost().Explained; alterStep1DivVisibility(false, priceInfo, HowManyNumbers.SelectedIndex, HowManyMessages.SelectedIndex, HowManyTopups.SelectedIndex, FullPayment.SelectedIndex ); CalcInfoDiv.Visible = true; CommitDiv.Visible = true; CommitButton.Focus(); } catch (Exception Ex) { logUpgrade.Debug(Ex.Message); } }
public void StoreNew(Data_AppUserWallet data, out bool fileArleadyUsed, IMyLog log) { fileArleadyUsed = false; string file = getWalletFullPath(data.Email); if (File.Exists(file)) { fileArleadyUsed = true; return; } try { using (BinaryWriter bw = new BinaryWriter(OpenFile.ForWrite(file, log))) { data.WriteToStream(bw); } } catch (IOException) { } }
protected void Page_Load(object sender, EventArgs e) { // This comes from a logged in user NiceASP.SessionData.LoggedOnOrRedirectToLogin(Session, Response, Request); sd = ConstantStrings.GetSessionData(Session); if (!IsPostBack) { // check if a committed request exists, if so display it Data_AppUserWallet existingWallet = DSSwitch.appWallet().RetrieveOne( sd.LoggedOnUserEmail, MyLog.GetVoidLogger()); Data_AppUserFile user = DSSwitch.appUser().RetrieveOne(sd.LoggedOnUserEmail, MyLog.GetVoidLogger()); if ((user != null) && (user.AccountStatus != Data_AppUserFile.eUserStatus.free_account)) { MainSection_Normal.Visible = false; TitleId.Text = "Upgrade Request"; string niceName = Data_AppUserFile.GetNiceStatusText(user.AccountStatus); Literal1.Text = "You currently hold a " + niceName + " account. Please contact us to do the upgrade."; } else if ((existingWallet != null) && (existingWallet.HasUpgradeRequest())) { // display existing request showStoredData(existingWallet); } else { // no commit yet UpdateInfo priceInfo = getHardcodedPriceInfoOrGoBackToPricePage(); TitleId.Text = priceInfo.Title + " - Upgrade Request"; userName.Text = sd.LoggedOnUserName; InfoText.Text = new UpgradeTextList(priceInfo.Info).GetAsHTML; alterStep1DivVisibility(true, priceInfo, 0, 0, 0, 0); CalculateButton.Focus(); } } }
public void UpdateAll( string Email, string Title, string[] DisplayLines, Data_AppUserFile.eUserStatus RequestedType, AmountAndPrice Numbers, AmountAndPrice Messages, AmountAndPrice Month, AmountAndPrice Setup, AmountAndPrice FullPayment, IMyLog log) { string filePath = getWalletFullPath(Email); using (Stream stream = OpenFile.ForRead(filePath, true, true, log)) { Data_AppUserWallet r = Data_AppUserWallet.CreateBlank(); //1) read it in BinaryReader br = new BinaryReader(stream); r.ReadFromStream(br); //2) update values r.Email = Email; r.Title = Title; r.DisplayLines = DisplayLines.MyClone(); r.RequestedType = RequestedType; r.Numbers = Numbers.Clone(); r.Messages = Messages.Clone(); r.Month = Month.Clone(); r.Setup = Setup.Clone(); r.FullPayment = FullPayment.Clone(); //3) write it back stream.Seek(0, SeekOrigin.Begin); BinaryWriter bw = new BinaryWriter(stream); r.WriteToStream(bw); } }
public static string DisplayLinesAsHTML(this Data_AppUserWallet appUserWallet) { UpgradeTextList t = new UpgradeTextList(appUserWallet.DisplayLines); return(t.GetAsHTML); }
public static bool HasUpgradeRequest(this Data_AppUserWallet appUserWallet) { return(true); }
public static PriceAndText CalucateCost(this Data_AppUserWallet appUserWallet) { PriceAndText ret = new PriceAndText(); List <string> left = new List <string>(); List <string> rigt = new List <string>(); if ((appUserWallet.Numbers != null) && (appUserWallet.Numbers.Amount != 0)) { left.Add(String.Format("{0:####} Registered Numbers * $ {1:0.00}", appUserWallet.Numbers.Amount, appUserWallet.Numbers.Price)); rigt.Add((appUserWallet.Numbers.Amount * appUserWallet.Numbers.Price).rigtStr()); ret.FinalPrice += appUserWallet.Numbers.Amount * appUserWallet.Numbers.Price; } if ((appUserWallet.Messages != null) && (appUserWallet.Messages.Amount != 0)) { left.Add(String.Format("{0:####} Messages * $ {1:0.00}", appUserWallet.Messages.Amount, appUserWallet.Messages.Price)); rigt.Add((appUserWallet.Messages.Amount * appUserWallet.Messages.Price).rigtStr()); ret.FinalPrice += appUserWallet.Messages.Amount * appUserWallet.Messages.Price; } if ((appUserWallet.Month != null) && (appUserWallet.Month.Amount != 0)) { left.Add(String.Format("{0:##} Month * $ {1:0.00}", appUserWallet.Month.Amount, appUserWallet.Month.Price)); rigt.Add((appUserWallet.Month.Amount * appUserWallet.Month.Price).rigtStr()); ret.FinalPrice += appUserWallet.Month.Amount * appUserWallet.Month.Price; } if ((appUserWallet.Setup != null) && (appUserWallet.Setup.Price != 0)) { left.Add(String.Format("$ {0:0.00} Setup Fee", appUserWallet.Setup.Price)); rigt.Add((appUserWallet.Setup.Price).rigtStr()); ret.FinalPrice += appUserWallet.Setup.Price; } if ((appUserWallet.FullPayment != null) && ((appUserWallet.FullPayment.Amount * appUserWallet.FullPayment.Price) != 0)) { left.Add(String.Format("$ {0:0.00} Payment", appUserWallet.FullPayment.Amount * appUserWallet.FullPayment.Price)); rigt.Add((appUserWallet.FullPayment.Amount * appUserWallet.FullPayment.Price).rigtStr()); ret.FinalPrice += appUserWallet.FullPayment.Amount * appUserWallet.FullPayment.Price; } // make left same length int maxLen = 0; foreach (string l1 in left) { if (l1.Length > maxLen) { maxLen = l1.Length; } } for (int i = 0; i < left.Count; i++) { ret.Explained += left[i].PadRight(maxLen + 1) + rigt[i] + "\n"; } ret.Explained += "".PadRight(maxLen + 1 + rigt[0].Length, '-') + "\n"; ret.Explained += "TOTAL".PadRight(maxLen + 1); ret.Explained += ret.FinalPrice.rigtStr(); return(ret); }