diff --git a/.vscode/launch.json b/.vscode/launch.json index d5d28f8..7cade77 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -33,7 +33,7 @@ "SOCKEYE_DB_CONNECTION": "Server=localhost;Username=postgres;Password=sockeye;Database=sockeye;CommandTimeout=300;", "SOCKEYE_DATA_PATH": "c:\\temp\\sockeye", "SOCKEYE_USE_URLS": "http://*:7676;", - "SOCKEYE_PERMANENTLY_ERASE_DATABASE": "true", + //"SOCKEYE_PERMANENTLY_ERASE_DATABASE": "true", //"SOCKEYE_REPORT_RENDERING_TIMEOUT":"1", "SOCKEYE_BACKUP_PG_DUMP_PATH": "C:\\data\\code\\postgres_14\\bin" }, diff --git a/server/DataList/VendorNotificationDataList.cs b/server/DataList/VendorNotificationDataList.cs index 2cc9510..440e80f 100644 --- a/server/DataList/VendorNotificationDataList.cs +++ b/server/DataList/VendorNotificationDataList.cs @@ -19,7 +19,7 @@ namespace Sockeye.DataList FieldDefinitions.Add(new DataListFieldDefinition { TKey = "VendorNotificationCreated", - FieldKey = "VendorNotificationSalesOrderNumber", + FieldKey = "VendorNotificationCreated", SockType = (int)SockType.VendorNotification, UiFieldDataType = (int)UiFieldDataType.DateTime, SqlIdColumnName = "avendornotification.id", diff --git a/server/biz/GlobalBizSettingsBiz.cs b/server/biz/GlobalBizSettingsBiz.cs index 12daba0..fdef2dd 100644 --- a/server/biz/GlobalBizSettingsBiz.cs +++ b/server/biz/GlobalBizSettingsBiz.cs @@ -354,6 +354,7 @@ namespace Sockeye.Biz vn.VendorId = 1; vn.VendorData = jVendorNotificationItem["data"].Value(); vn.Processed = vn.Created;//indicate it's been processed + ct.VendorNotification.Add(vn); await ct.SaveChangesAsync(); diff --git a/server/generator/SockBotProcessVendorNotifications.cs b/server/generator/SockBotProcessVendorNotifications.cs index b7be9b1..0ab8fd9 100644 --- a/server/generator/SockBotProcessVendorNotifications.cs +++ b/server/generator/SockBotProcessVendorNotifications.cs @@ -94,13 +94,6 @@ namespace Sockeye.Biz { 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?? if (jData["order_notification"]["purchase"]["is_test"] != null && jData["order_notification"]["purchase"]["is_test"].Value() == true) { @@ -153,23 +146,15 @@ namespace Sockeye.Biz //here there could be several potential issues: //name differs because it was a separate site in rockfish, it's not cool to change the name //email differs, this can happen and is ok - //account number differs if was empty then it's ok. If it wasn't empty and it differs this is a potential problem: + //account number differs if was empty then it's ok. If it wasn't empty and it differs this is unfortunately normal as users may re-buy again with new account or buy an addon with a new account + //so the vendor account nubmer should just be the most recent for finding them purposes I guess // if (customer.EmailAddress != jCustomerEmail) - { - customer.EmailAddress = jCustomerEmail;//assume it was empty or has been recently updated - } + customer.EmailAddress = jCustomerEmail;//assume it was empty or has been recently updated if (customer.AccountNumber != jCustomerAccountNumber) - { - if (string.IsNullOrWhiteSpace(customer.AccountNumber)) - customer.AccountNumber = jCustomerAccountNumber;//this is ok, there wasn't an account number before so we're just adding it - else - { - // this is problematic, it matched but for some reason the account numbers differ, there's no safe way to process this so alert and bail - throw new System.ApplicationException($"Not processed due to error updating existing Customer: {customer.Name} Account numbers differ, expected: {customer.AccountNumber} vendor data:{vn.VendorData}"); - } - } + customer.AccountNumber = jCustomerAccountNumber;//see above + //refresh UpdateCustomerFromVendorData(jData, customer); @@ -185,7 +170,7 @@ namespace Sockeye.Biz /////////////////////////////////////////////////////////////////////////////////////////// var salesOrderNumber = jData["order_notification"]["purchase"]["purchase_id"].Value(); -#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(); @@ -214,9 +199,22 @@ namespace Sockeye.Biz p.VendorFee = jPurchase["accounting"]["margin_net"].Value(); p.Revenue = jPurchase["accounting"]["your_revenue"].Value(); } - p.CouponCode = "UNKNOWN WHERE IN VENDOR DATA CONTAINS COUPON CODE"; + + if (jPurchase["promotion_coupon"] != null) + p.CouponCode = jPurchase["promotion_coupon"].Value(); + + if (jPurchase["promotion"] != null) + p.CouponCode += $" {jPurchase["promotion"].Value()}"; + p.Quantity = jPurchase["quantity"].Value(); p.VendorNotificationId = vn.Id; + + //it's a subscription? + if (jPurchase["subscription"] != null && jPurchase["subscription"]["expiration_date"] != null) + { + p.ExpireDate = jPurchase["subscription"]["expiration_date"].Value(); + } + PurchaseBiz pbiz = PurchaseBiz.GetBiz(ct); p = await pbiz.CreateAsync(p); if (p == null)