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 '48804990-9c6d-4579-9c39-eae6d93e5f94';
  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.     private ActivateDeactivate $activateDeactivate;
  50.     /**
  51.      * @Required
  52.      */
  53.     public function setActivateDeactivate(ActivateDeactivate $activateDeactivate): void
  54.     {
  55.         $this->activateDeactivate $activateDeactivate;
  56.     }
  57.     public function install(InstallContext $installContext): void
  58.     {
  59.         /** @var EntityRepositoryInterface $systemConfigRepository */
  60.         $systemConfigRepository $this->container->get('system_config.repository');
  61.         /** @var EntityRepositoryInterface $paymentRepository */
  62.         $paymentRepository $this->container->get('payment_method.repository');
  63.         /** @var EntityRepositoryInterface $salesChannelRepository */
  64.         $salesChannelRepository $this->container->get('sales_channel.repository');
  65.         /** @var EntityRepositoryInterface $ruleRepository */
  66.         $ruleRepository $this->container->get('rule.repository');
  67.         /** @var EntityRepositoryInterface $countryRepository */
  68.         $countryRepository $this->container->get('country.repository');
  69.         /** @var PluginIdProvider $pluginIdProvider */
  70.         $pluginIdProvider $this->container->get(PluginIdProvider::class);
  71.         /** @var SystemConfigService $systemConfigService */
  72.         $systemConfigService $this->container->get(SystemConfigService::class);
  73.         /** @var Connection $connection */
  74.         $connection $this->container->get(Connection::class);
  75.         (new InstallUninstall(
  76.             $systemConfigRepository,
  77.             $paymentRepository,
  78.             $salesChannelRepository,
  79.             $ruleRepository,
  80.             $countryRepository,
  81.             $pluginIdProvider,
  82.             $systemConfigService,
  83.             $connection,
  84.             static::class
  85.         ))->install($installContext->getContext());
  86.         parent::install($installContext);
  87.     }
  88.     public function uninstall(UninstallContext $uninstallContext): void
  89.     {
  90.         $context $uninstallContext->getContext();
  91.         /** @var EntityRepositoryInterface $paymentRepository */
  92.         $paymentRepository $this->container->get('payment_method.repository');
  93.         /** @var EntityRepositoryInterface $salesChannelRepository */
  94.         $salesChannelRepository $this->container->get('sales_channel.repository');
  95.         if ($uninstallContext->keepUserData()) {
  96.             parent::uninstall($uninstallContext);
  97.             return;
  98.         }
  99.         /** @var EntityRepositoryInterface $systemConfigRepository */
  100.         $systemConfigRepository $this->container->get('system_config.repository');
  101.         /** @var EntityRepositoryInterface $countryRepository */
  102.         $countryRepository $this->container->get('country.repository');
  103.         /** @var EntityRepositoryInterface $ruleRepository */
  104.         $ruleRepository $this->container->get('rule.repository');
  105.         /** @var PluginIdProvider $pluginIdProvider */
  106.         $pluginIdProvider $this->container->get(PluginIdProvider::class);
  107.         /** @var SystemConfigService $systemConfigService */
  108.         $systemConfigService $this->container->get(SystemConfigService::class);
  109.         /** @var Connection $connection */
  110.         $connection $this->container->get(Connection::class);
  111.         (new InstallUninstall(
  112.             $systemConfigRepository,
  113.             $paymentRepository,
  114.             $salesChannelRepository,
  115.             $ruleRepository,
  116.             $countryRepository,
  117.             $pluginIdProvider,
  118.             $systemConfigService,
  119.             $connection,
  120.             static::class
  121.         ))->uninstall($context);
  122.         parent::uninstall($uninstallContext);
  123.     }
  124.     public function update(UpdateContext $updateContext): void
  125.     {
  126.         /** @var SystemConfigService $systemConfigService */
  127.         $systemConfigService $this->container->get(SystemConfigService::class);
  128.         /** @var EntityRepositoryInterface $customFieldRepository */
  129.         $customFieldRepository $this->container->get(\sprintf('%s.repository', (new CustomFieldDefinition())->getEntityName()));
  130.         /** @var EntityRepositoryInterface $paymentRepository */
  131.         $paymentRepository $this->container->get('payment_method.repository');
  132.         /** @var WebhookService|null $webhookService */
  133.         $webhookService $this->container->get(WebhookService::class, ContainerInterface::NULL_ON_INVALID_REFERENCE);
  134.         /** @var EntityRepositoryInterface $salesChannelRepository */
  135.         $salesChannelRepository $this->container->get('sales_channel.repository');
  136.         /** @var EntityRepositoryInterface $salesChannelTypeRepository */
  137.         $salesChannelTypeRepository $this->container->get('sales_channel_type.repository');
  138.         /** @var InformationDefaultService|null $informationDefaultService */
  139.         $informationDefaultService $this->container->get(InformationDefaultService::class, ContainerInterface::NULL_ON_INVALID_REFERENCE);
  140.         /** @var EntityRepositoryInterface $shippingRepository */
  141.         $shippingRepository $this->container->get('shipping_method.repository');
  142.         /** @var PosWebhookService|null $posWebhookService */
  143.         $posWebhookService $this->container->get(PosWebhookService::class, ContainerInterface::NULL_ON_INVALID_REFERENCE);
  144.         (new Update(
  145.             $systemConfigService,
  146.             $paymentRepository,
  147.             $customFieldRepository,
  148.             $webhookService,
  149.             $salesChannelRepository,
  150.             $salesChannelTypeRepository,
  151.             $informationDefaultService,
  152.             $shippingRepository,
  153.             $posWebhookService
  154.         ))->update($updateContext);
  155.         parent::update($updateContext);
  156.     }
  157.     public function activate(ActivateContext $activateContext): void
  158.     {
  159.         $this->activateDeactivate->activate($activateContext->getContext());
  160.         parent::activate($activateContext);
  161.     }
  162.     public function deactivate(DeactivateContext $deactivateContext): void
  163.     {
  164.         $this->activateDeactivate->deactivate($deactivateContext->getContext());
  165.         parent::deactivate($deactivateContext);
  166.     }
  167.     public function enrichPrivileges(): array
  168.     {
  169.         return [
  170.             'sales_channel.viewer' => [
  171.                 self::PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_READ,
  172.                 self::PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_RUN_READ,
  173.                 self::PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_RUN_UPDATE,
  174.                 self::PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_RUN_CREATE,
  175.                 self::PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_RUN_LOG_READ,
  176.                 'sales_channel_payment_method:read',
  177.             ],
  178.             'sales_channel.editor' => [
  179.                 self::PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_UPDATE,
  180.                 self::PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_RUN_DELETE,
  181.                 'payment_method:update',
  182.             ],
  183.             'sales_channel.creator' => [
  184.                 self::PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_CREATE,
  185.                 'payment_method:create',
  186.                 'shipping_method:create',
  187.                 'delivery_time:create',
  188.             ],
  189.             'sales_channel.deleter' => [
  190.                 self::PAYPAL_POS_SALES_CHANNEL_PRIVILEGE_DELETE,
  191.             ],
  192.         ];
  193.     }
  194. }