custom/plugins/SwagPayPal/src/SwagPayPal.php line 26

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /*
  3.  * (c) shopware AG <info@shopware.com>
  4.  * For the full copyright and license information, please view the LICENSE
  5.  * file that was distributed with this source code.
  6.  */
  7. namespace Swag\PayPal;
  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 Shopware\Core\Framework\Plugin\Util\PluginIdProvider;
  16. use Shopware\Core\System\SystemConfig\SystemConfigService;
  17. use Swag\PayPal\Util\Lifecycle\ActivateDeactivate;
  18. use Swag\PayPal\Util\Lifecycle\InstallUninstall;
  19. use Swag\PayPal\Util\Lifecycle\Update;
  20. use Symfony\Component\Config\FileLocator;
  21. use Symfony\Component\DependencyInjection\ContainerBuilder;
  22. use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
  23. class SwagPayPal extends Plugin
  24. {
  25.     public const ORDER_TRANSACTION_CUSTOM_FIELDS_PAYPAL_TRANSACTION_ID 'swag_paypal_transaction_id';
  26.     public const ORDER_TRANSACTION_CUSTOM_FIELDS_PAYPAL_TOKEN 'swag_paypal_token';
  27.     public const ORDER_TRANSACTION_CUSTOM_FIELDS_PAYPAL_PUI_INSTRUCTION 'swag_paypal_pui_payment_instruction';
  28.     /**
  29.      * @var ActivateDeactivate
  30.      */
  31.     private $activateDeactivate;
  32.     /**
  33.      * @Required
  34.      */
  35.     public function setActivateDeactivate(ActivateDeactivate $activateDeactivate): void
  36.     {
  37.         $this->activateDeactivate $activateDeactivate;
  38.     }
  39.     /**
  40.      * {@inheritdoc}
  41.      */
  42.     public function build(ContainerBuilder $container): void
  43.     {
  44.         parent::build($container);
  45.         $loader = new XmlFileLoader($container, new FileLocator(__DIR__ '/DependencyInjection/'));
  46.         $loader->load('client.xml');
  47.         $loader->load('paypal_payment.xml');
  48.         $loader->load('resource.xml');
  49.         $loader->load('setting.xml');
  50.         $loader->load('util.xml');
  51.         $loader->load('webhook.xml');
  52.         $loader->load('express_checkout.xml');
  53.         $loader->load('spb_checkout.xml');
  54.         $loader->load('pui_checkout.xml');
  55.         $loader->load('checkout.xml');
  56.         $loader->load('plus.xml');
  57.         $loader->load('installment.xml');
  58.     }
  59.     public function install(InstallContext $installContext): void
  60.     {
  61.         /** @var EntityRepositoryInterface $systemConfigRepository */
  62.         $systemConfigRepository $this->container->get('system_config.repository');
  63.         /** @var EntityRepositoryInterface $paymentRepository */
  64.         $paymentRepository $this->container->get('payment_method.repository');
  65.         /** @var EntityRepositoryInterface $salesChannelRepository */
  66.         $salesChannelRepository $this->container->get('sales_channel.repository');
  67.         /** @var EntityRepositoryInterface $ruleRepository */
  68.         $ruleRepository $this->container->get('rule.repository');
  69.         /** @var EntityRepositoryInterface $countryRepository */
  70.         $countryRepository $this->container->get('country.repository');
  71.         (new InstallUninstall(
  72.             $systemConfigRepository,
  73.             $paymentRepository,
  74.             $salesChannelRepository,
  75.             $ruleRepository,
  76.             $countryRepository,
  77.             $this->container->get(PluginIdProvider::class),
  78.             $this->container->get(SystemConfigService::class),
  79.             \get_class($this)
  80.         ))->install($installContext->getContext());
  81.         parent::install($installContext);
  82.     }
  83.     public function uninstall(UninstallContext $uninstallContext): void
  84.     {
  85.         $context $uninstallContext->getContext();
  86.         /** @var EntityRepositoryInterface $paymentRepository */
  87.         $paymentRepository $this->container->get('payment_method.repository');
  88.         /** @var EntityRepositoryInterface $salesChannelRepository */
  89.         $salesChannelRepository $this->container->get('sales_channel.repository');
  90.         if ($uninstallContext->keepUserData()) {
  91.             parent::uninstall($uninstallContext);
  92.             return;
  93.         }
  94.         /** @var EntityRepositoryInterface $systemConfigRepository */
  95.         $systemConfigRepository $this->container->get('system_config.repository');
  96.         /** @var EntityRepositoryInterface $countryRepository */
  97.         $countryRepository $this->container->get('country.repository');
  98.         /** @var EntityRepositoryInterface $ruleRepository */
  99.         $ruleRepository $this->container->get('rule.repository');
  100.         (new InstallUninstall(
  101.             $systemConfigRepository,
  102.             $paymentRepository,
  103.             $salesChannelRepository,
  104.             $ruleRepository,
  105.             $countryRepository,
  106.             $this->container->get(PluginIdProvider::class),
  107.             $this->container->get(SystemConfigService::class),
  108.             \get_class($this)
  109.         ))->uninstall($context);
  110.         parent::uninstall($uninstallContext);
  111.     }
  112.     public function update(UpdateContext $updateContext): void
  113.     {
  114.         (new Update($this->container->get(SystemConfigService::class)))->update($updateContext);
  115.         parent::update($updateContext);
  116.     }
  117.     public function activate(ActivateContext $activateContext): void
  118.     {
  119.         $this->activateDeactivate->activate($activateContext->getContext());
  120.         parent::activate($activateContext);
  121.     }
  122.     public function deactivate(DeactivateContext $deactivateContext): void
  123.     {
  124.         $this->activateDeactivate->deactivate($deactivateContext->getContext());
  125.         parent::deactivate($deactivateContext);
  126.     }
  127. }