|
@@ -26,17 +26,70 @@ using System.Drawing;
|
|
|
using Image = System.Windows.Controls.Image;
|
|
|
using System.Diagnostics;
|
|
|
using Twilio.Rest.Api.V2010.Account;
|
|
|
+using InABox.Configuration;
|
|
|
+using RazorEngine.Compilation.ImpromptuInterface;
|
|
|
|
|
|
namespace PRSServer.Forms.DatabaseLicense
|
|
|
{
|
|
|
public class CreditCardGrid : DynamicGrid<CreditCardDetails>
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
+ private static readonly EncryptedLocalConfiguration<CreditCardSettings> DetailsConfiguration = new("g6+BoQpyti5bHsTZOY5Nbqq3Q3c90n0m3qZaQ3eAwkk=");
|
|
|
|
|
|
protected override void Reload(Filters<CreditCardDetails> criteria, Columns<CreditCardDetails> columns, ref SortOrder<CreditCardDetails>? sort, Action<CoreTable, Exception> action)
|
|
|
{
|
|
|
-
|
|
|
+ }
|
|
|
+
|
|
|
+ private static CreditCardDetails LoadSaved()
|
|
|
+ {
|
|
|
+ var settings = DetailsConfiguration.Load();
|
|
|
+ var details = new CreditCardDetails
|
|
|
+ {
|
|
|
+ CardNumber = settings.CardNumber,
|
|
|
+ Month = settings.Month,
|
|
|
+ Year = settings.Year,
|
|
|
+ Cvv = settings.Cvv,
|
|
|
+ // If the card number is not blank, it means we loaded from a saved file, and therefore the default should be to still save details
|
|
|
+ SaveDetails = !string.IsNullOrWhiteSpace(settings.CardNumber)
|
|
|
+ };
|
|
|
+ return details;
|
|
|
+ }
|
|
|
+ private static void SaveDetails(CreditCardDetails details)
|
|
|
+ {
|
|
|
+ var settings = new CreditCardSettings
|
|
|
+ {
|
|
|
+ CardNumber = details.CardNumber,
|
|
|
+ Month = details.Month,
|
|
|
+ Year = details.Year,
|
|
|
+ Cvv = details.Cvv
|
|
|
+ };
|
|
|
+ DetailsConfiguration.Save(settings);
|
|
|
+ }
|
|
|
+ private static void ClearDetails()
|
|
|
+ {
|
|
|
+ DetailsConfiguration.Delete();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static bool DoPayment(double amount, [NotNullWhen(true)] out string? transactionID)
|
|
|
+ {
|
|
|
+ var details = LoadSaved();
|
|
|
+ details.Amount = amount;
|
|
|
+
|
|
|
+ var grid = new CreditCardGrid();
|
|
|
+ if (grid.EditItems(new[] { details }))
|
|
|
+ {
|
|
|
+ if (details.SaveDetails)
|
|
|
+ {
|
|
|
+ SaveDetails(details);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ClearDetails();
|
|
|
+ }
|
|
|
+ transactionID = grid.TransactionID;
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ transactionID = null;
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
protected override CreditCardDetails LoadItem(CoreRow row)
|
|
@@ -44,7 +97,7 @@ namespace PRSServer.Forms.DatabaseLicense
|
|
|
return new CreditCardDetails();
|
|
|
}
|
|
|
|
|
|
- public string TransactionID = "";
|
|
|
+ private string TransactionID = "";
|
|
|
|
|
|
protected override void DoValidate(CreditCardDetails[] items, List<string> errors)
|
|
|
{
|
|
@@ -68,12 +121,12 @@ namespace PRSServer.Forms.DatabaseLicense
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- StripeConfiguration.ApiKey = "sk_test_51Lc39sA3OFNLFxjFvH2PYwCpl9DNhkIoce3rskpTXOvoxiFQUIgtYg1MRWrPUIx14lcs9oG4pFVco9UvRSxen0mT00P8AisayJ";
|
|
|
+ StripeConfiguration.ApiKey = "sk_test_51MRSuPIyPMVqmkXN8TeGxDAGBeFx0pLzn3fsHBR8X1oMBKQVwGPEbuv6DNIu0qSmuflpmFfQ4N8c3vzdknKa7G0o00wTOXwCeW";
|
|
|
var cardoptions = new TokenCreateOptions()
|
|
|
{
|
|
|
Card = new TokenCardOptions()
|
|
|
{
|
|
|
- Number = item.CardNumber,
|
|
|
+ Number = item.CardNumber.Replace(" ", ""),
|
|
|
ExpMonth = item.Month,
|
|
|
ExpYear = item.Year,
|
|
|
Cvc = item.Cvv
|
|
@@ -102,8 +155,8 @@ namespace PRSServer.Forms.DatabaseLicense
|
|
|
error = $"{ex.Message}";
|
|
|
}
|
|
|
});
|
|
|
- //if (!String.IsNullOrWhiteSpace(error))
|
|
|
- // throw new Exception(error);
|
|
|
+ if (!String.IsNullOrWhiteSpace(error))
|
|
|
+ throw new Exception(error);
|
|
|
}
|
|
|
|
|
|
protected override void DeleteItems(params CoreRow[] rows)
|
|
@@ -261,6 +314,13 @@ namespace PRSServer.Forms.DatabaseLicense
|
|
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
+ if (!LicenseTrackingItemGrid.LicenseClient.Ping("ping"))
|
|
|
+ {
|
|
|
+ MessageBox.Show("The PRS server is not available right now. Please try again later.");
|
|
|
+ Close();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
Modules.Refresh(true, false);
|
|
|
|
|
|
var license = LoadCurrentLicense();
|
|
@@ -279,6 +339,9 @@ namespace PRSServer.Forms.DatabaseLicense
|
|
|
{
|
|
|
if (CurrentLicense == null) return;
|
|
|
|
|
|
+ var lookups = new RenewalPeriodLookups(null).AsTable("RenewalPeriod");
|
|
|
+ RenewalPeriodEditor.LoadLookups(lookups);
|
|
|
+
|
|
|
RenewalPeriod = LicenseUtils.TimeDiscountLevels().OrderBy(x => x).First();
|
|
|
PayWithStripe.IsEnabled = CanRenew;
|
|
|
if (!PayWithStripe.IsEnabled)
|
|
@@ -331,6 +394,7 @@ namespace PRSServer.Forms.DatabaseLicense
|
|
|
GrossLicenseFee.Value = Gross;
|
|
|
DiscountEditor.Value = Discount;
|
|
|
NettLicenseFee.Value = Net;
|
|
|
+ PayWithStripe.IsEnabled = CanRenew && Net > 0;
|
|
|
}
|
|
|
|
|
|
private class RenewalPeriodLookups : LookupGenerator<object>
|
|
@@ -370,7 +434,7 @@ namespace PRSServer.Forms.DatabaseLicense
|
|
|
|
|
|
private void PayNowClick(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- if (!Client.Ping())
|
|
|
+ if (!LicenseTrackingItemGrid.LicenseClient.Ping("ping"))
|
|
|
{
|
|
|
MessageBox.Show("The PRS server is not available right now. Please try again later.");
|
|
|
return;
|
|
@@ -395,56 +459,57 @@ namespace PRSServer.Forms.DatabaseLicense
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- var ccdetails = new CreditCardDetails()
|
|
|
+ if (!CreditCardGrid.DoPayment(Net, out var transactionID))
|
|
|
+ return;
|
|
|
+
|
|
|
+ /*var grid = new CreditCardGrid();
|
|
|
+ var ccDetails = grid.LoadSaved();
|
|
|
+ ccDetails.Amount = Net;
|
|
|
+ if (grid.EditItems(new CreditCardDetails[] { ccDetails }))
|
|
|
{
|
|
|
- Amount = Net
|
|
|
+ var transactionID = grid.TransactionID;*/
|
|
|
+ var licenseRenewal = new LicenseRenewal
|
|
|
+ {
|
|
|
+ Company = companyInformation,
|
|
|
+ DateRenewed = RenewalDate,
|
|
|
+ OldLicense = CurrentLicense,
|
|
|
+ NewExpiry = NewExpiration,
|
|
|
+ LicenseTracking = Modules.Data.Rows.Select(x => x.ToObject<LicenseTrackingItem>()).ToArray(),
|
|
|
+ Gross = Gross,
|
|
|
+ Discount = Discount,
|
|
|
+ Net = Net,
|
|
|
+ TransactionID = transactionID
|
|
|
};
|
|
|
- var grid = new CreditCardGrid();
|
|
|
- if (grid.EditItems(new CreditCardDetails[] { ccdetails }))
|
|
|
+ string? error = null;
|
|
|
+ License? license = null;
|
|
|
+ Progress.ShowModal("Payment success, renewing license", progress =>
|
|
|
{
|
|
|
- var transactionID = grid.TransactionID;
|
|
|
- var licenseRenewal = new LicenseRenewal
|
|
|
+ try
|
|
|
{
|
|
|
- Company = companyInformation,
|
|
|
- DateRenewed = RenewalDate,
|
|
|
- OldLicense = CurrentLicense,
|
|
|
- NewExpiry = NewExpiration,
|
|
|
- LicenseTracking = Modules.Data.Rows.Select(x => x.ToObject<LicenseTrackingItem>()).ToArray(),
|
|
|
- Gross = Gross,
|
|
|
- Discount = Discount,
|
|
|
- Net = Net,
|
|
|
- TransactionID = transactionID
|
|
|
- };
|
|
|
- string? error = null;
|
|
|
- License? license = null;
|
|
|
- Progress.ShowModal("Payment success, renewing license", progress =>
|
|
|
+ license = GetNewLicense(licenseRenewal);
|
|
|
+ SaveLicense(license);
|
|
|
+ }
|
|
|
+ catch(Exception e)
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- license = GetNewLicense(licenseRenewal);
|
|
|
- SaveLicense(license);
|
|
|
- }
|
|
|
- catch(Exception e)
|
|
|
- {
|
|
|
- error = $"There was an error retrieving your new license:\n\n{e.Message}\n\nPlease contact the PRS team, and keep your transaction ID for future reference. Your transaction ID is '{transactionID}'";
|
|
|
- }
|
|
|
- });
|
|
|
- if(error != null)
|
|
|
+ error = $"There was an error retrieving your new license:\n\n{e.Message}\n\nPlease contact the PRS team, and keep your transaction ID for future reference. Your transaction ID is '{transactionID}'";
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if(error != null)
|
|
|
+ {
|
|
|
+ MessageBox.Show(error);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ MessageBox.Show("License Renewed!");
|
|
|
+
|
|
|
+ if(!LicenseUtils.TryDecryptLicense(license.Data, out var licenseData, out error))
|
|
|
{
|
|
|
MessageBox.Show(error);
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- MessageBox.Show("License Renewed!");
|
|
|
|
|
|
- if(!LicenseUtils.TryDecryptLicense(license.Data, out var licenseData, out error))
|
|
|
- {
|
|
|
- MessageBox.Show(error);
|
|
|
- }
|
|
|
-
|
|
|
- CurrentLicense = licenseData ?? new LicenseData();
|
|
|
- }
|
|
|
+ CurrentLicense = licenseData ?? new LicenseData();
|
|
|
}
|
|
|
+ //}
|
|
|
}
|
|
|
|
|
|
private void OK_Click(object sender, RoutedEventArgs e)
|