Permalink
Browse files

Store encrypted gateway configurations in the database

  • Loading branch information...
pamil committed Mar 29, 2017
1 parent 91da139 commit 6b28f694f5a1b4faa07459e451fe345fccd4904f
@@ -42,8 +42,8 @@
"knplabs/knp-menu-bundle": "^2.1",
"liip/imagine-bundle": "^1.6",
"ocramius/proxy-manager": "^1.0",
"payum/payum": "^1.3",
"payum/payum-bundle": "^2.1",
"payum/payum": "^1.4",
"payum/payum-bundle": "^2.2",
"php-http/guzzle6-adapter": "^1.1",
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"sensio/distribution-bundle": "^5.0",

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -11,8 +11,6 @@
namespace Sylius\Bundle\PayumBundle\DependencyInjection;
use Payum\Bundle\PayumBundle\DependencyInjection\MainConfiguration as PayumConfiguration;
use Payum\Bundle\PayumBundle\DependencyInjection\PayumExtension;
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -0,0 +1,82 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sylius\Bundle\PayumBundle\Form\Extension;
use Payum\Core\Security\CryptedInterface;
use Payum\Core\Security\CypherInterface;
use Sylius\Bundle\PayumBundle\Form\Type\GatewayConfigType;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
/**
* @author Kamil Kokot <kamil.kokot@lakion.com>
*/
final class CryptedGatewayConfigTypeExtension extends AbstractTypeExtension
{
/**
* @var CypherInterface|null
*/
private $cypher;
/**
* @param CypherInterface|null $cypher
*/
public function __construct(CypherInterface $cypher = null)
{
$this->cypher = $cypher;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if (null === $this->cypher) {
return;
}
$builder
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$gatewayConfig = $event->getData();
if (!$gatewayConfig instanceof CryptedInterface) {
return;
}
$gatewayConfig->decrypt($this->cypher);
$event->setData($gatewayConfig);
})
->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
$gatewayConfig = $event->getData();
if (!$gatewayConfig instanceof CryptedInterface) {
return;
}
$gatewayConfig->encrypt($this->cypher);
$event->setData($gatewayConfig);
})
;
}
/**
* {@inheritdoc}
*/
public function getExtendedType()
{
return GatewayConfigType::class;
}
}
@@ -37,7 +37,7 @@
*/
public function __construct(
$dataClass,
$validationGroups = [],
array $validationGroups = [],
FormTypeRegistryInterface $gatewayConfigurationTypeRegistry
) {
parent::__construct($dataClass, $validationGroups);
@@ -11,89 +11,21 @@
namespace Sylius\Bundle\PayumBundle\Model;
use Payum\Core\Model\GatewayConfigInterface;
use Payum\Core\Model\GatewayConfig as BaseGatewayConfig;
use Sylius\Component\Resource\Model\ResourceInterface;
class GatewayConfig implements GatewayConfigInterface, ResourceInterface
class GatewayConfig extends BaseGatewayConfig implements ResourceInterface
{
/**
* @var int
*/
protected $id;
/**
* @var string
*/
protected $gatewayName;
/**
* @var string
*/
protected $factoryName;
/**
* @var array
*/
protected $config;
public function __construct()
{
$this->config = [];
}
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* {@inheritdoc}
*/
public function getGatewayName()
{
return $this->gatewayName;
}
/**
* {@inheritdoc}
*/
public function setGatewayName($gatewayName)
{
$this->gatewayName = $gatewayName;
}
/**
* {@inheritdoc}
*/
public function getFactoryName()
{
return $this->factoryName;
}
/**
* {@inheritdoc}
*/
public function setFactoryName($factoryName)
{
$this->factoryName = $factoryName;
}
/**
* {@inheritdoc}
*/
public function getConfig()
{
return $this->config;
}
/**
* {@inheritdoc}
*/
public function setConfig(array $config)
{
$this->config = $config;
}
}
@@ -17,16 +17,8 @@
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>
<mapped-superclass name="Sylius\Bundle\PayumBundle\Model\GatewayConfig" table="sylius_gateway_config">

<id name="id" column="id" type="integer">
<generator strategy="AUTO" />
</id>

<field name="config" column="config" type="json_array" nullable="false" />

<field name="gatewayName" column="gateway_name" type="string" length="255" nullable="false" />

<field name="factoryName" column="factory_name" type="string" length="255" nullable="false" />

</mapped-superclass>
</doctrine-mapping>
Oops, something went wrong.

0 comments on commit 6b28f69

Please sign in to comment.