Skip to content

Commit

Permalink
Feature/gestpay (#72)
Browse files Browse the repository at this point in the history
implements banca sella gestpay payment method
  • Loading branch information
sangarbe committed Nov 6, 2018
1 parent 8fd1545 commit 4d141c7
Show file tree
Hide file tree
Showing 35 changed files with 2,473 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ bin
composer.phar
composer.lock
phpunit.xml
**/Tests/app/cache/
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
"twig/twig": "^1.23.1",
"stripe/stripe-php": "3.4.0",
"monolog/monolog": "^1.17",
"wearemarketing/paylands-php": "0.1.*"
"wearemarketing/paylands-php": "0.1.*",
"endelwar/gestpayws": "^1.4"
},
"require-dev": {
"elcodi/test-common-bundle": "^2.0",
"mmoreram/php-formatter": "1.1.0",
"friendsofphp/php-cs-fixer": "^2.0",
"phpunit/phpunit": "^7.0"
"phpunit/phpunit": "^7.0",
"symfony/phpunit-bridge": "^3.4"
},
"replace": {
"paymentsuite/bankwire-bundle": "self.version",
Expand All @@ -49,7 +51,8 @@
"paymentsuite/paypal-web-checkout-bundle": "self.version",
"paymentsuite/redsys-bundle": "self.version",
"paymentsuite/stripe-bundle": "self.version",
"paymentsuite/paylands-bundle": "self.version"
"paymentsuite/paylands-bundle": "self.version",
"paymentsuite/gestpay-bundle": "self.version"
},
"autoload": {
"psr-4": {
Expand Down
16 changes: 15 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
Expand All @@ -29,8 +28,23 @@
</filter>

<php>
<env name="GESTPAY_SHOP_LOGIN" value="GESPAYXXXX"/>
<env name="GESTPAY_API_KEY" value="api-key"/>
<env name="STRIPE_API_KEY" value="api-key"/>
<env name="ENABLE_API_INTEGRATION" value="false"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak" />
</php>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
<arguments>
<array>
<element key="time-sensitive">
<string>PaymentSuite\GestpayBundle\Services\Tests</string>
</element>
</array>
</arguments>
</listener>
</listeners>

</phpunit>
10 changes: 10 additions & 0 deletions src/PaymentSuite/GestpayBundle/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
; top-most EditorConfig file
root = true

; Unix-style newlines
[*]
end_of_line = LF

[*.php]
indent_style = space
indent_size = 4
9 changes: 9 additions & 0 deletions src/PaymentSuite/GestpayBundle/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Symfony directories
vendor/

# Composer
composer.phar
composer.lock

# PHPUnit
phpunit.xml
22 changes: 22 additions & 0 deletions src/PaymentSuite/GestpayBundle/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
language: php

sudo: false

php:
- 5.4
- 5.5
- 5.6
- hhvm
- 7.0

matrix:
fast_finish: true

before_script:
- composer update --no-interaction

script:
- phpunit

notifications:
email: false
99 changes: 99 additions & 0 deletions src/PaymentSuite/GestpayBundle/Controller/PaymentController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

/*
* This file is part of the PaymentSuite package.
*
* Copyright (c) 2013-2016 Marc Morera
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <yuhu@mmoreram.com>
*/

namespace PaymentSuite\GestpayBundle\Controller;

use PaymentSuite\GestpayBundle\GestpayMethod;
use PaymentSuite\PaymentCoreBundle\Exception\PaymentException;
use PaymentSuite\PaymentCoreBundle\Services\PaymentLogger;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use PaymentSuite\GestpayBundle\Services\GestpayManager;
use PaymentSuite\PaymentCoreBundle\Exception\PaymentOrderNotFoundException;
use Symfony\Component\HttpFoundation\Request;
use PaymentSuite\GestpayBundle\Exception\CurrencyNotSupportedException;
use Symfony\Component\HttpFoundation\Response;

/**
* PaymentController.
*
* @author WAM Team <develop@wearemarketing.com>
*/
class PaymentController extends Controller
{
/**
* @var GestpayManager
*/
private $gestpayManager;
/**
* @var PaymentLogger
*/
private $logger;

/**
* Construct.
*
* @param GestpayManager $gestpayManager Payment manager
*/
public function __construct(
GestpayManager $gestpayManager,
PaymentLogger $logger
) {
$this->gestpayManager = $gestpayManager;
$this->logger = $logger;
}

/**
* @return RedirectResponse
*
* @throws PaymentOrderNotFoundException
* @throws CurrencyNotSupportedException
*/
public function executeAction()
{
/*
* The execute action will redirect to gestpay gateway.
*/
$gestpayUrl = $this
->gestpayManager
->processPayment();

return new RedirectResponse($gestpayUrl);
}

/**
* @param Request $request
*
* @return Response
*/
public function resultAction(Request $request)
{
try {
$this
->gestpayManager
->processResult($request->query->all());
} catch (PaymentException $e) {
$this
->logger
->log(
'error',
'Gestpay error "'.$e->getMessage(),
GestpayMethod::METHOD_NAME
);
}

return new Response('OK');
}
}
145 changes: 145 additions & 0 deletions src/PaymentSuite/GestpayBundle/Controller/ResponseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?php

/*
* This file is part of the PaymentSuite package.
*
* Copyright (c) 2013-2016 Marc Morera
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Feel free to edit as you please, and have fun.
*
* @author Marc Morera <yuhu@mmoreram.com>
*/

namespace PaymentSuite\GestpayBundle\Controller;

use PaymentSuite\GestpayBundle\Services\GestpayEncrypter;
use PaymentSuite\GestpayBundle\Services\GestpayOrderIdAssembler;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use PaymentSuite\PaymentCoreBundle\ValueObject\RedirectionRouteCollection;

/**
* Class ResponseController.
*
* @author WAM Team <develop@wearemarketing.com>
*/
class ResponseController
{
/**
* @var RedirectionRouteCollection
*
* Redirection routes
*/
private $redirectionRoutes;

/**
* @var UrlGeneratorInterface
*
* Url generator
*/
private $urlGenerator;

/**
* @var GestpayEncrypter
*/
private $gestpayEncrypter;

/**
* ResponseController constructor.
*
* @param RedirectionRouteCollection $redirectionRoutes
* @param UrlGeneratorInterface $urlGenerator
* @param GestpayEncrypter $gestpayEncrypter
*/
public function __construct(
RedirectionRouteCollection $redirectionRoutes,
UrlGeneratorInterface $urlGenerator,
GestpayEncrypter $gestpayEncrypter
) {
$this->redirectionRoutes = $redirectionRoutes;
$this->urlGenerator = $urlGenerator;
$this->gestpayEncrypter = $gestpayEncrypter;
}

/**
* Payment success action.
*
* @param Request $request Request element
*
* @return Response
*/
public function successAction(Request $request)
{
$orderId = $this->getOrderId($request);

$successRoute = $this
->redirectionRoutes
->getRedirectionRoute('success');

$redirectUrl = $this
->urlGenerator
->generate(
$successRoute->getRoute(),
$successRoute->getRouteAttributes(
$orderId
)
);

return new RedirectResponse($redirectUrl);
}

/**
* Payment fail action.
*
* @param Request $request Request element
*
* @return Response
*/
public function failureAction(Request $request)
{
$orderId = $this->getOrderId($request);

$failureRoute = $this
->redirectionRoutes
->getRedirectionRoute('failure');

$redirectUrl = $this
->urlGenerator
->generate(
$failureRoute->getRoute(),
$failureRoute->getRouteAttributes(
$orderId
)
);

return new RedirectResponse($redirectUrl);
}

/**
* @param Request $request
*
* @return bool|int
*/
protected function getOrderId(Request $request)
{
$encrypted = $request
->query
->get('b');

try {
$decrypted = $this
->gestpayEncrypter
->decrypt($encrypted);
$orderId = GestpayOrderIdAssembler::extract($decrypted['ShopTransactionID']);
} catch (\Exception $e) {
$orderId = false;
}

return $orderId;
}
}
Loading

0 comments on commit 4d141c7

Please sign in to comment.