src/Domain/PaymentGateway/Model/PaymentGatewayConfig.php line 16

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Domain\PaymentGateway\Model;
  4. use App\Domain\Shared\Model\TimestampTrait;
  5. use App\Domain\Site\Model\Site;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Payum\Core\Model\GatewayConfigInterface;
  9. use Payum\Core\Security\CryptedInterface;
  10. use Payum\Core\Security\CypherInterface;
  11. use Symfony\Component\Uid\Uuid;
  12. class PaymentGatewayConfig implements GatewayConfigInterfaceCryptedInterface
  13. {
  14.     use TimestampTrait;
  15.     private array $decryptedConfig = [];
  16.     /**
  17.      * @var Collection<array-key, Site>
  18.      */
  19.     private Collection $sites;
  20.     public function __construct(
  21.         private Uuid $id,
  22.         private string $name,
  23.         private string $factoryName,
  24.         private string $gatewayName,
  25.         private array $config = [],
  26.         private bool $active true
  27.     ) {
  28.         $this->sites = new ArrayCollection();
  29.         $this->createdAt = new \DateTimeImmutable();
  30.         $this->updatedAt null;
  31.     }
  32.     public function getFactoryName(): string
  33.     {
  34.         return $this->factoryName;
  35.     }
  36.     /**
  37.      * {@inheritDoc}
  38.      */
  39.     public function setFactoryName($name): void
  40.     {
  41.         $this->factoryName $name;
  42.     }
  43.     public function getGatewayName(): string
  44.     {
  45.         return $this->gatewayName;
  46.     }
  47.     /**
  48.      * @param string $gatewayName
  49.      */
  50.     public function setGatewayName($gatewayName): void
  51.     {
  52.         $this->gatewayName $gatewayName;
  53.     }
  54.     /**
  55.      * {@inheritDoc}
  56.      */
  57.     public function getConfig(): array
  58.     {
  59.         if (isset($this->config['encrypted'])) {
  60.             return $this->decryptedConfig;
  61.         }
  62.         return $this->config;
  63.     }
  64.     /**
  65.      * {@inheritDoc}
  66.      */
  67.     public function setConfig(array $config): void
  68.     {
  69.         $this->config $config;
  70.         $this->decryptedConfig $config;
  71.     }
  72.     /**
  73.      * {@inheritdoc}
  74.      */
  75.     public function decrypt(CypherInterface $cypher): void
  76.     {
  77.         if (empty($this->config['encrypted'])) {
  78.             return;
  79.         }
  80.         foreach ($this->config as $name => $value) {
  81.             if ('encrypted' == $name || is_bool($value)) {
  82.                 $this->decryptedConfig[$name] = $value;
  83.                 continue;
  84.             }
  85.             $this->decryptedConfig[$name] = $cypher->decrypt($value);
  86.         }
  87.     }
  88.     /**
  89.      * {@inheritdoc}
  90.      */
  91.     public function encrypt(CypherInterface $cypher): void
  92.     {
  93.         $this->decryptedConfig['encrypted'] = true;
  94.         foreach ($this->decryptedConfig as $name => $value) {
  95.             if ('encrypted' == $name || is_bool($value)) {
  96.                 $this->config[$name] = $value;
  97.                 continue;
  98.             }
  99.             $this->config[$name] = $cypher->encrypt($value);
  100.         }
  101.     }
  102.     public function getId(): Uuid
  103.     {
  104.         return $this->id;
  105.     }
  106.     public function isActive(): bool
  107.     {
  108.         return $this->active;
  109.     }
  110.     public function getName(): string
  111.     {
  112.         return $this->name;
  113.     }
  114.     public function setName(string $name): void
  115.     {
  116.         $this->name $name;
  117.     }
  118. }