Integrating New Payment Processor (CardSave) with Redirect Method

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
I've been trying to integrate a new payment processor (Redirect Method) and have followed the steps detailed here https://www.nopcommerce.com/boards/t/2891/how-to-code-my-own-payment-method.aspx

I am however not hitting the PostProcessPayment method and I'm not sure why.

When I try to integrate the payment processor using the hosted pages method the ProcessPayment method is being hit correctly.

Is there a setting somewhere where I need to trigger the redirect method to work.

Here is how I have implemented the CardSavePaymentProcessor.




namespace NopSolutions.NopCommerce.Payment.Methods.CardSave
{
    public class CardSavePaymentProcessor : IPaymentMethod
    {
        #region IPaymentMethod Members

        public bool CanCapture
        {
            get
            {
                return false;
            }
        }

        public bool CanRefund
        {
            get
            {
                return false;
            }
        }

        public bool CanVoid
        {
            get
            {
                return false;
            }
        }

        public void CancelRecurringPayment(Order order, ref CancelPaymentResult cancelPaymentResult)
        {
            throw new NopException("Void method not supported");
        }

        public void Capture(Order order, ref ProcessPaymentResult processPaymentResult)
        {
            throw new NotImplementedException();
        }

        public decimal GetAdditionalHandlingFee()
        {
            return (decimal)0.00;
        }

        public PaymentMethodTypeEnum PaymentMethodType
        {
            get
            {
                return PaymentMethodTypeEnum.Standard;
            }
        }

         public string PostProcessPayment(Order order)
        {
            string strPreSharedKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
            string strPassword = "XXXXXXXXXXXXX";
            string strMerchantID = "XXXXXXXXXXXXXXX";
            string postUrl = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

            StringBuilder hashString = new StringBuilder();
            hashString.Append("PreSharedKey=" + strPreSharedKey);
            hashString.Append("&MerchantID=" + strMerchantID);
            hashString.Append("&Password=" + strPassword);
            hashString.Append("&Amount=" + order.OrderTotal);
            hashString.Append("&CurrencyCode=" + 826);
            hashString.Append("&OrderID=" + order.OrderID);
            hashString.Append("&TransactionType=" + TRANSACTION_TYPE.SALE);
            hashString.Append("&TransactionDateTime=" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss zzzz"));
            hashString.Append("&CallbackURL=" + "http://www.admin.shopnutter.co.uk");
            hashString.Append("&OrderDescription=");
            hashString.Append("&CustomerName=" + order.CardName);
            hashString.Append("&Address1=" + order.BillingAddress1);
            hashString.Append("&Address2=" + order.BillingAddress2);
            hashString.Append("&Address3=");
            hashString.Append("&Address4=");
            hashString.Append("&City=" + order.BillingCity);
            hashString.Append("&State=");
            hashString.Append("&PostCode=" + order.BillingZipPostalCode);
            hashString.Append("&CountryCode=" + 826);
            hashString.Append("&CV2Mandatory=" + "true");
            hashString.Append("&Address1Mandatory=" + "false");
            hashString.Append("&CityMandatory=" + "false");
            hashString.Append("&PostCodeMandatory=" + "false");
            hashString.Append("&StateMandatory=" + "false");
            hashString.Append("&CountryMandatory=" + "false");

            string hashDigest = CardSaveGateway.Hash.ComputeHashDigest(hashString.ToString(), strPreSharedKey,                CardSaveGateway.Hash.HASH_METHOD.SHA1);

            RemotePost remotePostHelper = new RemotePost();
            remotePostHelper.FormName = "CardSaveContactForm";
            remotePostHelper.Params.Add("HashDigest", hashDigest);
            remotePostHelper.Params.Add("MerchantID", strMerchantID);
            
            
            
            remotePostHelper.Url = postUrl;
            remotePostHelper.Post();

            return string.Empty;

            }

public void ProcessPayment(PaymentInfo paymentInfo, Customer customer, Guid OrderGuid, ref ProcessPaymentResult processPaymentResult)
        {
            processPaymentResult.PaymentStatus = PaymentStatusEnum.Pending;
        }

        public void ProcessRecurringPayment(PaymentInfo paymentInfo, Customer customer, Guid OrderGuid, ref ProcessPaymentResult processPaymentResult)
        {
            throw new NopException("Void method not supported");
        }

        public void Refund(Order order, ref CancelPaymentResult cancelPaymentResult)
        {
            throw new NopException("Void method not supported");
        }

        public RecurringPaymentTypeEnum SupportRecurringPayments
        {
            get
            {
                return RecurringPaymentTypeEnum.NotSupported;
            }
        }

        public void Void(Order order, ref CancelPaymentResult cancelPaymentResult)
        {
            throw new NopException("Void method not supported");
        }

        #endregion
    }
}
13 years ago
Do you hit the ProcessPayment method? If not, could be something wrong in your payment method configuration.

If it does, can you post the code for the customer payment module?
13 years ago
Thanks for the response..

The ProcessPayment method is being hit but the error I get below the confirm button is

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Nop_Order_Nop_OrderStatus". The conflict occurred in database "SQL2008_736369_shopnutter", table "dbo.Nop_OrderStatus", column 'OrderStatusID'. The statement has been terminated.

The payment process consists of the following steps

Cart
Address
Shipping
Payment
Confirm
Complete

But as the payment method is "redirect method" I do not want the CC details entered on my site but redirect the user to payment processor's site during the payment stage before CC details are collected. The CardSavePaymentProcessor is however not used until the confirm button is hit by which time the CC details have been entered on my site.


Please what do you mean by the customer payment module?
13 years ago
The only other addition / change I have made is to the Shipping method nothing else from the original code has been changed.
13 years ago
For each payment method you have a customer template. For redirect payment methods this will normall just inform the customer that they are to be redirected to another site. However in the code behind, you need to initialize the PaymentInfo like below.

These are located in /Templates/Payment/YourPaymentGatewayName.

In PaymentModule.ascx.cs you should have the following code:


    public partial class PaymentModule : BaseNopUserControl, IPaymentMethodModule
    {
        public bool ValidateForm()
        {
            return true;
        }

        public PaymentInfo GetPaymentInfo()
        {
            PaymentInfo paymentInfo = new PaymentInfo();
            paymentInfo.CreditCardType = string.Empty;
            paymentInfo.CreditCardName = string.Empty;
            paymentInfo.CreditCardNumber = string.Empty;
            paymentInfo.CreditCardExpireYear = 0;
            paymentInfo.CreditCardExpireMonth = 0;
            paymentInfo.CreditCardCvv2 = string.Empty;
            return paymentInfo;
        }

    }

13 years ago
I have corrected the payment module I had and just informed the customer that they will be redirected to the payment gateway.

Here is the codebehind in the PaymentModule

namespace NopSolutions.NopCommerce.Web.Templates.Payment.CardSave
{
    public partial class PaymentModule : BaseNopUserControl, IPaymentMethodModule
    {
        public bool ValidateForm()
        {
            return true;
        }

        public PaymentInfo GetPaymentInfo()
        {
            PaymentInfo paymentInfo = new PaymentInfo();
            paymentInfo.CreditCardType = string.Empty;
            paymentInfo.CreditCardName = string.Empty;
            paymentInfo.CreditCardNumber = string.Empty;
            paymentInfo.CreditCardExpireYear = 0;
            paymentInfo.CreditCardExpireMonth = 0;
            paymentInfo.CreditCardCVV2 = string.Empty;
            return paymentInfo;
        }
    }
}


The payment process now makes a lot of sense. And now with the changes made when the user hits the confirm button to place the order the ProcessPayment method is hit but the error below comes up under the confirm button and the PostProcessPayment method is not being hit.


The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Nop_Order_Nop_OrderStatus". The conflict occurred in database "SQL2008_736369_shopnutter", table "dbo.Nop_OrderStatus", column 'OrderStatusID'. The statement has been terminated.

Is an entry not being made in the nop_order table and if so at what point is the entry supposed to be made.

Or where have I gone wrong.
13 years ago
What version of nopCommerce are you running? Looks as if the order status that is being inserted in the order table, does not exist in the order status table.

I presume you haven't added you own custom order status?
13 years ago
Im using version 1.5 and I have not added any custom order status
13 years ago
At what point should the order by added to the nop_order table prior to payment processing.
13 years ago
After debugging I found where the order is inserted into the nop_Order table and the cause of the error

The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Nop_Order_Nop_OrderStatus". The conflict occurred in database "SQL2008_736369_shopnutter", table "dbo.Nop_OrderStatus", column 'OrderStatusID'. The statement has been terminated.

was right in fornt of me the whole time.

The table Nop_OrderStatus was empty. Somehow when I ran the scripts to pupolate the tables with nopCommerce_createData.sql something must have been missed.

NopCommerce team have been a great help...THANKS
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.