Skip to content

Commit

Permalink
Merge pull request #30 from logeecom/master
Browse files Browse the repository at this point in the history
remove hard coded divisors. Make migration transactional.
  • Loading branch information
hwysoszynski authored Oct 23, 2024
2 parents e384b9c + d99d457 commit 700208c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
10 changes: 8 additions & 2 deletions src/Controller/Action/Shop/QrCodeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use SyliusMolliePlugin\Entity\OrderInterface;
use SyliusMolliePlugin\Logger\MollieLoggerActionInterface;
use SyliusMolliePlugin\Resolver\MollieApiClientKeyResolverInterface;
use SyliusMolliePlugin\Helper\IntToStringConverterInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -43,6 +44,9 @@ final class QrCodeAction
/** @var RepositoryInterface */
private $methodRepository;

/** @var IntToStringConverterInterface */
private $intToStringConverter;

/**
* QrCodeAction constructor
*/
Expand All @@ -53,7 +57,8 @@ public function __construct(
MollieApiClientKeyResolverInterface $apiClientKeyResolver,
OrderRepositoryInterface $orderRepository,
UrlGeneratorInterface $urlGenerator,
RepositoryInterface $methodRepository
RepositoryInterface $methodRepository,
IntToStringConverterInterface $intToStringConverter
)
{
$this->loggerAction = $loggerAction;
Expand All @@ -63,6 +68,7 @@ public function __construct(
$this->orderRepository = $orderRepository;
$this->urlGenerator = $urlGenerator;
$this->methodRepository = $methodRepository;
$this->intToStringConverter = $intToStringConverter;
}

/**
Expand Down Expand Up @@ -189,7 +195,7 @@ private function setMolliePaymentIdOnOrder(OrderInterface $order, ?string $molli
private function buildPaymentObject(Request $request, OrderInterface $order): MolliePayment
{
$molliePayment = new MolliePayment();
$molliePayment->setAmount(new Amount((string)($order->getTotal() / 100), $order->getCurrencyCode()));
$molliePayment->setAmount(new Amount($this->intToStringConverter->convertIntToString($order->getTotal()), $order->getCurrencyCode()));
$molliePayment->setMethod($request->get('paymentMethod'));
$molliePayment->setDescription((string)$order->getId());
$molliePayment->setIssuer($request->get('issuer') ?? '');
Expand Down
10 changes: 1 addition & 9 deletions src/Migrations/Version20231225151033.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function up(Schema $schema): void

/**
* @param Schema $schema
*
*
* @return void
*/
public function down(Schema $schema): void
Expand All @@ -69,14 +69,6 @@ public function down(Schema $schema): void
$this->renameTableIfExists($schema, 'mollie_subscription_schedule', 'bitbag_mollie_subscription_schedule');
}

/**
* @return bool
*/
public function isTransactional(): bool
{
return false;
}

/**
* @param Schema $schema
* @param string $oldTableName
Expand Down
10 changes: 8 additions & 2 deletions src/Resolver/MolliePaymentsMethodResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use SyliusMolliePlugin\Entity\OrderInterface as MollieOrderInterface;
use SyliusMolliePlugin\Logger\MollieLoggerActionInterface;
use SyliusMolliePlugin\Repository\MollieGatewayConfigRepository;
use SyliusMolliePlugin\Provider\Divisor\DivisorProviderInterface;
use SyliusMolliePlugin\Repository\MollieGatewayConfigRepositoryInterface;
use SyliusMolliePlugin\Repository\PaymentMethodRepositoryInterface;
use SyliusMolliePlugin\Resolver\Order\PaymentCheckoutOrderResolverInterface;
Expand Down Expand Up @@ -49,6 +50,9 @@ final class MolliePaymentsMethodResolver implements MolliePaymentsMethodResolver
/** @var MollieFactoryNameResolverInterface */
private $mollieFactoryNameResolver;

/** @var DivisorProviderInterface */
private $divisorProvider;

public function __construct(
MollieGatewayConfigRepository $mollieGatewayRepository,
MollieCountriesRestrictionResolverInterface $countriesRestrictionResolver,
Expand All @@ -57,7 +61,8 @@ public function __construct(
PaymentMethodRepositoryInterface $paymentMethodRepository,
MollieAllowedMethodsResolverInterface $allowedMethodsResolver,
MollieLoggerActionInterface $loggerAction,
MollieFactoryNameResolverInterface $mollieFactoryNameResolver
MollieFactoryNameResolverInterface $mollieFactoryNameResolver,
DivisorProviderInterface $divisorProvider
) {
$this->mollieGatewayRepository = $mollieGatewayRepository;
$this->countriesRestrictionResolver = $countriesRestrictionResolver;
Expand All @@ -67,6 +72,7 @@ public function __construct(
$this->allowedMethodsResolver = $allowedMethodsResolver;
$this->loggerAction = $loggerAction;
$this->mollieFactoryNameResolver = $mollieFactoryNameResolver;
$this->divisorProvider = $divisorProvider;
}

public function resolve(): array
Expand Down Expand Up @@ -128,7 +134,7 @@ private function getMolliePaymentOptions(MollieOrderInterface $order, string $co
return $this->getDefaultOptions();
}

$allowedMethods = $this->filterPaymentMethods($paymentConfigs, $allowedMethodsIds, (float)$order->getTotal()/100);
$allowedMethods = $this->filterPaymentMethods($paymentConfigs, $allowedMethodsIds, (float)$order->getTotal()/$this->divisorProvider->getDivisor());

if (0 === count($allowedMethods)) {
return $this->getDefaultOptions();
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services/controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<argument type="service" id="sylius.repository.order" />
<argument type="service" id="router" />
<argument type="service" id="sylius_mollie_plugin.repository.mollie_gateway_config"/>
<argument type="service" id="sylius_mollie_plugin.helper.int_to_string"/>
</service>
<service id="sylius_mollie_plugin.controller.action.shop.payum_controller" class="SyliusMolliePlugin\Controller\Action\Shop\PayumController">
<argument type="service" id="payum" />
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/services/resolver.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<argument type="service" id="sylius_mollie_plugin.resolver.mollie_allowed_methods_resolver"/>
<argument type="service" id="sylius_mollie_plugin.logger.mollie_logger_action"/>
<argument type="service" id="sylius_mollie_plugin.resolver.mollie_factory_name"/>
<argument type="service" id="sylius_mollie_plugin.provider.divisor.divisor_provider"/>
</service>
<service id="sylius_mollie_plugin.resolver.payment_methods_image" class="SyliusMolliePlugin\Resolver\MolliePaymentMethodImageResolver">
<argument>%images_dir%</argument>
Expand Down

0 comments on commit 700208c

Please sign in to comment.