This commit is contained in:
2023-01-23 19:47:40 +00:00
parent 176f31c591
commit 82adb594ab
3 changed files with 54 additions and 34 deletions

View File

@@ -88,13 +88,20 @@ namespace Sockeye.Biz
} }
internal static async Task<bool> ParseVendorNotificationData(VendorNotification vn, AyContext ct, ILogger log) internal static async Task<bool> ParseVendorNotificationData(VendorNotification vn, AyContext ct, ILogger log)
{ {
try try
{ {
var jData = JObject.Parse(vn.VendorData); var jData = JObject.Parse(vn.VendorData);
#if (DEBUG)
if (vn.VendorData.Contains("coupon"))
{
//trying to find out where the coupon code key is located in the order
System.Diagnostics.Debugger.Break();
}
#endif
//It's a test purchase, no need to process it any further...or is there?? //It's a test purchase, no need to process it any further...or is there??
if (jData["order_notification"]["purchase"]["is_test"].Value<bool>() == true) if (jData["order_notification"]["purchase"]["is_test"].Value<bool>() == true)
{ {
@@ -108,8 +115,6 @@ namespace Sockeye.Biz
throw new System.FormatException($"Vendor data unexpected format:{vn.VendorData}"); throw new System.FormatException($"Vendor data unexpected format:{vn.VendorData}");
} }
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
#region CUSTOMER MAKE OR LOCATED #region CUSTOMER MAKE OR LOCATED
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@@ -172,6 +177,9 @@ namespace Sockeye.Biz
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
var salesOrderNumber = jData["order_notification"]["purchase"]["purchase_id"].Value<string>(); var salesOrderNumber = jData["order_notification"]["purchase"]["purchase_id"].Value<string>();
#warning Is this processing the date into UTC properly??
//https://www.newtonsoft.com/json/help/html/DatesInJSON.htm
var purchaseDate = jData["order_notification"]["purchase"]["purchase_date"].Value<DateTime>();
if (await ct.Purchase.AnyAsync(z => z.SalesOrderNumber == salesOrderNumber)) if (await ct.Purchase.AnyAsync(z => z.SalesOrderNumber == salesOrderNumber))
throw new System.ApplicationException($"Sales order already exists: {salesOrderNumber} will not be processed"); throw new System.ApplicationException($"Sales order already exists: {salesOrderNumber} will not be processed");
@@ -182,39 +190,29 @@ namespace Sockeye.Biz
foreach (JObject jPurchase in jaPurchaseList) foreach (JObject jPurchase in jaPurchaseList)
{ {
Purchase p = new Purchase(); Purchase p = new Purchase();
p.PurchaseDate = purchaseDate;
p.CustomerId = customer.Id; p.CustomerId = customer.Id;
p.VendorId = vn.VendorId; p.VendorId = vn.VendorId;
p.Notes = vn.VendorData;//redundantly keep it
p.SalesOrderNumber = salesOrderNumber; p.SalesOrderNumber = salesOrderNumber;
p.Currency = jPurchase["currency"].Value<string>(); var SalesItemProductVendorCode = jPurchase["product_id"].Value<string>();
var pId = jPurchase["product_id"].Value<string>(); var product = await ct.Product.AsNoTracking().FirstOrDefaultAsync(z => z.VendorCode == SalesItemProductVendorCode) ?? throw new System.ArgumentOutOfRangeException($"Vendor product code:{SalesItemProductVendorCode} was not found in Sockeye Products, record not processed");
var product = await ct.Product.AsNoTracking().FirstOrDefaultAsync(z => z.VendorCode == pId) ?? throw new System.ArgumentOutOfRangeException($"Vendor product code:{pId} was not found in Sockeye Products, record not processed");
p.ProductId = product.Id; p.ProductId = product.Id;
p.PGroup = product.PGroup; p.PGroup = product.PGroup;
p. p.Currency = jPurchase["accounting"]["currency"].Value<string>();
p.ProductNet = jPurchase["accounting"]["product_net"].Value<decimal>();
if (p.ProductId == 0) p.Discount = jPurchase["accounting"]["discount"].Value<decimal>();
p.VendorFee = jPurchase["accounting"]["margin_net"].Value<decimal>();
switch (p.PGroup) p.Revenue = jPurchase["accounting"]["your_revenue"].Value<decimal>();
{ p.CouponCode = "UNKNOWN WHERE IN VENDOR DATA CONTAINS COUPON CODE";
case ProductGroup.Misc: p.Quantity = jPurchase["quantity"].Value<int>();
//not a licensed product, probably misc custom or some fee or etc p.VendorNotificationId = vn.Id;
p.Processed = true;//flag no further processing is required PurchaseBiz pbiz = PurchaseBiz.GetBiz(ct);
break; p = await pbiz.CreateAsync(p);
case ProductGroup.AyaNova7: if (p == null)
{
break; //did not save, throw an error
case ProductGroup.RavenPerpetual: throw new System.ApplicationException($"Error creating purchase: {pbiz.GetErrorsAsString()} for product item: {SalesItemProductVendorCode} vendor data :{vn.VendorData}");
}
break;
case ProductGroup.RavenSubscription:
break;
default://not set or unrecognized
throw new System.NotSupportedException($"Product group {p.PGroup} not recognized or supported for processing into purchase");
}
} }
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
@@ -222,11 +220,12 @@ namespace Sockeye.Biz
} }
catch (Exception ex) catch (Exception ex)
{ {
var err = $"ParseVendorNotificationData: Purchase record {vn.Id}-{vn.Created} triggered exception, see log"; var err = $"ParseVendorNotificationData: VendorNotification record {vn.Id}-{vn.Created} triggered exception, see log";
await NotifyEventHelper.AddOpsProblemEvent(err);//notify, this is serious await NotifyEventHelper.AddOpsProblemEvent(err);//notify, this is serious
log.LogError(ex, err); log.LogError(ex, err);
return false; return false;
} }
return true; //successfully processed so vendor notification should be set to processed by caller
} }
private static void UpdateCustomerFromVendorData(JObject jData, Customer c) private static void UpdateCustomerFromVendorData(JObject jData, Customer c)
@@ -1183,6 +1182,7 @@ namespace Sockeye.Biz
#endregion sample vendor notifications #endregion sample vendor notifications
//order notification json schema on this page down //order notification json schema on this page down
//actual schema: https://api.shareit.com/xml/2.4/ordernotification.xsd
//https://account.mycommerce.com/home/wiki/7479997 //json format //https://account.mycommerce.com/home/wiki/7479997 //json format
//https://account.mycommerce.com/home/wiki/7479805 //overall info //https://account.mycommerce.com/home/wiki/7479805 //overall info

View File

@@ -55,7 +55,7 @@ namespace Sockeye.Models
public bool RenewNoticeSent { get; set; } = false; public bool RenewNoticeSent { get; set; } = false;
public int Quantity { get; set; } = 1; public int Quantity { get; set; } = 1;
public long? VendorNotificationId { get; set; } public long? VendorNotificationId { get; set; }
public bool Processed { get; set; } = false;//indicates it was fully processed and need not be processed by purchase or license generating jobs (all imported data set to processed) public bool Processed { get; set; } = false;//indicates it was fully processed and need not be processed by license generating jobs (all imported data set to processed)
public string Wiki { get; set; } public string Wiki { get; set; }
public List<string> Tags { get; set; } public List<string> Tags { get; set; }
//workaround for notification //workaround for notification

View File

@@ -12,7 +12,27 @@ TODO:
IDEA: if v7 don't process into a license until the newest purchase for the same customer are at least XX minutes old IDEA: if v7 don't process into a license until the newest purchase for the same customer are at least XX minutes old
they almost seem to be done manually by mycommerce but I'd say there's no more than 15 minutes max for all to come in they almost seem to be done manually by mycommerce but I'd say there's no more than 15 minutes max for all to come in
!!! maybe look at email history of previous orders and see what the max delay is between order recepts !!!! !!! maybe look at email history of previous orders and see what the max delay is between order recepts !!!!
// if (p.ProductId == 0)
// switch (p.PGroup)
// {
// case ProductGroup.Misc:
// //not a licensed product, probably misc custom or some fee or etc
// p.Processed = true;//flag no further processing is required
// break;
// case ProductGroup.AyaNova7:
// break;
// case ProductGroup.RavenPerpetual:
// break;
// case ProductGroup.RavenSubscription:
// break;
// default://not set or unrecognized
// throw new System.NotSupportedException($"Product group {p.PGroup} not recognized or supported for processing into purchase");
// }
- JOB: "SOCKBOT" virtual staff member, - JOB: "SOCKBOT" virtual staff member,
sockbot - does everything we have to do manually on a delay if it hasn't been done by us yet sockbot - does everything we have to do manually on a delay if it hasn't been done by us yet