<?php
namespace WAM\Bundle\PaymentBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use WAM\Bundle\PaymentBundle\Service\PaymentBridge;
/**
* Class Configuration.
*
* @author Juanjo MartÃnez <jmartinez@wearemarketing.com>
*/
class Configuration implements ConfigurationInterface
{
const FREE_PAYMENT_METHOD = 'wam_payment.free_payment';
const PAYLANDS_METHOD = 'wam_payment.paylands';
const PAYPAL_WEB_CHECKOUT_METHOD = 'wam_payment.paypal_web_checkout';
const REDSYS_METHOD = 'wam_payment.redsys';
const STRIPE_METHOD = 'wam_payment.stripe';
const ENABLED_METHODS = [
self::FREE_PAYMENT_METHOD,
];
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('wam_payment');
$rootNode
->children()
->scalarNode('payment_bridge_class')->defaultValue(PaymentBridge::class)->end()
->arrayNode('enabled_methods')
->defaultValue(self::ENABLED_METHODS)
->prototype('scalar')
->validate()
->ifTrue(function ($value) {
return 2 != count(explode('.', $value)) or 'wam_payment.' != substr($value, 0, 12);
})
->thenInvalid('Method name should follow the pattern wam_payment.{method_name}')
->end()
->end()
->end()
->end()
;
return $treeBuilder;
}
}