This commit is contained in:
1235
server/generator/SockBotProcessPurchasesIntoLicenses.cs
Normal file
1235
server/generator/SockBotProcessPurchasesIntoLicenses.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -109,10 +109,31 @@ namespace Sockeye.Biz
|
|||||||
//this is not the expected format data, stop processing and alert:
|
//this is not the expected format data, stop processing and alert:
|
||||||
throw new System.FormatException($"Vendor data unexpected format:{vn.VendorData}");
|
throw new System.FormatException($"Vendor data unexpected format:{vn.VendorData}");
|
||||||
}
|
}
|
||||||
|
//parse purchases collection needed up front as it potentially contains Customer record relevant data
|
||||||
|
var jaPurchaseList = (JArray)jData["order_notification"]["purchase"]["purchase_item"];
|
||||||
|
string RavenDBId = string.Empty;
|
||||||
|
foreach (JObject jPurchase in jaPurchaseList)
|
||||||
|
{
|
||||||
|
/////DATABASE ID if available used to matchup
|
||||||
|
//Capture raven database id if present
|
||||||
|
if (jPurchase["additional_information"] != null)
|
||||||
|
{
|
||||||
|
var jaAdditionalItems = (JArray)jPurchase["additional_information"];
|
||||||
|
foreach (JObject jAdditionalItem in jaAdditionalItems)
|
||||||
|
{
|
||||||
|
if (jAdditionalItem["additional_id"] != null && jAdditionalItem["additional_id"].Value<string>() == "DATABASEID")
|
||||||
|
{
|
||||||
|
RavenDBId = jAdditionalItem["additional_value"].Value<string>();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
#region CUSTOMER MAKE OR LOCATED
|
#region CUSTOMER MAKE OR LOCATED
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//Note: always use reg name not customer name as it may vary between the two and regname is the one we care about
|
||||||
var jCustomerName = jData["order_notification"]["purchase"]["customer_data"]["reg_name"].Value<string>() ?? throw new System.FormatException($"Vendor data empty reg_name:{vn.VendorData}");
|
var jCustomerName = jData["order_notification"]["purchase"]["customer_data"]["reg_name"].Value<string>() ?? throw new System.FormatException($"Vendor data empty reg_name:{vn.VendorData}");
|
||||||
if (jData["order_notification"]["purchase"]["customer_data"]["delivery_contact"]["email"] == null)//we can't process orders with no email at all hard no
|
if (jData["order_notification"]["purchase"]["customer_data"]["delivery_contact"]["email"] == null)//we can't process orders with no email at all hard no
|
||||||
throw new System.FormatException($"Vendor data empty email:{vn.VendorData}");
|
throw new System.FormatException($"Vendor data empty email:{vn.VendorData}");
|
||||||
@@ -121,11 +142,22 @@ namespace Sockeye.Biz
|
|||||||
|
|
||||||
var customerBiz = CustomerBiz.GetBiz(ct);
|
var customerBiz = CustomerBiz.GetBiz(ct);
|
||||||
|
|
||||||
|
|
||||||
//attempt to match to existing customer
|
//attempt to match to existing customer
|
||||||
//account number is most ideal match, name second but could be multiple in sockeye from rockfish sites so name will start the same, finally email if nothing else
|
//databaseID for raven is best match,account number is next most ideal match, , then name but could be multiple in sockeye from rockfish sites so name will start the same, finally email if nothing else
|
||||||
Customer customer = await ct.Customer.AsNoTracking().FirstOrDefaultAsync(z => z.AccountNumber == jCustomerAccountNumber)
|
Customer customer = null;
|
||||||
?? await ct.Customer.AsNoTracking().FirstOrDefaultAsync(z => z.Name.StartsWith(jCustomerName))
|
|
||||||
?? await ct.Customer.AsNoTracking().FirstOrDefaultAsync(z => z.EmailAddress == jCustomerEmail);
|
//First best match is RavenDBID
|
||||||
|
if (!string.IsNullOrWhiteSpace(RavenDBId))
|
||||||
|
customer = await ct.Customer.AsNoTracking().FirstOrDefaultAsync(z => z.DbId == RavenDBId);
|
||||||
|
|
||||||
|
//if not found then try match in order of best matching
|
||||||
|
if (customer == null)
|
||||||
|
customer = await ct.Customer.AsNoTracking().FirstOrDefaultAsync(z => z.AccountNumber == jCustomerAccountNumber)
|
||||||
|
?? await ct.Customer.AsNoTracking().FirstOrDefaultAsync(z => z.Name.StartsWith(jCustomerName))
|
||||||
|
?? await ct.Customer.AsNoTracking().FirstOrDefaultAsync(z => z.EmailAddress == jCustomerEmail);
|
||||||
|
|
||||||
|
//still no match, consider it a new customer
|
||||||
if (customer == null)
|
if (customer == null)
|
||||||
{
|
{
|
||||||
//New customer
|
//New customer
|
||||||
@@ -181,8 +213,6 @@ namespace Sockeye.Biz
|
|||||||
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");
|
||||||
|
|
||||||
//iterate purchase items array
|
//iterate purchase items array
|
||||||
var jaPurchaseList = (JArray)jData["order_notification"]["purchase"]["purchase_item"];
|
|
||||||
|
|
||||||
foreach (JObject jPurchase in jaPurchaseList)
|
foreach (JObject jPurchase in jaPurchaseList)
|
||||||
{
|
{
|
||||||
Purchase p = new Purchase();
|
Purchase p = new Purchase();
|
||||||
@@ -203,19 +233,8 @@ namespace Sockeye.Biz
|
|||||||
p.Revenue = jPurchase["accounting"]["your_revenue"].Value<decimal>();
|
p.Revenue = jPurchase["accounting"]["your_revenue"].Value<decimal>();
|
||||||
}
|
}
|
||||||
|
|
||||||
//Capture raven database id if present
|
if (!string.IsNullOrWhiteSpace(RavenDBId))
|
||||||
if (jPurchase["additional_information"] != null)
|
p.DbId = RavenDBId;
|
||||||
{
|
|
||||||
var jaAdditionalItems = (JArray)jPurchase["additional_information"];
|
|
||||||
foreach (JObject jAdditionalItem in jaAdditionalItems)
|
|
||||||
{
|
|
||||||
if (jAdditionalItem["additional_id"] != null && jAdditionalItem["additional_id"].Value<string>() == "DATABASEID")
|
|
||||||
{
|
|
||||||
p.DbId = jAdditionalItem["additional_value"].Value<string>();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (jPurchase["promotion_coupon"] != null)
|
if (jPurchase["promotion_coupon"] != null)
|
||||||
p.CouponCode = jPurchase["promotion_coupon"].Value<string>();
|
p.CouponCode = jPurchase["promotion_coupon"].Value<string>();
|
||||||
|
|||||||
4
todo.txt
4
todo.txt
@@ -1,7 +1,9 @@
|
|||||||
TODO:
|
TODO:
|
||||||
|
|
||||||
|
Licenses JOB
|
||||||
|
|
||||||
|
- VendorNotifications, add match by dbid to customer matching code
|
||||||
|
|
||||||
Then on to licenses job
|
|
||||||
then on to all the basics, fetch licenses for v7 and v8, trial request processing trigger route, trial subscription server processing and trigger route
|
then on to all the basics, fetch licenses for v7 and v8, trial request processing trigger route, trial subscription server processing and trigger route
|
||||||
|
|
||||||
- JOB: Process purchases that are from vendor notification
|
- JOB: Process purchases that are from vendor notification
|
||||||
|
|||||||
Reference in New Issue
Block a user