This pull request introduces changes to the module which add the support for various tax and discount configurations in Magento.
Summary of changes
1. Removing totalAmount calculation
The custom totalAmount calculation from Svea\Maksuturva\Model\Gateway\Implementation::getForm() was removed and replaced with Total\TotalCalculation::getProductsTotal() where the total is coming from Magento and it automatically respects all tax and discount configurations. From orders grand total we need to subtract only the things we need separately EXCEPT discounts. Discounts should be included in the productsTotal amount.
2. Refactoring discount calculation
Discounts use a custom calculation implemented in Total\TotalCalculation::getDiscountAmount(). The discount amount is 'tax compensated' so it also respects Magentos discount configurations automatically. The logic is based on productsTotal and orders subtotal. That's how we can calculate the discount amount without worrying about configurations so pmt_amount and pmt_sellercosts with discount rows always match the real total of the order.
3. Removing total calculation logic from gift card row
Gift cards are added as a separate row in Svea\Maksuturva\Observer\AddGiftCardPaymentRow. The logic is the same as before but the total is not modified in the observer because the total already includes all discounts.
4. Making sure gift card amount is always negative
Gift card amount has to be sent as a negative number so there was an additional logic added to the observer which makes the discount always negative even if the discount comes as a positive number from Magento.
This pull request introduces changes to the module which add the support for various tax and discount configurations in Magento.
Summary of changes
1. Removing totalAmount calculation
The custom totalAmount calculation from Svea\Maksuturva\Model\Gateway\Implementation::getForm() was removed and replaced with Total\TotalCalculation::getProductsTotal() where the total is coming from Magento and it automatically respects all tax and discount configurations. From orders grand total we need to subtract only the things we need separately EXCEPT discounts. Discounts should be included in the productsTotal amount.
2. Refactoring discount calculation
Discounts use a custom calculation implemented in Total\TotalCalculation::getDiscountAmount(). The discount amount is 'tax compensated' so it also respects Magentos discount configurations automatically. The logic is based on productsTotal and orders subtotal. That's how we can calculate the discount amount without worrying about configurations so pmt_amount and pmt_sellercosts with discount rows always match the real total of the order.
3. Removing total calculation logic from gift card row
Gift cards are added as a separate row in Svea\Maksuturva\Observer\AddGiftCardPaymentRow. The logic is the same as before but the total is not modified in the observer because the total already includes all discounts.
4. Making sure gift card amount is always negative
Gift card amount has to be sent as a negative number so there was an additional logic added to the observer which makes the discount always negative even if the discount comes as a positive number from Magento.