From 02d4ea540252c1b8836a20be225fef2f9e1a3d3b Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Thu, 3 Mar 2016 19:20:57 +0000 Subject: [PATCH] [paytrail] add lib and basic config. --- app/config/parameters.yml.dist | 3 + app/config/payum.yml | 11 +++ composer.json | 9 ++- composer.lock | 61 +++++++++++++--- .../Controller/SimplePaytrailController.php | 71 +++++++++++++++++++ .../Resources/views/Default/index.html.twig | 5 ++ 6 files changed, 151 insertions(+), 9 deletions(-) create mode 100644 src/Acme/PaymentBundle/Controller/SimplePaytrailController.php diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist index 712e4d0..4c508e1 100644 --- a/app/config/parameters.yml.dist +++ b/app/config/parameters.yml.dist @@ -48,6 +48,9 @@ parameters: sofort.config_key: EDIT ME + paytrail.merchant_id: EDIT ME + paytrail.merchant_secret: EDIT ME + # configure if you want to use console create token commands router.request_context.host: sandbox.payum.org router.request_context.scheme: http diff --git a/app/config/payum.yml b/app/config/payum.yml index c770448..f5ad767 100644 --- a/app/config/payum.yml +++ b/app/config/payum.yml @@ -186,6 +186,11 @@ payum: factory: sofort config_key: %sofort.config_key% + paytrail: + factory: paytrail + merchantId: %paytrail.merchant_id% + merchantSecret: %paytrail.merchant_secret% + foo_bar_gateway: payum.action.capture: @acme_payment.foo_bar.capture payum.action.status: @acme_payment.foo_bar.status @@ -197,6 +202,12 @@ services: tags: - { name: payum.gateway_factory_builder, factory: redsys } + acme_payment.paytrail.gateway_factory: + class: Payum\Core\Bridge\Symfony\Builder\GatewayFactoryBuilder + arguments: [Paradigm\PayumPaytrail\PaytrailGatewayFactory] + tags: + - { name: payum.gateway_factory_builder, factory: paytrail } + acme_payment.jms_payment.gateway_factory: class: Payum\Core\Bridge\Symfony\Builder\GatewayFactoryBuilder arguments: [Payum\Bridge\JMSPayment\JmsGatewayFactory] diff --git a/composer.json b/composer.json index 22acebd..09b3845 100644 --- a/composer.json +++ b/composer.json @@ -41,8 +41,15 @@ "stripe/stripe-php": "^2.0", "sofort/sofortlib-php": "^3.0", "phpunit/phpunit": "^4.0", - "fabpot/php-cs-fixer": "^1.10" + "fabpot/php-cs-fixer": "^1.10", + "paradigm/payum-paytrail": "dev-master@dev" }, + "repositories": [ + { + "type": "vcs", + "url": "git@github.com:Paradigmfi/PayumPaytrail.git" + } + ], "scripts": { "post-install-cmd": [ "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", diff --git a/composer.lock b/composer.lock index b294471..0957e6a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "4ebb778750cffab88465a0e72688da7f", - "content-hash": "6c563a4e4fedebe97bbfa3e3a108fe18", + "hash": "4cde79a6e61a29d945eac876812ae0b4", + "content-hash": "4ce49dc5b2bea35caa4ffed480ada3f3", "packages": [ { "name": "authorizenet/authorizenet", @@ -2521,6 +2521,49 @@ ], "time": "2016-01-13 04:00:45" }, + { + "name": "paradigm/payum-paytrail", + "version": "dev-master", + "target-dir": "Paradigm/PayumPaytrail", + "source": { + "type": "git", + "url": "https://github.com/Paradigmfi/PayumPaytrail.git", + "reference": "d9399de8b29b2aea86af2e4dfb01c3637ec8c176" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Paradigmfi/PayumPaytrail/zipball/d9399de8b29b2aea86af2e4dfb01c3637ec8c176", + "reference": "d9399de8b29b2aea86af2e4dfb01c3637ec8c176", + "shasum": "" + }, + "require": { + "payum/core": "^1.2.3" + }, + "type": "project", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-0": { + "Paradigm\\PayumPaytrail": "" + } + }, + "license": [ + "MIT" + ], + "description": "The Payum extension for Paytrail payment gateway", + "keywords": [ + "payment", + "paytrail" + ], + "support": { + "source": "https://github.com/Paradigmfi/PayumPaytrail/tree/master", + "issues": "https://github.com/Paradigmfi/PayumPaytrail/issues" + }, + "time": "2016-03-07 18:34:14" + }, { "name": "paragonie/random_compat", "version": "v1.2.1", @@ -2802,16 +2845,16 @@ }, { "name": "payum/payum", - "version": "1.2.2", + "version": "1.2.3", "source": { "type": "git", "url": "https://github.com/Payum/Payum.git", - "reference": "5724785027c1ac6ce5c9f25931af0dfdd907397a" + "reference": "85135397fa2210dfb0d3027ec1c809fd69a046a5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Payum/Payum/zipball/5724785027c1ac6ce5c9f25931af0dfdd907397a", - "reference": "5724785027c1ac6ce5c9f25931af0dfdd907397a", + "url": "https://api.github.com/repos/Payum/Payum/zipball/85135397fa2210dfb0d3027ec1c809fd69a046a5", + "reference": "85135397fa2210dfb0d3027ec1c809fd69a046a5", "shasum": "" }, "require": { @@ -2929,7 +2972,7 @@ "stripe checkout", "stripe.js" ], - "time": "2016-03-01 19:16:57" + "time": "2016-03-04 20:04:43" }, { "name": "payum/payum-bundle", @@ -5806,7 +5849,9 @@ "packages-dev": [], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "paradigm/payum-paytrail": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/src/Acme/PaymentBundle/Controller/SimplePaytrailController.php b/src/Acme/PaymentBundle/Controller/SimplePaytrailController.php new file mode 100644 index 0000000..29e197e --- /dev/null +++ b/src/Acme/PaymentBundle/Controller/SimplePaytrailController.php @@ -0,0 +1,71 @@ +createPurchaseForm(); + $form->handleRequest($request); + if ($form->isValid()) { + $data = $form->getData(); + + $storage = $this->getPayum()->getStorage(PaymentDetails::class); + + $payment = $storage->create(); + $payment['orderNumber'] = '12345678'; + $payment['locale'] = 'fi_FI'; + $payment['price'] = (float) $data['amount']; + $payment['currency'] = $data['currency']; + + $storage->update($payment); + + $captureToken = $this->getPayum()->getTokenFactory()->createCaptureToken( + $gatewayName, + $payment, + 'acme_payment_details_view' + ); + + return $this->redirect($captureToken->getTargetUrl()); + } + + return ['form' => $form->createView()]; + } + + /** + * @return \Symfony\Component\Form\Form + */ + protected function createPurchaseForm() + { + return $this->createFormBuilder() + ->add('amount', null, array( + 'data' => 1.1, + 'constraints' => array(new Range(array('max' => 2))) + )) + ->add('currency', null, array('data' => 'EUR')) + + ->getForm() + ; + } + + /** + * @return Payum + */ + protected function getPayum() + { + return $this->get('payum'); + } +} diff --git a/src/Acme/PaymentBundle/Resources/views/Default/index.html.twig b/src/Acme/PaymentBundle/Resources/views/Default/index.html.twig index 79aee94..d378a42 100644 --- a/src/Acme/PaymentBundle/Resources/views/Default/index.html.twig +++ b/src/Acme/PaymentBundle/Resources/views/Default/index.html.twig @@ -106,6 +106,11 @@ Reserve&Activate Invoice +

Paytrail

+
  • + Prepare +
  • +

    Redsys\Sermepa

  • Simple purchase