Example #1
0
 public function cronAction()
 {
     $request = $this->getRequest();
     // Make sure that we are running in a console and the user has not tricked our
     // application into running this action from a public web server.
     if (!$request instanceof ConsoleRequest) {
         throw new \RuntimeException('You can only use this action from a console! Got this request from ' . get_class($request));
     }
     // Get system service name  from console and check if the user used --verbose or -v flag
     #$doname   = $request->getParam('doname', false);
     #$verbose     = $request->getParam('verbose');
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $orderStatus = $em->getRepository("ErsBase\\Entity\\OrderStatus")->findBy(array('value' => 'cron'));
     foreach ($orderStatus as $status) {
         $em->remove($status);
     }
     $em->flush();
     $orders = $em->getRepository("ErsBase\\Entity\\Order")->findBy(array(), array('created' => 'DESC'));
     $logger = $this->getServiceLocator()->get('Logger');
     $logger->info('We are in runCron of TestCron');
     $output = '';
     foreach ($orders as $order) {
         if ($order->hasOrderStatus('cron')) {
             continue;
         }
         $output .= $order->getCode()->getValue() . PHP_EOL;
         $orderStatus = new Entity\OrderStatus();
         $orderStatus->setValue('cron');
         $orderStatus->setOrder($order);
         $em->persist($orderStatus);
         $em->flush();
     }
     $output .= 'ready!';
     /*
      * ensure a newline at the end of output.
      */
     $output .= PHP_EOL;
     return $output;
 }
Example #2
0
 public function ccCheckAction()
 {
     $response = $this->getResponse();
     $response->setStatusCode(200);
     $response->setContent("Thank you");
     $config = $this->getServiceLocator()->get('Config');
     $sec_key = $config['ERS\\iPayment']['sec_key'];
     $allowed_ips = array('212.227.34.218', '212.227.34.219', '212.227.34.220');
     $logger = $this->getServiceLocator()->get('Logger');
     $request = new \Zend\Http\PhpEnvironment\Request();
     $ipmatch = false;
     if (in_array($request->getServer('REMOTE_ADDR'), $allowed_ips)) {
         $ipmatch = true;
     } else {
         $logger->info('unauthorized hidden trigger from: ' . $request->getServer('REMOTE_ADDR'));
         return $response;
     }
     $post_param = $this->params()->fromPost();
     $logger->info('$_POST:');
     $logger->info($post_param);
     $return_checksum = array();
     if (isset($post_param["trxuser_id"])) {
         $return_checksum[] = $post_param["trxuser_id"];
     }
     if (isset($post_param["trx_amount"])) {
         $return_checksum[] = $post_param["trx_amount"];
     }
     if (isset($post_param["trx_currency"])) {
         $return_checksum[] = $post_param["trx_currency"];
     }
     if (isset($post_param["ret_authcode"])) {
         $return_checksum[] = $post_param["ret_authcode"];
     }
     if (isset($post_param["ret_trx_number"])) {
         $return_checksum[] = $post_param["ret_trx_number"];
     }
     $return_checksum[] = $sec_key;
     $logger->info($return_checksum);
     $logger->info('ret_param: ' . $post_param["ret_param_checksum"]);
     $logger->info('hash     : ' . md5(implode($return_checksum)));
     if ($post_param["ret_param_checksum"] != md5(implode($return_checksum))) {
         // Error because hash do not match!
         $logger->emerg('Unable to finish payment, checksums do not match.');
         return $response;
         #exit;
     }
     $hashkey = $this->params()->fromRoute('hashkey', '');
     if ($hashkey == '') {
         $logger->warn('no hashkey given in route');
         return $response;
     }
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $order = $em->getRepository("ErsBase\\Entity\\Order")->findOneBy(array('hashkey' => $hashkey));
     if ($order == null) {
         $logger->warn('unable to find order with hashkey: ' . $hashkey);
         return $response;
     }
     $order->setPaymentStatus('paid');
     foreach ($order->getItems() as $item) {
         $item->setStatus('paid');
         $em->persist($item);
     }
     $orderStatus = new Entity\OrderStatus();
     $orderStatus->setOrder($order);
     $orderStatus->setValue('paid');
     $order->addOrderStatus($orderStatus);
     $em->persist($order);
     $em->persist($orderStatus);
     $em->flush();
     return $response;
 }