Close

Profile: Samson.Gabriels

Avatar

User posts

Hi

I'm having trouble getting the SagePayServer payment and Nop One Page Checkout plugins to work together well. When the sagepay plugin shows its view (in an iframe) and I enter payment details within it, I can then click its "pay now" button for it to submit the initial transaction to sagepay.

It then returns with an OrderGuid, an example as follows:-



<html><head>
    <title>Sagepay Server Response page</title>
    <script src="/Plugins/Payments.SagePayServer/Scripts/jquery-1.7.1.min.js"></script>
</head>
<body>
    <div class="cols cols--white clearfix">
            <form id="sagepayPaymentInfoForm" action="/checkout/paymentinfo" method="post" target="_parent">
                <p>
                    Your payment has been made.
                </p>
                <p id="sagepayPleaseWait">
                    You will be automatically redirected <span id="sagepaySeconds">3</span> seconds...
                </p>

                <input type="hidden" id="OrderGuid" name="OrderGuid" value="ed58e495-0463-4426-b2ec-1adbc56efb21">
                <input type="hidden" name="nextstep" id="nextstep" value="this form value is required">

                <input id="sagepayPostPaymentInfo" type="submit" value="Click to continue" style="display: none;">
            </form>
                <script type="text/javascript">
                    var serialisedPaymentinfo;
                    $(function() {
                        var checkout = window.parent.Checkout;
                        var paymentInfo = window.parent.PaymentInfo;
                        serialisedPaymentinfo = $('#sagepayPaymentInfoForm').serialize();
                        paymentInfo.save = function() { //Extending PaymentInfo Class
                            if (checkout.loadWaiting != false) return;
                            console.log(serialisedPaymentinfo);
                            checkout.setLoadWaiting('payment-info');
                            $.ajax({
                                url: 'http://demosite.co.uk/checkout/OpcSavePaymentInfo/',
                                data: serialisedPaymentinfo,
                                type: 'post',
                                success: paymentInfo.nextStep,
                                complete: paymentInfo.resetLoadWaiting,
                                error: checkout.ajaxFailure
                            });
                        };

                        paymentInfo.save();
                    });
                </script>
    </div>
</body>
</html>



When I then proceed to click "Complete" in the checkout page, One Page Checkout would refresh the different elements of the page as it usually does and then show again with an error/warning saying that it couldn't find the OrderGuid. At this point, SagePay has used jQuery to get the OrderGuid and it does get it successfully at first but I found that it tries to get it again and it returns with an empty/null result which is causing problems as NopCommerce will attempt to generate a new guid in OrderProcessingService.cs in the PlaceOrder function and sagepay would fail to match the new guid with the one it had originally.

The functions I've found to be hit a second time in SagePay are GetPaymentInfo and ValidatePaymentForm in PaymentSagePayServerController.cs. These functions are only hit once in the original one page checkout module in nop commerce. I assume this is related to the multiple forms on the checkout page; one for one page checkout and another within sagepay's iframe.

Please have a look at the original files for sagepay on https://github.com/seanrockster/NopCommerce-Sagepay

I am using Nop-Commerce 3.8.

Do you have any suggestions as to how I can overcome this?

Any help would be much appreciated.

Kind Regards,

Samson