/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$builder = new TreeBuilder();
$rootNode = $builder->root('sylius_omnipay');
$gateways = GatewayFactory::find();
$omnipayCc = new CreditCard();
$ccTypes = array_keys($omnipayCc->getSupportedBrands());
$rootNode->children()->arrayNode('gateways')->useAttributeAsKey('name')->prototype('array')->children()->scalarNode('type')->validate()->ifTrue(function ($type) use($gateways) {
if (empty($type)) {
return true;
}
if (0 !== strpos($type, '\\') && !in_array($type, $gateways)) {
return true;
}
return false;
})->thenInvalid(sprintf('Unknown payment gateway selected. Valid gateways are: %s.', implode(", ", $gateways)))->end()->end()->scalarNode('label')->cannotBeEmpty()->end()->booleanNode('mode')->defaultFalse()->end()->booleanNode('active')->defaultTrue()->end()->arrayNode('cc_types')->prototype('scalar')->validate()->ifTrue(function ($ccType) use($ccTypes) {
if (empty($ccType)) {
return true;
}
if (!in_array($ccType, $ccTypes)) {
return true;
}
return false;
})->thenInvalid(sprintf('Unknown credit card type selected. Valid credit card types are: %s.', implode(", ", $ccTypes)))->end()->end()->end()->arrayNode('options')->prototype('scalar')->end()->end()->end()->end()->end();
return $builder;
}