Last active
August 29, 2015 14:14
-
-
Save jkanclerz/02cc0e2a446eead8746d to your computer and use it in GitHub Desktop.
Redirect to dotpay - Pay Action
This file contains hidden or 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
| $logger = $this->get('monolog.logger.dotpay'); | |
| $logger->info('================= NEW URLC NOTIFICATION ================='); | |
| $logger->info(var_export($request->request, true)); |
This file contains hidden or 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
| public function payAction() | |
| { | |
| //v-ie.uek.krakow.pl/~s153412/app_dev.php/payment/pay | |
| $data = [ | |
| 'id' =>'', | |
| 'kwota' => 160.49, | |
| 'waluta' => 'PLN', | |
| 'opis' => 'Zapłata za wypożyczenia', | |
| 'control' => 'DOK000045/01/2015', | |
| 'URLC' => 'http://myDomain.dev/app_dev.php/payment/handle', | |
| 'firstname' => 'myName', | |
| 'lastname' => 'mySurname', | |
| 'email' => '[email protected]' | |
| ]; | |
| $params = http_build_query($data); | |
| $url = sprintf( | |
| '%s?%s', | |
| 'https://ssl.dotpay.pl', | |
| $params | |
| ); | |
| return new RedirectResponse($url); | |
| } |
This file contains hidden or 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
| monolog: | |
| channels: ["dotpay"] | |
| handlers: | |
| dotpay: | |
| type: stream | |
| path: %kernel.root_dir%/logs/dotpay.log | |
| channels: ["dotpay"] |
This file contains hidden or 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
| <?php | |
| namespace Jkanclerz\DemoBundle\Payment; | |
| use Symfony\Component\HttpFoundation\Request; | |
| class PaymentHandler | |
| { | |
| const TRANSACTION_OK = 'OK'; | |
| const TRANSACTION_ERROR = 'ERROR'; | |
| const TRANSACTION_STATUS_OK = 2; | |
| protected $id; | |
| protected $pin; | |
| protected $orderRepository; | |
| protected $successHandler; | |
| public function __construct( | |
| $id, | |
| $pin, | |
| $orderRepository = null, | |
| $successHandler = null | |
| ) { | |
| $this->id = $id; | |
| $this->pin = $pin; | |
| } | |
| public function handleRequest($request) | |
| { | |
| $hash = $this->calculateHash($request); | |
| if ($this->isTransactionValid( | |
| $hash, | |
| $request->request->get('md5'), | |
| $request->request->get('controle'), | |
| $request->request->get('t_status') | |
| )) { | |
| // miejsce na wykonanie success handler; | |
| return self::TRANSACTION_OK; | |
| } else { | |
| return self::TRANSACTION_ERROR; | |
| } | |
| } | |
| protected function calculateHash($request) | |
| { | |
| $hash = sprintf( | |
| '%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s', | |
| $this->pin, | |
| $this->id, | |
| $request->request->get('control'), | |
| $request->request->get('t_id'), | |
| $request->request->get('amount'), | |
| $request->request->get('email'), | |
| $request->request->get('service'), | |
| $request->request->get('code'), | |
| $request->request->get('username'), | |
| $request->request->get('password'), | |
| $request->request->get('t_status') | |
| ); | |
| return md5($hash); | |
| } | |
| protected function isTransactionValid( | |
| $hash, | |
| $md5, | |
| $control, | |
| $status | |
| ) { | |
| if ($hash != $md5) { | |
| return false; | |
| } | |
| if ($status != self::TRANSACTION_STATUS_OK) { | |
| return false; | |
| } | |
| if (!$this->orderRepository->findOneBy([ | |
| 'number' => $control | |
| ] | |
| )) { | |
| return false; | |
| } | |
| return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment