Skip to content

Commit

Permalink
Merge pull request #9 from alpin11/fix/roundig
Browse files Browse the repository at this point in the history
use same procedure as coreshop in payment processor
  • Loading branch information
dlhck authored Sep 21, 2021
2 parents eac6b0d + 79201df commit 91c7b02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/Extension/ConvertOrderItemsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,25 @@
use CoreShop\Component\Pimcore\Templating\Helper\LinkGeneratorHelperInterface;
use CoreShop\Component\Product\Model\ProductInterface;
use CoreShop\Component\Taxation\Model\TaxItemInterface;
use Doctrine\ORM\Mapping as ORM;
use Mollie\Api\Types\OrderLineType;
use Pimcore\Model\Asset;
use Pimcore\Model\DataObject\Fieldcollection;
use Pimcore\Tool;

class ConvertOrderItemsExtension extends AbstractConvertOrderExtension
{
/**
* @var int|float
*/
protected $decimalFactor;
/**
* @var LinkGeneratorHelperInterface
*/
protected $linkGeneratorHelper;
protected int $decimalFactor;

public function __construct(LinkGeneratorHelperInterface $linkGeneratorHelper, $decimalFactor)
protected LinkGeneratorHelperInterface $linkGeneratorHelper;

private int $decimalPrecision;

public function __construct(LinkGeneratorHelperInterface $linkGeneratorHelper, int $decimalFactor, int $decimalPrecision)
{
$this->decimalFactor = $decimalFactor;
$this->linkGeneratorHelper = $linkGeneratorHelper;
$this->decimalPrecision = $decimalPrecision;
}

/**
Expand Down Expand Up @@ -252,10 +251,12 @@ protected function transformOrderItemToLineItem(OrderItemInterface $orderItem, $
*
* @return string[]
*/
protected function transformMoneyWithCurrency(int $amount, string $currencyCode)
protected function transformMoneyWithCurrency(int $amount, string $currencyCode): array
{
$value = (int)round((round($amount / $this->decimalFactor, $this->decimalPrecision) * 100), 0);

return [
'value' => sprintf("%01.2f", ($amount / $this->decimalFactor)),
'value' => sprintf("%01.2f", ($value / 100)),
'currency' => $currencyCode
];
}
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services/extensions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
arguments:
- '@CoreShop\Component\Pimcore\Templating\Helper\LinkGeneratorHelper'
- '%coreshop.currency.decimal_factor%'
- '%coreshop.currency.decimal_precision%'
tags:
- { name: payum.extension, alias: mollie_order_items_extension, factory: mollie, gateway: mollie, prepend: false }

Expand Down

0 comments on commit 91c7b02

Please sign in to comment.