This commit is contained in:
2023-02-06 22:18:22 +00:00
parent 5ad6e67ff9
commit 6d536b9e92

View File

@@ -116,21 +116,19 @@ namespace Sockeye.Biz
if (isV7 && isLessThanV7Age)
continue;
License newLicense = new License();
//Get last license if any, set up some basic stuff common to all license types
var firstPurchase = purchaseGroup.First();
var lastLicense = await ct.License.AsNoTracking().OrderByDescending(z => z.Id).FirstOrDefaultAsync(z => z.CustomerId == firstPurchase.CustomerId && z.PGroup == firstPurchase.PGroup);
newLicense.CustomerId = firstPurchase.CustomerId;
newLicense.Active = false;
newLicense.RegTo = firstPurchase.RegTo;
//if v7 license then lookup last license for same pgroup for same customer, if none then consider it a new license fresh
//if there is one and it's not entirely expired then duplicate and fixup from purchases in this group
if (isV7)
{
//get one representative product in the group, first is fine
var firstPurchase = purchaseGroup.First();
var lastLicense = await ct.License.AsNoTracking().OrderByDescending(z => z.Id).FirstOrDefaultAsync(z => z.CustomerId == firstPurchase.CustomerId && z.PGroup == firstPurchase.PGroup);
var newLicense = new License();
newLicense.CustomerId = firstPurchase.CustomerId;
newLicense.Active = false;
newLicense.RegTo = firstPurchase.RegTo;
newLicense.FetchEmail = purchaseGroupCustomer.EmailAddress;
//is there a prior license?
@@ -284,22 +282,85 @@ namespace Sockeye.Biz
log.LogError(err);
continue;
}//switch product code
}//each purchase in purchasegroup
//license done ready to save not active so still requires manual intervention but should be substantially ready to send out by here fingers crossed!
}//if v7 block
else
{
//it's a RAVEN license
//iterate the purchases and update / set the license
foreach (var purchase in purchaseGroup)
{
var product = await ct.Product.AsNoTracking().FirstOrDefaultAsync(z => z.Id == purchase.ProductId);//should *always* exist
if (product == null)
{
var err = $"SockBotProcessPurchasesIntoLicenses purchase: {purchase.Id} has un-matchable product id: {purchase.ProductId}";
//serious issue requires immediate notification
await NotifyEventHelper.AddOpsProblemEvent(err);
log.LogError(err);
continue;
}
}
/*
301028317 AyaNova perpetual single user license includes one year maintenance plan perpetual Product 12 months HD1 Aug 15, 2022, 9:07 PM
301028467 AyaNova subscription one user monthly subscriptionmonthly Product monthly HD1 Aug 18, 2022, 1:21 AM
301028468 AyaNova subscription one user yearly subscriptionyearly Product 12 months HD1 Aug 18, 2022, 1:25 AM
301033167 AyaNova subscription additional 250 customer users monthly 250customerusersmonthly Product monthly HD1 Oct 6, 2022, 12:56 AM
301033168 AyaNova subscription additional 250 customer users yearly 250customerusersyearly Product 12 months HD1 Oct 6, 2022, 12:59 AM
*/
//RAVEN licenses have one week padding to be on the safe side
var dtOneYear = DateTime.UtcNow.AddYears(1).AddDays(7);
var dtOneMonth = DateTime.UtcNow.AddMonths(1).AddDays(7);
switch (product.VendorCode)
{
case "301028317"://perpetual
newLicense.Users = purchase.Quantity;
newLicense.MaintenanceExpire = dtOneYear;
break;
case "301028467"://subscription monthly
newLicense.Users = purchase.Quantity;
newLicense.MaintenanceExpire = dtOneMonth;
//FUTURE: for now subscriptions all 20gb if ever add ability to go higher max data with product code etc then remove this
newLicense.MaxDataGB = 20;
break;
case "301028468"://subscription yearly
newLicense.Users = purchase.Quantity;
newLicense.MaintenanceExpire = dtOneYear;
//FUTURE: for now subscriptions all 20gb if ever add ability to go higher max data with product code etc then remove this
newLicense.MaxDataGB = 20;
break;
case "301033167"://Customer users monthly price
case "301033168"://Customer users yearly price
newLicense.CustomerUsers = purchase.Quantity;
break;
default:
var err = $"SockBotProcessPurchasesIntoLicenses purchase: {purchase.Id} has product not part of RAVEN products expected: {product.Name}-{product.VendorCode}";
//serious issue requires immediate notification
await NotifyEventHelper.AddOpsProblemEvent(err);
log.LogError(err);
continue;
}//switch product code
}//each purchase in purchasegroup
}
//IF raven license and have what is likely a recognizable dbid that ends in an = symbol then just make the new license and cancel the last one if that's necessary (NARRATOR: it wasn't, raven only ever fetches the newest)
// log.LogDebug($"Processing purchase id:{purchaseGroup[0].Id},purchasedate:{purchaseGroup.PurchaseDate}, custid:{purchaseGroup.CustomerId}");
//we have a new savable license at this point
if (newLicense != null)
{
LicenseBiz lbiz = LicenseBiz.GetBiz(ct);
newLicense = await lbiz.CreateAsync(newLicense);
if (newLicense == null)
{
//did not save, throw an error
throw new System.ApplicationException($"Error creating purchase: {lbiz.GetErrorsAsString()} for product item: {SalesItemProductVendorCode} vendor data :{vn.VendorData}");
}
}