Skip to content

Commit

Permalink
[Payum] consider CoreShop decimal factor
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed Mar 3, 2020
1 parent d0476c9 commit 111003d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ final class AuthorizePaymentAction implements ActionInterface, GatewayAwareInter
{
use GatewayAwareTrait;

/**
* @var int
*/
protected $decimalFactor;

public function __construct(int $decimalFactor)
{
$this->decimalFactor = $decimalFactor;
}

/**
* {@inheritdoc}
*
Expand All @@ -46,7 +56,8 @@ public function execute($request): void
} catch (RequestNotSupportedException $e) {
$payumPayment = new PayumPayment();
$payumPayment->setNumber($payment->getNumber());
$payumPayment->setTotalAmount($payment->getTotalAmount());
//Payum Payment works with ints with a precision of 2
$payumPayment->setTotalAmount(100 * round($payment->getTotalAmount() / $this->decimalFactor, 2));
$payumPayment->setCurrencyCode($payment->getCurrency()->getIsoCode());
$payumPayment->setDescription($payment->getDescription());
$payumPayment->setDetails($payment->getDetails());
Expand Down
13 changes: 12 additions & 1 deletion src/CoreShop/Bundle/PayumBundle/Action/CapturePaymentAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ final class CapturePaymentAction implements ActionInterface, GatewayAwareInterfa
{
use GatewayAwareTrait;

/**
* @var int
*/
protected $decimalFactor;

public function __construct(int $decimalFactor)
{
$this->decimalFactor = $decimalFactor;
}

/**
* {@inheritdoc}
*
Expand All @@ -48,7 +58,8 @@ public function execute($request): void
} catch (RequestNotSupportedException $e) {
$payumPayment = new PayumPayment();
$payumPayment->setNumber($payment->getNumber());
$payumPayment->setTotalAmount($payment->getTotalAmount());
//Payum Payment works with ints with a precision of 2
$payumPayment->setTotalAmount(100 * round($payment->getTotalAmount() / $this->decimalFactor, 2));
$payumPayment->setCurrencyCode($payment->getCurrency()->getIsoCode());
$payumPayment->setDescription($payment->getDescription());
$payumPayment->setDetails($payment->getDetails());
Expand Down
4 changes: 4 additions & 0 deletions src/CoreShop/Bundle/PayumBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ services:

coreshop.payum_action.authorize_payment: '@CoreShop\Bundle\PayumBundle\Action\AuthorizePaymentAction'
CoreShop\Bundle\PayumBundle\Action\AuthorizePaymentAction:
arguments:
- '%coreshop.currency.decimal_factor%'
tags:
- { name: payum.action, all: true, alias: coreshop.authorize_payment }

coreshop.payum_action.capture_payment: '@CoreShop\Bundle\PayumBundle\Action\CapturePaymentAction'
CoreShop\Bundle\PayumBundle\Action\CapturePaymentAction:
arguments:
- '%coreshop.currency.decimal_factor%'
tags:
- { name: payum.action, all: true, alias: coreshop.capture_payment }

Expand Down

0 comments on commit 111003d

Please sign in to comment.