This commit is contained in:
2023-01-23 00:59:38 +00:00
parent dec9ca1fff
commit ec6ec2701e
17 changed files with 924 additions and 94 deletions

View File

@@ -20,9 +20,9 @@ namespace Sockeye.Biz
/// A Separate job will make licenses
///
/// </summary>
internal static class SockBotProcessPurchases
internal static class SockBotProcessVendorNotifications
{
private static ILogger log = Sockeye.Util.ApplicationLogging.CreateLogger("SockBotProcessPurchases");
private static ILogger log = Sockeye.Util.ApplicationLogging.CreateLogger("SockBotProcessVendorNotifications");
private static DateTime lastSweep = DateTime.MinValue;
private static TimeSpan PROCESS_EVERY_INTERVAL = new TimeSpan(0, 5, 10);//every 5 minutes roughly meaning 15 minutes down is highest fail state
////////////////////////////////////////////////////////////////////////////////////////////////
@@ -36,8 +36,8 @@ namespace Sockeye.Biz
if (ServerBootConfig.MIGRATING) return;//don't do this during migration (migration is one time only so can remove after up and running)
log.LogDebug("Process purchases starting");
await ProcessVendorDataIntoPurchases();
log.LogDebug("Process vendor notifications starting");
await ProcessVendorNotificationDataIntoPurchases();
// log.LogDebug("Process licenses from purchases starting");
// await ProcessPurchasesIntoLicenses();
@@ -45,14 +45,14 @@ namespace Sockeye.Biz
lastSweep = DateTime.UtcNow;
}
private static async Task ProcessVendorDataIntoPurchases()
private static async Task ProcessVendorNotificationDataIntoPurchases()
{
return;
using (AyContext ct = Sockeye.Util.ServiceProviderProvider.DBContext)
{
//get a list of all actionable purchases
//get a list of all actionable vendor notifications
var ProcessablePurchaseIdList = await ct.Purchase
.AsNoTracking()
.Where(z => z.Processed == false
@@ -115,25 +115,25 @@ namespace Sockeye.Biz
internal static async Task ParseVendorNotificationData(Purchase p, AyContext ct, ILogger log)
internal static async Task ParseVendorNotificationData(VendorNotification vn, AyContext ct, ILogger log)
{
if (string.IsNullOrWhiteSpace(p.VendorData)) return;
if (string.IsNullOrWhiteSpace(vn.VendorData)) return;
try
{
var jData = JObject.Parse(p.VendorData);
var jData = JObject.Parse(vn.VendorData);
//fundamentally validate the object is a purchase notification
if (jData["order_notification"]["purchase"]["purchase_id"] == null)
{
//this is not the expected format data, stop processing and alert:
throw new System.FormatException($"Vendor data unexpected format:{p.VendorData}");
throw new System.FormatException($"Vendor data unexpected format:{vn.VendorData}");
}
//CUSTOMER create or locate
var jCustomerName = jData["order_notification"]["purchase"]["customer_data"]["reg_name"].Value<string>() ?? throw new System.FormatException($"Vendor data empty reg_name:{p.VendorData}");
var jCustomerEmail = jData["order_notification"]["purchase"]["customer_data"]["delivery_contact"]["email"].Value<string>() ?? throw new System.FormatException($"Vendor data empty email:{p.VendorData}");
var jCustomerName = jData["order_notification"]["purchase"]["customer_data"]["reg_name"].Value<string>() ?? throw new System.FormatException($"Vendor data empty reg_name:{vn.VendorData}");
var jCustomerEmail = jData["order_notification"]["purchase"]["customer_data"]["delivery_contact"]["email"].Value<string>() ?? throw new System.FormatException($"Vendor data empty email:{vn.VendorData}");
var customerBiz = CustomerBiz.GetBiz(ct);
@@ -148,7 +148,7 @@ namespace Sockeye.Biz
UpdateCustomerFromVendorData(jData, jCustomerEmail, c);
c = await customerBiz.CreateAsync(c);
if (c == null)
throw new System.ApplicationException($"Error creating new Customer: {customerBiz.GetErrorsAsString()} vendor data :{p.VendorData}");
throw new System.ApplicationException($"Error creating new Customer: {customerBiz.GetErrorsAsString()} vendor data :{vn.VendorData}");
}
else
{
@@ -156,7 +156,7 @@ namespace Sockeye.Biz
UpdateCustomerFromVendorData(jData, jCustomerEmail, c);
c = await customerBiz.PutAsync(c);
if (c == null)
throw new System.ApplicationException($"Error updating existing Customer: {customerBiz.GetErrorsAsString()} vendor data :{p.VendorData}");
throw new System.ApplicationException($"Error updating existing Customer: {customerBiz.GetErrorsAsString()} vendor data :{vn.VendorData}");
}
var salesOrderNumber = jData["order_notification"]["purchase"]["purchase_id"].Value<string>();
@@ -166,11 +166,14 @@ namespace Sockeye.Biz
//ok, turn this into a fully realized Purchase record
//Product group
}
catch (Exception ex)
{
var err = $"ParseVendorNotificationData: Purchase record {p.Id}-{p.PurchaseDate} triggered exception, see log";
var err = $"ParseVendorNotificationData: Purchase record {vn.Id}-{vn.PurchaseDate} triggered exception, see log";
await NotifyEventHelper.AddOpsProblemEvent(err);//notify, this is serious
log.LogError(ex, err);
}
@@ -204,6 +207,268 @@ namespace Sockeye.Biz
#region SAMPLE VENDOR PURCHASE NOTIFICATIONS
/*
/////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////// V7 MULTIPLE PRODUCTS IN ONE ORDER/////////////////////////////
{
"creation_date": "2023-01-22T23:21:49Z",
"id": 357678128,
"order_notification": {
"purchase": {
"customer_data": {
"billing_contact": {
"address": {
"city": "Courtenay",
"country": "Canada",
"country_id": "CA",
"postal_code": "V9J9T6",
"state": "British Columbia",
"state_id": "BC",
"street1": "05-3610 Christie Parkway"
},
"company": "GZTestCo",
"email": "gzmailadmin@gmail.com",
"first_name": "Test",
"last_name": "Testerson"
},
"customer_payment_data": {
"currency": "USD",
"payment_method": "Other"
},
"delivery_contact": {
"address": {
"city": "Courtenay",
"country": "Canada",
"country_id": "CA",
"postal_code": "V9J9T6",
"state": "British Columbia",
"state_id": "BC",
"street1": "05-3610 Christie Parkway"
},
"company": "GZTestCo",
"email": "gzmailadmin@gmail.com",
"first_name": "Test",
"last_name": "Testerson"
},
"language": "English",
"language_iso": "en",
"reg_name": "GZTestCo",
"shopper_id": "65860321",
"subscribe_newsletter": false,
"user_id": "gzmailadmin@gmail.com-38"
},
"is_test": true,
"payment_complete_date": "2023-01-22T23:21:48Z",
"payment_status": "testpaymentarrived",
"payment_status_id": "TCA",
"purchase_date": "2023-01-22T23:21:47Z",
"purchase_id": 843671213,
"purchase_item": [
{
"additional_information": [
{
"additional_id": "ADDITIONAL1",
"additional_value": "YES"
},
{
"additional_id": "ADDITIONAL2",
"additional_value": "YES"
},
{
"additional_id": "ADDITIONAL3",
"additional_value": "YES"
}
],
"currency": "USD",
"delivery_type": "Electronically",
"discount": 0.0,
"extended_download_price": 0.0,
"manual_order_price": 0.0,
"notification_no": 0,
"product_id": 300740317,
"product_name": "Up to 5 AyaNova schedulable resource 1 year subscription license",
"product_single_price": 695.0,
"purchase_item_key": [],
"quantity": 1,
"running_no": 1,
"shipping_price": 0.0,
"shipping_vat_pct": 0.0,
"subscription": {
"expiration_date": "2024-01-22T23:21:48Z",
"id": "843671213-1",
"interval": "Yearly without end",
"renewal_discount_count": "",
"renewal_discount_start": "",
"renewal_type": "auto",
"retention_discount_count": "",
"retention_discount_percent": "",
"start_date": "2023-01-23T00:00:00",
"status": "ToProcess",
"status_id": "TOP"
},
"vat_pct": 12.0
},
{
"additional_information": [
{
"additional_id": "ADDITIONAL1",
"additional_value": "YES"
},
{
"additional_id": "ADDITIONAL2",
"additional_value": "YES"
},
{
"additional_id": "ADDITIONAL3",
"additional_value": "YES"
}
],
"currency": "USD",
"delivery_type": "Electronically",
"discount": 0.0,
"extended_download_price": 0.0,
"manual_order_price": 0.0,
"notification_no": 0,
"product_id": 300740314,
"product_name": "optional add-on AyaNova RI (responsive interface) 1 year subscription license",
"product_single_price": 199.0,
"purchase_item_key": [],
"quantity": 1,
"running_no": 2,
"shipping_price": 0.0,
"shipping_vat_pct": 0.0,
"subscription": {
"expiration_date": "2024-01-22T23:21:48Z",
"id": "843671213-2",
"interval": "Yearly without end",
"renewal_discount_count": "",
"renewal_discount_start": "",
"renewal_type": "auto",
"retention_discount_count": "",
"retention_discount_percent": "",
"start_date": "2023-01-23T00:00:00",
"status": "ToProcess",
"status_id": "TOP"
},
"vat_pct": 12.0
},
{
"additional_information": [
{
"additional_id": "ADDITIONAL1",
"additional_value": "YES"
}
],
"currency": "USD",
"delivery_type": "Electronically",
"discount": 0.0,
"extended_download_price": 0.0,
"manual_order_price": 0.0,
"notification_no": 0,
"product_id": 300740321,
"product_name": "optional add-on AyaNova WBI (web browser interface) 1 year subscription license",
"product_single_price": 99.0,
"purchase_item_key": [],
"quantity": 1,
"running_no": 3,
"shipping_price": 0.0,
"shipping_vat_pct": 0.0,
"subscription": {
"expiration_date": "2024-01-22T23:21:48Z",
"id": "843671213-3",
"interval": "Yearly without end",
"renewal_discount_count": "",
"renewal_discount_start": "",
"renewal_type": "auto",
"retention_discount_count": "",
"retention_discount_percent": "",
"start_date": "2023-01-23T00:00:00",
"status": "ToProcess",
"status_id": "TOP"
},
"vat_pct": 12.0
},
{
"additional_information": [
{
"additional_id": "ADDITIONAL1",
"additional_value": "YES"
}
],
"currency": "USD",
"delivery_type": "Electronically",
"discount": 0.0,
"extended_download_price": 0.0,
"manual_order_price": 0.0,
"notification_no": 0,
"product_id": 300740322,
"product_name": "optional add-on AyaNova MBI (minimal browser interface) 1 year subscription license",
"product_single_price": 99.0,
"purchase_item_key": [],
"quantity": 1,
"running_no": 4,
"shipping_price": 0.0,
"shipping_vat_pct": 0.0,
"subscription": {
"expiration_date": "2024-01-22T23:21:48Z",
"id": "843671213-4",
"interval": "Yearly without end",
"renewal_discount_count": "",
"renewal_discount_start": "",
"renewal_type": "auto",
"retention_discount_count": "",
"retention_discount_percent": "",
"start_date": "2023-01-23T00:00:00",
"status": "ToProcess",
"status_id": "TOP"
},
"vat_pct": 12.0
},
{
"additional_information": [
{
"additional_id": "ADDITIONAL1",
"additional_value": "YES"
}
],
"currency": "USD",
"delivery_type": "Electronically",
"discount": 0.0,
"extended_download_price": 0.0,
"manual_order_price": 0.0,
"notification_no": 0,
"product_id": 300740323,
"product_name": "optional add-on AyaNova QBI(QuickBooks interface) 1 year subscription license",
"product_single_price": 99.0,
"purchase_item_key": [],
"quantity": 1,
"running_no": 5,
"shipping_price": 0.0,
"shipping_vat_pct": 0.0,
"subscription": {
"expiration_date": "2024-01-22T23:21:48Z",
"id": "843671213-5",
"interval": "Yearly without end",
"renewal_discount_count": "",
"renewal_discount_start": "",
"renewal_type": "auto",
"retention_discount_count": "",
"retention_discount_percent": "",
"start_date": "2023-01-23T00:00:00",
"status": "ToProcess",
"status_id": "TOP"
},
"vat_pct": 12.0
}
],
"purchase_origin": "online"
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////v7 export to xls add on/////////////////////////////
{