Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Adrian Blake 10 posts 40 karma points
    Nov 22, 2013 @ 22:21
    Adrian Blake
    0

    Adding Moneris payment gateway to UCommerce

    I'm trying to add a new payment option. I'm struggling A LOT because the documentation I find everywhere is from all different versions / combinations of uCommerce / Umbraco. However, my error is that I keep getting a null reference exception. I don't really know why, and I can't even say if I am using the right code examples.

    So, in Payment.cshtml (this seems to work fine)

            int newPaymentMethodId;

            if (int.TryParse(HttpContext.Current.Request.Form["payment-method"], out newPaymentMethodId))

            {

                TransactionLibrary.CreatePayment(newPaymentMethodId, requestPayment:true);

                TransactionLibrary.ExecuteBasketPipeline();

                HttpContext.Current.Response.Redirect("Preview.aspx");

            }

     

    My DLL

     

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Globalization;

    using UCommerce.Infrastructure.Globalization;

    using UCommerce.EntitiesV2;

    using UCommerce.Transactions.Payments;

    using Moneris;

     

    namespace uCommerceMoneris

    {

        class MonerisPurchase : IPaymentMethodService, IPaymentFactory

        {

            public string Name { get; set; }

     

            /// <summary>

            /// Creates a new payment fully initialized

            /// </summary>

            /// <param name="request"></param>

            /// <returns></returns>

            public Payment CreatePayment(PaymentRequest request)

            {

                PurchaseOrder order = request.PurchaseOrder;

                var paymentMethod = request.Payment.PaymentMethod;

                var paymentFactory = paymentMethod as IPaymentFactory;

                Payment payment = paymentFactory.CreatePayment(request);

                return payment;

            }

            public Payment RequestPayment(PaymentRequest request)

            {

                // Processing is happening synchronously so we just

                // call the backend service with ProcessPaymentRequest

                return ProcessPaymentRequest(request);

            }

     

     

            public Payment ProcessPaymentRequest(PaymentRequest request)

            {

                // Send request to remote party

     

                // Update payment according to received status from remote 

                // party, e.g. Accepted, Declined

     

     

                // Grab any transaction ids and put them on the payment before 

                // returning the Payment

                request.Payment.TransactionId = "123";

     

                return request.Payment;

     

            }

            public Payment AcquirePayment(Payment payment)

            {

                // Send request to remote party

     

                // Update payment according to received status from remote 

                // party, e.g. Accepted, Declined

     

                // Grab any transaction ids and put them on the payment before 

                // returning the Payment

                return payment;

            }

            public Payment CancelPayment(Payment payment)

            {

                // Update payment according to received status from remote 

                // party, e.g. Cancelled

     

                // Grab any transaction ids and put them on the payment before 

                // returning the Payment

                return payment;

            }

            public virtual UCommerce.Money CalculatePaymentFee(PaymentRequest request)

            {

                var order = request.PurchaseOrder;

                var paymentMethod = request.PaymentMethod;

     

                var fee = paymentMethod.GetFeeForCurrency(order.BillingCurrency);

     

                if (!order.SubTotal.HasValue)

                    return new UCommerce.Money(0,

                    new CultureInfo(order.CultureCode), order.BillingCurrency);

     

                return new UCommerce.Money(order.SubTotal.Value

                   * (paymentMethod.FeePercent / 100)

                   + fee.Fee, 

                  new CultureInfo(order.CultureCode), order.BillingCurrency);

            }

        }

    }

    Executing Macro Script (file: uCommerce Payment) 0.0275780120300752 0.000015
    umbracoMacro Error Loading Razor Script (file: uCommerce Payment) Object reference not set to an instance of an object.    at uCommerceMoneris.MonerisPurchase.ProcessPaymentRequest(PaymentRequest request)

    it seems that request is always NULL and I don't know why. Can someone please help me? This project is due in less than a week and I have got no where with this. At least point me to proper documentation for the latest versions of Umbraco and UCommerce regarding setting up a new payment gateway? Umbraco 6.1.6 and UCommerce version provided from the packages section.

    Any help is greatly appreciated.

Please Sign in or register to post replies

Write your reply to:

Draft