Try our conversational search powered by Generative AI!

How to make serializable carts to work with ICreditCardPayment (Authorize.NET)?


I am trying to enable serializable carts in our project and after some testing found that it doesn't work with Authorize.NET.

I am adding ICreditCardPayment correctly with new APIs:

var payment = orderGroup.CreateCardPayment(_orderGroupFactory);

// Fill the properties ..

cart.AddPayment(payment, _orderGroupFactory);


But when I load the card next time it doesn't have my payment, but instead it has SerializablePayment which doesn't have any of my filled up properties. It also does not have billing address anymore.

Is there a way to configure serializable carts to work with ICreditCardPayment?

I have Commerce 11.2.1.

Oct 03, 2017 17:04

Sounds like a bug to me. How do you fill the properties? Do you use the .Properties property? 

Oct 03, 2017 17:22

No, I am just setting properties on the ICreditCartPayment:

payment.CardType = CardType;
payment.PaymentMethodId = PaymentMethodId;
payment.PaymentMethodName = SystemKeyword;
payment.Amount = amount;
payment.CreditCardNumber = CreditCardNumber;
payment.CreditCardSecurityCode = CreditCardSecurityCode;
payment.ExpirationMonth = ExpirationMonth;
payment.ExpirationYear = ExpirationYear;
payment.Status = PaymentStatus.Pending.ToString();
payment.CustomerName = CreditCardName;
payment.TransactionType = TransactionType.Sale.ToString();
Oct 04, 2017 9:19

That's bad. I'll file a bug for this and we will look into it ASAP. Thanks for bringing it into our attention.

Oct 04, 2017 9:36

I checked the database and it looks like that the data is stored properly.

"Payments": [{
    "__MetaClass": "CreditCardPayment",
    "CreatorId": null,
    "ModifierId": null,
    "Created": "2017-10-03T14:48:51.6390544Z",
    "Modified": "2017-10-03T14:48:51.6390544Z",
    "CardType": "Generic",
    "CreditCardNumber": "4007000000027",
    "CreditCardSecurityCode": "123",
    "ExpirationMonth": "10",
    "ExpirationYear": "2017",
    "PaymentStatus": null,
    "ProviderPaymentId": null,
    "ProviderProfileId": null,
    "ImplementationClass": "Mediachase.Commerce.Orders.CreditCardPayment,Mediachase.Commerce",
    "AuthorizationCode": null,
    "OrderGroupId": "0",
    "PaymentMethodId": "4b6e692f-d6fb-4552-9439-3a39d2251316",
    "Status": "Pending",
    "BillingAddressId": "Billing",
    "OrderFormId": "0",
    "PaymentMethodName": "Authorize",
    "ValidationCode": null,
    "PaymentId": "-3",
    "TransactionID": null,
    "Amount": "96.5000000000",
    "PaymentType": "CreditCard",
    "TransactionType": "Sale",
    "ProviderTransactionID": null,
    "CustomerName": "Asda"

It seems that loading the cart does not restore the state properly.

Oct 04, 2017 9:39

@Maris: After investigation and tests, Save cart with added payment seems ok to me.

Could you give me more details about how to reproduce your bug ( which methods/API did you use to load the cart, where/when do you use it... ) ?

Edited, Oct 06, 2017 6:10
<p>Not the Save is working wrongly, but loading. Instead of loading ICreditCartPayment, it loads SerializablePayment.</p> <p>I am loading the cart like this:</p> <pre class="brush:csharp;auto-links:false;toolbar:false" contenteditable="false">var cart = _orderRepository.LoadCart&lt;ICart&gt;(_customerContext.CurrentContactId, Mediachase.Commerce.Orders.Cart.DefaultName, _currentMarket);</pre> <p></p>
Oct 09, 2017 8:42

To be clear, just CreditCard data is missing when loading SerializableCart because SerializablePayment doesn't have any property related to CreditCard data like CreditCardNumber, CreditCardSecurityCode, ExpirationMonth, ExpirationYear ...

Other payment info like Amount, PaymentMethodName... still loaded correctly.

And the BillingAddressId was stored in DB instead of entire BillingAddress so when load data from SerializableCart the BillingAddress will be null.


It should be able to deserialize Payment info to CreditCartPayment base on ImplementationClass property. I'm working on it right now .

You can do a workaround to get the CreditCard info by using Hashtable Properties  of SerializablePayment to store CreditCard info if you can't wait for the change laughing.

For example :

payment.Properties["CreditCardNumber"] = "4007000000027";

Edited, Oct 10, 2017 13:16
<p>Thanks, Khiem. I will wait for the fix and then switch over to Serializable carts.</p>
Oct 10, 2017 13:20

SerializableCart always return SerializablePayment in OrderForm and we also want to have Credit Card info from ICreditCardPayment.

So I use SerializableCreditCardPayment which inherited from SerializablePayment and ICreditCardPayment to make sure we can load all data about Credit Card payment.

After load Cart, you will have SerializableCreditCardPayment instead of SerializablePayment and you can cast it to ICreditCartPayment if you want.

I hope this can fix your issue laughing.

Thank you for reporting it.

Edited, Oct 12, 2017 6:25
<p>In which version it will be available?</p>
Oct 12, 2017 8:55

As usual - it's done when it's done :) . The current version under testing is 11.3 so the bug will be fixed in a later version, probably 11.3.1 or 11.4 - we don't know yet 

Oct 12, 2017 9:24

There were some issues with the bug fix, and we had to push back. It will probably be in Commerce 11.5 which is CMS-11 compatible. Is that something you can afford? 

Nov 09, 2017 12:51

Yes, it is fine. We are not using Serialized carts yet because of this issue. But once it will be available, will move forward.

Edited, Nov 09, 2017 12:52
<p>For future visitors, the bug was fixed and released in Commerce 11.4.1&nbsp;</p> <p>We of course recommend to upgrade to latest version possible&nbsp;</p>
Mar 19, 2018 13:19

@Khiem Nguyen Duy: Regarding this comment, is this something that has been implemented yet?

"It should be able to deserialize Payment info to CreditCartPayment base on ImplementationClass property. I'm working on it right now ."

The reason I'm asking is that we have our own custom payment method implementations that I'd like to deserialize into from Serializable Payments.

May 30, 2018 14:33

@Martin : Yes, we did some changes in PaymentConverter of Commerce 11.4.1 release.

Make sure YourCustomPayment inherit SerializablePayment and specify the converter for it : [JsonConverter(typeof(PaymentConverter))].

When create payment :

public IPayment CreatePayment()
  return new YourCustomPayment { ImplementationClass = typeof(YourCustomPayment).AssemblyQualifiedName };

Based on ImplementationClass of YourCustomPayment, PaymentConverter can deserialize SerializablePayment into YourCustomPayment.

Edited, May 31, 2018 6:43

@Khiem: 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 your last comment, 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 

var cardPayment = payment as BarclaysFusePayment;

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

Apr 22, 2022 16:52

The thread is very old so it's best to create a new thread (And link to this if necessary).

You should not inherit from SerializablePayment. It is an internal implementation. Should extend IPayment instead.

What do you return in your ProcessPayment exactly? 

Apr 25, 2022 11:18

Thanks Quan, I've created a new thread. I've also added a bit more of the payment gateway class to give context.

I'll try using IPayment in the meantime and report back if that works

Edited, Apr 25, 2022 13:45
* 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.