-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implements banca sella gestpay payment method
- Loading branch information
Showing
35 changed files
with
2,473 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ bin | |
composer.phar | ||
composer.lock | ||
phpunit.xml | ||
**/Tests/app/cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
99
src/PaymentSuite/GestpayBundle/Controller/PaymentController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
145
src/PaymentSuite/GestpayBundle/Controller/ResponseController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.