I am working on a custom module which acts on 'commerce_order.place.post_transition' event. On the event handler, I check the value of field [total paid] and top up another custom field with the value. But I found the value is actually doubled. For example, ordered one product with a unit price of $10 CAD, the cart and the order all show total $10. but the value of [total paid] field on the order shows
[total_paid] => Array( [x-default] => Array (
[number] => 19.990000
[currency_code] => CAD
) )
and the value of [total price] of the order shows:
[total_price] => Array( [x-default] => Array (
[number] => 10.000000
[currency_code] => CAD
) )
why does [total paid] value get doubled? My goal is to top up a custom field with the amount of money a customer has paid. So I thought the [total paid] field on the order is the field I am after.

Thanks

Comments

sprklinginfo created an issue. See original summary.

bojanz’s picture

Could be a bug in your custom code somewhere. The PaymentOrderManager always calculates total_paid from scratch, so the only way to get a double amount is to actually have two payment entities (due to a buggy gateway?)

sprklinginfo’s picture

Thanks bojanz, you are right about the two payment entities. when checking the order from admin/commerce/orders page, there are two payments: one payment is CA$9.99, the 2nd is CA$10.00. The 2nd is the product I ordered, I guess that is why the value for 'total paid' is $19.99. but I really don't know why the first payment is added automatically since I only ordered one product with a price of $10. The payment gateway is just the 'example (on-site)' payment in test mode. My custom code is very simple now: subscribe to the event of 'commerce_order.place.post_transition'. On my event handler function, I get the order object and dump it:

$order = $event->getEntity();
dsm($order, 'order');

Where should I check to find out why there is a hidden payment ($9.99) added automatically?
Thanks.

bojanz’s picture

Status: Active » Fixed

Look at the payment's payment_gateway field, that will tell you which gateway created it. Then go from there.

You can join us on Drupal Slack, room #commerce for further instructions.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.