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

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 Doctrine\DBAL\Connection;
  9. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  10. use Shopware\Core\Framework\Plugin;
  11. use Shopware\Core\Framework\Plugin\Context\ActivateContext;
  12. use Shopware\Core\Framework\Plugin\Context\DeactivateContext;
  13. use Shopware\Core\Framework\Plugin\Context\InstallContext;
  14. use Shopware\Core\Framework\Plugin\Context\UninstallContext;
  15. use Shopware\Core\Framework\Plugin\Context\UpdateContext;
  16. use Shopware\Core\Framework\Plugin\Util\PluginIdProvider;
  17. use Shopware\Core\System\CustomField\CustomFieldDefinition;
  18. use Shopware\Core\System\SystemConfig\SystemConfigService;
  19. use Swag\PayPal\Pos\Setting\Service\InformationDefaultService;
  20. use Swag\PayPal\Pos\Webhook\WebhookService as PosWebhookService;
  21. use Swag\PayPal\Util\Lifecycle\ActivateDeactivate;
  22. use Swag\PayPal\Util\Lifecycle\InstallUninstall;
  23. use Swag\PayPal\Util\Lifecycle\Update;
  24. use Swag\PayPal\Webhook\WebhookService;
  25. use Symfony\Component\DependencyInjection\ContainerInterface;
  26. class SwagPayPal extends Plugin
  27. {
  28.     public const ORDER_TRANSACTION_CUSTOM_FIELDS_PAYPAL_TRANSACTION_ID 'swag_paypal_transaction_id';
  29.     public const ORDER_TRANSACTION_CUSTOM_FIELDS_PAYPAL_TOKEN 'swag_paypal_token';
  30.     public const ORDER_TRANSACTION_CUSTOM_FIELDS_PAYPAL_PUI_INSTRUCTION 'swag_paypal_pui_payment_instruction';
  31.     public const ORDER_TRANSACTION_CUSTOM_FIELDS_PAYPAL_ORDER_ID 'swag_paypal_order_id';
  32.     public const ORDER_TRANSACTION_CUSTOM_FIELDS_PAYPAL_PARTNER_ATTRIBUTION_ID 'swag_paypal_partner_attribution_id';
  33.     public const ORDER_TRANSACTION_CUSTOM_FIELDS_PAYPAL_RESOURCE_ID 'swag_paypal_resource_id';
  34.     public const SALES_CHANNEL_TYPE_POS '1ce0868f406d47d98cfe4b281e62f099';
  35.     public const SALES_CHANNEL_POS_EXTENSION 'paypalPosSalesChannel';
  36.     public const PRODUCT_LOG_POS_EXTENSION 'paypalPosLog';
  37.     public const PRODUCT_SYNC_POS_EXTENSION 'paypalPosSync';
  38.     public const POS_PARTNER_CLIENT_ID '456dadab-3085-4fa3-bf2b-a2efd01c3593';
  39.     public const POS_PARTNER_IDENTIFIER 'shopware';
  40.     private const PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_READ 'swag_paypal_pos_sales_channel:read';
  41.     private const PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_UPDATE 'swag_paypal_pos_sales_channel:update';
  42.     private const PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_CREATE 'swag_paypal_pos_sales_channel:create';
  43.     private const PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_DELETE 'swag_paypal_pos_sales_channel:delete';
  44.     private const PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_RUN_READ 'swag_paypal_pos_sales_channel_run:read';
  45.     private const PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_RUN_UPDATE 'swag_paypal_pos_sales_channel_run:update';
  46.     private const PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_RUN_CREATE 'swag_paypal_pos_sales_channel_run:create';
  47.     private const PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_RUN_DELETE 'swag_paypal_pos_sales_channel_run:delete';
  48.     private const PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_RUN_LOG_READ 'swag_paypal_pos_sales_channel_run_log:read';
  49.     /**
  50.      * @var ActivateDeactivate
  51.      */
  52.     private $activateDeactivate;
  53.     /**
  54.      * @Required
  55.      */
  56.     public function setActivateDeactivate(ActivateDeactivate $activateDeactivate): void
  57.     {
  58.         $this->activateDeactivate $activateDeactivate;
  59.     }
  60.     public function install(InstallContext $installContext): void
  61.     {
  62.         /** @var EntityRepositoryInterface $systemConfigRepository */
  63.         $systemConfigRepository $this->container->get('system_config.repository');
  64.         /** @var EntityRepositoryInterface $paymentRepository */
  65.         $paymentRepository $this->container->get('payment_method.repository');
  66.         /** @var EntityRepositoryInterface $salesChannelRepository */
  67.         $salesChannelRepository $this->container->get('sales_channel.repository');
  68.         /** @var EntityRepositoryInterface $ruleRepository */
  69.         $ruleRepository $this->container->get('rule.repository');
  70.         /** @var EntityRepositoryInterface $countryRepository */
  71.         $countryRepository $this->container->get('country.repository');
  72.         /** @var PluginIdProvider $pluginIdProvider */
  73.         $pluginIdProvider $this->container->get(PluginIdProvider::class);
  74.         /** @var SystemConfigService $systemConfigService */
  75.         $systemConfigService $this->container->get(SystemConfigService::class);
  76.         /** @var Connection $connection */
  77.         $connection $this->container->get(Connection::class);
  78.         (new InstallUninstall(
  79.             $systemConfigRepository,
  80.             $paymentRepository,
  81.             $salesChannelRepository,
  82.             $ruleRepository,
  83.             $countryRepository,
  84.             $pluginIdProvider,
  85.             $systemConfigService,
  86.             $connection,
  87.             static::class
  88.         ))->install($installContext->getContext());
  89.         parent::install($installContext);
  90.     }
  91.     public function uninstall(UninstallContext $uninstallContext): void
  92.     {
  93.         $context $uninstallContext->getContext();
  94.         /** @var EntityRepositoryInterface $paymentRepository */
  95.         $paymentRepository $this->container->get('payment_method.repository');
  96.         /** @var EntityRepositoryInterface $salesChannelRepository */
  97.         $salesChannelRepository $this->container->get('sales_channel.repository');
  98.         if ($uninstallContext->keepUserData()) {
  99.             parent::uninstall($uninstallContext);
  100.             return;
  101.         }
  102.         /** @var EntityRepositoryInterface $systemConfigRepository */
  103.         $systemConfigRepository $this->container->get('system_config.repository');
  104.         /** @var EntityRepositoryInterface $countryRepository */
  105.         $countryRepository $this->container->get('country.repository');
  106.         /** @var EntityRepositoryInterface $ruleRepository */
  107.         $ruleRepository $this->container->get('rule.repository');
  108.         /** @var PluginIdProvider $pluginIdProvider */
  109.         $pluginIdProvider $this->container->get(PluginIdProvider::class);
  110.         /** @var SystemConfigService $systemConfigService */
  111.         $systemConfigService $this->container->get(SystemConfigService::class);
  112.         /** @var Connection $connection */
  113.         $connection $this->container->get(Connection::class);
  114.         (new InstallUninstall(
  115.             $systemConfigRepository,
  116.             $paymentRepository,
  117.             $salesChannelRepository,
  118.             $ruleRepository,
  119.             $countryRepository,
  120.             $pluginIdProvider,
  121.             $systemConfigService,
  122.             $connection,
  123.             static::class
  124.         ))->uninstall($context);
  125.         parent::uninstall($uninstallContext);
  126.     }
  127.     public function update(UpdateContext $updateContext): void
  128.     {
  129.         /** @var SystemConfigService $systemConfigService */
  130.         $systemConfigService $this->container->get(SystemConfigService::class);
  131.         /** @var EntityRepositoryInterface $customFieldRepository */
  132.         $customFieldRepository $this->container->get(\sprintf('%s.repository', (new CustomFieldDefinition())->getEntityName()));
  133.         /** @var EntityRepositoryInterface $paymentRepository */
  134.         $paymentRepository $this->container->get('payment_method.repository');
  135.         /** @var WebhookService|null $webhookService */
  136.         $webhookService $this->container->get(WebhookService::class, ContainerInterface::NULL_ON_INVALID_REFERENCE);
  137.         /** @var EntityRepositoryInterface $salesChannelRepository */
  138.         $salesChannelRepository $this->container->get('sales_channel.repository');
  139.         /** @var EntityRepositoryInterface $salesChannelTypeRepository */
  140.         $salesChannelTypeRepository $this->container->get('sales_channel_type.repository');
  141.         /** @var InformationDefaultService|null $informationDefaultService */
  142.         $informationDefaultService $this->container->get(InformationDefaultService::class, ContainerInterface::NULL_ON_INVALID_REFERENCE);
  143.         /** @var EntityRepositoryInterface $shippingRepository */
  144.         $shippingRepository $this->container->get('shipping_method.repository');
  145.         /** @var PosWebhookService|null $posWebhookService */
  146.         $posWebhookService $this->container->get(PosWebhookService::class, ContainerInterface::NULL_ON_INVALID_REFERENCE);
  147.         (new Update(
  148.             $systemConfigService,
  149.             $paymentRepository,
  150.             $customFieldRepository,
  151.             $webhookService,
  152.             $salesChannelRepository,
  153.             $salesChannelTypeRepository,
  154.             $informationDefaultService,
  155.             $shippingRepository,
  156.             $posWebhookService
  157.         ))->update($updateContext);
  158.         parent::update($updateContext);
  159.     }
  160.     public function activate(ActivateContext $activateContext): void
  161.     {
  162.         $this->activateDeactivate->activate($activateContext->getContext());
  163.         parent::activate($activateContext);
  164.     }
  165.     public function deactivate(DeactivateContext $deactivateContext): void
  166.     {
  167.         $this->activateDeactivate->deactivate($deactivateContext->getContext());
  168.         parent::deactivate($deactivateContext);
  169.     }
  170.     public function enrichPrivileges(): array
  171.     {
  172.         return [
  173.             'sales_channel.viewer' => [
  174.                 self::PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_READ,
  175.                 self::PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_RUN_READ,
  176.                 self::PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_RUN_UPDATE,
  177.                 self::PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_RUN_CREATE,
  178.                 self::PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_RUN_LOG_READ,
  179.                 'sales_channel_payment_method:read',
  180.             ],
  181.             'sales_channel.editor' => [
  182.                 self::PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_UPDATE,
  183.                 self::PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_RUN_DELETE,
  184.                 'payment_method:update',
  185.             ],
  186.             'sales_channel.creator' => [
  187.                 self::PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_CREATE,
  188.                 'payment_method:create',
  189.                 'shipping_method:create',
  190.                 'delivery_time:create',
  191.             ],
  192.             'sales_channel.deleter' => [
  193.                 self::PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_DELETE,
  194.             ],
  195.         ];
  196.     }
  197. }