custom/plugins/MolliePayments/src/MolliePayments.php line 19

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Kiener\MolliePayments;
  3. use Kiener\MolliePayments\Compatibility\DependencyLoader;
  4. use Kiener\MolliePayments\Service\ApplePayDirect\ApplePayDomainVerificationService;
  5. use Kiener\MolliePayments\Service\CustomFieldService;
  6. use Kiener\MolliePayments\Service\PaymentMethodService;
  7. use Shopware\Core\Framework\Context;
  8. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  9. use Shopware\Core\Framework\Plugin;
  10. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  11. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  12. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  13. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  14. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  15. use Symfony\Component\DependencyInjection\ContainerBuilder;
  16. class MolliePayments extends Plugin
  17. {
  18.     const PLUGIN_VERSION '2.2.0';
  19.     /**
  20.      * @param ContainerBuilder $container
  21.      */
  22.     public function build(ContainerBuilder $container): void
  23.     {
  24.         parent::build($container);
  25.         $this->container $container;
  26.         # load the dependencies that are compatible
  27.         # with our current shopware version
  28.         $loader = new DependencyLoader($container);
  29.         $loader->loadServices();
  30.     }
  31.     public function boot(): void
  32.     {
  33.         parent::boot();
  34.     }
  35.     public function install(InstallContext $context): void
  36.     {
  37.         parent::install($context);
  38.         /** @var EntityRepositoryInterface $customFieldRepository */
  39.         $customFieldRepository $this->container->get('custom_field_set.repository');
  40.         // Add custom fields
  41.         $customFieldService = new CustomFieldService(
  42.             $this->container,
  43.             $customFieldRepository
  44.         );
  45.         $customFieldService->addCustomFields($context->getContext());
  46.     }
  47.     public function update(UpdateContext $context): void
  48.     {
  49.         parent::update($context);
  50.         if ($context->getPlugin()->isActive() === true) {
  51.             // Install and activate payment methods
  52.             $this->installAndActivatePaymentMethods($context->getContext());
  53.             // add domain verification
  54.             /** @var ApplePayDomainVerificationService $domainVerificationService */
  55.             $domainVerificationService $this->container->get(ApplePayDomainVerificationService::class);
  56.             $domainVerificationService->downloadDomainAssociationFile();
  57.         }
  58.     }
  59.     public function postInstall(InstallContext $context): void
  60.     {
  61.         parent::postInstall($context);
  62.     }
  63.     public function uninstall(UninstallContext $context): void
  64.     {
  65.         parent::uninstall($context);
  66.     }
  67.     public function activate(ActivateContext $context): void
  68.     {
  69.         parent::activate($context);
  70.         // Install and activate payment methods
  71.         $this->installAndActivatePaymentMethods($context->getContext());
  72.         // Add domain verification
  73.         /** @var ApplePayDomainVerificationService $domainVerificationService */
  74.         $domainVerificationService $this->container->get(ApplePayDomainVerificationService::class);
  75.         $domainVerificationService->downloadDomainAssociationFile();
  76.     }
  77.     public function deactivate(DeactivateContext $context): void
  78.     {
  79.         parent::deactivate($context);
  80.     }
  81.     /**
  82.      * @param Context $context
  83.      */
  84.     private function installAndActivatePaymentMethods(Context $context): void
  85.     {
  86.         /** @var PaymentMethodService $paymentMethodService */
  87.         $paymentMethodService $this->container->get(PaymentMethodService::class);
  88.         $paymentMethodService->installAndActivatePaymentMethods($context);
  89.     }
  90. }