"IExtendedProperties" on payment disappear after saving cart as a purchaseOrder

Vote:
 

Hi Forum,

I have a question about "IExtendedProperties". After saving a cart as a purchaseOrder, the values added to "IExtendedProperties" on payments disappear.

Is it a bug or intended behavior. Do I misunderstand something? :)

Screenshot cart order form
https://screenpresso.com/=j1wlf

Screenshot purchaseOrder order form
https://screenpresso.com/=DZgdc

Code

var orderReference = _orderRepository.SaveAsPurchaseOrder(cart);
var purchaseOrder = _orderRepository.Load<IPurchaseOrder>(orderReference.OrderGroupId);

EpiServer.Business.Commerce
12.17.2.3575

BR
Lasse

#207684
Edited, Oct 01, 2019 17:29
Vote:
 

No, that shouldn't disappear. We are storing Project Name and retrieving that back to show on Order History Block.

OrderName = order.Properties[MetadataPlusFields.ProjectName.Name]?.ToString();

This is propery information

public static readonly MetadataPlusField ProjectName = new MetadataPlusField
{
    DataType = MetaDataType.ShortString,
    Description = string.Empty,
    FriendlyName = "Project Name",
    IsEncrypted = false,
    IsMultiLanguage = false,
    IsNullable = true,
    IsSearchable = false,
    Length = 512,
    Name = "ProjectName",
    Namespace = OrderContext.Current.OrderGroupMetaClass.Namespace,
};
#207714
Oct 01, 2019 10:12
Vote:
 

Hi Praful :)

Thank you for your reply.

Properties on our order forms and line items are working fine. It is only on our payments that the value disappears when saving a cart as a purchaseOrder!

BR
Lasse

#207721
Oct 01, 2019 10:50
Vote:
 

Can you share your code where you are setting those values on the payment?

#207727
Edited, Oct 01, 2019 13:02
Vote:
 

Hej Erik :)

Here is a simplified version of the code:

public IPayment CreatePayment(ICart cart, Guid paymentMethodId, decimal amount) {
            var payment = cart.CreatePayment();
            PopulatePayment(payment, paymentMethodId, amount);
            return payment;
}

private void PopulatePayment(IPayment payment, Guid paymentMethodId, decimal amount) {
            var row = _paymentService.GetPaymentMethodRow(paymentMethodId);
            payment.Amount = amount;
            payment.PaymentMethodId = paymentMethodId;
            payment.PaymentMethodName = row?.Name;
            payment.Status = PaymentStatus.Pending.ToString();
            payment.TransactionType = TransactionType.Authorization.ToString();
}

var orderForm = cart.GetFirstForm();
var voucherPayment = CreatePayment(cart, voucherPaymentMethodId, voucherAmountTobeDeducted);
voucherPayment.Properties[Metadata.Payment.VoucherCode] = response.Code;
voucherPayment.Properties[Metadata.Payment.VoucherAvailableAmount] = response.Amount;
orderForm.Payments.Add(voucherPayment);
_orderRepository.Save(cart) // IOrderRepository

And this is how I experience it when I debug:

        public IPurchaseOrder PlaceOrder(ICart cart)
        {
				// Below is what I see when I debug (Can also be seen on the screenshots I have linked to)
		
				var cartForm = cart.GetFirstForm(); // Debug shows: Payment in cartForm got properties
                var orderReference = _orderRepository.SaveAsPurchaseOrder(cart);
				
				var purchaseOrder = _orderRepository.Load<IPurchaseOrder>(orderReference.OrderGroupId);
				var orderForm = purchaseOrder.GetFirstForm(); // Debug shows: Payment in orderForm got no properites
		
		}

Br
Lasse

#207734
Oct 01, 2019 14:47
Vote:
 

Can you try to remove the IPayment and just use GiftCardPayment directly?

public GiftCardPayment CreateVoucherPayment(ICart cart, Guid paymentMethodId, decimal amount, string voucherCode, decimal voucherAmount) {
            var row = _paymentService.GetPaymentMethodRow(paymentMethodId);
            var payment = new GiftCardPayment{
                Amount = amount;
                PaymentMethodId = paymentMethodId;
                PaymentMethodName = row?.Name;
                Status = PaymentStatus.Pending.ToString();
                TransactionType = TransactionType.Authorization.ToString()};
            payment.Properties[Metadata.Payment.VoucherCode] = voucherCode;
            payment.Properties[Metadata.Payment.VoucherAvailableAmount] = voucherAmount;
            return payment;
}

var voucherPayment = CreateVoucherPayment(cart, voucherPaymentMethodId, voucherAmountTobeDeducted, response.Code, response.Amount);

(Disclaimer: free hand code so might not even be formatted correctly)

#207741
Oct 01, 2019 15:16
Vote:
 

Did  you add equivalent metafields to your payment? 

#207744
Oct 01, 2019 15:33
Vote:
 

Hi Quan,

Dooh :/

It helped adding a equivalent metafield to payment? 

Thanks a lot to all of you for spending time looking into my issue. It is much appreciated.

Thanks! :)

#207777
Oct 02, 2019 20:13
* 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.