HotcakesCommerce / hotcakes-commerce-core

The core of the e-commerce part of the overall solution. This is an ecommerce shopping cart solution built on top of the DNN (DotNetNuke) CMS. Anyone can do commerce online now!
https://mmmcommerce.com
MIT License
70 stars 55 forks source link

Custom Payment Gateway Missing Order CustomProperties #308

Open puresystems opened 4 years ago

puresystems commented 4 years ago

Describe the bug

When using order.CustomProperties.SetProperty or order.CustomProperties.Add in a PaymentGateway CreateCharge method, calling HccApp.OrderServices.Orders.Update(order) will update the corresponding xml in the CustomProperties field in the hcc_Order table correctly.

We would then access this CustomProperty from the OrderPaid: OrderTask class in the PaymentProvider via context.Order object.

But if we upgrade Dnn to v9.4.4 or above this functionality now fails at some point after leaving the our PaymentGateway code and hitting our PaymentProvider code. The hcc_order.CustomProperties database field is still updated correctly in the CreateCharge method when we call HccApp.OrderServices.Orders.Update(order), but once it hits our OrderPaid: OrderTask class, the order has lost this CustomProperty and checking the database field confirms this. So something is updating the database field without our CustomProperty.

Is this something which you are able to replicate? Should we be using a different way of updating CustomProperties?

Software Versions

To Reproduce

Steps to reproduce the behavior:

  1. In the Custom PaymentGateway code CreateCharge(Transaction t) method, use this code:
var HccApp2 = HccAppHelper.InitHccApp();
var results = HccApp2.OrderServices.Orders.FindByCriteria(new OrderSearchCriteria()
{
OrderNumber = t.MerchantInvoiceNumber
});

// get an actual order from the search results
var order = HccApp2.OrderServices.Orders.FindForCurrentStore(results[0].bvin);

// create a new order property
order.CustomProperties.Add(DEVELOPERID, "xref", dict["xref"]);

// update the order to save the new property
HccApp2.OrderServices.Orders.Update(order);
  1. In the OrderPaid: OrderTask class in your custom PaymentProvder, in the Execute(OrderTaskContext context) method use code such as this to retrieve the CustomProperty:

var prop = context.Order.CustomProperties.GetProperty(DEVELOPERID, "xref");

This should retrieve the CustomProperty from the order. But after the Dnn upgrade, at this stage the CustomProperty has been removed from the CustomProperties field in the hcc_Order database table.

WillStrohl commented 4 years ago

Hmmm... DNN should not have a direct impact on this extension point.

puresystems commented 4 years ago

Agreed, it doesn't make much sense.

We're looking to rebuild our PaymentGateway code against HC 3.4.1 to test further and one issue is that this helper is now missing:

var HccApp2 = HccAppHelper.InitHccApp();

It's obviously depreciated but what can we use instead? We are using it to find the HC order which we're processing payment for using this:

var results = HccApp2.OrderServices.Orders.FindByCriteria(new OrderSearchCriteria()
{
OrderNumber = t.MerchantInvoiceNumber
});
var order = HccApp2.OrderServices.Orders.FindForCurrentStore(results[0].bvin);
WillStrohl commented 4 years ago

Here is one way to get it:

https://github.com/hotcakesCommerce/hotcakes-commerce-core/blob/master/Website/DesktopModules/Hotcakes/Core/Admin/AppCode/BaseAdminPage.cs#L84-L87

Here is the other way to get it, which may be more relevant to your use case:

https://github.com/HotcakesCommerce/ProcessImagesModule/blob/master/Modules/ProcessImagesModule/Services/Data/ImageProcessingController.cs

puresystems commented 4 years ago

Thanks for the pointers.

We've retested on a working version of the site (Dnn 9.3.2) which was on HC 3.2.3 and upgraded to HC 3.4.1 and the CustomProperties value is being lost once it leaves our custom PaymentGateway. We can pause the code after we add the custom property and check the Order table and the CustomProperties field contains our new value.

But once it leaves and completes, the CustomProperties field reverts back to it's previous state.

So in this isntance we have left Dnn on 9.3.2 and only upgraded HC. It's as if the code after our Payment Gateway is using a cached version of the Order and so is missing our new custom property.

WillStrohl commented 4 years ago

Thanks, Dan. We'll look into this as soon as we can. :)