Last active
October 30, 2015 08:33
-
-
Save jerronimo/e28ebbf03b65bd554e61 to your computer and use it in GitHub Desktop.
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 Mlm\PaymentBundle\Controller; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | |
use Symfony\Component\HttpFoundation\Request; | |
use Mlm\PaymentBundle\Entity\Order; | |
use Symfony\Component\HttpFoundation\JsonResponse; | |
class PaymentController extends Controller | |
{ | |
/** | |
* @param Request $request | |
*@return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response | |
* @Route("/payment/status", name="payment_status") | |
*/ | |
public function paymentStatusAction(Request $request) | |
{ | |
$post = $request->request->all(); | |
$shopId = $this->container->getParameter('interkassa_id'); | |
$testKey = $this->container->getParameter('interkassa_secret_test_key'); | |
$secretKey = $this->container->getParameter('interkassa_secret_key'); | |
if ($post['ik_co_id'] != $shopId ) { | |
return false; | |
} | |
$ik_key = ($post['ik_pw_via'] == 'test_interkassa_test_xts') ? $testKey : $secretKey; | |
$data = array(); | |
foreach ($post as $key => $value) | |
{ | |
if (!preg_match('/ik_/', $key)) | |
continue; | |
$data[$key] = $value; | |
} | |
$ik_sign = $data['ik_sign']; | |
unset($data['ik_sign']); | |
ksort($data, SORT_STRING); | |
array_push($data, $ik_key); | |
$signString = implode(':', $data); | |
$sign = base64_encode(md5($signString, true)); | |
$order = $this->getEM()->getRepository('MlmPaymentBundle:Order')->findBy(['billNumber' => $post['ik_pm_no']])[0]; | |
if ($sign === $ik_sign && $data['ik_inv_st'] == 'success') { | |
$order->setStatus(Order::ORDER_STATUS_PAID); | |
$this->getEM()->persist($order); | |
$this->getEM()->flush(); | |
return new JsonResponse(true); | |
} else { | |
$order->setStatus(Order::ORDER_STATUS_CANCELLED); | |
$this->getEM()->persist($order); | |
$this->getEM()->flush(); | |
return new JsonResponse(false); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment