Hello Pramil,

I have a strong background with VB, and coding C# only for the last year. So I'm a bit of a newbie when it comes to coding a plugin. :)

I have a similar issue with my plugin I did for a client using SagePay South Africa. I got the plugin to work in terms of processing transactions via a redirect to SagePay SA's payment gateway.

When a transaction is processed SagePay sends a postback notification to a URL that we have to specify in the SagePay Control panel for the following:

1) ACCEPT URL: Transaction Successful - this is sent directly after the transaction request is accepted and received by SagePay

2) NOTIFY URL: Transaction Successful - this is sent as soon as the transaction is successfully processed by the banking institution.

3) DECLINE URL: Transaction Unsuccessful - sent is the transaction was declined

4) REDIRECT URL: - this URl is used when a user cancels the transaction.

If you need more details on the messages being sent back (bottom of the page) you may have a look at their API documentation here:
https://sagepay.co.za/integration/sage-pay-integration-documents/pay-now-gateway-technical-guide/


So the way I understand it (I may be wrong) is that I need to add the code to handle the post-back notifications in my PaymentsSagePayController.cs file.


I had a look at your code you posted here, and I'm a little confused. The the challenges I'm facing is the following:

1) I need to code a method that handles each URL, get the post-back message and then display a notification of the details of the message to the user (Accept, Decline, Redirect).

2) How do I update the database (Payment Status) for each of the above URL's. For example if the transaction has been successful I need to change the Payment Status to "Paid". And what do I use as a Payment Status for "Declined".

3) If I understand it correctly I need to create a separate entry in my RouteProvider.cs for each URL?

Do I need to add anything to any other file? Here is what I have so far, and excuse me for just copying and modifying you code:

-------------------------->
[ValidateInput(false)]
    public ActionResult SagePayAccept(FormCollection form)
    {
            var processor = _paymentService.LoadPaymentMethodBySystemName("Payments.SagePayZA") as SagePayPaymentProcessor;
            if (processor == null || !processor.IsPaymentMethodActive(_paymentSettings) || !processor.PluginDescriptor.Installed)
                throw new NopException("SagePay module cannot be loaded");

            if (String.IsNullOrWhiteSpace(_sagePayPaymentSettings.MerchantId))
                throw new NopException("SagePay Merchant ID is not set");

            if (String.IsNullOrWhiteSpace(_sagePayPaymentSettings.SagePayServiceKey))
                throw new NopException("SagePay Service Key is not set");

            var myUtility = new SagePayHelper();
            string TransactionAccepted, CardHolderIpAddr, RequestTrace, Reference, Extra1, Extra2, Extra3, Amount, Reason;

            TransactionAccepted = Request["TransactionAccepted"];
            CardHolderIpAddr = Request["CardHolderIpAddr"];
            RequestTrace = Request["RequestTrace"];
            Reference = Request["Reference"];
            Extra1 = Request["Extra1"];
            Extra2 = Request["Extra2"];
            Extra3 = Request["Extra3"];
            Amount = Request["Amount"];
            Reason = Request["Reason"];

            if (TransactionAccepted == "true")
            {
                var order = _orderService.GetOrderById(Convert.ToInt32(Reference));
                if (_orderProcessingService.CanMarkOrderAsPaid(order))
                {
                    _orderProcessingService.MarkOrderAsPaid(order);
                }

                //Thank you for shopping with us. Your credit card has been charged and your transaction is successful
                return RedirectToRoute("CheckoutCompleted", new { Reference = order.Id });
            }
-------------------------->



I'm really confused by this bit:

            var processor = _paymentService.LoadPaymentMethodBySystemName("Payments.SagePayZA") as SagePayPaymentProcessor;
            if (processor == null || !processor.IsPaymentMethodActive(_paymentSettings) || !processor.PluginDescriptor.Installed)
                throw new NopException("SagePay module cannot be loaded");

            if (String.IsNullOrWhiteSpace(_sagePayPaymentSettings.MerchantId))
                throw new NopException("SagePay Merchant ID is not set");

            if (String.IsNullOrWhiteSpace(_sagePayPaymentSettings.SagePayServiceKey))
                throw new NopException("SagePay Service Key is not set");

            var myUtility = new SagePayHelper();
            string TransactionAccepted, CardHolderIpAddr, RequestTrace, Reference, Extra1, Extra2, Extra3,


I hope you can give some advise and guidance here. Been wrestling with this for a week now.

Thank you in advance.
Best regards

Jaco Ferreira
[email protected]