Beispiel #1
0
 * @license   http://www.x-cart.com/license-agreement.html X-Cart 5 License Agreement
 * @link      http://www.x-cart.com/
 */
return function () {
    $method = \XLite\Core\Database::getRepo('XLite\\Model\\Payment\\Method')->findOneBy(array('service_name' => 'Stripe'));
    if ($method) {
        $isInTestMode = \XLite\View\FormField\Select\TestLiveMode::TEST === $method->getSetting('mode');
        $accessToken = $method->getSetting('accessToken');
        $publishKey = $method->getSetting('publishKey');
        $setting = new \XLite\Model\Payment\MethodSetting();
        $setting->setName('accessTokenTest');
        $setting->setValue($isInTestMode ? $accessToken : '');
        $setting->setPaymentMethod($method);
        $setting->persist();
        $method->addSettings($setting);
        $setting = new \XLite\Model\Payment\MethodSetting();
        $setting->setName('publishKeyTest');
        $setting->setValue($isInTestMode ? $publishKey : '');
        $setting->setPaymentMethod($method);
        $setting->persist();
        $method->addSettings($setting);
        if ($isInTestMode) {
            foreach ($method->getSettings() as $setting) {
                if (in_array($setting->getName(), array('accessToken', 'publishKey'))) {
                    $setting->setValue('');
                }
            }
        }
        \XLite\Core\Database::getEM()->flush();
    }
};
Beispiel #2
0
 /**
  * Set setting value by name
  *
  * @param string $name  Name
  * @param string $value Value
  *
  * @return boolean
  */
 public function setSetting($name, $value)
 {
     $result = false;
     // Update settings which is already stored in database
     foreach ($this->getSettings() as $setting) {
         if ($setting->getName() == $name) {
             $setting->setValue(strval($value));
             $result = true;
             break;
         }
     }
     if (!$result) {
         // Create setting which is not in database but specified in the processor class
         $processor = $this->getProcessor();
         if ($processor && method_exists($processor, 'getAvailableSettings')) {
             $availableSettings = $processor->getAvailableSettings();
             if (in_array($name, $availableSettings)) {
                 $setting = new \XLite\Model\Payment\MethodSetting();
                 $setting->setName($name);
                 $setting->setValue($value);
                 $setting->setPaymentMethod($this);
                 \XLite\Core\Database::getEM()->persist($setting);
             }
         }
     }
     return $result;
 }