I have an odd situation. I just created a payment plugin (Mollie) which is working fine, although in local environment.
I have a callback method in the same controller as the configure methods. The callback is being called by the payment provider after payment. This is happens successfully. After this I call the _OrderService to retrieve the order by ordernumber, also this happens successfully in localhost BUT not in PRODUCTION. There I get NullReferenceException.
IOrderService orderService = EngineContext.Current.Resolve<IOrderService>(); var order = orderService.GetOrderById(Convert.ToInt32(retrieveOrder.OrderNumber));
No Resolve does not trow an error. Not in system log.
I do have an Loglevel: Error of type: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object. at Nop.Plugin.Payments.MolliePayments.Controllers.PaymentMolliePaymentsController.MollieWebHook(String id) at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
[IgnoreAntiforgeryToken] public virtual IActionResult MollieWebhook(int? orderId, string id) { ...... if (orderId.HasValue) { //Load order by identifier (if provided) order = _orderService.GetOrderById(orderId.Value); } ...... }
[HttpPost] public IActionResult MollieWebHook(string id) { var retrieveOrderTask = Task.Run(() => (_mollieOrderClient.GetOrderAsync(id))); retrieveOrderTask.Wait(); var result = retrieveOrderTask.Result;
Order order = _orderService.GetOrderById(Convert.ToInt32(result.OrderNumber)); order.PaymentStatus = MolliePaymentStatusToNopCommercePaymentStatus(result.Status);
return Ok(200); }
But I still get the 'Object reference not set to an instance of an object.' exception.
[HttpPost] public IActionResult MollieWebHook(string id) { var retrieveOrderTask = Task.Run(() => (_mollieOrderClient.GetOrderAsync(id))); retrieveOrderTask.Wait(); var result = retrieveOrderTask.Result;
var orderService= EngineContext.Current.Resolve<IOrderService>(); Order order = orderService.GetOrderById(Convert.ToInt32(result.OrderNumber)); order.PaymentStatus = MolliePaymentStatusToNopCommercePaymentStatus(result.Status);
return Ok(200); }
if that doesn't work, set some break points so we know exactly what is null
Sadly but it dit not work. Also I did a little loging. And the problem is with IOrderService being NULL
First log is information log: ord_023ki... Second log is the result.OrderNumber: 3255 Then I did a loggin on orderService and got: OrderService Nop.Services.Orders.OrderService
Then I added a Warning log in case orderService == null > The warning is Order object is null
So orderObject is definetly null
Because after that I got a NullReference Error
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.