/** * {@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; }
/** * {@inheritdoc} */ public function addConfiguration(ArrayNodeDefinition $builder) { parent::addConfiguration($builder); $builder->children()->scalarNode('type')->isRequired()->cannotBeEmpty()->end()->arrayNode('options')->isRequired()->useAttributeAsKey('key')->prototype('scalar')->end()->end()->end(); $builder->validate()->ifTrue(function ($v) { $gatewayFactory = new GatewayFactory(); $gatewayFactory->find(); $supportedTypes = $gatewayFactory->all(); if (false == in_array($v['type'], $supportedTypes)) { throw new LogicException(sprintf('Given type %s is not supported. Try one of supported types: %s.', $v['type'], implode(', ', $supportedTypes))); } return false; })->thenInvalid('A message'); }
public function testFind() { $gateways = GatewayFactory::find(); $this->assertContains('PayPal_Express', $gateways); $this->assertContains('Stripe', $gateways); }