Hi,

I developed a Payment Plugin for Sage Pay South Africa. I am currently testing it with Sage Pay going through various scenarios and payments options. The plugin is a Redirect plugin, and works perfectly in terms of processing payments.

However we noticed something odd when an order that has been redirected for payment to Sage Pay, is cancelled by the customer at Sage Pay's website. The way Sage Pay notifies the plugin of the status of payments are through the use of  the following 4 URL's that is specified in the Sage Pay customer profile. These URL's correspond to ActionResult Methods in the plugin Controller, I've included the code foe each URL:

In the Decline URL & Redirect URL, nopCommerce marks the cancelled Order Status as "Cancelled", which is correct, but marks the Payment Status as "Paid". Is this correct for a cancelled order. Should there not be a "Cancelled" payment status option?


=============================================================================================================
Code for handling post-back notifications in the payment controller:
=============================================================================================================

1) ACCEPT URL - Handles INSTANT Successful Transactions
Accept URL - "~/Plugins/PaymentSagePay/PaymentResultAccept"
Payment Methods: Credit Card & Instant EFT(iPay)
(Order Status = Processing, Payment Status = Paid)
=============================================================================================================

        public ActionResult SagePayResultAccept(FormCollection form)
  {

            var sagePayResult = new SagePayResultModel
            {
                TransactionAccepted = Request["TransactionAccepted"],
                CardHolderIpAddr = Request["CardHolderIpAddr"],
                RequestTrace = Request["RequestTrace"],
                Reference = Request["Reference"],
                Extra1 = Request["Extra1"],
                Extra2 = Request["Extra2"],
                Extra3 = Request["Extra3"],
                Amount = Request["Amount"],
                Method = Request["Method"],
                Reason = Request["Reason"]
            };

            var order = _orderService.GetOrderById(Convert.ToInt32(sagePayResult.Reference));
            if (_orderProcessingService.CanMarkOrderAsPaid(order))
            {
                _orderProcessingService.MarkOrderAsPaid(order);
            }
            return View("~/Plugins/Payments.SagePay/Views/SagePayResultAccept.cshtml", sagePayResult);

        }


1) DECLINE URL - Handles INSTANT Declined/Cancelled Transactions
Accept URL - "~/Plugins/PaymentSagePay/PaymentResultDecline"
Payment Methods: Credit Card & Instant EFT(iPay)
Plugin marks "Order Status = Cancelled", "Payment Status = Paid"
=============================================================================================================

        public ActionResult SagePayResultDecline(FormCollection form)
        {

            var sagePayResult = new SagePayResultModel
            {
                TransactionAccepted = Request["TransactionAccepted"],
                CardHolderIpAddr = Request["CardHolderIpAddr"],
                RequestTrace = Request["RequestTrace"],
                Reference = Request["Reference"],
                Extra1 = Request["Extra1"],
                Extra2 = Request["Extra2"],
                Extra3 = Request["Extra3"],
                Amount = Request["Amount"],
                Method = Request["Method"],
                Reason = Request["Reason"]
            };

            var order = _orderService.GetOrderById(Convert.ToInt32(sagePayResult.Reference));
            if (_orderProcessingService.CanCancelOrder(order))
            {
                _orderProcessingService.CancelOrder(order, true);
                _orderProcessingService.CancelOrder(order, true);
            }
            return View("~/Plugins/Payments.SagePay/Views/SagePayResultDecline.cshtml", sagePayResult);

        }

1) NOTIFY URL - Handles  DELAYED  Successful Transactions (initially handles by PaymentResultRedirect)
Accept URL - "~/Plugins/PaymentSagePay/PaymentResultNotify"
Payment Methods: Normal EFT & Cash
Plugin marks "Order Status = Processing", "Payment Status = Paid"
=============================================================================================================

        public ActionResult SagePayResultNotify(FormCollection form)
        {

            var sagePayResult = new SagePayResultModel
            {
                TransactionAccepted = Request["TransactionAccepted"],
                CardHolderIpAddr = Request["CardHolderIpAddr"],
                RequestTrace = Request["RequestTrace"],
                Reference = Request["Reference"],
                Extra1 = Request["Extra1"],
                Extra2 = Request["Extra2"],
                Extra3 = Request["Extra3"],
                Amount = Request["Amount"],
                Method = Request["Method"],
                Reason = Request["Reason"]
            };

            var order = _orderService.GetOrderById(Convert.ToInt32(sagePayResult.Reference));
            if (_orderProcessingService.CanMarkOrderAsPaid(order))
            {
                _orderProcessingService.MarkOrderAsPaid(order);
            }
            return View("~/Plugins/Payments.SagePay/Views/SagePayResultNotify.cshtml", sagePayResult);

        }

1) REDIRECT URL - Handles  DELAYED  Pending Transactions
Accept URL - "~/Plugins/PaymentSagePay/PaymentResultRedirect"
Payment Methods: Normal EFT & Cash
Plugin marks "Order Status = Pending", "Payment Status = Pending"
=============================================================================================================

        public ActionResult SagePayResultRedirect(FormCollection form)
        {

            var sagePayResult = new SagePayResultModel
            {
                TransactionAccepted = Request["TransactionAccepted"],
                CardHolderIpAddr = Request["CardHolderIpAddr"],
                RequestTrace = Request["RequestTrace"],
                Reference = Request["Reference"],
                Extra1 = Request["Extra1"],
                Extra2 = Request["Extra2"],
                Extra3 = Request["Extra3"],
                Amount = Request["Amount"],
                Method = Request["Method"],
                Reason = Request["Reason"]
            };

            return View("~/Plugins/Payments.SagePay/Views/SagePayResultRedirect.cshtml", sagePayResult);

        }

        #endregion
    }

=============================================================================================================

Any help/advice/explanation would be greatly appreciated.

Thank you!