EncryptionPaymentDataUpdateCommand.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Sales\Console\Command;
  8. use Symfony\Component\Console\Input\InputInterface;
  9. use Symfony\Component\Console\Output\OutputInterface;
  10. use Symfony\Component\Console\Command\Command;
  11. use Magento\Framework\Console\Cli;
  12. /**
  13. * Command for updating encrypted credit card data to the latest cipher
  14. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  15. */
  16. class EncryptionPaymentDataUpdateCommand extends Command
  17. {
  18. /** Command name */
  19. const NAME = 'encryption:payment-data:update';
  20. /**
  21. * @var \Magento\Sales\Model\ResourceModel\Order\Payment\EncryptionUpdate
  22. */
  23. private $paymentResource;
  24. /**
  25. * @param \Magento\Sales\Model\ResourceModel\Order\Payment\EncryptionUpdate $paymentResource
  26. */
  27. public function __construct(
  28. \Magento\Sales\Model\ResourceModel\Order\Payment\EncryptionUpdate $paymentResource
  29. ) {
  30. $this->paymentResource = $paymentResource;
  31. parent::__construct();
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. protected function configure()
  37. {
  38. $this->setName(self::NAME)
  39. ->setDescription(
  40. 'Re-encrypts encrypted credit card data with latest encryption cipher.'
  41. );
  42. parent::configure();
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. protected function execute(InputInterface $input, OutputInterface $output)
  48. {
  49. try {
  50. $this->paymentResource->reEncryptCreditCardNumbers();
  51. } catch (\Exception $e) {
  52. $output->writeln('<error>' . $e->getMessage() . '</error>');
  53. return Cli::RETURN_FAILURE;
  54. }
  55. return Cli::RETURN_SUCCESS;
  56. }
  57. }