app/Plugin/PayPalCheckout42/Entity/Config.php line 15

Open in your IDE?
  1. <?php
  2. namespace Plugin\PayPalCheckout42\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Plugin\PayPalCheckout42\Util\StringUtil;
  5. use stdClass;
  6. /**
  7.  * Config
  8.  *
  9.  * @ORM\Table(name="plg_paypal_config")
  10.  * @ORM\Entity(repositoryClass="Plugin\PayPalCheckout42\Repository\ConfigRepository")
  11.  */
  12. class Config
  13. {
  14.     /**
  15.      * @var int
  16.      *
  17.      * @ORM\Column(name="id", type="integer", options={"unsigned":true})
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue(strategy="IDENTITY")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @var string
  24.      *
  25.      * @ORM\Column(name="client_id", type="string", length=255)
  26.      */
  27.     private $client_id;
  28.     /**
  29.      * @var string
  30.      *
  31.      * @ORM\Column(name="client_secret", type="string", length=255)
  32.      */
  33.     private $client_secret;
  34.     /**
  35.      * @var boolean
  36.      *
  37.      * @ORM\Column(name="use_sandbox", type="boolean", options={"default":true})
  38.      */
  39.     private $use_sandbox;
  40.     /**
  41.      * @var string
  42.      *
  43.      * @ORM\Column(name="paypal_logo", type="string", length=255)
  44.      */
  45.     private $paypal_logo;
  46.     /**
  47.      * @var string
  48.      *
  49.      * @ORM\Column(name="payment_paypal_logo", type="string", length=255)
  50.      */
  51.     private $payment_paypal_logo;
  52.     /**
  53.      * @var boolean
  54.      *
  55.      * @ORM\Column(name="use_express_btn", type="boolean", options={"default":false})
  56.      */
  57.     private $use_express_btn;
  58.     /**
  59.      * @var boolean
  60.      *
  61.      * @ORM\Column(name="use_vault", type="boolean", options={"default":false})
  62.      */
  63.     private $use_vault;
  64.     /**
  65.      * @var boolean
  66.      *
  67.      * @ORM\Column(name="use_3dsecure", type="boolean", options={"default":false})
  68.      */
  69.     private $use_3dsecure;
  70.     /**
  71.      * @var int|null
  72.      *
  73.      * @ORM\Column(name="reference_day", type="integer", nullable=true)
  74.      */
  75.     private $reference_day;
  76.     /**
  77.      * @var int|null
  78.      *
  79.      * @ORM\Column(name="cut_off_day", type="integer", nullable=true)
  80.      */
  81.     private $cut_off_day;
  82.     /**
  83.      * @var string
  84.      *
  85.      * @ORM\Column(name="site_unique_key", type="string", length=255)
  86.      */
  87.     private $site_unique_key;
  88.     /**
  89.      * Config constructor.
  90.      * @param stdClass $params
  91.      */
  92.     private function __construct(stdClass $params)
  93.     {
  94.         $this->client_id $params->client_id;
  95.         $this->client_secret $params->client_secret;
  96.         $this->use_sandbox $params->use_sandbox;
  97.         $this->use_express_btn $params->use_express_btn;
  98.         $this->paypal_logo $params->paypal_logo;
  99.         $this->payment_paypal_logo $params->payment_paypal_logo;
  100.         $this->reference_day $params->reference_day;
  101.         $this->cut_off_day $params->cut_off_day;
  102.         $this->use_express_btn $params->use_express_btn;
  103.         $this->use_vault $params->use_vault;
  104.         $this->use_3dsecure $params->use_3dsecure;
  105.         $this->site_unique_key $params->site_unique_key;
  106.     }
  107.     /**
  108.      * @return Config
  109.      */
  110.     public static function createInitialConfig(): Config
  111.     {
  112.         /** @var stdClass $params */
  113.         $params = new stdClass();
  114.         $params->client_id '';
  115.         $params->client_secret '';
  116.         $params->use_sandbox true;
  117.         $params->use_express_btn true;
  118.         $params->use_vault false;
  119.         $params->use_3dsecure false;
  120.         $params->paypal_logo 1;
  121.         $params->payment_paypal_logo 1;
  122.         $params->reference_day 2;
  123.         $params->cut_off_day 15;
  124.         $params->site_unique_key StringUtil::createRandomString();
  125.         return new static($params);
  126.     }
  127.     /**
  128.      * @return int
  129.      */
  130.     public function getId()
  131.     {
  132.         return $this->id;
  133.     }
  134.     /**
  135.      * @return string
  136.      */
  137.     public function getClientId()
  138.     {
  139.         return $this->client_id;
  140.     }
  141.     /**
  142.      * @return string
  143.      */
  144.     public function getClientSecret()
  145.     {
  146.         return $this->client_secret;
  147.     }
  148.     /**
  149.      * Get use_sandbox
  150.      *
  151.      * @return boolean
  152.      */
  153.     public function getUseSandbox()
  154.     {
  155.         return $this->use_sandbox;
  156.     }
  157.     /**
  158.      * Get paypal_logo
  159.      *
  160.      * @return string
  161.      */
  162.     public function getPaypalLogo()
  163.     {
  164.         return $this->paypal_logo;
  165.     }
  166.     /**
  167.      * Get payment_paypal_logo
  168.      *
  169.      * @return string
  170.      */
  171.     public function getPaymentPaypalLogo()
  172.     {
  173.         return $this->payment_paypal_logo;
  174.     }
  175.     /**
  176.      * @return int|null
  177.      */
  178.     public function getReferenceDay()
  179.     {
  180.         return $this->reference_day;
  181.     }
  182.     /**
  183.      * @return int|null
  184.      */
  185.     public function getCutOffDay()
  186.     {
  187.         return $this->cut_off_day;
  188.     }
  189.     /**
  190.      * @return bool
  191.      */
  192.     public function getUseExpressBtn()
  193.     {
  194.         return $this->use_express_btn;
  195.     }
  196.     /**
  197.      * @return bool
  198.      */
  199.     public function getUseVault()
  200.     {
  201.         return $this->use_vault;
  202.     }
  203.     /**
  204.      * @return bool
  205.      */
  206.     public function getUse3dsecure()
  207.     {
  208.         return $this->use_3dsecure;
  209.     }
  210.     /**
  211.      * @return string
  212.      */
  213.     public function getSiteUniqueKey()
  214.     {
  215.         return $this->site_unique_key;
  216.     }
  217.     /**
  218.      * @return PluginSetting
  219.      */
  220.     public function createPluginSettingForm(): PluginSetting
  221.     {
  222.         /** @var PluginSetting $pluginSetting */
  223.         $pluginSetting = new PluginSetting();
  224.         $pluginSetting
  225.             ->setClientId($this->client_id)
  226.             ->setClientSecret($this->client_secret)
  227.             ->setUseSandbox($this->use_sandbox)
  228.             ->setPaypalLogo($this->paypal_logo)
  229.             ->setPaymentPaypalLogo($this->payment_paypal_logo)
  230.             ->setReferenceDay($this->reference_day)
  231.             ->setCutOffDay($this->cut_off_day)
  232.             ->setUseExpressBtn($this->use_express_btn)
  233.             ->setUseVault($this->use_vault)
  234.             ->setUse3dsecure($this->use_3dsecure);
  235.         return $pluginSetting;
  236.     }
  237.     /**
  238.      * @param PluginSetting $pluginSetting
  239.      */
  240.     public function savePluginSetting(PluginSetting $pluginSetting): void
  241.     {
  242.         $this->client_id $pluginSetting->getClientId();
  243.         $this->client_secret $pluginSetting->getClientSecret();
  244.         $this->use_sandbox $pluginSetting->getUseSandbox();
  245.         $this->paypal_logo $pluginSetting->getPaypalLogo();
  246.         $this->payment_paypal_logo $pluginSetting->getPaymentPaypalLogo();
  247.         $this->reference_day $pluginSetting->getReferenceDay();
  248.         $this->cut_off_day $pluginSetting->getCutOffDay();
  249.         $this->use_express_btn $pluginSetting->getUseExpressBtn();
  250.         $this->use_vault $pluginSetting->getUseVault();
  251.         $this->use_3dsecure $pluginSetting->getUse3dsecure();
  252.     }
  253. }