I currently have a custom payment gateway that I created for Kentico 7, that is working in my install of Kentico 7. Currently it's giving me an error in Kentico 8 I can't remedy. The error is:
"Unable to cast object of type 'CMS.Ecommerce.PaymentResultInfo' to type 'CMS.Ecommerce.FirstDataResultInfo'."
The error occurs at the following line:
FirstDataResultInfo firstDataResult = (FirstDataResultInfo)(firstDataProvider.PaymentResult);
The code compiles clean and from what I can see, doesn't interfere with any of the API changes from one to another, but something is inconsistent. The code and definition for my FirstDataResultInfo is as follows:
`using System;
using System.Collections.Generic;
using System.Text;
using CMS.GlobalHelper;
namespace CMS.Ecommerce
{
///
public class FirstDataResultInfo : PaymentResultInfo
{
private const string HEADER_TRANSTAG = "Transaction Tag:";
private const string HEADER_AUTHNO = "Authorization Number:";
private const string HEADER_SYSERROR = "System Error Description:";
private const string HEADER_REFNO = "Reference Number:";
private const string HEADER_CUSTREF = "Customer Reference:";
private const string HEADER_REFNO3 = "Reference Number 3:";
//private const string HEADER_VERIFIED = "Payment Verification:";
/// <summary>
/// First Data payment status.
/// </summary>
public FirstDataPaymentStatusEnum FirstDataPaymentStatus
{
get
{
return GetFirstDataPaymentStatusEnum();
}
set
{
SetFirstDataPaymentStatus(value);
}
}
/// <summary>
/// TRUE - payment was verified by PN (Payment notification) successfully, payment is VALID.
/// FALSE - payment verification by PN failed, payment is INVALID.
/// </summary>
public string FirstDataPaymentSysError
{
get
{
PaymentResultItemInfo itemObj = this.EnsurePaymentResultItemInfo("sysError", HEADER_SYSERROR);
if (itemObj != null)
{
return itemObj.Value;
}
return "";
}
set
{
PaymentResultItemInfo item = EnsurePaymentResultItemInfo("sysError", HEADER_SYSERROR);
if (item != null)
{
item.Value = value;
item.Text = value;
this.SetPaymentResultItemInfo(item);
}
}
}
public string FirstDataPaymentAuthNo
{
get
{
PaymentResultItemInfo itemObj = this.EnsurePaymentResultItemInfo("authNo", HEADER_AUTHNO);
if (itemObj != null)
{
return itemObj.Value;
}
return "";
}
set
{
PaymentResultItemInfo item = EnsurePaymentResultItemInfo("authNo", HEADER_AUTHNO);
if (item != null)
{
item.Value = value;
item.Text = value;
this.SetPaymentResultItemInfo(item);
}
}
}
public string FirstDataPaymentTransTag
{
get
{
PaymentResultItemInfo itemObj = this.EnsurePaymentResultItemInfo("transTag", HEADER_TRANSTAG);
if (itemObj != null)
{
return itemObj.Value;
}
return "";
}
set
{
PaymentResultItemInfo item = EnsurePaymentResultItemInfo("transTag", HEADER_TRANSTAG);
if (item != null)
{
item.Value = value;
item.Text = value;
this.SetPaymentResultItemInfo(item);
}
}
}
public string FirstDataPaymentRefNo
{
get
{
PaymentResultItemInfo itemObj = this.EnsurePaymentResultItemInfo("refNo", HEADER_REFNO);
if (itemObj != null)
{
return itemObj.Value;
}
return "";
}
set
{
PaymentResultItemInfo item = EnsurePaymentResultItemInfo("refNo", HEADER_REFNO);
if (item != null)
{
item.Value = value;
item.Text = value;
this.SetPaymentResultItemInfo(item);
}
}
}
public string FirstDataPaymentCustRef
{
get
{
PaymentResultItemInfo itemObj = this.EnsurePaymentResultItemInfo("custRef", HEADER_CUSTREF);
if (itemObj != null)
{
return itemObj.Value;
}
return "";
}
set
{
PaymentResultItemInfo item = EnsurePaymentResultItemInfo("custRef", HEADER_CUSTREF);
if (item != null)
{
item.Value = value;
item.Text = value;
this.SetPaymentResultItemInfo(item);
}
}
}
public string FirstDataPaymentRefNo3
{
get
{
PaymentResultItemInfo itemObj = this.EnsurePaymentResultItemInfo("refNo3", HEADER_REFNO3);
if (itemObj != null)
{
return itemObj.Value;
}
return "";
}
set
{
PaymentResultItemInfo item = EnsurePaymentResultItemInfo("refNo3", HEADER_REFNO3);
if (item != null)
{
item.Value = value;
item.Text = value;
this.SetPaymentResultItemInfo(item);
}
}
}
/// <summary>
/// Returns First Data payment status according to the returned status string from the First Data payment gateway.
/// </summary>
/// <param name="status">Payment status string returned from the First Data payment gateway</param>
public static FirstDataPaymentStatusEnum GetFirstDataPaymentStatus(string status)
{
switch (status) //.ToLower())
{
case "Pre-Authorization Completed":
return FirstDataPaymentStatusEnum.PreAuthCompleted;
case "Pre-Authorization Failed":
return FirstDataPaymentStatusEnum.PreAuthFailed;
case "Payment Completed":
return FirstDataPaymentStatusEnum.PaymentCompleted;
case "Payment Failed":
return FirstDataPaymentStatusEnum.PaymentFailed;
default:
return FirstDataPaymentStatusEnum.Unknown;
}
}
#region " Private methods"
/// <summary>
/// Sets First Data payment status according to the returned status from tha First Data payment gateway.
/// </summary>
/// <param name="status">Payment status string returned from the First Data payment gateway</param>
private void SetFirstDataPaymentStatus(FirstDataPaymentStatusEnum status)
{
switch (status)
{
case FirstDataPaymentStatusEnum.PreAuthCompleted:
this.PaymentStatusValue = "y";
this.PaymentStatusName = "Pre-Authorization Complete";//"{$FirstData.PaymentResult.Status.Completed$}";
break;
case FirstDataPaymentStatusEnum.PreAuthFailed:
this.PaymentStatusValue = "c";
this.PaymentStatusName = "Pre-Authorization Failed";//"{$FirstData.PaymentResult.Status.Failed$}";
break;
case FirstDataPaymentStatusEnum.PaymentCompleted:
this.PaymentStatusValue = "z";
this.PaymentStatusName = "Completed";//"{$FirstData.PaymentResult.Status.Completed$}";
break;
case FirstDataPaymentStatusEnum.PaymentFailed:
this.PaymentStatusValue = "b";
this.PaymentStatusName = "Failed";//"{$FirstData.PaymentResult.Status.Failed$}";
break;
default:
this.PaymentStatusValue = "";
this.PaymentStatusName = "Unknown";//"{$FirstData.PaymentResult.Status.Unknown$}";
break;
}
}
/// <summary>
/// Returns First Data payment status enumeration from payment result status string.
/// </summary>
private FirstDataPaymentStatusEnum GetFirstDataPaymentStatusEnum()
{
switch (this.PaymentStatusValue.ToLower())
{
case "y":
return FirstDataPaymentStatusEnum.PreAuthCompleted;
case "c":
return FirstDataPaymentStatusEnum.PreAuthFailed;
case "z":
return FirstDataPaymentStatusEnum.PaymentCompleted;
case "b":
return FirstDataPaymentStatusEnum.PaymentFailed;
default:
return FirstDataPaymentStatusEnum.Unknown;
}
}
#endregion
/// <summary>
/// Creates base payment result info object + add First Data payment result properties.
/// </summary>
//public FirstDataResultInfo()
// : base()
//{
// // Add payment system error description - not known
// //EnsurePaymentResultItemInfo("syserror", HEADER_SYSERROR);
//}
}
}`
What issue am I not seeing?