From e8e2661977dbe6e2fd9dd208014a972eb19868d9 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 14 Jun 2013 16:45:44 +0300 Subject: [PATCH 01/14] add payex payment factory. --- .../Factory/Payment/PayexPaymentFactory.php | 91 ++++++ PayumBundle.php | 2 + Resources/config/payment/payex.xml | 64 ++++ Resources/doc/configuration_reference.md | 11 + .../Payment/Be2BillPaymentFactoryTest.php | 2 - .../Payment/PayexPaymentFactoryTest.php | 290 ++++++++++++++++++ .../PayumExtensionTest.php | 44 +++ 7 files changed, 502 insertions(+), 2 deletions(-) create mode 100644 DependencyInjection/Factory/Payment/PayexPaymentFactory.php create mode 100644 Resources/config/payment/payex.xml create mode 100644 Tests/DependencyInjection/Factory/Payment/PayexPaymentFactoryTest.php diff --git a/DependencyInjection/Factory/Payment/PayexPaymentFactory.php b/DependencyInjection/Factory/Payment/PayexPaymentFactory.php new file mode 100644 index 00000000..c3f466f5 --- /dev/null +++ b/DependencyInjection/Factory/Payment/PayexPaymentFactory.php @@ -0,0 +1,91 @@ +getDefinition($paymentId); + + $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../../Resources/config/payment')); + $loader->load('payex.xml'); + + $orderApiDefinition = new DefinitionDecorator('payum.payex.api.order.prototype'); + $orderApiDefinition->replaceArgument(1, array( + 'encryptionKey' => $config['api']['options']['encryption_key'], + 'accountNumber' => $config['api']['options']['account_number'], + 'sandbox' => $config['api']['options']['sandbox'] + )); + $orderApiDefinition->setPublic(true); + $orderApiId = 'payum.context.'.$contextName.'.api.order'; + $container->setDefinition($orderApiId, $orderApiDefinition); + $paymentDefinition->addMethodCall('addApi', array(new Reference($orderApiId))); + + $initializeOrderActionDefinition = new DefinitionDecorator('payum.payex.action.api.initialize_order'); + $initializeOrderActionId = 'payum.context.'.$contextName.'.action.api.initialize_order'; + $container->setDefinition($initializeOrderActionId, $initializeOrderActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($initializeOrderActionId))); + + $completeOrderActionDefinition = new DefinitionDecorator('payum.payex.action.api.complete_order'); + $completeOrderActionId = 'payum.context.'.$contextName.'.action.api.complete_order'; + $container->setDefinition($completeOrderActionId, $completeOrderActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($completeOrderActionId))); + + $captureActionDefinition = new DefinitionDecorator('payum.payex.action.capture'); + $captureActionId = 'payum.context.'.$contextName.'.action.capture'; + $container->setDefinition($captureActionId, $captureActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($captureActionId))); + + $statusActionDefinition = new DefinitionDecorator('payum.payex.action.status'); + $statusActionId = 'payum.context.'.$contextName.'.action.status'; + $container->setDefinition($statusActionId, $statusActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($statusActionId))); +// + 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/PayumBundle.php b/PayumBundle.php index 909885e8..b419d1b1 100644 --- a/PayumBundle.php +++ b/PayumBundle.php @@ -9,6 +9,7 @@ use Payum\Bundle\PayumBundle\DependencyInjection\Factory\Payment\PaypalExpressCheckoutNvpPaymentFactory; use Payum\Bundle\PayumBundle\DependencyInjection\Factory\Payment\PaypalProCheckoutNvpPaymentFactory; use Payum\Bundle\PayumBundle\DependencyInjection\Factory\Payment\Be2BillPaymentFactory; +use Payum\Bundle\PayumBundle\DependencyInjection\Factory\Payment\PayexPaymentFactory; use Payum\Bundle\PayumBundle\DependencyInjection\Factory\Payment\AuthorizeNetAimPaymentFactory; use Payum\Bundle\PayumBundle\DependencyInjection\Factory\Storage\DoctrineStorageFactory; use Payum\Bundle\PayumBundle\DependencyInjection\Factory\Storage\FilesystemStorageFactory; @@ -26,6 +27,7 @@ public function build(ContainerBuilder $container) $extension->addPaymentFactory(new PaypalProCheckoutNvpPaymentFactory); $extension->addPaymentFactory(new Be2BillPaymentFactory); $extension->addPaymentFactory(new AuthorizeNetAimPaymentFactory); + $extension->addPaymentFactory(new PayexPaymentFactory); $extension->addPaymentFactory(new OmnipayPaymentFactory); $extension->addPaymentFactory(new CustomPaymentFactory); diff --git a/Resources/config/payment/payex.xml b/Resources/config/payment/payex.xml new file mode 100644 index 00000000..c6f48b11 --- /dev/null +++ b/Resources/config/payment/payex.xml @@ -0,0 +1,64 @@ + + + + + + Payum\Payex\Api\SoapClientFactory + Payum\Payex\Api\OrderApi + Payum\Payex\Action\Api\InitializeOrderAction + Payum\Payex\Action\Api\CompleteOrderAction + Payum\Payex\Action\CaptureAction + Payum\Payex\Action\StatusAction + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md index 43bc486c..59d1c0b9 100644 --- a/Resources/doc/configuration_reference.md +++ b/Resources/doc/configuration_reference.md @@ -86,6 +86,17 @@ be2bill: sandbox: true ``` +### Payex payment + +```yml +payex: + api: + options: + encryption_key: 'required' + account_number: 'required' + sandbox: true +``` + ### Omnipay payment ```yml diff --git a/Tests/DependencyInjection/Factory/Payment/Be2BillPaymentFactoryTest.php b/Tests/DependencyInjection/Factory/Payment/Be2BillPaymentFactoryTest.php index 2ef62e64..b9cb43b7 100644 --- a/Tests/DependencyInjection/Factory/Payment/Be2BillPaymentFactoryTest.php +++ b/Tests/DependencyInjection/Factory/Payment/Be2BillPaymentFactoryTest.php @@ -289,8 +289,6 @@ public function shouldDecorateBasicCaptureActionDefinitionAndAddItToPayment() 'extensions' => array(), )); - $this->assertTrue($container->hasDefinition('payum.context.aContextName.action.capture')); - $this->assertDefinitionContainsMethodCall( $container->getDefinition($paymentId), 'addAction', diff --git a/Tests/DependencyInjection/Factory/Payment/PayexPaymentFactoryTest.php b/Tests/DependencyInjection/Factory/Payment/PayexPaymentFactoryTest.php new file mode 100644 index 00000000..a7093cf7 --- /dev/null +++ b/Tests/DependencyInjection/Factory/Payment/PayexPaymentFactoryTest.php @@ -0,0 +1,290 @@ + array('payum.context.aContextName.action.api.initialize_order'), + 'api.complete_order' => array('payum.context.aContextName.action.api.complete_order'), + + 'capture' => array('payum.context.aContextName.action.capture'), + 'status' => array('payum.context.aContextName.action.status'), + ); + } + + /** + * @test + */ + public function shouldBeSubClassOfAbstractPaymentFactory() + { + $rc = new \ReflectionClass('Payum\Bundle\PayumBundle\DependencyInjection\Factory\Payment\PayexPaymentFactory'); + + $this->assertTrue($rc->isSubclassOf('Payum\Bundle\PayumBundle\DependencyInjection\Factory\Payment\AbstractPaymentFactory')); + } + + /** + * @test + */ + public function couldBeConstructedWithoutAnyArguments() + { + new PayexPaymentFactory; + } + + /** + * @test + */ + public function shouldAllowGetName() + { + $factory = new PayexPaymentFactory; + + $this->assertEquals('payex', $factory->getName()); + } + + /** + * @test + */ + public function shouldAllowAddConfiguration() + { + $factory = new PayexPaymentFactory; + + $tb = new TreeBuilder(); + $rootNode = $tb->root('foo'); + + $factory->addConfiguration($rootNode); + + $processor = new Processor(); + $config = $processor->process($tb->buildTree(), array(array( + 'api' => array( + 'options' => array( + 'encryption_key' => 'aKey', + 'account_number' => 'aNum', + ) + ) + ))); + + $this->assertArrayHasKey('api', $config); + + $this->assertArrayHasKey('options', $config['api']); + + $this->assertArrayHasKey('encryption_key', $config['api']['options']); + $this->assertEquals('aKey', $config['api']['options']['encryption_key']); + + $this->assertArrayHasKey('account_number', $config['api']['options']); + $this->assertEquals('aNum', $config['api']['options']['account_number']); + + //come from abstract payment factory + $this->assertArrayHasKey('actions', $config); + $this->assertArrayHasKey('apis', $config); + $this->assertArrayHasKey('extensions', $config); + } + + /** + * @test + * + * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException + * @expectedExceptionMessage The child node "api" at path "foo" must be configured. + */ + public function thrownIfApiSectionMissing() + { + $factory = new PayexPaymentFactory; + + $tb = new TreeBuilder(); + $rootNode = $tb->root('foo'); + + $factory->addConfiguration($rootNode); + + $processor = new Processor(); + $processor->process($tb->buildTree(), array()); + } + + /** + * @test + * + * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException + * @expectedExceptionMessage The child node "options" at path "foo.api" must be configured. + */ + public function thrownIfApiOptionsSectionMissing() + { + $factory = new PayexPaymentFactory; + + $tb = new TreeBuilder(); + $rootNode = $tb->root('foo'); + + $factory->addConfiguration($rootNode); + + $processor = new Processor(); + $processor->process($tb->buildTree(), array(array( + 'api' => array() + ))); + } + + /** + * @test + * + * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException + * @expectedExceptionMessage The child node "encryption_key" at path "foo.api.options" must be configured. + */ + public function thrownIfApiOptionEncryptionKeySectionMissing() + { + $factory = new PayexPaymentFactory; + + $tb = new TreeBuilder(); + $rootNode = $tb->root('foo'); + + $factory->addConfiguration($rootNode); + + $processor = new Processor(); + $processor->process($tb->buildTree(), array(array( + 'api' => array( + 'options' => array() + ) + ))); + } + + /** + * @test + * + * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException + * @expectedExceptionMessage The child node "account_number" at path "foo.api.options" must be configured. + */ + public function thrownIfApiOptionAccountNumberSectionMissing() + { + $factory = new PayexPaymentFactory; + + $tb = new TreeBuilder(); + $rootNode = $tb->root('foo'); + + $factory->addConfiguration($rootNode); + + $processor = new Processor(); + $processor->process($tb->buildTree(), array(array( + 'api' => array( + 'options' => array( + 'encryption_key' => 'aKey' + ) + ) + ))); + } + + /** + * @test + */ + public function shouldAllowCreatePaymentAndReturnItsId() + { + $factory = new PayexPaymentFactory; + + $container = new ContainerBuilder; + + $paymentId = $factory->create($container, 'aContextName', array( + 'api' => array( + 'options' => array( + 'encryption_key' => 'aKey', + 'account_number' => 'aNum', + 'sandbox' => true + ), + ), + 'actions' => array(), + 'apis' => array(), + 'extensions' => array(), + )); + + $this->assertEquals('payum.context.aContextName.payment', $paymentId); + $this->assertTrue($container->hasDefinition($paymentId)); + } + + /** + * @test + */ + public function shouldCallParentsCreateMethod() + { + $factory = new PayexPaymentFactory; + + $container = new ContainerBuilder; + + $paymentId = $factory->create($container, 'aContextName', array( + 'api' => array( + 'options' => array( + 'encryption_key' => 'aKey', + 'account_number' => 'aNum', + 'sandbox' => true + ), + ), + 'actions' => array('payum.action.foo'), + 'apis' => array('payum.api.bar'), + 'extensions' => array('payum.extension.ololo'), + )); + + $this->assertDefinitionContainsMethodCall( + $container->getDefinition($paymentId), + 'addAction', + new Reference('payum.action.foo') + ); + $this->assertDefinitionContainsMethodCall( + $container->getDefinition($paymentId), + 'addApi', + new Reference('payum.api.bar') + ); + $this->assertDefinitionContainsMethodCall( + $container->getDefinition($paymentId), + 'addExtension', + new Reference('payum.extension.ololo') + ); + } + + /** + * @test + * + * @dataProvider provideDecoratedActions + */ + public function shouldDecorateExpectedActionDefinitionsAndAddItToPayment($expectedActionDefinitionId) + { + $factory = new PayexPaymentFactory; + + $container = new ContainerBuilder; + + $paymentId = $factory->create($container, 'aContextName', array( + 'api' => array( + 'options' => array( + 'encryption_key' => 'aKey', + 'account_number' => 'aNum', + 'sandbox' => true + ), + ), + 'actions' => array(), + 'apis' => array(), + 'extensions' => array(), + )); + + $this->assertDefinitionContainsMethodCall( + $container->getDefinition($paymentId), + 'addAction', + new Reference($expectedActionDefinitionId) + ); + } + + protected function assertDefinitionContainsMethodCall(Definition $serviceDefinition, $expectedMethod, $expectedFirstArgument) + { + foreach ($serviceDefinition->getMethodCalls() as $methodCall) { + if ($expectedMethod == $methodCall[0] && $expectedFirstArgument == $methodCall[1][0]) { + return; + } + } + + $this->fail(sprintf( + 'Failed assert that service (Class: %s) has method %s been called with first argument %s', + $serviceDefinition->getClass(), + $expectedMethod, + $expectedFirstArgument + )); + } +} \ No newline at end of file diff --git a/Tests/Functional/DependencyInjection/PayumExtensionTest.php b/Tests/Functional/DependencyInjection/PayumExtensionTest.php index f326978e..bbbd7347 100644 --- a/Tests/Functional/DependencyInjection/PayumExtensionTest.php +++ b/Tests/Functional/DependencyInjection/PayumExtensionTest.php @@ -7,6 +7,7 @@ use Payum\Bundle\PayumBundle\DependencyInjection\Factory\Payment\AuthorizeNetAimPaymentFactory; use Payum\Bundle\PayumBundle\DependencyInjection\Factory\Payment\Be2BillPaymentFactory; +use Payum\Bundle\PayumBundle\DependencyInjection\Factory\Payment\PayexPaymentFactory; use Payum\Bundle\PayumBundle\DependencyInjection\Factory\Payment\OmnipayPaymentFactory; use Payum\Bundle\PayumBundle\DependencyInjection\Factory\Payment\PaypalExpressCheckoutNvpPaymentFactory; use Payum\Bundle\PayumBundle\DependencyInjection\Factory\Payment\PaypalProCheckoutNvpPaymentFactory; @@ -229,6 +230,49 @@ public function shouldLoadExtensionWithOmnipayConfiguredPayment() ); } + /** + * @test + */ + public function shouldLoadExtensionWithPayexConfiguredPayment() + { + if (false == class_exists('Payum\Payex\PaymentFactory')) { + $this->markTestSkipped('Skipped because payment library is not installed.'); + } + + $config = array( + 'contexts' => array( + 'a_context' => array( + 'payex' => array( + 'api' => array( + 'options' => array( + 'encryption_key' => 'aKey', + 'account_number' => 'aNum' + ) + ) + ), + ) + ) + ); + + $configs = array($config); + + $containerBuilder = new ContainerBuilder(new ParameterBag); + + $extension = new PayumExtension; + $extension->addPaymentFactory(new PayexPaymentFactory); + + $extension->load($configs, $containerBuilder); + + $this->assertTrue($containerBuilder->hasDefinition('payum.context.a_context.api.order')); + $this->assertTrue($containerBuilder->hasDefinition('payum.context.a_context.payment')); + + $this->assertDefinitionContainsMethodCall( + $containerBuilder->getDefinition('payum.context.a_context.payment'), + 'addApi', + new Reference('payum.context.a_context.api.order') + ); + } + protected function assertDefinitionContainsMethodCall(Definition $serviceDefinition, $expectedMethod, $expectedFirstArgument) { foreach ($serviceDefinition->getMethodCalls() as $methodCall) { From c72b4c905658673073e8fc51c64be545dd379999 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 14 Jun 2013 23:15:54 +0300 Subject: [PATCH 02/14] add a check that lib installed to skip gracefully. --- .../Factory/Payment/PayexPaymentFactoryTest.php | 7 +++++++ composer.json | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Tests/DependencyInjection/Factory/Payment/PayexPaymentFactoryTest.php b/Tests/DependencyInjection/Factory/Payment/PayexPaymentFactoryTest.php index a7093cf7..a0fd08ae 100644 --- a/Tests/DependencyInjection/Factory/Payment/PayexPaymentFactoryTest.php +++ b/Tests/DependencyInjection/Factory/Payment/PayexPaymentFactoryTest.php @@ -11,6 +11,13 @@ class PayexPaymentFactoryTest extends \PHPUnit_Framework_TestCase { + public static function setUpBeforeClass() + { + if (false == class_exists('Payum\Payex\PaymentFactory')) { + throw new \PHPUnit_Framework_SkippedTestError('Skipped because payment library is not installed.'); + } + } + public static function provideDecoratedActions() { return array( diff --git a/composer.json b/composer.json index f0b76a3b..12238b84 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "payum/payum-bundle", "type": "symfony-bundle", "description": "The payment bundle integrates payum libs into symfony2 framework", - "keywords": ["payment", "paypal", "be2bill", "authorize.net", "omnipay", "paypal express checkout", "paypal pro checkout", "paypal recurring payment"], + "keywords": ["payment", "paypal", "be2bill", "authorize.net", "omnipay", "paypal express checkout", "paypal pro checkout", "paypal recurring payment", "payex"], "homepage": "https://github.com/Payum/PayumBundle", "license": "MIT", "authors": [ @@ -27,6 +27,7 @@ "payum/paypal-express-checkout-nvp": "0.5.*", "payum/paypal-pro-checkout-nvp": "0.5.*", "payum/be2bill": "0.5.*", + "payum/payex": "0.5.x-dev", "payum/authorize-net-aim": "0.5.*", "payum/omnipay-bridge": "0.5.*" }, @@ -35,6 +36,7 @@ "payum/paypal-pro-checkout-nvp": "If you want to use paypal pro checkout nvp gateway", "payum/authorize-net-aim": "If you want to use authorize.net gateway", "payum/be2bill": "If you want to use be2bill gateway", + "payum/payex": "If you want to use payex gateway", "payum/omnipay-bridge": "If you want to use omnipay provided gateways" }, "autoload": { From 97cccc52a766c902f50ed71e82469a72a6f9765d Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Sat, 15 Jun 2013 17:18:45 +0300 Subject: [PATCH 03/14] [payex][payment-factory] add agreement related api and actions --- .../Factory/Payment/PayexPaymentFactory.php | 33 +++++++++++++- Resources/config/payment/payex.xml | 45 +++++++++++++++++++ .../Payment/PayexPaymentFactoryTest.php | 39 ++++++++++++++++ 3 files changed, 116 insertions(+), 1 deletion(-) diff --git a/DependencyInjection/Factory/Payment/PayexPaymentFactory.php b/DependencyInjection/Factory/Payment/PayexPaymentFactory.php index c3f466f5..37662720 100644 --- a/DependencyInjection/Factory/Payment/PayexPaymentFactory.php +++ b/DependencyInjection/Factory/Payment/PayexPaymentFactory.php @@ -40,6 +40,17 @@ public function create(ContainerBuilder $container, $contextName, array $config) $container->setDefinition($orderApiId, $orderApiDefinition); $paymentDefinition->addMethodCall('addApi', array(new Reference($orderApiId))); + $agreementApiDefinition = new DefinitionDecorator('payum.payex.api.agreement.prototype'); + $agreementApiDefinition->replaceArgument(1, array( + 'encryptionKey' => $config['api']['options']['encryption_key'], + 'accountNumber' => $config['api']['options']['account_number'], + 'sandbox' => $config['api']['options']['sandbox'] + )); + $agreementApiDefinition->setPublic(true); + $agreementApiId = 'payum.context.'.$contextName.'.api.agreement'; + $container->setDefinition($agreementApiId, $agreementApiDefinition); + $paymentDefinition->addMethodCall('addApi', array(new Reference($agreementApiId))); + $initializeOrderActionDefinition = new DefinitionDecorator('payum.payex.action.api.initialize_order'); $initializeOrderActionId = 'payum.context.'.$contextName.'.action.api.initialize_order'; $container->setDefinition($initializeOrderActionId, $initializeOrderActionDefinition); @@ -49,6 +60,26 @@ public function create(ContainerBuilder $container, $contextName, array $config) $completeOrderActionId = 'payum.context.'.$contextName.'.action.api.complete_order'; $container->setDefinition($completeOrderActionId, $completeOrderActionDefinition); $paymentDefinition->addMethodCall('addAction', array(new Reference($completeOrderActionId))); + + $createAgreementActionDefinition = new DefinitionDecorator('payum.payex.action.api.create_agreement'); + $createAgreementActionId = 'payum.context.'.$contextName.'.action.api.create_agreement'; + $container->setDefinition($createAgreementActionId, $createAgreementActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($createAgreementActionId))); + + $deleteAgreementActionDefinition = new DefinitionDecorator('payum.payex.action.api.delete_agreement'); + $deleteAgreementActionId = 'payum.context.'.$contextName.'.action.api.delete_agreement'; + $container->setDefinition($deleteAgreementActionId, $deleteAgreementActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($deleteAgreementActionId))); + + $checkAgreementActionDefinition = new DefinitionDecorator('payum.payex.action.api.check_agreement'); + $checkAgreementActionId = 'payum.context.'.$contextName.'.action.api.check_agreement'; + $container->setDefinition($checkAgreementActionId, $checkAgreementActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($checkAgreementActionId))); + + $autoPayAgreementActionDefinition = new DefinitionDecorator('payum.payex.action.api.autopay_agreement'); + $autoPayAgreementActionId = 'payum.context.'.$contextName.'.action.api.autopay_agreement'; + $container->setDefinition($autoPayAgreementActionId, $autoPayAgreementActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($autoPayAgreementActionId))); $captureActionDefinition = new DefinitionDecorator('payum.payex.action.capture'); $captureActionId = 'payum.context.'.$contextName.'.action.capture'; @@ -59,7 +90,7 @@ public function create(ContainerBuilder $container, $contextName, array $config) $statusActionId = 'payum.context.'.$contextName.'.action.status'; $container->setDefinition($statusActionId, $statusActionDefinition); $paymentDefinition->addMethodCall('addAction', array(new Reference($statusActionId))); -// + return $paymentId; } diff --git a/Resources/config/payment/payex.xml b/Resources/config/payment/payex.xml index c6f48b11..2d8e3f76 100644 --- a/Resources/config/payment/payex.xml +++ b/Resources/config/payment/payex.xml @@ -7,8 +7,13 @@ Payum\Payex\Api\SoapClientFactory Payum\Payex\Api\OrderApi + Payum\Payex\Api\AgreementApi Payum\Payex\Action\Api\InitializeOrderAction Payum\Payex\Action\Api\CompleteOrderAction + Payum\Payex\Action\Api\CreateAgreementAction + Payum\Payex\Action\Api\CheckAgreementAction + Payum\Payex\Action\Api\DeleteAgreementAction + Payum\Payex\Action\Api\AutoPayAgreementAction Payum\Payex\Action\CaptureAction Payum\Payex\Action\StatusAction @@ -33,6 +38,18 @@ + + + + + + + + + + + + + + + + + + + array('payum.context.aContextName.action.api.initialize_order'), 'api.complete_order' => array('payum.context.aContextName.action.api.complete_order'), + 'api.create_agreement' => array('payum.context.aContextName.action.api.create_agreement'), + 'api.delete_agreement' => array('payum.context.aContextName.action.api.delete_agreement'), + 'api.check_agreement' => array('payum.context.aContextName.action.api.check_agreement'), + 'api.autopay_agreement' => array('payum.context.aContextName.action.api.autopay_agreement'), 'capture' => array('payum.context.aContextName.action.capture'), 'status' => array('payum.context.aContextName.action.status'), @@ -248,6 +252,41 @@ public function shouldCallParentsCreateMethod() ); } + /** + * @test + */ + public function shouldAddExpectedApisToPayment() + { + $factory = new PayexPaymentFactory; + + $container = new ContainerBuilder; + + $paymentId = $factory->create($container, 'aContextName', array( + 'api' => array( + 'options' => array( + 'encryption_key' => 'aKey', + 'account_number' => 'aNum', + 'sandbox' => true + ), + ), + 'actions' => array(), + 'apis' => array(), + 'extensions' => array(), + )); + + $this->assertDefinitionContainsMethodCall( + $container->getDefinition($paymentId), + 'addApi', + new Reference('payum.context.aContextName.api.order') + ); + + $this->assertDefinitionContainsMethodCall( + $container->getDefinition($paymentId), + 'addApi', + new Reference('payum.context.aContextName.api.agreement') + ); + } + /** * @test * From c1a11cf602760f4dba008b64454bbfd3a4788b9c Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Sat, 15 Jun 2013 18:15:56 +0300 Subject: [PATCH 04/14] [payex][payment-factory] configure status actions for payment and agreement. --- .../Factory/Payment/PayexPaymentFactory.php | 13 +++++++++---- Resources/config/payment/payex.xml | 14 +++++++++++--- .../Factory/Payment/PayexPaymentFactoryTest.php | 3 ++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/DependencyInjection/Factory/Payment/PayexPaymentFactory.php b/DependencyInjection/Factory/Payment/PayexPaymentFactory.php index 37662720..8796c311 100644 --- a/DependencyInjection/Factory/Payment/PayexPaymentFactory.php +++ b/DependencyInjection/Factory/Payment/PayexPaymentFactory.php @@ -86,10 +86,15 @@ public function create(ContainerBuilder $container, $contextName, array $config) $container->setDefinition($captureActionId, $captureActionDefinition); $paymentDefinition->addMethodCall('addAction', array(new Reference($captureActionId))); - $statusActionDefinition = new DefinitionDecorator('payum.payex.action.status'); - $statusActionId = 'payum.context.'.$contextName.'.action.status'; - $container->setDefinition($statusActionId, $statusActionDefinition); - $paymentDefinition->addMethodCall('addAction', array(new Reference($statusActionId))); + $paymentDetailsStatusActionDefinition = new DefinitionDecorator('payum.payex.action.payment_details_status'); + $paymentDetailsStatusActionActionId = 'payum.context.'.$contextName.'.action.payment_details_status'; + $container->setDefinition($paymentDetailsStatusActionActionId, $paymentDetailsStatusActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($paymentDetailsStatusActionActionId))); + + $agreementDetailsStatusActionDefinition = new DefinitionDecorator('payum.payex.action.agreement_details_status'); + $agreementDetailsStatusActionActionId = 'payum.context.'.$contextName.'.action.agreement_details_status'; + $container->setDefinition($agreementDetailsStatusActionActionId, $agreementDetailsStatusActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($agreementDetailsStatusActionActionId))); return $paymentId; } diff --git a/Resources/config/payment/payex.xml b/Resources/config/payment/payex.xml index 2d8e3f76..efa49ba1 100644 --- a/Resources/config/payment/payex.xml +++ b/Resources/config/payment/payex.xml @@ -15,7 +15,8 @@ Payum\Payex\Action\Api\DeleteAgreementAction Payum\Payex\Action\Api\AutoPayAgreementAction Payum\Payex\Action\CaptureAction - Payum\Payex\Action\StatusAction + Payum\Payex\Action\PaymentDetailsStatusAction + Payum\Payex\Action\AgreementDetailsStatusAction @@ -100,8 +101,15 @@ + + + diff --git a/Tests/DependencyInjection/Factory/Payment/PayexPaymentFactoryTest.php b/Tests/DependencyInjection/Factory/Payment/PayexPaymentFactoryTest.php index cf6767d5..e0243fc3 100644 --- a/Tests/DependencyInjection/Factory/Payment/PayexPaymentFactoryTest.php +++ b/Tests/DependencyInjection/Factory/Payment/PayexPaymentFactoryTest.php @@ -29,7 +29,8 @@ public static function provideDecoratedActions() 'api.autopay_agreement' => array('payum.context.aContextName.action.api.autopay_agreement'), 'capture' => array('payum.context.aContextName.action.capture'), - 'status' => array('payum.context.aContextName.action.status'), + 'payment_details_status' => array('payum.context.aContextName.action.payment_details_status'), + 'agreement_details_status' => array('payum.context.aContextName.action.agreement_details_status'), ); } From 64342b35284b8080e58c125913463a6e0d2e1113 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Mon, 17 Jun 2013 22:23:36 +0300 Subject: [PATCH 05/14] [action] add some missing action for auto pay logic. --- .../Factory/Payment/PayexPaymentFactory.php | 18 +++++++++++---- Resources/config/payment/payex.xml | 22 ++++++++++++++++--- .../Payment/PayexPaymentFactoryTest.php | 4 +++- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/DependencyInjection/Factory/Payment/PayexPaymentFactory.php b/DependencyInjection/Factory/Payment/PayexPaymentFactory.php index 8796c311..e2a1b994 100644 --- a/DependencyInjection/Factory/Payment/PayexPaymentFactory.php +++ b/DependencyInjection/Factory/Payment/PayexPaymentFactory.php @@ -81,10 +81,20 @@ public function create(ContainerBuilder $container, $contextName, array $config) $container->setDefinition($autoPayAgreementActionId, $autoPayAgreementActionDefinition); $paymentDefinition->addMethodCall('addAction', array(new Reference($autoPayAgreementActionId))); - $captureActionDefinition = new DefinitionDecorator('payum.payex.action.capture'); - $captureActionId = 'payum.context.'.$contextName.'.action.capture'; - $container->setDefinition($captureActionId, $captureActionDefinition); - $paymentDefinition->addMethodCall('addAction', array(new Reference($captureActionId))); + $paymentDetailsCaptureActionDefinition = new DefinitionDecorator('payum.payex.action.payment_details_capture'); + $paymentDetailsCaptureActionId = 'payum.context.'.$contextName.'.action.payment_details_capture'; + $container->setDefinition($paymentDetailsCaptureActionId, $paymentDetailsCaptureActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($paymentDetailsCaptureActionId))); + + $autoPayPaymentDetailsCaptureActionDefinition = new DefinitionDecorator('payum.payex.action.autopay_payment_details_capture'); + $autoPayPaymentDetailsCaptureActionId = 'payum.context.'.$contextName.'.action.autopay_payment_details_capture'; + $container->setDefinition($autoPayPaymentDetailsCaptureActionId, $autoPayPaymentDetailsCaptureActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($autoPayPaymentDetailsCaptureActionId))); + + $autoPayPaymentDetailsStatusActionDefinition = new DefinitionDecorator('payum.payex.action.autopay_payment_details_status'); + $autoPayPaymentDetailsStatusActionId = 'payum.context.'.$contextName.'.action.autopay_payment_details_status'; + $container->setDefinition($autoPayPaymentDetailsStatusActionId, $autoPayPaymentDetailsStatusActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($autoPayPaymentDetailsStatusActionId))); $paymentDetailsStatusActionDefinition = new DefinitionDecorator('payum.payex.action.payment_details_status'); $paymentDetailsStatusActionActionId = 'payum.context.'.$contextName.'.action.payment_details_status'; diff --git a/Resources/config/payment/payex.xml b/Resources/config/payment/payex.xml index efa49ba1..eed3e7f4 100644 --- a/Resources/config/payment/payex.xml +++ b/Resources/config/payment/payex.xml @@ -14,7 +14,9 @@ Payum\Payex\Action\Api\CheckAgreementAction Payum\Payex\Action\Api\DeleteAgreementAction Payum\Payex\Action\Api\AutoPayAgreementAction - Payum\Payex\Action\CaptureAction + Payum\Payex\Action\PaymentDetailsCaptureAction + Payum\Payex\Action\AutoPayPaymentDetailsCaptureAction + Payum\Payex\Action\AutoPayPaymentDetailsStatusAction Payum\Payex\Action\PaymentDetailsStatusAction Payum\Payex\Action\AgreementDetailsStatusAction @@ -94,12 +96,26 @@ + + + + + + array('payum.context.aContextName.action.api.check_agreement'), 'api.autopay_agreement' => array('payum.context.aContextName.action.api.autopay_agreement'), - 'capture' => array('payum.context.aContextName.action.capture'), + 'payment_details_capture' => array('payum.context.aContextName.action.payment_details_capture'), 'payment_details_status' => array('payum.context.aContextName.action.payment_details_status'), + 'autopay_payment_details_capture' => array('payum.context.aContextName.action.autopay_payment_details_capture'), + 'autopay_payment_details_status' => array('payum.context.aContextName.action.autopay_payment_details_status'), 'agreement_details_status' => array('payum.context.aContextName.action.agreement_details_status'), ); } From e90000ea67fb939d9e7ebc172e872adac3420a28 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 28 Jun 2013 20:01:24 +0300 Subject: [PATCH 06/14] [payex] add missing actions recurring, sync etc. --- .../Factory/Payment/PayexPaymentFactory.php | 41 +++++++++++ Resources/config/payment/payex.xml | 71 +++++++++++++++++-- .../Payment/PayexPaymentFactoryTest.php | 14 +++- 3 files changed, 120 insertions(+), 6 deletions(-) diff --git a/DependencyInjection/Factory/Payment/PayexPaymentFactory.php b/DependencyInjection/Factory/Payment/PayexPaymentFactory.php index e2a1b994..acd33f57 100644 --- a/DependencyInjection/Factory/Payment/PayexPaymentFactory.php +++ b/DependencyInjection/Factory/Payment/PayexPaymentFactory.php @@ -51,6 +51,17 @@ public function create(ContainerBuilder $container, $contextName, array $config) $container->setDefinition($agreementApiId, $agreementApiDefinition); $paymentDefinition->addMethodCall('addApi', array(new Reference($agreementApiId))); + $recurringApiDefinition = new DefinitionDecorator('payum.payex.api.recurring.prototype'); + $recurringApiDefinition->replaceArgument(1, array( + 'encryptionKey' => $config['api']['options']['encryption_key'], + 'accountNumber' => $config['api']['options']['account_number'], + 'sandbox' => $config['api']['options']['sandbox'] + )); + $recurringApiDefinition->setPublic(true); + $recurringApiId = 'payum.context.'.$contextName.'.api.recurring'; + $container->setDefinition($recurringApiId, $recurringApiDefinition); + $paymentDefinition->addMethodCall('addApi', array(new Reference($recurringApiId))); + $initializeOrderActionDefinition = new DefinitionDecorator('payum.payex.action.api.initialize_order'); $initializeOrderActionId = 'payum.context.'.$contextName.'.action.api.initialize_order'; $container->setDefinition($initializeOrderActionId, $initializeOrderActionDefinition); @@ -61,6 +72,11 @@ public function create(ContainerBuilder $container, $contextName, array $config) $container->setDefinition($completeOrderActionId, $completeOrderActionDefinition); $paymentDefinition->addMethodCall('addAction', array(new Reference($completeOrderActionId))); + $checkOrderActionDefinition = new DefinitionDecorator('payum.payex.action.api.check_order'); + $checkOrderActionId = 'payum.context.'.$contextName.'.action.api.check_order'; + $container->setDefinition($checkOrderActionId, $checkOrderActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($checkOrderActionId))); + $createAgreementActionDefinition = new DefinitionDecorator('payum.payex.action.api.create_agreement'); $createAgreementActionId = 'payum.context.'.$contextName.'.action.api.create_agreement'; $container->setDefinition($createAgreementActionId, $createAgreementActionDefinition); @@ -80,6 +96,21 @@ public function create(ContainerBuilder $container, $contextName, array $config) $autoPayAgreementActionId = 'payum.context.'.$contextName.'.action.api.autopay_agreement'; $container->setDefinition($autoPayAgreementActionId, $autoPayAgreementActionDefinition); $paymentDefinition->addMethodCall('addAction', array(new Reference($autoPayAgreementActionId))); + + $startRecurringPaymentsActionDefinition = new DefinitionDecorator('payum.payex.action.api.start_recurring_payment'); + $startRecurringPaymentsActionId = 'payum.context.'.$contextName.'.action.api.start_recurring_payment'; + $container->setDefinition($startRecurringPaymentsActionId, $startRecurringPaymentsActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($startRecurringPaymentsActionId))); + + $stopRecurringPaymentsActionDefinition = new DefinitionDecorator('payum.payex.action.api.stop_recurring_payment'); + $stopRecurringPaymentsActionId = 'payum.context.'.$contextName.'.action.api.stop_recurring_payment'; + $container->setDefinition($stopRecurringPaymentsActionId, $stopRecurringPaymentsActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($stopRecurringPaymentsActionId))); + + $checkRecurringPaymentsActionDefinition = new DefinitionDecorator('payum.payex.action.api.check_recurring_payment'); + $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'; @@ -101,11 +132,21 @@ public function create(ContainerBuilder $container, $contextName, array $config) $container->setDefinition($paymentDetailsStatusActionActionId, $paymentDetailsStatusActionDefinition); $paymentDefinition->addMethodCall('addAction', array(new Reference($paymentDetailsStatusActionActionId))); + $paymentDetailsSyncActionDefinition = new DefinitionDecorator('payum.payex.action.payment_details_sync'); + $paymentDetailsSyncActionActionId = 'payum.context.'.$contextName.'.action.payment_details_sync'; + $container->setDefinition($paymentDetailsSyncActionActionId, $paymentDetailsSyncActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($paymentDetailsSyncActionActionId))); + $agreementDetailsStatusActionDefinition = new DefinitionDecorator('payum.payex.action.agreement_details_status'); $agreementDetailsStatusActionActionId = 'payum.context.'.$contextName.'.action.agreement_details_status'; $container->setDefinition($agreementDetailsStatusActionActionId, $agreementDetailsStatusActionDefinition); $paymentDefinition->addMethodCall('addAction', array(new Reference($agreementDetailsStatusActionActionId))); + $agreementDetailsSyncActionDefinition = new DefinitionDecorator('payum.payex.action.agreement_details_sync'); + $agreementDetailsSyncActionActionId = 'payum.context.'.$contextName.'.action.agreement_details_sync'; + $container->setDefinition($agreementDetailsSyncActionActionId, $agreementDetailsSyncActionDefinition); + $paymentDefinition->addMethodCall('addAction', array(new Reference($agreementDetailsSyncActionActionId))); + return $paymentId; } diff --git a/Resources/config/payment/payex.xml b/Resources/config/payment/payex.xml index eed3e7f4..105e6259 100644 --- a/Resources/config/payment/payex.xml +++ b/Resources/config/payment/payex.xml @@ -8,17 +8,24 @@ Payum\Payex\Api\SoapClientFactory Payum\Payex\Api\OrderApi Payum\Payex\Api\AgreementApi + Payum\Payex\Api\RecurringApi Payum\Payex\Action\Api\InitializeOrderAction Payum\Payex\Action\Api\CompleteOrderAction + Payum\Payex\Action\Api\CheckOrderAction Payum\Payex\Action\Api\CreateAgreementAction Payum\Payex\Action\Api\CheckAgreementAction Payum\Payex\Action\Api\DeleteAgreementAction Payum\Payex\Action\Api\AutoPayAgreementAction + Payum\Payex\Action\Api\StartRecurringPaymentAction + Payum\Payex\Action\Api\StopRecurringPaymentAction + Payum\Payex\Action\Api\CheckRecurringPaymentAction Payum\Payex\Action\PaymentDetailsCaptureAction + Payum\Payex\Action\PaymentDetailsSyncAction + Payum\Payex\Action\PaymentDetailsStatusAction Payum\Payex\Action\AutoPayPaymentDetailsCaptureAction Payum\Payex\Action\AutoPayPaymentDetailsStatusAction - Payum\Payex\Action\PaymentDetailsStatusAction Payum\Payex\Action\AgreementDetailsStatusAction + Payum\Payex\Action\AgreementDetailsSyncAction @@ -53,6 +60,18 @@ + + + + + + + + + + + + + + + + + + + + id="payum.payex.action.autopay_payment_details_status" + class="%payum.payex.action.autopay_payment_details_status.class%" + public="false" + > + + + + + + \ No newline at end of file diff --git a/Tests/DependencyInjection/Factory/Payment/PayexPaymentFactoryTest.php b/Tests/DependencyInjection/Factory/Payment/PayexPaymentFactoryTest.php index f97928b4..3beb7c7d 100644 --- a/Tests/DependencyInjection/Factory/Payment/PayexPaymentFactoryTest.php +++ b/Tests/DependencyInjection/Factory/Payment/PayexPaymentFactoryTest.php @@ -23,16 +23,22 @@ public static function provideDecoratedActions() return array( 'api.initialize_order' => array('payum.context.aContextName.action.api.initialize_order'), 'api.complete_order' => array('payum.context.aContextName.action.api.complete_order'), + 'api.check_order' => array('payum.context.aContextName.action.api.check_order'), 'api.create_agreement' => array('payum.context.aContextName.action.api.create_agreement'), 'api.delete_agreement' => array('payum.context.aContextName.action.api.delete_agreement'), 'api.check_agreement' => array('payum.context.aContextName.action.api.check_agreement'), 'api.autopay_agreement' => array('payum.context.aContextName.action.api.autopay_agreement'), - + 'api.start_recurring_payment' => array('payum.context.aContextName.action.api.start_recurring_payment'), + 'api.stop_recurring_payment' => array('payum.context.aContextName.action.api.stop_recurring_payment'), + 'api.check_recurring_payment' => array('payum.context.aContextName.action.api.check_recurring_payment'), + 'payment_details_capture' => array('payum.context.aContextName.action.payment_details_capture'), 'payment_details_status' => array('payum.context.aContextName.action.payment_details_status'), + 'payment_details_sync' => array('payum.context.aContextName.action.payment_details_sync'), 'autopay_payment_details_capture' => array('payum.context.aContextName.action.autopay_payment_details_capture'), 'autopay_payment_details_status' => array('payum.context.aContextName.action.autopay_payment_details_status'), 'agreement_details_status' => array('payum.context.aContextName.action.agreement_details_status'), + 'agreement_details_sync' => array('payum.context.aContextName.action.agreement_details_sync'), ); } @@ -288,6 +294,12 @@ public function shouldAddExpectedApisToPayment() 'addApi', new Reference('payum.context.aContextName.api.agreement') ); + + $this->assertDefinitionContainsMethodCall( + $container->getDefinition($paymentId), + 'addApi', + new Reference('payum.context.aContextName.api.recurring') + ); } /** From b2f85d847e50899efaee03556805cb3999374d96 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Mon, 29 Jul 2013 20:30:08 +0300 Subject: [PATCH 07/14] fix merge of configurations defined in different configs. --- DependencyInjection/MainConfiguration.php | 1 + 1 file changed, 1 insertion(+) diff --git a/DependencyInjection/MainConfiguration.php b/DependencyInjection/MainConfiguration.php index 0a1ff6e7..54d18a58 100644 --- a/DependencyInjection/MainConfiguration.php +++ b/DependencyInjection/MainConfiguration.php @@ -50,6 +50,7 @@ public function getConfigTreeBuilder() $contextsPrototypeNode = $rootNode ->children() ->arrayNode('contexts') + ->useAttributeAsKey('name') ->prototype('array') ; From bfad1185719c895b952c1bbc503122b78334ea72 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 2 Aug 2013 19:26:53 +0300 Subject: [PATCH 08/14] [payex] add doc. --- Resources/doc/capture_funds_with_payex.md | 199 ++++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 Resources/doc/capture_funds_with_payex.md diff --git a/Resources/doc/capture_funds_with_payex.md b/Resources/doc/capture_funds_with_payex.md new file mode 100644 index 00000000..dcafdcd0 --- /dev/null +++ b/Resources/doc/capture_funds_with_payex.md @@ -0,0 +1,199 @@ +## Capture funds with payex + +### Step 1. Download payex payum lib + +Add the following lines in your `composer.json` file: + +```json +{ + "require": { + "payum/payex": "dev-master" + } +} +``` + +_**Note:** You may want to adapt this line to use a specific version._ + +Now, run composer.phar to download the bundle: + +```bash +$ php composer.phar install +``` + +_**Note:** You can immediately start using it. The autoloading files have been generated by composer and already included to the app autoload file._ + +### Step 2: Basic configuration. + +#### 1. Configure payment context + +```yml +#app/config/config.yml + +payum: + contexts: + your_payment_name: + payex: + api: + options: + account_number: 'get this from gateway side' + encryption_key: 'get this from gateway side' + sandbox: true +``` + +**Warning:** + +> You have to changed this name `your_payment_name` to something related to your domain, for example `post_a_job_with_payex` + +#### 2-a. Configure doctrine storage + +Extend PaymentDetails class with added id property: + +```php +id; + } +} +``` + +and configure storage to use this model: + +```yaml +#app/config/config.yml + +payum: + contexts: + your_payment_name: + storages: + Acme\DemoBundle\Model\PayexPaymentDetails: + filesystem: + storage_dir: %kernel.root_dir%/Resources/payments + id_property: id + payment_extension: true +``` + +### Step 3. Capture payment: + +_**Note** : We assume you [configured capture controller](basic_setup.md#step-3-configure-capture-controller-optional)_ + +_**Note** : We assume you choose a storage._ + +```php +getPayum()->getStorageForClass( + 'Acme\DemoBundle\Model\PayexPaymentDetails', + $paymentName + ); + + /** @var $paymentDetails PaymentDetails */ + $paymentDetails = $storage->createModel(); + $paymentDetails->setPrice($data['amount'] * 100); + $paymentDetails->setPriceArgList(''); + $paymentDetails->setVat(0); + $paymentDetails->setCurrency($data['currency']); + $paymentDetails->setOrderId(123); + $paymentDetails->setProductNumber(123); + $paymentDetails->setPurchaseOperation(OrderApi::PURCHASEOPERATION_AUTHORIZATION); + $paymentDetails->setView(OrderApi::VIEW_CREDITCARD); + $paymentDetails->setDescription('a desc'); + $paymentDetails->setClientIPAddress($request->getClientIp()); + $paymentDetails->setClientIdentifier(''); + $paymentDetails->setAdditionalValues(''); + $paymentDetails->setAgreementRef(''); + $paymentDetails->setClientLanguage('en-US'); + + $storage->updateModel($paymentDetails); + + $captureToken = $this->get('payum.token_manager')->createTokenForCaptureRoute( + $paymentName, + $paymentDetails, + 'acme_payment_details_view' + ); + + $paymentDetails->setReturnurl($captureToken->getTargetUrl()); + $paymentDetails->setCancelurl($captureToken->getTargetUrl()); + $storage->updateModel($paymentDetails); + + return $this->redirect($captureToken->getTargetUrl()); + } +} +``` + +### Next Step + +* [Configuration reference](configuration_reference.md). \ No newline at end of file From 3494154eb10659267a5726a0c52c9af9b61be2b3 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 2 Aug 2013 19:51:28 +0300 Subject: [PATCH 09/14] [doc] add doc about payment done action. --- .../capture_funds_with_authorize_net_aim.md | 7 ++- Resources/doc/capture_funds_with_be2bill.md | 7 ++- Resources/doc/capture_funds_with_ominpay.md | 7 ++- Resources/doc/capture_funds_with_payex.md | 7 ++- ...ture_funds_with_paypal_express_checkout.md | 7 ++- .../capture_funds_with_paypal_pro_checkout.md | 7 ++- Resources/doc/configuration_reference.md | 6 +- ...how_payment_done_action_could_look_like.md | 57 +++++++++++++++++++ Resources/doc/index.md | 4 +- Resources/doc/install_as_git_submodules.md | 6 +- Resources/doc/sandbox.md | 10 ++++ 11 files changed, 110 insertions(+), 15 deletions(-) create mode 100644 Resources/doc/how_payment_done_action_could_look_like.md create mode 100644 Resources/doc/sandbox.md diff --git a/Resources/doc/capture_funds_with_authorize_net_aim.md b/Resources/doc/capture_funds_with_authorize_net_aim.md index 33679636..d79874e1 100644 --- a/Resources/doc/capture_funds_with_authorize_net_aim.md +++ b/Resources/doc/capture_funds_with_authorize_net_aim.md @@ -173,7 +173,7 @@ class PaymentController extends Controller $captureToken = $this->get('payum.token_manager')->createTokenForCaptureRoute( $paymentName, $paymentDetails, - 'acme_payment_details_view' // the route to redirect after capture; + 'acme_payment_done' // the route to redirect after capture; ); return $this->forward('PayumBundle:Capture:do', array( @@ -186,4 +186,7 @@ class PaymentController extends Controller ### Next Step -* [Configuration reference](configuration_reference.md). \ No newline at end of file +* [How payment dome action could look like?](how_payment_done_action_could_look_like.md). +* [Configuration reference](configuration_reference.md). +* [Sandbox](sandbox.md). +* [Back to index](index.md). \ No newline at end of file diff --git a/Resources/doc/capture_funds_with_be2bill.md b/Resources/doc/capture_funds_with_be2bill.md index c111b71e..5f15eb25 100644 --- a/Resources/doc/capture_funds_with_be2bill.md +++ b/Resources/doc/capture_funds_with_be2bill.md @@ -179,7 +179,7 @@ class PaymentController extends Controller $captureToken = $this->get('payum.token_manager')->createTokenForCaptureRoute( $paymentName, $paymentDetails, - 'acme_payment_details_view' // the route to redirect after capture; + 'acme_payment_done' // the route to redirect after capture; ); return $this->forward('PayumBundle:Capture:do', array( @@ -192,4 +192,7 @@ class PaymentController extends Controller ### Next Step -* [Configuration reference](configuration_reference.md). \ No newline at end of file +* [How payment dome action could look like?](how_payment_done_action_could_look_like.md). +* [Configuration reference](configuration_reference.md). +* [Sandbox](sandbox.md). +* [Back to index](index.md). \ No newline at end of file diff --git a/Resources/doc/capture_funds_with_ominpay.md b/Resources/doc/capture_funds_with_ominpay.md index 98a56b2b..1eea539c 100644 --- a/Resources/doc/capture_funds_with_ominpay.md +++ b/Resources/doc/capture_funds_with_ominpay.md @@ -123,7 +123,7 @@ class PaymentController extends Controller $captureToken = $this->get('payum.token_manager')->createTokenForCaptureRoute( $paymentName, $paymentDetails, - 'acme_payment_details_view' // the route to redirect after capture; + 'acme_payment_done' // the route to redirect after capture; ); return $this->forward('PayumBundle:Capture:do', array( @@ -136,4 +136,7 @@ class PaymentController extends Controller ### Next Step -* [Configuration reference](configuration_reference.md). \ No newline at end of file +* [How payment dome action could look like?](how_payment_done_action_could_look_like.md). +* [Configuration reference](configuration_reference.md). +* [Sandbox](sandbox.md). +* [Back to index](index.md). \ No newline at end of file diff --git a/Resources/doc/capture_funds_with_payex.md b/Resources/doc/capture_funds_with_payex.md index dcafdcd0..3f8042e5 100644 --- a/Resources/doc/capture_funds_with_payex.md +++ b/Resources/doc/capture_funds_with_payex.md @@ -182,7 +182,7 @@ class PaymentController extends Controller $captureToken = $this->get('payum.token_manager')->createTokenForCaptureRoute( $paymentName, $paymentDetails, - 'acme_payment_details_view' + 'acme_payment_done' // the route to redirect after capture; ); $paymentDetails->setReturnurl($captureToken->getTargetUrl()); @@ -196,4 +196,7 @@ class PaymentController extends Controller ### Next Step -* [Configuration reference](configuration_reference.md). \ No newline at end of file +* [How payment dome action could look like?](how_payment_done_action_could_look_like.md). +* [Configuration reference](configuration_reference.md). +* [Sandbox](sandbox.md). +* [Back to index](index.md). \ No newline at end of file diff --git a/Resources/doc/capture_funds_with_paypal_express_checkout.md b/Resources/doc/capture_funds_with_paypal_express_checkout.md index 8e7e7c9f..cd20aa89 100644 --- a/Resources/doc/capture_funds_with_paypal_express_checkout.md +++ b/Resources/doc/capture_funds_with_paypal_express_checkout.md @@ -171,7 +171,7 @@ class PaymentController extends Controller $captureToken = $this->get('payum.token_manager')->createTokenForCaptureRoute( $paymentName, $paymentDetails, - 'acme_payment_details_view' // the route to redirect after capture; + 'acme_payment_done' // the route to redirect after capture; ); $paymentDetails->setInvnum($paymentDetails->getId()); @@ -187,4 +187,7 @@ class PaymentController extends Controller ### Next Step -* [Configuration reference](configuration_reference.md). \ No newline at end of file +* [How payment dome action could look like?](how_payment_done_action_could_look_like.md). +* [Configuration reference](configuration_reference.md). +* [Sandbox](sandbox.md). +* [Back to index](index.md). \ No newline at end of file diff --git a/Resources/doc/capture_funds_with_paypal_pro_checkout.md b/Resources/doc/capture_funds_with_paypal_pro_checkout.md index 7919da61..7e722723 100644 --- a/Resources/doc/capture_funds_with_paypal_pro_checkout.md +++ b/Resources/doc/capture_funds_with_paypal_pro_checkout.md @@ -121,7 +121,7 @@ class PaymentController extends Controller $captureToken = $this->get('payum.token_manager')->createTokenForCaptureRoute( $paymentName, $paymentDetails, - 'acme_payment_details_view' // the route to redirect after capture; + 'acme_payment_done' // the route to redirect after capture; ); return $this->forward('PayumBundle:Capture:do', array( @@ -134,4 +134,7 @@ class PaymentController extends Controller ### Next Step -* [Configuration reference](configuration_reference.md). \ No newline at end of file +* [How payment dome action could look like?](how_payment_done_action_could_look_like.md). +* [Configuration reference](configuration_reference.md). +* [Sandbox](sandbox.md). +* [Back to index](index.md). \ No newline at end of file diff --git a/Resources/doc/configuration_reference.md b/Resources/doc/configuration_reference.md index 59d1c0b9..46097924 100644 --- a/Resources/doc/configuration_reference.md +++ b/Resources/doc/configuration_reference.md @@ -113,4 +113,8 @@ omnipay: custom: #if service not set an empty payment will be created. service: ~ -``` \ No newline at end of file +``` + +### Next Step + +* [Back to index](index.md). \ No newline at end of file diff --git a/Resources/doc/how_payment_done_action_could_look_like.md b/Resources/doc/how_payment_done_action_could_look_like.md new file mode 100644 index 00000000..b1f3a204 --- /dev/null +++ b/Resources/doc/how_payment_done_action_could_look_like.md @@ -0,0 +1,57 @@ +How payment dome action could look like? +======================================== + +We assume you already know how to prepare payment details and how to capture them. +The last thing in this store what to do after? +This chapter should answer this question. + +Well, let's assume you created capture token this way: + +```php +get('payum.token_manager')->createTokenForCaptureRoute( + $paymentName, + $paymentDetails, + 'acme_payment_done' +); +``` + +Pay attention to third parameter `acme_payment_done`. +It is the url you will be redirected after capture done its job. Let's look at an example of how this action may look like: + +```php + public function captureDoneAction(Request $request) + { + $token = $this->get('payum.token_manager')->getTokenFromRequest($request); + + $payment = $this->get('payum')->getPayment($token->getPaymentName()); + + $status = new BinaryMaskStatusRequest($token); + $payment->execute($status); + + if ($status->isSuccess()) { + $this->getUser()->addCredits(100); + $this->getRequest()->getSession()->getFlashBag()->set( + 'notice', + 'Payment success. Credits were added' + ); + } else if ($status->isPending()) { + $this->getRequest()->getSession()->getFlashBag()->set( + 'notice', + 'Payment is still pending. Credits were not added' + ); + } else { + $this->getRequest()->getSession()->getFlashBag()->set('error', 'Payment failed'); + } + + return $this->redirect('homepage'); + } +``` + +In general you have to check status of the payment and do whatever you want depending on the status. +For example if payment success you would add a user some credits or update expiration date. +If not you redirect him to homepage and show a flash message "payment failed. try again later". + +### Next Step + +* [Back to index](index.md). \ No newline at end of file diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 6d00f6fc..38e216b5 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -15,4 +15,6 @@ The installation has two steps: ### Other documents: -* [Configuration reference](configuration_reference.md). \ No newline at end of file +* [How payment dome action could look like?](how_payment_done_action_could_look_like.md). +* [Configuration reference](configuration_reference.md). +* [Sandbox](configuration_reference.md). \ No newline at end of file diff --git a/Resources/doc/install_as_git_submodules.md b/Resources/doc/install_as_git_submodules.md index 6b3fe541..8b0cfcb6 100644 --- a/Resources/doc/install_as_git_submodules.md +++ b/Resources/doc/install_as_git_submodules.md @@ -26,4 +26,8 @@ $loader->registerNamespaces(array( )); $loader->register(); -``` \ No newline at end of file +``` + +### Next Step + +* [Back to index](index.md). \ No newline at end of file diff --git a/Resources/doc/sandbox.md b/Resources/doc/sandbox.md new file mode 100644 index 00000000..30ea5959 --- /dev/null +++ b/Resources/doc/sandbox.md @@ -0,0 +1,10 @@ +Sandbox +======= + +There is a sandbox ([source](https://github.com/Payum/PayumBundleSandbox) or [web](http://sandbox.payum.forma-dev.com/)) with bunch of examples and howtos. +It contains basic example as well as some advanced (paypal recurring payments, or paypal IPN). +So if you want to dig in payum or dont find an answer in the doc sandbox is a good place to continue. + +### Next Step + +* [Back to index](index.md). \ No newline at end of file From 2185cfac5d1f3307d1f00ea9f24c1ca026409e3c Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 2 Aug 2013 19:55:05 +0300 Subject: [PATCH 10/14] [doc] tweek a bit. --- .../doc/how_payment_done_action_could_look_like.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Resources/doc/how_payment_done_action_could_look_like.md b/Resources/doc/how_payment_done_action_could_look_like.md index b1f3a204..fb09772b 100644 --- a/Resources/doc/how_payment_done_action_could_look_like.md +++ b/Resources/doc/how_payment_done_action_could_look_like.md @@ -1,11 +1,11 @@ -How payment dome action could look like? +How payment done action could look like? ======================================== We assume you already know how to prepare payment details and how to capture them. The last thing in this store what to do after? -This chapter should answer this question. +This chapter should cover these questions. -Well, let's assume you created capture token this way: +Well, let's assume you created capture token this way while preparing payment: ```php get('payum.token_manager')->createTokenForCaptureRoute( ``` Pay attention to third parameter `acme_payment_done`. -It is the url you will be redirected after capture done its job. Let's look at an example of how this action may look like: +It is the route of url you will be redirected after capture done its job. Let's look at an example of how this action may look like: ```php public function captureDoneAction(Request $request) @@ -48,9 +48,9 @@ It is the url you will be redirected after capture done its job. Let's look at a } ``` -In general you have to check status of the payment and do whatever you want depending on the status. +In general you have to check status of the payment and do whatever you want depending on it. For example if payment success you would add a user some credits or update expiration date. -If not you redirect him to homepage and show a flash message "payment failed. try again later". +If not you redirect him to homepage and show a flash message with a bad news. ### Next Step From ff04382e632b89951b3988c548b7cbe659f6593c Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 2 Aug 2013 20:12:39 +0300 Subject: [PATCH 11/14] [doc] fix link --- Resources/doc/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/doc/index.md b/Resources/doc/index.md index 38e216b5..bab670d9 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -17,4 +17,4 @@ The installation has two steps: * [How payment dome action could look like?](how_payment_done_action_could_look_like.md). * [Configuration reference](configuration_reference.md). -* [Sandbox](configuration_reference.md). \ No newline at end of file +* [Sandbox](sandbox.md). \ No newline at end of file From 141c01a89f3b056562fae535c7c070989a021790 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 2 Aug 2013 20:13:29 +0300 Subject: [PATCH 12/14] [doc] tweek a bit. --- Resources/doc/sandbox.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/doc/sandbox.md b/Resources/doc/sandbox.md index 30ea5959..b7b44a31 100644 --- a/Resources/doc/sandbox.md +++ b/Resources/doc/sandbox.md @@ -1,7 +1,7 @@ Sandbox ======= -There is a sandbox ([source](https://github.com/Payum/PayumBundleSandbox) or [web](http://sandbox.payum.forma-dev.com/)) with bunch of examples and howtos. +There is a sandbox app ([source](https://github.com/Payum/PayumBundleSandbox) or [web](http://sandbox.payum.forma-dev.com/)) with bunch of examples and howtos. It contains basic example as well as some advanced (paypal recurring payments, or paypal IPN). So if you want to dig in payum or dont find an answer in the doc sandbox is a good place to continue. From 5055f696955ef634e7e3043058f9a71046c4d7be Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 2 Aug 2013 20:15:41 +0300 Subject: [PATCH 13/14] [doc] fix doc. --- Resources/doc/sandbox.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Resources/doc/sandbox.md b/Resources/doc/sandbox.md index b7b44a31..cc48eaad 100644 --- a/Resources/doc/sandbox.md +++ b/Resources/doc/sandbox.md @@ -1,7 +1,7 @@ Sandbox ======= -There is a sandbox app ([source](https://github.com/Payum/PayumBundleSandbox) or [web](http://sandbox.payum.forma-dev.com/)) with bunch of examples and howtos. +There is a sandbox app ([source](https://github.com/Payum/PayumBundleSandbox) or [web](http://sandbox.payum.forma-dev.com/)) with bunch of examples. It contains basic example as well as some advanced (paypal recurring payments, or paypal IPN). So if you want to dig in payum or dont find an answer in the doc sandbox is a good place to continue. From e8bc67be33b4884a02a77b6dd58146d717b79ba8 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Fri, 2 Aug 2013 20:18:30 +0300 Subject: [PATCH 14/14] [payex] use stable version of the lib. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 12238b84..0f897352 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "payum/paypal-express-checkout-nvp": "0.5.*", "payum/paypal-pro-checkout-nvp": "0.5.*", "payum/be2bill": "0.5.*", - "payum/payex": "0.5.x-dev", + "payum/payex": "0.5.*", "payum/authorize-net-aim": "0.5.*", "payum/omnipay-bridge": "0.5.*" },