Custom payment service - Payments.cshtml CreatePayment null reference exception
Hello, I desperately seek help with adding a custom payment service to UCommerce. It seem to see my DLL fine with Payments.cshtml script, my entry Payments.config entry is as follows:
However during checkout when i choose the only payment method available that is setup (Moneris, my custom service I added to the backend). I get this error:
Error Loading Razor Script (file: uCommerce Payment) Object reference not set to an instance of an object. at uCommerceMoneris.MonerisPurchase.CreatePayment(PaymentRequest request) at UCommerce.Transactions.TransactionLibraryInternal.CreatePayment(Int32 paymentMethodId, Decimal amount, Boolean requestPayment, Boolean overwriteExisting) at Castle.Proxies.TransactionLibraryInternalProxy.CreatePayment_callback(Int32 paymentMethodId, Decimal amount, Boolean requestPayment, Boolean overwriteExisting) at Castle.Proxies.Invocations.TransactionLibraryInternal_CreatePayment.InvokeMethodOnTarget() at Castle.DynamicProxy.AbstractInvocation.Proceed() at UCommerce.Infrastructure.Interceptor.ExceptionLoggingInterceptor.Intercept(IInvocation invocation) at Castle.DynamicProxy.AbstractInvocation.Proceed() at Castle.Proxies.TransactionLibraryInternalProxy.CreatePayment(Int32 paymentMethodId, Decimal amount, Boolean requestPayment, Boolean overwriteExisting) at UCommerce.Api.TransactionLibrary.CreatePayment(Int32 paymentMethodId, Decimal amount, Boolean requestPayment, Boolean overwriteExisting) at ASP._Page_macroScripts_uCommerce_Payment_cshtml.Execute() in d:\Virtuals\cybertekssystems_com\ktfloral_ca\Web\MacroScripts\uCommerce\Payment.cshtml:line 15 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) at System.Web.WebPages.WebPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage) at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
Error loading MacroEngine script (file: uCommerce/Payment.cshtml, Type: '' Object reference not set to an instance of an object. at uCommerceMoneris.MonerisPurchase.CreatePayment(PaymentRequest request) at UCommerce.Transactions.TransactionLibraryInternal.CreatePayment(Int32 paymentMethodId, Decimal amount, Boolean requestPayment, Boolean overwriteExisting) at Castle.Proxies.TransactionLibraryInternalProxy.CreatePayment_callback(Int32 paymentMethodId, Decimal amount, Boolean requestPayment, Boolean overwriteExisting) at Castle.Proxies.Invocations.TransactionLibraryInternal_CreatePayment.InvokeMethodOnTarget() at Castle.DynamicProxy.AbstractInvocation.Proceed() at UCommerce.Infrastructure.Interceptor.ExceptionLoggingInterceptor.Intercept(IInvocation invocation) at Castle.DynamicProxy.AbstractInvocation.Proceed() at Castle.Proxies.TransactionLibraryInternalProxy.CreatePayment(Int32 paymentMethodId, Decimal amount, Boolean requestPayment, Boolean overwriteExisting) at UCommerce.Api.TransactionLibrary.CreatePayment(Int32 paymentMethodId, Decimal amount, Boolean requestPayment, Boolean overwriteExisting) at ASP._Page_macroScripts_uCommerce_Payment_cshtml.Execute() in d:\Virtuals\cybertekssystems_com\ktfloral_ca\Web\MacroScripts\uCommerce\Payment.cshtml:line 15 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) at System.Web.WebPages.WebPage.ExecutePageHierarchy() at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage) at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage) at umbraco.macro.loadMacroScript(MacroModel macro) at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
This is my DLL with the class which implements IPaymentFactory, IPaymentMethodService for the service:
namespace uCommerceMoneris
{
public class MonerisPurchase : IPaymentFactory, IPaymentMethodService
{
public string Name { get; set; }
///
/// Creates a new payment fully initialized
///
///
///
public Payment CreatePayment(PaymentRequest request)
Does annyone have any ideas what's going on here? I've seen similar issues and tried everything I've found in the forums to no avail. Version info: Umbraco 6.1.6 and uCommerce 4.0.3.13287
I am guessing a little bit, since you havent specifed exactly which line throws the exception. I am guessing it is "PaymentMethodName = request.Payment.PaymentMethodName".
It looks like you are trying to access the payment you are currently in the process of creating. The request does not have a payment yet.
Instead you should get the payment method from the payment request object. It has a PaymentMethod property.
Something like "PaymentMethodName = request.PaymentMethod,Name"?
I don't know how to get the line number, could you please tell me where would it say that? It seems that no matter what CreatePayment will never work even if it is just Console.WriteLine("test") for debugging purpoes I tried that and still had problems.
If the assembly was build in "debug" target, the exception should contain line number information, if you deploy the ".pdb" file along with the assembly to the bin folder.
If you are using Visual Studio, you can try and debug the application.
1. In the menu: Debug -> Attach to Process 2. Select the process "w3wp.exe" 3. Set at break point in the first line in your method 4. Generate the payment.
Custom payment service - Payments.cshtml CreatePayment null reference exception
Hello, I desperately seek help with adding a custom payment service to UCommerce. It seem to see my DLL fine with Payments.cshtml script, my entry Payments.config entry is as follows:
<!-- Moneris (Canada) --> <component id="Moneris" service="UCommerce.Transactions.Payments.IPaymentMethodService, UCommerce" type="uCommerceMoneris.MonerisPurchase, uCommerceMoneris" />
However during checkout when i choose the only payment method available that is setup (Moneris, my custom service I added to the backend). I get this error:
Error Loading Razor Script (file: uCommerce Payment) Object reference not set to an instance of an object. at uCommerceMoneris.MonerisPurchase.CreatePayment(PaymentRequest request)
at UCommerce.Transactions.TransactionLibraryInternal.CreatePayment(Int32 paymentMethodId, Decimal amount, Boolean requestPayment, Boolean overwriteExisting)
at Castle.Proxies.TransactionLibraryInternalProxy.CreatePayment_callback(Int32 paymentMethodId, Decimal amount, Boolean requestPayment, Boolean overwriteExisting)
at Castle.Proxies.Invocations.TransactionLibraryInternal_CreatePayment.InvokeMethodOnTarget()
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at UCommerce.Infrastructure.Interceptor.ExceptionLoggingInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.TransactionLibraryInternalProxy.CreatePayment(Int32 paymentMethodId, Decimal amount, Boolean requestPayment, Boolean overwriteExisting)
at UCommerce.Api.TransactionLibrary.CreatePayment(Int32 paymentMethodId, Decimal amount, Boolean requestPayment, Boolean overwriteExisting)
at ASP._Page_macroScripts_uCommerce_Payment_cshtml.Execute() in d:\Virtuals\cybertekssystems_com\ktfloral_ca\Web\MacroScripts\uCommerce\Payment.cshtml:line 15
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors)
at System.Web.WebPages.WebPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
Error loading MacroEngine script (file: uCommerce/Payment.cshtml, Type: ''
Object reference not set to an instance of an object.
at uCommerceMoneris.MonerisPurchase.CreatePayment(PaymentRequest request)
at UCommerce.Transactions.TransactionLibraryInternal.CreatePayment(Int32 paymentMethodId, Decimal amount, Boolean requestPayment, Boolean overwriteExisting)
at Castle.Proxies.TransactionLibraryInternalProxy.CreatePayment_callback(Int32 paymentMethodId, Decimal amount, Boolean requestPayment, Boolean overwriteExisting)
at Castle.Proxies.Invocations.TransactionLibraryInternal_CreatePayment.InvokeMethodOnTarget()
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at UCommerce.Infrastructure.Interceptor.ExceptionLoggingInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.TransactionLibraryInternalProxy.CreatePayment(Int32 paymentMethodId, Decimal amount, Boolean requestPayment, Boolean overwriteExisting)
at UCommerce.Api.TransactionLibrary.CreatePayment(Int32 paymentMethodId, Decimal amount, Boolean requestPayment, Boolean overwriteExisting)
at ASP._Page_macroScripts_uCommerce_Payment_cshtml.Execute() in d:\Virtuals\cybertekssystems_com\ktfloral_ca\Web\MacroScripts\uCommerce\Payment.cshtml:line 15
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors)
at System.Web.WebPages.WebPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
at umbraco.macro.loadMacroScript(MacroModel macro)
at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
This is my DLL with the class which implements IPaymentFactory, IPaymentMethodService for the service:
namespace uCommerceMoneris
{
public class MonerisPurchase : IPaymentFactory, IPaymentMethodService
{
public string Name { get; set; }
///
/// Creates a new payment fully initialized
///
///
///
public Payment CreatePayment(PaymentRequest request)
{
PurchaseOrder order = request.PurchaseOrder;
var payment = new Payment
{
TransactionId = Guid.NewGuid().ToString(),
PaymentMethodName = request.Payment.PaymentMethodName,
Created = DateTime.Now,
Fee = CalculatePaymentFee(request).Value,
FeePercentage = request.PaymentMethod.FeePercent,
Amount = request.Amount.Value
};
return payment;
}
Does annyone have any ideas what's going on here? I've seen similar issues and tried everything I've found in the forums to no avail. Version info: Umbraco 6.1.6 and uCommerce 4.0.3.13287
Thanks!
Hi Adrian,
I am guessing a little bit, since you havent specifed exactly which line throws the exception. I am guessing it is
"PaymentMethodName = request.Payment.PaymentMethodName".
It looks like you are trying to access the payment you are currently in the process of creating. The request does not have a payment yet.
Instead you should get the payment method from the payment request object. It has a PaymentMethod property.
Something like "PaymentMethodName = request.PaymentMethod,Name"?
Kind regards,
Jesper
I don't know how to get the line number, could you please tell me where would it say that? It seems that no matter what CreatePayment will never work even if it is just Console.WriteLine("test") for debugging purpoes I tried that and still had problems.
Hi Adrian,
If the assembly was build in "debug" target, the exception should contain line number information, if you deploy the ".pdb" file along with the assembly to the bin folder.
If you are using Visual Studio, you can try and debug the application.
1. In the menu: Debug -> Attach to Process
2. Select the process "w3wp.exe"
3. Set at break point in the first line in your method
4. Generate the payment.
Kind regards,
Jesper
is working on a reply...