From 948f3af14bb923463cdfb7d11d49b7103333c6ef Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Sun, 18 Aug 2013 22:33:59 +0300 Subject: [PATCH] [payment-factory] add apis before actions. --- .../Payment/AbstractPaymentFactory.php | 116 +++++++++++++++--- .../Payment/AuthorizeNetAimPaymentFactory.php | 55 +++++---- .../Factory/Payment/Be2BillPaymentFactory.php | 53 ++++---- .../Factory/Payment/OmnipayPaymentFactory.php | 70 ++++++----- .../Factory/Payment/PayexPaymentFactory.php | 73 ++++++----- ...PaypalExpressCheckoutNvpPaymentFactory.php | 77 +++++++----- .../PaypalProCheckoutNvpPaymentFactory.php | 53 ++++---- 7 files changed, 312 insertions(+), 185 deletions(-) diff --git a/DependencyInjection/Factory/Payment/AbstractPaymentFactory.php b/DependencyInjection/Factory/Payment/AbstractPaymentFactory.php index 1c1fa4c0..30312f31 100644 --- a/DependencyInjection/Factory/Payment/AbstractPaymentFactory.php +++ b/DependencyInjection/Factory/Payment/AbstractPaymentFactory.php @@ -19,29 +19,17 @@ public function create(ContainerBuilder $container, $contextName, array $config) $paymentId = 'payum.context.'.$contextName.'.payment'; $container->setDefinition($paymentId, $paymentDefinition); - foreach (array_reverse($config['apis']) as $apiId) { - $paymentDefinition->addMethodCall( - 'addApi', - array(new Reference($apiId), $forcePrepend = true) - ); - } - - foreach (array_reverse($config['actions']) as $actionId) { - $paymentDefinition->addMethodCall( - 'addAction', - array(new Reference($actionId), $forcePrepend = true) - ); - } + $this->addCommonApis($paymentDefinition, $container, $contextName, $config); + $this->addApis($paymentDefinition, $container, $contextName, $config); + $this->addCustomApis($paymentDefinition, $container, $contextName, $config); - foreach (array_reverse($config['extensions']) as $extensionId) { - $paymentDefinition->addMethodCall( - 'addExtension', - array(new Reference($extensionId), $forcePrepend = true) - ); - } - $this->addCommonActions($paymentDefinition); + $this->addActions($paymentDefinition, $container, $contextName, $config); + $this->addCustomActions($paymentDefinition, $container, $contextName, $config); + $this->addCommonExtensions($paymentDefinition); + $this->addExtensions($paymentDefinition, $container, $contextName, $config); + $this->addCustomExtensions($paymentDefinition, $container, $contextName, $config); return $paymentId; } @@ -104,6 +92,94 @@ protected function createContextParameter(ContainerBuilder $container, $contextN return "%{$contextParameter}%"; } + /** + * @param Definition $paymentDefinition + * @param ContainerBuilder $container + * @param $contextName + * @param array $config + */ + protected function addCustomApis(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config) + { + foreach (array_reverse($config['apis']) as $apiId) { + $paymentDefinition->addMethodCall( + 'addApi', + array(new Reference($apiId), $forcePrepend = true) + ); + } + } + + /** + * @param Definition $paymentDefinition + * @param ContainerBuilder $container + * @param $contextName + * @param array $config + */ + protected function addCustomActions(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config) + { + foreach (array_reverse($config['actions']) as $actionId) { + $paymentDefinition->addMethodCall( + 'addAction', + array(new Reference($actionId), $forcePrepend = true) + ); + } + } + + /** + * @param Definition $paymentDefinition + * @param ContainerBuilder $container + * @param $contextName + * @param array $config + */ + protected function addCustomExtensions(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config) + { + foreach (array_reverse($config['extensions']) as $extensionId) { + $paymentDefinition->addMethodCall( + 'addExtension', + array(new Reference($extensionId), $forcePrepend = true) + ); + } + } + + /** + * @param Definition $paymentDefinition + * @param ContainerBuilder $container + * @param $contextName + * @param array $config + */ + protected function addApis(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config) + { + } + + /** + * @param Definition $paymentDefinition + * @param ContainerBuilder $container + * @param $contextName + * @param array $config + */ + protected function addActions(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config) + { + } + + /** + * @param Definition $paymentDefinition + * @param ContainerBuilder $container + * @param $contextName + * @param array $config + */ + protected function addExtensions(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config) + { + } + + /** + * @param Definition $paymentDefinition + * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container + * @param $contextName + * @param array $config + */ + protected function addCommonApis(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config) + { + } + /** * @param Definition $paymentDefinition */ diff --git a/DependencyInjection/Factory/Payment/AuthorizeNetAimPaymentFactory.php b/DependencyInjection/Factory/Payment/AuthorizeNetAimPaymentFactory.php index d6d7e30a..9778a130 100644 --- a/DependencyInjection/Factory/Payment/AuthorizeNetAimPaymentFactory.php +++ b/DependencyInjection/Factory/Payment/AuthorizeNetAimPaymentFactory.php @@ -22,32 +22,11 @@ public function create(ContainerBuilder $container, $contextName, array $config) if (false == class_exists('Payum\AuthorizeNet\Aim\PaymentFactory')) { throw new RuntimeException('Cannot find Authorize.net payment factory class. Have you installed payum/authorize-net-aim package?'); } - - $paymentId = parent::create($container, $contextName, $config); - $paymentDefinition = $container->getDefinition($paymentId); - + $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/payment')); $loader->load('authorize_net_aim.xml'); - - $apiDefinition = new DefinitionDecorator('payum.authorize_net_aim.api'); - $apiDefinition->replaceArgument(0, $config['api']['options']['login_id']); - $apiDefinition->replaceArgument(1, $config['api']['options']['transaction_key']); - $apiDefinition->addMethodCall('setSandbox', array($config['api']['options']['sandbox'])); - $apiId = 'payum.context.'.$contextName.'.api'; - $container->setDefinition($apiId, $apiDefinition); - $paymentDefinition->addMethodCall('addApi', array(new Reference($apiId))); - - $captureActionDefinition = new DefinitionDecorator('payum.authorize_net_aim.action.capture'); - $captureActionId = 'payum.context.'.$contextName.'.action.capture'; - $container->setDefinition($captureActionId, $captureActionDefinition); - $paymentDefinition->addMethodCall('addAction', array(new Reference($captureActionId))); - - $statusActionDefinition = new DefinitionDecorator('payum.authorize_net_aim.action.status'); - $statusActionId = 'payum.context.'.$contextName.'.action.status'; - $container->setDefinition($statusActionId, $statusActionDefinition); - $paymentDefinition->addMethodCall('addAction', array(new Reference($statusActionId))); - return $paymentId; + return parent::create($container, $contextName, $config); } /** @@ -75,4 +54,34 @@ public function addConfiguration(ArrayNodeDefinition $builder) ->end() ->end(); } + + /** + * {@inheritDoc} + */ + protected function addApis(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config) + { + $apiDefinition = new DefinitionDecorator('payum.authorize_net_aim.api'); + $apiDefinition->replaceArgument(0, $config['api']['options']['login_id']); + $apiDefinition->replaceArgument(1, $config['api']['options']['transaction_key']); + $apiDefinition->addMethodCall('setSandbox', array($config['api']['options']['sandbox'])); + $apiId = 'payum.context.'.$contextName.'.api'; + $container->setDefinition($apiId, $apiDefinition); + $paymentDefinition->addMethodCall('addApi', array(new Reference($apiId))); + } + + /** + * {@inheritDoc} + */ + protected function addActions(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config) + { + $captureActionDefinition = new DefinitionDecorator('payum.authorize_net_aim.action.capture'); + $captureActionId = 'payum.context.'.$contextName.'.action.capture'; + $container->setDefinition($captureActionId, $captureActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($captureActionId))); + + $statusActionDefinition = new DefinitionDecorator('payum.authorize_net_aim.action.status'); + $statusActionId = 'payum.context.'.$contextName.'.action.status'; + $container->setDefinition($statusActionId, $statusActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($statusActionId))); + } } \ No newline at end of file diff --git a/DependencyInjection/Factory/Payment/Be2BillPaymentFactory.php b/DependencyInjection/Factory/Payment/Be2BillPaymentFactory.php index a128ea0e..df892fac 100644 --- a/DependencyInjection/Factory/Payment/Be2BillPaymentFactory.php +++ b/DependencyInjection/Factory/Payment/Be2BillPaymentFactory.php @@ -23,31 +23,10 @@ public function create(ContainerBuilder $container, $contextName, array $config) throw new RuntimeException('Cannot find be2bill payment factory class. Have you installed payum/be2bill package?'); } - $paymentId = parent::create($container, $contextName, $config); - $paymentDefinition = $container->getDefinition($paymentId); - $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/payment')); $loader->load('be2bill.xml'); - $apiDefinition = new DefinitionDecorator('payum.be2bill.api'); - $apiDefinition->replaceArgument(0, new Reference($config['api']['client'])); - $apiDefinition->replaceArgument(1, $config['api']['options']); - $apiDefinition->setPublic(true); - $apiId = 'payum.context.'.$contextName.'.api'; - $container->setDefinition($apiId, $apiDefinition); - $paymentDefinition->addMethodCall('addApi', array(new Reference($apiId))); - - $captureActionDefinition = new DefinitionDecorator('payum.be2bill.action.capture'); - $captureActionId = 'payum.context.'.$contextName.'.action.capture'; - $container->setDefinition($captureActionId, $captureActionDefinition); - $paymentDefinition->addMethodCall('addAction', array(new Reference($captureActionId))); - - $statusActionDefinition = new DefinitionDecorator('payum.be2bill.action.status'); - $statusActionId = 'payum.context.'.$contextName.'.action.status'; - $container->setDefinition($statusActionId, $statusActionDefinition); - $paymentDefinition->addMethodCall('addAction', array(new Reference($statusActionId))); - - return $paymentId; + return parent::create($container, $contextName, $config); } /** @@ -76,4 +55,34 @@ public function addConfiguration(ArrayNodeDefinition $builder) ->end() ->end(); } + + /** + * {@inheritDoc} + */ + protected function addApis(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config) + { + $apiDefinition = new DefinitionDecorator('payum.be2bill.api'); + $apiDefinition->replaceArgument(0, new Reference($config['api']['client'])); + $apiDefinition->replaceArgument(1, $config['api']['options']); + $apiDefinition->setPublic(true); + $apiId = 'payum.context.'.$contextName.'.api'; + $container->setDefinition($apiId, $apiDefinition); + $paymentDefinition->addMethodCall('addApi', array(new Reference($apiId))); + } + + /** + * {@inheritDoc} + */ + protected function addActions(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config) + { + $captureActionDefinition = new DefinitionDecorator('payum.be2bill.action.capture'); + $captureActionId = 'payum.context.'.$contextName.'.action.capture'; + $container->setDefinition($captureActionId, $captureActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($captureActionId))); + + $statusActionDefinition = new DefinitionDecorator('payum.be2bill.action.status'); + $statusActionId = 'payum.context.'.$contextName.'.action.status'; + $container->setDefinition($statusActionId, $statusActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($statusActionId))); + } } \ No newline at end of file diff --git a/DependencyInjection/Factory/Payment/OmnipayPaymentFactory.php b/DependencyInjection/Factory/Payment/OmnipayPaymentFactory.php index cf0220ce..9a22e22c 100644 --- a/DependencyInjection/Factory/Payment/OmnipayPaymentFactory.php +++ b/DependencyInjection/Factory/Payment/OmnipayPaymentFactory.php @@ -28,38 +28,7 @@ public function create(ContainerBuilder $container, $contextName, array $config) throw new RuntimeException('Cannot find GatewayInterface interface. Have you installed omnipay/omnipay package?'); } - $paymentId = parent::create($container, $contextName, $config); - $paymentDefinition = $container->getDefinition($paymentId); - - $gatewayDefinition = new Definition(); - $gatewayDefinition->setClass('Omnipay\Common\GatewayInterface'); - $gatewayDefinition->setFactoryClass('Omnipay\Common\GatewayFactory'); - $gatewayDefinition->setFactoryMethod('create'); - $gatewayDefinition->addArgument($config['type']); - $gatewayDefinition->setPublic(true); - foreach ($config['options'] as $name => $value) { - $gatewayDefinition->addMethodCall('set'.strtoupper($name), array($value)); - } - - $gatewayId = 'payum.context.'.$contextName.'.gateway'; - $container->setDefinition($gatewayId, $gatewayDefinition); - - //TODO: work around for current version. Do better fix in 0.6.x - $methodCalls = $paymentDefinition->getMethodCalls(); - array_unshift($methodCalls, array('addApi', array(new Reference($gatewayId)))); - $paymentDefinition->setMethodCalls($methodCalls); - - $captureActionDefinition = new Definition('Payum\Bridge\Omnipay\Action\CaptureAction'); - $captureActionId = 'payum.context.'.$contextName.'.action.capture'; - $container->setDefinition($captureActionId, $captureActionDefinition); - $paymentDefinition->addMethodCall('addAction', array(new Reference($captureActionId))); - - $statusActionDefinition = new Definition('Payum\Bridge\Omnipay\Action\StatusAction'); - $statusActionId = 'payum.context.'.$contextName.'.action.status'; - $container->setDefinition($statusActionId, $statusActionDefinition); - $paymentDefinition->addMethodCall('addAction', array(new Reference($statusActionId))); - - return $paymentId; + return parent::create($container, $contextName, $config); } /** @@ -102,4 +71,41 @@ public function addConfiguration(ArrayNodeDefinition $builder) ->thenInvalid('A message') ; } + + /** + * {@inheritDoc} + */ + protected function addApis(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config) + { + $gatewayDefinition = new Definition(); + $gatewayDefinition->setClass('Omnipay\Common\GatewayInterface'); + $gatewayDefinition->setFactoryClass('Omnipay\Common\GatewayFactory'); + $gatewayDefinition->setFactoryMethod('create'); + $gatewayDefinition->addArgument($config['type']); + $gatewayDefinition->setPublic(true); + foreach ($config['options'] as $name => $value) { + $gatewayDefinition->addMethodCall('set'.strtoupper($name), array($value)); + } + + $gatewayId = 'payum.context.'.$contextName.'.gateway'; + $container->setDefinition($gatewayId, $gatewayDefinition); + + $paymentDefinition->addMethodCall('addApi', array(new Reference($gatewayId))); + } + + /** + * {@inheritDoc} + */ + protected function addActions(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config) + { + $captureActionDefinition = new Definition('Payum\Bridge\Omnipay\Action\CaptureAction'); + $captureActionId = 'payum.context.'.$contextName.'.action.capture'; + $container->setDefinition($captureActionId, $captureActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($captureActionId))); + + $statusActionDefinition = new Definition('Payum\Bridge\Omnipay\Action\StatusAction'); + $statusActionId = 'payum.context.'.$contextName.'.action.status'; + $container->setDefinition($statusActionId, $statusActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($statusActionId))); + } } \ No newline at end of file diff --git a/DependencyInjection/Factory/Payment/PayexPaymentFactory.php b/DependencyInjection/Factory/Payment/PayexPaymentFactory.php index acd33f57..7682ef8e 100644 --- a/DependencyInjection/Factory/Payment/PayexPaymentFactory.php +++ b/DependencyInjection/Factory/Payment/PayexPaymentFactory.php @@ -23,12 +23,43 @@ public function create(ContainerBuilder $container, $contextName, array $config) throw new RuntimeException('Cannot find payex payment factory class. Have you installed payum/payex package?'); } - $paymentId = parent::create($container, $contextName, $config); - $paymentDefinition = $container->getDefinition($paymentId); - $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/payment')); $loader->load('payex.xml'); + return parent::create($container, $contextName, $config); + } + + /** + * {@inheritDoc} + */ + public function getName() + { + return 'payex'; + } + + /** + * {@inheritDoc} + */ + public function addConfiguration(ArrayNodeDefinition $builder) + { + parent::addConfiguration($builder); + + $builder->children() + ->arrayNode('api')->isRequired()->children() + ->arrayNode('options')->isRequired()->children() + ->scalarNode('encryption_key')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('account_number')->isRequired()->cannotBeEmpty()->end() + ->booleanNode('sandbox')->defaultTrue()->end() + ->end() + ->end() + ->end(); + } + + /** + * {@inheritDoc} + */ + protected function addApis(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config) + { $orderApiDefinition = new DefinitionDecorator('payum.payex.api.order.prototype'); $orderApiDefinition->replaceArgument(1, array( 'encryptionKey' => $config['api']['options']['encryption_key'], @@ -61,7 +92,13 @@ public function create(ContainerBuilder $container, $contextName, array $config) $recurringApiId = 'payum.context.'.$contextName.'.api.recurring'; $container->setDefinition($recurringApiId, $recurringApiDefinition); $paymentDefinition->addMethodCall('addApi', array(new Reference($recurringApiId))); + } + /** + * {@inheritDoc} + */ + protected function addActions(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config) + { $initializeOrderActionDefinition = new DefinitionDecorator('payum.payex.action.api.initialize_order'); $initializeOrderActionId = 'payum.context.'.$contextName.'.action.api.initialize_order'; $container->setDefinition($initializeOrderActionId, $initializeOrderActionDefinition); @@ -111,7 +148,7 @@ public function create(ContainerBuilder $container, $contextName, array $config) $checkRecurringPaymentsActionId = 'payum.context.'.$contextName.'.action.api.check_recurring_payment'; $container->setDefinition($checkRecurringPaymentsActionId, $checkRecurringPaymentsActionDefinition); $paymentDefinition->addMethodCall('addAction', array(new Reference($checkRecurringPaymentsActionId))); - + $paymentDetailsCaptureActionDefinition = new DefinitionDecorator('payum.payex.action.payment_details_capture'); $paymentDetailsCaptureActionId = 'payum.context.'.$contextName.'.action.payment_details_capture'; $container->setDefinition($paymentDetailsCaptureActionId, $paymentDetailsCaptureActionDefinition); @@ -146,33 +183,5 @@ public function create(ContainerBuilder $container, $contextName, array $config) $agreementDetailsSyncActionActionId = 'payum.context.'.$contextName.'.action.agreement_details_sync'; $container->setDefinition($agreementDetailsSyncActionActionId, $agreementDetailsSyncActionDefinition); $paymentDefinition->addMethodCall('addAction', array(new Reference($agreementDetailsSyncActionActionId))); - - return $paymentId; - } - - /** - * {@inheritDoc} - */ - public function getName() - { - return 'payex'; - } - - /** - * {@inheritDoc} - */ - public function addConfiguration(ArrayNodeDefinition $builder) - { - parent::addConfiguration($builder); - - $builder->children() - ->arrayNode('api')->isRequired()->children() - ->arrayNode('options')->isRequired()->children() - ->scalarNode('encryption_key')->isRequired()->cannotBeEmpty()->end() - ->scalarNode('account_number')->isRequired()->cannotBeEmpty()->end() - ->booleanNode('sandbox')->defaultTrue()->end() - ->end() - ->end() - ->end(); } } \ No newline at end of file diff --git a/DependencyInjection/Factory/Payment/PaypalExpressCheckoutNvpPaymentFactory.php b/DependencyInjection/Factory/Payment/PaypalExpressCheckoutNvpPaymentFactory.php index 76ceff64..f26b7c82 100644 --- a/DependencyInjection/Factory/Payment/PaypalExpressCheckoutNvpPaymentFactory.php +++ b/DependencyInjection/Factory/Payment/PaypalExpressCheckoutNvpPaymentFactory.php @@ -23,12 +23,45 @@ public function create(ContainerBuilder $container, $contextName, array $config) throw new RuntimeException('Cannot find paypal express checkout payment factory class. Have you installed payum/paypal-express-checkout-nvp package?'); } - $paymentId = parent::create($container, $contextName, $config); - $paymentDefinition = $container->getDefinition($paymentId); - $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/payment')); $loader->load('paypal_express_checkout_nvp.xml'); + return parent::create($container, $contextName, $config); + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return 'paypal_express_checkout_nvp'; + } + + /** + * {@inheritdoc} + */ + public function addConfiguration(ArrayNodeDefinition $builder) + { + parent::addConfiguration($builder); + + $builder->children() + ->arrayNode('api')->isRequired()->children() + ->scalarNode('client')->defaultValue('payum.buzz.client')->cannotBeEmpty()->end() + ->arrayNode('options')->isRequired()->children() + ->scalarNode('username')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('password')->isRequired()->cannotBeEmpty()->end() + ->scalarNode('signature')->isRequired()->cannotBeEmpty()->end() + ->booleanNode('sandbox')->defaultTrue()->end() + ->end() + ->end() + ->end(); + } + + /** + * {@inheritDoc} + */ + protected function addApis(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config) + { $apiDefinition = new DefinitionDecorator('payum.paypal.express_checkout_nvp.api'); $apiDefinition->replaceArgument(0, new Reference($config['api']['client'])); $apiDefinition->replaceArgument(1, $config['api']['options']); @@ -36,12 +69,18 @@ public function create(ContainerBuilder $container, $contextName, array $config) $apiId = 'payum.context.'.$contextName.'.api'; $container->setDefinition($apiId, $apiDefinition); $paymentDefinition->addMethodCall('addApi', array(new Reference($apiId))); + } + /** + * {@inheritDoc} + */ + protected function addActions(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config) + { $authorizeTokenDefinition = new DefinitionDecorator('payum.paypal.express_checkout_nvp.action.api.authorize_token'); $authorizeTokenId = 'payum.context.'.$contextName.'.action.api.authorize_token'; $container->setDefinition($authorizeTokenId, $authorizeTokenDefinition); $paymentDefinition->addMethodCall('addAction', array(new Reference($authorizeTokenId))); - + $doExpressCheckoutPaymentDefinition = new DefinitionDecorator('payum.paypal.express_checkout_nvp.action.api.do_express_checkout_payment'); $doExpressCheckoutPaymentId = 'payum.context.'.$contextName.'.action.api.do_express_checkout_payment'; $container->setDefinition($doExpressCheckoutPaymentId, $doExpressCheckoutPaymentDefinition); @@ -101,35 +140,5 @@ public function create(ContainerBuilder $container, $contextName, array $config) $recurringPaymentDetailsSyncsId = 'payum.context.' . $contextName . '.action.recurring_payment_details_sync'; $container->setDefinition($recurringPaymentDetailsSyncsId, $recurringPaymentDetailsSyncDefinition); $paymentDefinition->addMethodCall('addAction', array(new Reference($recurringPaymentDetailsSyncsId))); - - return $paymentId; - } - - /** - * {@inheritdoc} - */ - public function getName() - { - return 'paypal_express_checkout_nvp'; - } - - /** - * {@inheritdoc} - */ - public function addConfiguration(ArrayNodeDefinition $builder) - { - parent::addConfiguration($builder); - - $builder->children() - ->arrayNode('api')->isRequired()->children() - ->scalarNode('client')->defaultValue('payum.buzz.client')->cannotBeEmpty()->end() - ->arrayNode('options')->isRequired()->children() - ->scalarNode('username')->isRequired()->cannotBeEmpty()->end() - ->scalarNode('password')->isRequired()->cannotBeEmpty()->end() - ->scalarNode('signature')->isRequired()->cannotBeEmpty()->end() - ->booleanNode('sandbox')->defaultTrue()->end() - ->end() - ->end() - ->end(); } } \ No newline at end of file diff --git a/DependencyInjection/Factory/Payment/PaypalProCheckoutNvpPaymentFactory.php b/DependencyInjection/Factory/Payment/PaypalProCheckoutNvpPaymentFactory.php index df89d964..95fcc466 100644 --- a/DependencyInjection/Factory/Payment/PaypalProCheckoutNvpPaymentFactory.php +++ b/DependencyInjection/Factory/Payment/PaypalProCheckoutNvpPaymentFactory.php @@ -28,31 +28,10 @@ public function create(ContainerBuilder $container, $contextName, array $config) ); } - $paymentId = parent::create($container, $contextName, $config); - $paymentDefinition = $container->getDefinition($paymentId); - $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/payment')); $loader->load('paypal_pro_checkout_nvp.xml'); - $apiDefinition = new DefinitionDecorator('payum.paypal.pro_checkout_nvp.api'); - $apiDefinition->replaceArgument(0, new Reference($config['api']['client'])); - $apiDefinition->replaceArgument(1, $config['api']['options']); - $apiDefinition->setPublic(true); - $apiId = 'payum.context.'.$contextName.'.api'; - $container->setDefinition($apiId, $apiDefinition); - $paymentDefinition->addMethodCall('addApi', array(new Reference($apiId))); - - $captureDefinition = new DefinitionDecorator('payum.paypal.pro_checkout_nvp.action.capture'); - $captureId = 'payum.context.' . $contextName . '.action.capture'; - $container->setDefinition($captureId, $captureDefinition); - $paymentDefinition->addMethodCall('addAction', array(new Reference($captureId))); - - $statusDefinition = new DefinitionDecorator('payum.paypal.pro_checkout_nvp.action.status'); - $statusId = 'payum.context.' . $contextName . '.action.status'; - $container->setDefinition($statusId, $statusDefinition); - $paymentDefinition->addMethodCall('addAction', array(new Reference($statusId))); - - return $paymentId; + return parent::create($container, $contextName, $config); } /** @@ -85,4 +64,34 @@ public function addConfiguration(ArrayNodeDefinition $builder) ->end() ->end(); } + + /** + * {@inheritDoc} + */ + protected function addApis(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config) + { + $apiDefinition = new DefinitionDecorator('payum.paypal.pro_checkout_nvp.api'); + $apiDefinition->replaceArgument(0, new Reference($config['api']['client'])); + $apiDefinition->replaceArgument(1, $config['api']['options']); + $apiDefinition->setPublic(true); + $apiId = 'payum.context.'.$contextName.'.api'; + $container->setDefinition($apiId, $apiDefinition); + $paymentDefinition->addMethodCall('addApi', array(new Reference($apiId))); + } + + /** + * {@inheritDoc} + */ + protected function addActions(Definition $paymentDefinition, ContainerBuilder $container, $contextName, array $config) + { + $captureDefinition = new DefinitionDecorator('payum.paypal.pro_checkout_nvp.action.capture'); + $captureId = 'payum.context.' . $contextName . '.action.capture'; + $container->setDefinition($captureId, $captureDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($captureId))); + + $statusDefinition = new DefinitionDecorator('payum.paypal.pro_checkout_nvp.action.status'); + $statusId = 'payum.context.' . $contextName . '.action.status'; + $container->setDefinition($statusId, $statusDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($statusId))); + } } \ No newline at end of file