Try our conversational search powered by Generative AI!

Unable to cast IPayment to CustomPayment in cart.ProcessPayment method


I am using a custom payment and passing in the ImplementationClass when adding the payment to the cart. Using cart.AddPayment method. However, when ProcessPayment is called in my custom payment gateway I get the IPayment Object which is iternally a 'SerializablePayment' object.

Following last comment from Khiem, I understand that I should get a CustomPayment object back. Is there a something I need to do in ProcessPayment method to convert?

    public class BarclaysFusePayment : SerializablePayment
        /// <summary>
        /// Initializes a new instance of the <see cref="BarclaysFusePayment"/> class.
        /// </summary>
        public BarclaysFusePayment()
            this.Properties = new Hashtable();
            this.BillingAddress = (IOrderAddress)new SerializableOrderAddress();
            this.PaymentType = PaymentType.Other;
            this.ImplementationClass = typeof(BarclaysFusePayment).AssemblyQualifiedName;

The following code use to work with Mediachase version but now thows an exception as it cant cast 

public class BarclaysFusePaymentGateway : AbstractWexPaymentGateway, IPaymentPlugin
        public PaymentProcessingResult ProcessPayment(IOrderGroup orderGroup, IPayment payment)
            var cardPayment = payment as BarclaysFusePayment;
            var paymentSuccessful = false;

           //payment processing logic

           if (paymentSuccessful)
               return PaymentProcessingResult.CreateSuccessfulResult(string.Empty);
               return PaymentProcessingResult.CreateUnsuccessfulResult("Error processing payment");

Admittedly, we've not upgraded in a few years we are upgrading from Mediachase.Commerce to Mediachase.Commerce

Apr 25, 2022 13:42

Can you show us how you are creating the IPayment object before you call ProcessPayment on your custom gateway?

Also I don't think you should be inheriting from SerializablePayment. Ideally you should be using the CreatePayment method() from the PaymentOption (payment method) or directly from OrderGroupFactory. You've mentioned the ImplementationClass so I assume your doing the latter correctly.

May 09, 2022 20:04
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.