Esempio n. 1
0
        $card_type = 'DINERS';
        break;
    case 'sol':
        $card_type = 'SOLO';
        break;
    case 'swi':
        $card_type = 'UK MAESTRO';
        break;
}
$_order_id = $order_info['repaid'] ? $order_id . '_' . $order_info['repaid'] : $order_id;
$expiry_date = $order_info['payment_info']['expiry_month'] . $order_info['payment_info']['expiry_year'];
$test = $processor_data['params']['test'] == '1' ? true : false;
$avs = $processor_data['params']['avs'] == '1' ? true : false;
$cvv = $order_info['payment_info']['cvv2'];
require_once 'worldnettps_files/worldnet_tps_xml.php';
$sale = new XmlAuthRequest($processor_data['params']['terminal_id'], $_order_id, $processor_data['params']['currency'], $order_info['total'], $order_info['email'] . " " . $_order_id, $order_info['email'], $order_info['payment_info']['card_number'], $card_type, $expiry_date, $order_info['payment_info']['cardholder_name']);
if ($cvv != "") {
    $sale->SetCvv($cvv);
}
if ($avs) {
    $address1 = $order_info['b_address'];
    $address2 = $order_info['b_city'] . $order_info['b_state'];
    $postcode = $order_info['b_zipcode'];
    $sale->SetAvs($address1, $address2, $postcode);
}
// Perform Auth
$response = $sale->ProcessRequest($processor_data['params']['shared_secret'], false, true);
// Verify response hash
$hash = md5($processor_data['params']['terminal_id'] . $_order_id . $order_info['total'] . $response->DateTime() . $response->ResponseCode() . $response->ResponseText() . $processor_data['params']['shared_secret']);
$pp_response = array();
if ($response->Hash() != $hash) {
 public function indexAction(Request $request)
 {
     $session = $request->getSession();
     $lan = $session->get('language');
     $request->setLocale($lan);
     if ($session->get('bookingId')) {
         $bookingid = $session->get('bookingId');
         $em = $this->container->get('doctrine')->getManager();
         $booking = $em->createQuery("SELECT d,IDENTITY(d.hostal) AS hostal FROM MytripAdminBundle:Booking d WHERE d.bookingId=" . $bookingid)->getArrayResult();
         $hostal_content = $em->createQuery("SELECT d FROM MytripAdminBundle:HostalContent d WHERE d.hostal=" . $booking[0]['hostal'] . " AND d.lan='" . $lan . "'")->getArrayResult();
         $bookingprice = $em->createQuery("SELECT p FROM MytripAdminBundle:BookingPrice p WHERE p.booking='" . $booking[0][0]['bookingId'] . "'")->getArrayResult();
         $bookinginfo = $em->createQuery("SELECT p FROM MytripAdminBundle:BookingInfo p WHERE p.booking='" . $booking[0][0]['bookingId'] . "'")->getArrayResult();
         if ($bookinginfo[0]['province'] != '') {
             $province = $em->createQuery("SELECT p FROM MytripAdminBundle:States p WHERE p.sid='" . $bookinginfo[0]['province'] . "'")->getArrayResult();
         }
         if ($bookinginfo[0]['country'] != '') {
             $country = $em->createQuery("SELECT p FROM MytripAdminBundle:Country p WHERE p.cid='" . $bookinginfo[0]['country'] . "'")->getArrayResult();
         }
         /** @var $paymentDetails PaymentDetails */
         if ($request->getMethod() == "POST") {
             $currency = strtolower($bookingprice[0]['conversionCurrency']);
             $ownername = urlencode($request->request->get('cardowner'));
             $cardnumber = urlencode(str_replace(" ", "", $request->request->get('cardnumber')));
             $cardtype = urlencode(str_replace(" ", "", $request->request->get('cardtype')));
             $exmonth = urlencode($request->request->get('exmonth'));
             $exyear = urlencode($request->request->get('exyear'));
             $cvv = urlencode($request->request->get('cvv'));
             $name = urlencode($bookinginfo[0]['firstname'] . " " . $bookinginfo[0]['lastname']);
             $email = urlencode($bookinginfo[0]['email']);
             $phone = urlencode($bookinginfo[0]['mobile']);
             $orderno = urlencode($booking[0][0]['bookingId'] * 1024);
             $amount = urlencode($bookingprice[0]['reservationTotalPrice'] * $bookingprice[0]['conversionRate']);
             $terminalid = $this->container->get('mytrip_admin.helper.globalone')->getOption('terminalid');
             $secret = $this->container->get('mytrip_admin.helper.globalone')->getOption('secret');
             $cardExpiry = $exmonth . substr($exyear, -2);
             $multicur = $this->container->get('mytrip_admin.helper.globalone')->getOption('multicurrency');
             $testAccount = $this->container->get('mytrip_admin.helper.globalone')->getOption('testaccount');
             $gateway = 'globalone';
             $auth = new \XmlAuthRequest($terminalid, $orderno, $bookingprice[0]['conversionCurrency'], $amount, $cardnumber, $cardtype);
             if ($cardtype != "SECURECARD") {
                 $auth->SetNonSecureCardCardInfo($cardExpiry, $ownername);
             }
             if ($cvv != "") {
                 $auth->SetCvv($cvv);
             }
             if ($multicur) {
                 $auth->SetMultiCur();
             }
             $response = $auth->ProcessRequestToGateway($secret, $testAccount, $gateway);
             $expectedResponseHash = md5($terminalid . $response->UniqueRef() . ($multicur == true ? $currency : '') . $amount . $response->DateTime() . $response->ResponseCode() . $response->ResponseText() . $secret);
             if ($response->IsError()) {
                 $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('Sorry, Payment failed try once again'));
                 return $this->redirect($this->generateUrl('mytrip_user_makepayment', array('bookingId' => $booking[0][0]['bookingId'] * 1024)));
             } elseif ($expectedResponseHash == $response->Hash()) {
                 switch ($response->ResponseCode()) {
                     case "A":
                         # -- If using local database, update order as Authorised.
                         //echo 'Payment Processed successfully. Thanks you for your order.';
                         $uniqueRef = $response->UniqueRef();
                         $responseText = $response->ResponseText();
                         $approvalCode = $response->ApprovalCode();
                         $avsResponse = $response->AvsResponse();
                         $cvvResponse = $response->CvvResponse();
                         $booking_transaction = new \Mytrip\AdminBundle\Entity\BookingTransaction();
                         $booking_transaction->setBooking($this->getDoctrine()->getRepository('MytripAdminBundle:Booking')->find($bookingid));
                         $booking_transaction->setPaymentType('Globalone');
                         $booking_transaction->setTransactionId($uniqueRef);
                         $booking_transaction->setTransactionDate(date('Y-m-d H:i:s'));
                         $booking_transaction->setTransactionAmount($amount);
                         $booking_transaction->setTransactionCurrency($bookingprice[0]['conversionCurrency']);
                         if (empty($btransaction)) {
                             $em->persist($booking_transaction);
                         }
                         $em->flush();
                         $em->createQuery("UPDATE MytripAdminBundle:Booking p SET p.status='Confirmed' WHERE p.bookingId='" . $bookingid . "'")->execute();
                         $booking = $em->createQuery("SELECT d,IDENTITY(d.hostal) AS hostal FROM MytripAdminBundle:Booking d WHERE d.bookingId=" . $bookingid)->getArrayResult();
                         $booking_info = $em->createQuery("SELECT d FROM MytripAdminBundle:BookingInfo d WHERE d.booking=" . $bookingid)->getArrayResult();
                         /*******Contact mail send to admin***********/
                         $this->mailsend("Mytrip Cuba", "*****@*****.**", $booking_info[0]['email'], $this->get('translator')->trans('Booking Details'), '', '', 0, '', 'ticket');
                         $login = $this->container->get('mytrip_admin.helper.sms')->getOption('smsusername');
                         $password = $this->container->get('mytrip_admin.helper.sms')->getOption('smspassword');
                         $prefix = $booking_info[0]['cmcode'];
                         $number = $booking_info[0]['mobile'];
                         $msg = urlencode($this->get('translator')->trans('Dear Customer, You are successfully booked the hotel rooms in our site. Your reference no is') . ' ' . "venacuba-" . $bookingid * 1024);
                         $URL = "http://api.smsacuba.com/api10allcountries.php?";
                         $URL .= "login="******"&password="******"&prefix=" . $prefix . "&number=" . $number . "&sender=Mytriptocuba" . "&msg=" . $msg;
                         $r = @file($URL);
                         $succmsg = $r[0];
                         if ($succmsg == "SMS ENVIADO") {
                             $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('Rooms booking successfull. Booking details sent to your mail id and SMS.'));
                         } else {
                             $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('Rooms booking successfull. Booking details sent to your mail id.'));
                         }
                         $hostal_query = $em->createQuery("SELECT h FROM MytripAdminBundle:Hostal h WHERE h.status='Active' AND h.hostalId='" . $booking[0]['hostal'] . "'");
                         $hostals = $hostal_query->getArrayResult();
                         if (empty($hostals)) {
                             return $this->redirect($this->generateUrl('mytrip_user_destination'));
                         }
                         $hostal_content_query = $em->createQuery("SELECT d FROM MytripAdminBundle:HostalContent d WHERE d.lan='{$lan}' AND d.hostal=" . $hostals[0]['hostalId']);
                         $hostal_content = $hostal_content_query->getArrayResult();
                         if (empty($hostal_content)) {
                             $hostal_content_query = $em->createQuery("SELECT d FROM MytripAdminBundle:HostalContent d WHERE d.lan='en' AND d.hostal=" . $hostals[0]['hostalId']);
                             $hostal_content = $hostal_content_query->getArrayResult();
                         }
                         /*
                                                         if($hostal_content[0]['province']!=''){
                                                             $province=$em->createQuery("SELECT d FROM MytripAdminBundle:States d WHERE d.sid=".$hostal_content[0]['province'])->getArrayResult();
                                                         }
                                                         if($hostal_content[0]['country']!=''){
                                                             $country=$em->createQuery("SELECT d FROM MytripAdminBundle:Country d WHERE d.cid=".$hostal_content[0]['country'])->getArrayResult();
                                                         } */
                         $address = $hostal_content[0]['address'] . ', ' . $hostal_content[0]['city'] . ', ' . ($hostal_content[0]['province'] != '' ? $province[0]['state'] . ', ' : '') . ($hostal_content[0]['country'] != '' ? $country[0]['country'] : '');
                         // booking rooms data.
                         $rooms_data = '| ';
                         foreach ($booking[0][0]['rooms'] as $room) {
                             $rooms_data .= $room['roomtype'] . ' | ';
                         }
                         //$hostal_rooms = $em->createQuery("SELECT d FROM MytripAdminBundle:HostalRooms d WHERE d.hostal=".$hostals[0]['hostalId'])->getArrayResult();
                         $bookingprice = $em->createQuery("SELECT d FROM MytripAdminBundle:BookingPrice d WHERE d.booking=" . $bookingid)->getArrayResult();
                         $booking_transaction = $em->createQuery("SELECT d FROM MytripAdminBundle:BookingTransaction d WHERE d.booking=" . $bookingid)->getArrayResult();
                         $buser = $session->get('user');
                         $uid = $buser['userId'];
                         /**Booking send to the hostal owner email id***/
                         $setting = $em->createQuery("SELECT p FROM MytripAdminBundle:Settings p")->getArrayResult();
                         $busers = $em->createQuery("SELECT p FROM MytripAdminBundle:User p  WHERE  p.userId='" . $uid . "'")->getArrayResult();
                         //if($busers[0]['province']!=''){
                         //	$province=$em->createQuery("SELECT d FROM MytripAdminBundle:States d WHERE d.sid=".$busers[0]['province'])->getArrayResult();
                         //}
                         //if($busers[0]['country']!=''){
                         //	$country=$em->createQuery("SELECT d FROM MytripAdminBundle:Country d WHERE d.cid=".$busers[0]['country'])->getArrayResult();
                         //}
                         $user_name = $busers[0]['firstname'] . ' ' . $busers[0]['lastname'];
                         //$address=$busers[0]['address'].', '.$busers[0]['city'].', '.($busers[0]['province']!=''?$province[0]['state'].', ':'').($busers[0]['country']!=''?$country[0]['country']:'');
                         $emaillist = $em->getRepository('MytripAdminBundle:EmailList')->findOneBy(array('emailListId' => '10'));
                         $emailcontent = $em->getRepository('MytripAdminBundle:EmailContent')->findOneBy(array('emailList' => '10', 'lan' => $lan));
                         if (empty($emailcontent)) {
                             $emailcontent = $em->getRepository('MytripAdminBundle:EmailContent')->findOneBy(array('emailList' => '10', 'lan' => 'en'));
                         }
                         $from_date = $booking[0][0]['fromDate'];
                         $to_date = $booking[0][0]['toDate'];
                         if ($hostals[0]['ownerEmail'] != '') {
                             $message = str_replace(array('{owner_name}', '{hostal_name}', '{check_in}', '{check_out}', '{rooms}', '{nights}', '{username}', '{address}', '{accommodation_cost}', '{reservation_charge}', '{total_cost}', '{ref_no}', '{paid_amount}', '{balance_amount}'), array($hostal_content[0]['ownerName'], $hostal_content[0]['name'], $from_date->format('Y-m-d H:i:s'), $to_date->format('Y-m-d H:i:s'), $rooms_data, $booking[0][0]['noOfDays'], $user_name, $address, number_format($bookingprice[0]['totalPrice'] * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency'], number_format($bookingprice[0]['reservationCharge'] * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency'], number_format(($bookingprice[0]['totalPrice'] + $bookingprice[0]['reservationCharge']) * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency'], "venacuba-" . $bookingid * 1024, number_format($bookingprice[0]['reservationTotalPrice'] * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency'], number_format(($bookingprice[0]['totalPrice'] + $bookingprice[0]['reservationCharge'] - $bookingprice[0]['reservationTotalPrice']) * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency']), $emailcontent->getEmailContent());
                             $subject = str_replace(array('{owner_name}', '{hostal_name}', '{check_in}', '{check_out}', '{rooms}', '{nights}', '{username}', '{address}', '{accommodation_cost}', '{reservation_charge}', '{total_cost}', '{ref_no}', '{paid_amount}', '{balance_amount}'), array($hostal_content[0]['ownerName'], $hostal_content[0]['name'], $from_date->format('Y-m-d H:i:s'), $to_date->format('Y-m-d H:i:s'), $rooms_data, $booking[0][0]['noOfDays'], $user_name, $address, number_format($bookingprice[0]['totalPrice'] * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency'], number_format($bookingprice[0]['reservationCharge'] * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency'], number_format(($bookingprice[0]['totalPrice'] + $bookingprice[0]['reservationCharge']) * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency'], "venacuba-" . $bookingid * 1024, number_format($bookingprice[0]['reservationTotalPrice'] * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency'], number_format(($bookingprice[0]['totalPrice'] + $bookingprice[0]['reservationCharge'] - $bookingprice[0]['reservationTotalPrice']) * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency']), $emailcontent->getSubject());
                             $this->mailsend($emaillist->getFromname(), $emaillist->getFromemail(), $hostals[0]['ownerEmail'], $subject, $message, '', 0, '', 'email');
                         }
                         if ($hostals[0]['cmcode'] != '' && $hostals[0]['mobile'] != '') {
                             /**Booking send to the hostal owner mobile***/
                             $prefix = $hostals[0]['cmcode'];
                             $number = $hostals[0]['mobile'];
                             $msg = urlencode($this->get('translator')->trans('Dear ' . $hostal_content[0]['ownerName'] . ', ' . $user_name . ' has booked room in the ' . $hostal_content[0]['name'] . '. Reference no is') . ' ' . "venacuba-" . $bookingid * 1024);
                             $URL = "http://api.smsacuba.com/api10allcountries.php?";
                             $URL .= "login="******"&password="******"&prefix=" . $prefix . "&number=" . $number . "&sender=Mytriptocuba" . "&msg=" . $msg;
                             $r = @file($URL);
                             $succmsg = $r[0];
                         }
                         /**Booking send to the Site Admin email id***/
                         $emaillist = $em->getRepository('MytripAdminBundle:EmailList')->findOneBy(array('emailListId' => '11'));
                         $emailcontent = $em->getRepository('MytripAdminBundle:EmailContent')->findOneBy(array('emailList' => '11', 'lan' => $lan));
                         if (empty($emailcontent)) {
                             $emailcontent = $em->getRepository('MytripAdminBundle:EmailContent')->findOneBy(array('emailList' => '11', 'lan' => 'en'));
                         }
                         $admin = $em->createQuery("SELECT p FROM MytripAdminBundle:Admin p WHERE p.adminId='1'")->getArrayResult();
                         $message = str_replace(array('{admin_name}', '{owner_name}', '{hostal_name}', '{check_in}', '{check_out}', '{rooms}', '{nights}', '{username}', '{address}', '{accommodation_cost}', '{reservation_charge}', '{total_cost}', '{ref_no}', '{paid_amount}', '{balance_amount}'), array($admin[0]['name'], $hostal_content[0]['ownerName'], $hostal_content[0]['name'], $from_date->format('Y-m-d H:i:s'), $to_date->format('Y-m-d H:i:s'), $rooms_data, $booking[0][0]['noOfDays'], $user_name, $address, number_format($bookingprice[0]['totalPrice'] * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency'], number_format($bookingprice[0]['reservationCharge'] * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency'], number_format(($bookingprice[0]['totalPrice'] + $bookingprice[0]['reservationCharge']) * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency'], "venacuba-" . $bookingid * 1024, number_format($bookingprice[0]['reservationTotalPrice'] * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency'], number_format(($bookingprice[0]['totalPrice'] + $bookingprice[0]['reservationCharge'] - $bookingprice[0]['reservationTotalPrice']) * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency']), $emailcontent->getEmailContent());
                         $subject = str_replace(array('{admin_name}', '{owner_name}', '{hostal_name}', '{check_in}', '{check_out}', '{rooms}', '{nights}', '{username}', '{address}', '{accommodation_cost}', '{reservation_charge}', '{total_cost}', '{ref_no}', '{paid_amount}', '{balance_amount}'), array($admin[0]['name'], $hostal_content[0]['ownerName'], $hostal_content[0]['name'], $from_date->format('Y-m-d H:i:s'), $to_date->format('Y-m-d H:i:s'), $rooms_data, $booking[0][0]['noOfDays'], $user_name, $address, number_format($bookingprice[0]['totalPrice'] * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency'], number_format($bookingprice[0]['reservationCharge'] * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency'], number_format(($bookingprice[0]['totalPrice'] + $bookingprice[0]['reservationCharge']) * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency'], "venacuba-" . $bookingid * 1024, number_format($bookingprice[0]['reservationTotalPrice'] * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency'], number_format(($bookingprice[0]['totalPrice'] + $bookingprice[0]['reservationCharge'] - $bookingprice[0]['reservationTotalPrice']) * $bookingprice[0]['conversionRate'], 2) . ' ' . $bookingprice[0]['conversionCurrency']), $emailcontent->getSubject());
                         $this->mailsend($emaillist->getFromname(), $emaillist->getFromemail(), $admin[0]['email'], $subject, $message, '', 0, '', 'email');
                         if ($admin[0]['cmcode'] != '' && $admin[0]['mobile'] != '') {
                             /**Booking send to the site admin mobile***/
                             $prefix = $admin[0]['cmcode'];
                             $number = $admin[0]['mobile'];
                             $msg = urlencode($this->get('translator')->trans('Dear ' . $admin[0]['name'] . ', ' . $user_name . ' has booked room in the ' . $hostal_content[0]['name'] . '. Reference no is') . ' ' . "venacuba-" . $bookingid * 1024);
                             $URL = "http://api.smsacuba.com/api10allcountries.php?";
                             $URL .= "login="******"&password="******"&prefix=" . $prefix . "&number=" . $number . "&sender=Mytriptocuba" . "&msg=" . $msg;
                             $r = @file($URL);
                             $succmsg = $r[0];
                         }
                         $session->remove('payment');
                         $session->remove('bookingId');
                         //$this->get('session')->getFlashBag()->add('success',$this->get('translator')->trans('Rooms booking successfully. Booking details send to your mail id.'));
                         return $this->redirect($this->generateUrl('mytrip_user_bookinghistory'));
                         break;
                     case "R":
                     case "D":
                     case "C":
                     case "S":
                     default:
                         # -- If using local database, update order as declined/failed --
                         $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('Sorry, Payment failed try once again'));
                         return $this->redirect($this->generateUrl('mytrip_user_makepayment', array('bookingId' => $booking[0][0]['bookingId'] * 1024)));
                 }
             } else {
                 $this->get('session')->getFlashBag()->add('success', $this->get('translator')->trans('Sorry, Payment failed try once again'));
                 return $this->redirect($this->generateUrl('mytrip_user_makepayment', array('bookingId' => $booking[0][0]['bookingId'] * 1024)));
             }
         } else {
             return $this->redirect($this->generateUrl('mytrip_user_homepage'));
         }
     } else {
         return $this->redirect($this->generateUrl('mytrip_user_homepage'));
     }
 }