From a2fda0e7386ab47aa864e8505834207a6694a525 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 18 Jan 2023 00:41:04 +0000 Subject: [PATCH] --- server/Controllers/OrderController.cs | 39 ++++++++++++++++----------- server/biz/PrimeData.cs | 2 +- server/util/Mailer.cs | 17 ++++++++++++ todo.txt | 12 +-------- 4 files changed, 43 insertions(+), 27 deletions(-) diff --git a/server/Controllers/OrderController.cs b/server/Controllers/OrderController.cs index 034c113..f12c919 100644 --- a/server/Controllers/OrderController.cs +++ b/server/Controllers/OrderController.cs @@ -6,6 +6,7 @@ using Sockeye.Models; using Sockeye.Api.ControllerHelpers; using Newtonsoft.Json.Linq; using System; +using Sockeye.Biz; namespace Sockeye.Api.Controllers { @@ -36,6 +37,14 @@ namespace Sockeye.Api.Controllers [HttpPost("shareit")] public async Task Post([FromHeader] string Authorization, [FromBody] JObject j) { + if (!serverState.IsOpen) + { + var msg = ("Server state was not open when Vendor Order notification received; returning 503 (temp. unavailable) to them, they should retry when server open again."); + log.LogError(msg); + await NotifyEventHelper.AddOpsProblemEvent(msg); + return StatusCode(503, new ApiErrorResponse(serverState.ApiErrorCode, null, serverState.Reason)); + } + if (!ModelState.IsValid) { return BadRequest(ModelState); @@ -50,19 +59,20 @@ namespace Sockeye.Api.Controllers //put the jobject notification into the db as json string freeform notification information //to be processed by other code later. i.e. just capture it as is cleanly and don't bother trying to do anything fancy here this should be tight and focused and side effect free -TODO -//although...on second thought it could just make a purchase record with some sort of state of unprocessed so a job could swing by and process it or we could -//do that manually so then there would be no need for extra UI and stuff, and it wont' conflict with the need to process immediately and lightly here -//i.e. two stage: one is to make the record barebones for purchase then a job comes along and turns it into a real purchase -//also add error handling here iwth proper notification see trial request code so we get notified on error -//and don't return OK / 200 unless the order is stored successfully in db as shareit will retry until it's successful several times, see the link below for deets + + //although...on second thought it could just make a purchase record with some sort of state of unprocessed so a job could swing by and process it or we could + //do that manually so then there would be no need for extra UI and stuff, and it wont' conflict with the need to process immediately and lightly here + //i.e. two stage: one is to make the record barebones for purchase then a job comes along and turns it into a real purchase + //also add error handling here iwth proper notification see trial request code so we get notified on error + //and don't return OK / 200 unless the order is stored successfully in db as shareit will retry until it's successful several times, see the link below for deets + //Need to be able to make a manual purchase record with almost nothing more than the vendor notifciation text so can recover if auto system fails and for testing //save it to the database - var VendorNotification = new VendorNotification(); - VendorNotification.Vendor = "shareit"; - VendorNotification.Data = j.ToString(); - VendorNotification.Processed = false; - await ct.VendorNotification.AddAsync(VendorNotification); + var Purchase = new Purchase(); + Purchase.PurchaseDate = DateTime.UtcNow;//this is kind of fucky, what if the order takes more than a day to arrive? I guess fixup from the vendordata later + Purchase.VendorId = 1;//MyCommerce/shareit is vendor 1, for now that's all that's needed + Purchase.VendorData = j.ToString(); + await ct.Purchase.AddAsync(Purchase); await ct.SaveChangesAsync(); } @@ -70,12 +80,11 @@ TODO } catch (Exception ex) { - //todo Log this here - System.Diagnostics.Debug.WriteLine($"order/shareit - Exception processing request: {ex.Message}"); + log.LogError(ex, "OrderController/shareit - Exception processing vendor notification, returned 503 to vendor"); + await NotifyEventHelper.AddOpsProblemEvent("OrderController/shareit - Exception processing vendor notification, see log"); + return StatusCode(503);//ask it to retry again later } - return Ok("ok");//shareit robot looks for an OK response to know if it should resend or not https://account.mycommerce.com/home/wiki/7479805 - } //------------ diff --git a/server/biz/PrimeData.cs b/server/biz/PrimeData.cs index 207e23f..a6b54f6 100644 --- a/server/biz/PrimeData.cs +++ b/server/biz/PrimeData.cs @@ -38,7 +38,7 @@ namespace Sockeye.Biz } /// - /// Prime the database with SuperUser account + /// Prime the database with ShareIt / MyCommerce Vendor account /// public static async Task PrimeVendor(AyContext ct) { diff --git a/server/util/Mailer.cs b/server/util/Mailer.cs index 9365308..1d8de03 100644 --- a/server/util/Mailer.cs +++ b/server/util/Mailer.cs @@ -21,6 +21,23 @@ namespace Sockeye.Util public async Task SendEmailAsync(string email, string subject, string body, Sockeye.Models.GlobalOpsNotificationSettings smtpSettings, string attachPDFPath = null, string forceFileName = null, string htmlBody = null) { +#if (DEBUG) + switch (email) + { + case "support@ayanova.com": + case "johncrdnl@gmail.com": + case "gzmailadmin@gmail.com": + case "sales@ayanova.com": + case "support@onayanova.com": + case "techworks@shaw.ca": + break; + default: + System.Diagnostics.Debug.WriteLine($"DANGER: about to email someone {email} outside our test network"); + //DANGER: about to email someone outside our test network + System.Diagnostics.Debugger.Break(); + break; + } +#endif try { var message = new MimeMessage(); diff --git a/todo.txt b/todo.txt index 3a44f5a..c718159 100644 --- a/todo.txt +++ b/todo.txt @@ -5,12 +5,6 @@ Once it's up and running update docs to mention that perpetual trial period is t - Purchase event must trigger notification event subscribable (might already due to created etc) -- figure out and implement default notifications for Customers where appropriate - these do not need to be subscribed to, they are automatic unless we need a way to prevent like a certain tag or something? - but do the ones only that are currently in rockfish - - This would be done just like any current customer notification but wouldn't check for subscribers as it would be automatic - maybe like how ayanova does //## CUSTOMER "PROXY" NOTIFICATIONS like in wokrorder closed make sure to add @@ -21,10 +15,6 @@ Once it's up and running update docs to mention that perpetual trial period is t - - -- shareit payment notification route - triggers purchase if of that type, needs to analyze it and need to test it out somehow here first - trial server request route that contact form can trigger - JOB: notify user active license - JOB: vendor notification to purchase, create customer if necessary from purchase notification or add to existing @@ -65,7 +55,7 @@ Once it's up and running update docs to mention that perpetual trial period is t - SUBSCRIPTION SERVER UI - - Menu option generate server commision script based on settings in form + - Menu option generate server creation standup script based on settings in form can fill out form, click on it and it will generate the script needed to paste into new server - Button to trigger D.O. API to requisition server automatically, spin it up etc