This commit is contained in:
@@ -123,7 +123,44 @@ namespace Sockeye.Biz
|
||||
try
|
||||
{
|
||||
var jData = JObject.Parse(p.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}");
|
||||
}
|
||||
|
||||
//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 customerBiz = CustomerBiz.GetBiz(ct);
|
||||
|
||||
Customer c = await ct.Customer.FirstOrDefaultAsync(z => z.Name == jCustomerName) ?? await ct.Customer.FirstOrDefaultAsync(z => z.EmailAddress == jCustomerEmail);
|
||||
if (c == null)
|
||||
{
|
||||
//New customer
|
||||
c = new Customer();
|
||||
|
||||
c.Name = jCustomerName;
|
||||
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}");
|
||||
}
|
||||
else
|
||||
{
|
||||
//existing customer, refresh it
|
||||
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}");
|
||||
}
|
||||
|
||||
var salesOrderNumber = jData["order_notification"]["purchase"]["purchase_id"].Value<string>();
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -133,6 +170,30 @@ namespace Sockeye.Biz
|
||||
}
|
||||
}
|
||||
|
||||
private static void UpdateCustomerFromVendorData(JObject jData, string jCustomerEmail, Customer c)
|
||||
{
|
||||
c.EmailAddress = jCustomerEmail;
|
||||
c.Active = true;//if they just made a purchase they are active even if they weren't before
|
||||
c.DoNotContact = false;//if they just made a purchase they are contactable even if they weren't before
|
||||
c.AccountNumber = jData["order_notification"]["purchase"]["customer_data"]["shopper_id"].Value<string>();//appears to be mycommerce customer id number hopefully static between orders
|
||||
c.Address = c.PostAddress = jData["order_notification"]["purchase"]["customer_data"]["delivery_contact"]["address"]["street1"].Value<string>();
|
||||
c.City = c.PostCity = jData["order_notification"]["purchase"]["customer_data"]["delivery_contact"]["address"]["city"].Value<string>();
|
||||
c.Region = c.PostRegion = jData["order_notification"]["purchase"]["customer_data"]["delivery_contact"]["address"]["state"].Value<string>();
|
||||
c.Country = c.PostCountry = jData["order_notification"]["purchase"]["customer_data"]["delivery_contact"]["address"]["country"].Value<string>();
|
||||
c.PostCode = c.AddressPostal = jData["order_notification"]["purchase"]["customer_data"]["delivery_contact"]["address"]["postal_code"].Value<string>();
|
||||
var firstName = jData["order_notification"]["purchase"]["customer_data"]["delivery_contact"]["first_name"].Value<string>() ?? "FirstNameEmpty";
|
||||
var lastName = jData["order_notification"]["purchase"]["customer_data"]["delivery_contact"]["last_name"].Value<string>() ?? "LastNameEmpty";
|
||||
var language = jData["order_notification"]["purchase"]["customer_data"]["language"].Value<string>() ?? "LanguageEmpty";
|
||||
if (string.IsNullOrWhiteSpace(c.Notes))
|
||||
c.Notes = string.Empty;
|
||||
if (!c.Notes.Contains(lastName))
|
||||
{
|
||||
if (c.Notes.Length > 0 && !c.Notes.EndsWith('\n'))
|
||||
c.Notes += "\n";
|
||||
c.Notes += $"Purchase contact:{firstName} {lastName}, language: {language}\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#region SAMPLE VENDOR PURCHASE NOTIFICATIONS
|
||||
/*
|
||||
|
||||
@@ -71,3 +71,31 @@ namespace Sockeye.Models
|
||||
public SockType SType { get => SockType.Purchase; }
|
||||
}//eoc
|
||||
}//eons
|
||||
|
||||
/*
|
||||
|
||||
## How to make test sales and product links in ShareIt
|
||||
|
||||
fake sale of v8 to get license emails to update rockfish to auto read in the deets
|
||||
FAKE CREDIT CARD
|
||||
I have generated a test credit card number for your account. Please use the following as the credit card number making sure to use the word test and the 12 digit number with no spaces.
|
||||
You can use any valid information you would like for the other fields.
|
||||
test134661442658
|
||||
Expiration Date: any date in the future
|
||||
CVS code: 123
|
||||
Example typical database ID:
|
||||
tZy9aSHjacFf9a9v3EtzUqM1amq/eMvJa2nXswLle74=
|
||||
Links to purchase
|
||||
$50 customization charge https://order.mycommerce.com/cart/new?vendorid=14466&PRODUCT%5B300525428%5D=1
|
||||
Use this for custom report work minimum $50 for small changes
|
||||
|
||||
subscription month to month https://order.mycommerce.com/cart/new?vendorid=14466&PRODUCT%5B301028467%5D=1
|
||||
subscription yearly https://order.mycommerce.com/cart/new?vendorid=14466&PRODUCT%5B301028468%5D=1
|
||||
Perpetual single license: https://order.mycommerce.com/cart/new?vendorid=14466&PRODUCT%5B301028314%5D=1
|
||||
*** TESTING THIS ONE FIRST Perpetual single one year maintenance ACTIVE DISCOUNT PRICE: https://order.mycommerce.com/cart/new?vendorid=14466&PRODUCT%5B301028315%5D=1
|
||||
Perpetual single one year maintenance NEW FULL PRICE: https://order.mycommerce.com/cart/new?vendorid=14466&PRODUCT%5B301028317%5D=1
|
||||
v7 single for comparison 300740315 https://order.mycommerce.com/cart/new?vendorid=14466&PRODUCT%5B300740315%5D=1
|
||||
Address to use for testing
|
||||
05-3610 Christie Parkway Courtenay B.C. Canada V9J 9T6
|
||||
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user