# PaymentInfoCalculator.CalculateFromCarrier causing double rows on payment info

**URL:** <https://forum.litium.com/t/paymentinfocalculator-calculatefromcarrier-causing-double-rows-on-payment-info/2247>\
**Category:** Questions\
**Tags:** litium-7\
**Created:** [October 11, 2021, 11:32am UTC](https://forum.litium.com/t/paymentinfocalculator-calculatefromcarrier-causing-double-rows-on-payment-info/2247 "2021-10-11T11:32:25Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ericsj11](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/ericsj11/32/899_2.png) [@Ericsj11](https://forum.litium.com/u/Ericsj11)\
**Post date:** [October 11, 2021, 11:32am UTC](https://forum.litium.com/t/paymentinfocalculator-calculatefromcarrier-causing-double-rows-on-payment-info/2247/1 "2021-10-11T11:32:25Z")

</div>

Scenario:

1. Go to checkout with one item - 123
2. Go to PayPal
3. Click cancel
4. Select payment method Nets Easy
5. Code goes to “GetWidget”
6. Code runs : \_paymentInfoCalculator.CalculateFromCarrier(orderCarrier, \_securityToken);
7. Payment info on the carrier ends up with 2 order rows with the same item, and 2 delivery rows. (Should be 1 order row, and 1 delivery row)
8. But order total is unchanged so the widget crashes with error: {“errors”:{“amount”:[“Amount does not match sum of orderitems”]}}

Is the Payment info missing some info that gets lost when going to PayPal then cancel?  
It’s working if i select Nets Easy directly without going to PayPal first.

Litium version: 7.7.1

---

<div class="post-metadata">

**Author:** ![Ericsj11](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/ericsj11/32/899_2.png) [@Ericsj11](https://forum.litium.com/u/Ericsj11)\
**Post date:** [October 11, 2021, 11:39am UTC](https://forum.litium.com/t/paymentinfocalculator-calculatefromcarrier-causing-double-rows-on-payment-info/2247/2 "2021-10-11T11:39:37Z")

</div>

Paymentinfo row before CalculateFromCarrier:  
 ![image](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/0a73e6b7facd413253a6c408029e7d8689bda433.png)

Paymentinfo row after CalculateFromCarrier (And the newly created):  
 ![image](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/ba2b4870dc711f17e4afaf2d4d8c75d73d8140a1.png)

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [October 11, 2021, 12:12pm UTC](https://forum.litium.com/t/paymentinfocalculator-calculatefromcarrier-causing-double-rows-on-payment-info/2247/3 "2021-10-11T12:12:27Z")

</div>

Without looking at any code it looks like you order not are persisted after they are re-calculated. That’s the reason you have one item that is marked for deletion and one that is marked for creation.

What will happen if you persist the order after you have change the payment method?

---

<div class="post-metadata">

**Author:** ![Ericsj11](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/ericsj11/32/899_2.png) [@Ericsj11](https://forum.litium.com/u/Ericsj11)\
**Post date:** [October 11, 2021, 12:17pm UTC](https://forum.litium.com/t/paymentinfocalculator-calculatefromcarrier-causing-double-rows-on-payment-info/2247/4 "2021-10-11T12:17:13Z")

</div>

Not exactly sure how to persist the order?  
But yes, i guess something has to remove the rows marked for deleteing.

After some decompiling i found this, feels like it might be a bug in the addon:

**Creating order lines for Klarna**

```
  foreach (PaymentInfoRowCarrier paymentInfoRowCarrier in paymentInfoCarrier.Rows.Where<PaymentInfoRowCarrier>((Func<PaymentInfoRowCarrier, bool>) (x => !x.CarrierState.IsMarkedForDeleting)))

```

**Creating order lines for Nets Easy**

```
  foreach (PaymentInfoRowCarrier row in orderCarrier.PaymentInfo.FirstOrDefault<PaymentInfoCarrier>().Rows)
```

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [October 11, 2021, 12:20pm UTC](https://forum.litium.com/t/paymentinfocalculator-calculatefromcarrier-causing-double-rows-on-payment-info/2247/5 "2021-10-11T12:20:25Z")

</div>

Agree, looks like a bug if the add-on not is filtering the rows based on the carrier state.

Please, create a bug on docs site about this so we can investigate more.

---

<div class="post-metadata">

**Author:** ![Ericsj11](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/ericsj11/32/899_2.png) [@Ericsj11](https://forum.litium.com/u/Ericsj11)\
**Post date:** [October 11, 2021, 12:24pm UTC](https://forum.litium.com/t/paymentinfocalculator-calculatefromcarrier-causing-double-rows-on-payment-info/2247/6 "2021-10-11T12:24:27Z")

</div>

Thanks, will do that!  
Is it safe that i remove all those lines myself? This has already caused faulty orders in production

```
orderCarrier.PaymentInfo.FirstOrDefault().Rows.RemoveAll(x => x.CarrierState.IsMarkedForDeleting);
```

---

<div class="post-metadata">

**Author:** ![patric.forsgard](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/patric.forsgard/32/10_2.png) [@patric.forsgard](https://forum.litium.com/u/patric.forsgard)\
**Post date:** [October 11, 2021, 1:21pm UTC](https://forum.litium.com/t/paymentinfocalculator-calculatefromcarrier-causing-double-rows-on-payment-info/2247/7 "2021-10-11T13:21:55Z")

</div>

No, you should not remove them by yourself, then you will get stale data in database.

Instead you need to do fetch the order and run the order.SetValuesFromCarrier where you adding the updated order carrier in, then the order will clean up the data that not should be used.

---

<div class="post-metadata">

**Author:** ![steve.redstorm](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/steve.redstorm/32/14_2.png) [@steve.redstorm](https://forum.litium.com/u/steve.redstorm)\
**Post date:** [October 12, 2021, 3:38pm UTC](https://forum.litium.com/t/paymentinfocalculator-calculatefromcarrier-causing-double-rows-on-payment-info/2247/8 "2021-10-12T15:38:40Z")

</div>

You have a preRelease 6.3.103-pre01 which fixes this.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/12eddac3b8b661de1db86af10ac8151b571e6fb9.png) [@system](https://forum.litium.com/u/system)\
**Post date:** [November 9, 2021, 3:39pm UTC](https://forum.litium.com/t/paymentinfocalculator-calculatefromcarrier-causing-double-rows-on-payment-info/2247/9 "2021-11-09T15:39:23Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
