Skip to content

Instantly share code, notes, and snippets.

@jkanclerz
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save jkanclerz/02cc0e2a446eead8746d to your computer and use it in GitHub Desktop.

Select an option

Save jkanclerz/02cc0e2a446eead8746d to your computer and use it in GitHub Desktop.
Redirect to dotpay - Pay Action
$logger = $this->get('monolog.logger.dotpay');
$logger->info('================= NEW URLC NOTIFICATION =================');
$logger->info(var_export($request->request, true));
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);
}
monolog:
channels: ["dotpay"]
handlers:
dotpay:
type: stream
path: %kernel.root_dir%/logs/dotpay.log
channels: ["dotpay"]
<?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