Exemplo n.º 1
0
 /**
  * Store a newly created booking in storage.
  * This includes Clients, FlightDetails
  *
  * @return Response
  */
 public function store()
 {
     if (Auth::check()) {
         $user = Auth::user();
         if (Entrust::hasRole('Agent')) {
             $rules = Booking::$agentRules;
         }
     } else {
         $rules = Booking::$guestRules;
     }
     $data = Input::all();
     if (Auth::check()) {
         $data['user_id'] = Auth::id();
     }
     $validator = Validator::make($data, $rules);
     if ($validator->fails()) {
         //dd($validator->errors());
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $data['val'] = 1;
     if ($x = Booking::find(Booking::max('id'))) {
         $data['reference_number'] = ++$x->reference_number;
     } else {
         $data['reference_number'] = 10000000;
     }
     Session::put('MyBookingData', $data);
     $clients = null;
     $newBooking = $this->storeAllData();
     $booking_name = $newBooking->booking_name;
     $booking_amount = Booking::getTotalBookingAmount($newBooking);
     $data = array('details' => $booking_name, 'ip_address' => $_SERVER['REMOTE_ADDR'], 'amount' => $booking_amount, 'payment_status' => 0, 'my_booking' => 2);
     $reserv_id = Payment::create($data);
     $data_tab_HSBC_payment = array('currency' => 'USD');
     $tab_HSBC_payment_id = HsbcPayment::create($data_tab_HSBC_payment);
     $stamp = strtotime("now");
     $payment_id = Payment::orderBy('created_at', 'desc')->first()->id;
     $orderid = "{$stamp}" . 'A' . "{$payment_id}";
     $last_res_resid = str_replace(".", "", $orderid);
     $hsbc_id = HsbcPayment::orderBy('created_at', 'desc')->first()->id;
     $hsbc_payment_id_pre = "{$stamp}" . 'HSBC' . "{$hsbc_id}";
     $hsbc_payment_id = str_replace(".", "", $hsbc_payment_id_pre);
     if ($last_res_resid) {
         $payment = DB::table('payments')->where('id', $payment_id)->update(array('reference_number' => $last_res_resid, 'HSBC_payment_id' => $hsbc_payment_id));
         $data_tab_HSBC_payment = DB::table('hsbc_payments')->where('id', $hsbc_id)->update(array('HSBC_payment_id' => $hsbc_payment_id));
     }
     $currency = 'USD';
     //$x = Booking::getTotalBookingAmount($newBooking) * 100 * 1.037;
     // $x = 2 * 100 * 1.037;
     //$total_price_all_hsbc = round($x, 2);
     $total_price_all_hsbc = $booking_amount * 100;
     dd($total_price_all_hsbc);
     //        dd($hsbc_payment_id . '/' . $currency . '/' . $total_price_all_hsbc . '/' . $last_res_resid);
     HsbcPayment::goto_hsbc_gateway($hsbc_payment_id, $currency, $total_price_all_hsbc, $last_res_resid);
 }
 public function paymentGet()
 {
     if (isset($_GET)) {
         $amount = HsbcPayment::null2unknown($_GET["vpc_Amount"]);
         $locale = HsbcPayment::null2unknown($_GET["vpc_Locale"]);
         $batchNo = HsbcPayment::null2unknown($_GET["vpc_BatchNo"]);
         $command = HsbcPayment::null2unknown($_GET["vpc_Command"]);
         $message = HsbcPayment::null2unknown($_GET["vpc_Message"]);
         $version = HsbcPayment::null2unknown($_GET["vpc_Version"]);
         $cardType = HsbcPayment::null2unknown($_GET["vpc_Card"]);
         $orderInfo = HsbcPayment::null2unknown($_GET["vpc_OrderInfo"]);
         $receiptNo = HsbcPayment::null2unknown($_GET["vpc_ReceiptNo"]);
         $merchantID = HsbcPayment::null2unknown($_GET["vpc_Merchant"]);
         $authorizeID = HsbcPayment::null2unknown($_GET["vpc_AuthorizeId"]);
         $merchTxnRef = HsbcPayment::null2unknown($_GET["vpc_MerchTxnRef"]);
         $transactionNo = HsbcPayment::null2unknown($_GET["vpc_TransactionNo"]);
         $acqResponseCode = HsbcPayment::null2unknown($_GET["vpc_AcqResponseCode"]);
         $txnResponseCode = HsbcPayment::null2unknown($_GET["vpc_TxnResponseCode"]);
         $verType = array_key_exists("vpc_VerType", $_GET) ? $_GET["vpc_VerType"] : "No Value Returned";
         $verStatus = array_key_exists("vpc_VerStatus", $_GET) ? $_GET["vpc_VerStatus"] : "No Value Returned";
         $token = array_key_exists("vpc_VerToken", $_GET) ? $_GET["vpc_VerToken"] : "No Value Returned";
         $verSecurLevel = array_key_exists("vpc_VerSecurityLevel", $_GET) ? $_GET["vpc_VerSecurityLevel"] : "No Value Returned";
         $enrolled = array_key_exists("vpc_3DSenrolled", $_GET) ? $_GET["vpc_3DSenrolled"] : "No Value Returned";
         $xid = array_key_exists("vpc_3DSXID", $_GET) ? $_GET["vpc_3DSXID"] : "No Value Returned";
         $acqECI = array_key_exists("vpc_3DSECI", $_GET) ? $_GET["vpc_3DSECI"] : "No Value Returned";
         $authStatus = array_key_exists("vpc_3DSstatus", $_GET) ? $_GET["vpc_3DSstatus"] : "No Value Returned";
         $payment_info = HsbcPayment::where('HSBC_payment_id', $merchTxnRef);
         if ($payment_info) {
             $qsi_res_code = HsbcPayment::getResponseDescription($txnResponseCode);
             $pay = array();
             $pay = array('paid_amount' => $amount / 100, 'vpc_txn_res_code' => $txnResponseCode, 'qsi_res_code' => $qsi_res_code, 'vpc_message' => $message, 'vpc_receipt_number' => $receiptNo, 'vpc_txn_no' => $transactionNo, 'vpc_acq_res_code' => $acqResponseCode, 'vpc_bank_auth_id' => $authorizeID, 'vpc_batch_no' => $batchNo, 'card_type' => $cardType, 'vpc_merchant' => $merchantID, 'vpc_command' => $command, 'vpc_version' => $version, 'vpc_Locale' => $locale, 'vpc_OrderInfo' => $orderInfo);
             $HSBC_payments = DB::table('hsbc_payments')->where('HSBC_payment_id', $merchTxnRef)->update($pay);
             if (substr_count($orderInfo, 'A') != 0) {
                 if ($txnResponseCode == 0) {
                     $mybooking = 0;
                     $payment = DB::table('payments')->where('HSBC_payment_id', $merchTxnRef)->update(array('my_booking' => $mybooking));
                     $booking = Booking::where('payment_reference_number', $orderInfo)->first();
                     $this->sendBookingEmails($booking);
                 }
             }
             if (substr_count($orderInfo, 'B') != 0) {
                 if ($txnResponseCode == 0) {
                     $mybooking = 0;
                     $payment = DB::table('payments')->where('HSBC_payment_id', $merchTxnRef)->update(array('my_booking' => $mybooking));
                     $booking = Booking::where('payment_reference_number', $orderInfo)->first();
                     $this->sendBookingEmails($booking);
                 }
             }
             if (substr_count($orderInfo, 'O') != 0) {
                 if ($txnResponseCode == 0) {
                     $mybooking = 0;
                     $payment = DB::table('payments')->where('HSBC_payment_id', $merchTxnRef)->update(array('my_booking' => $mybooking));
                     $booking = Booking::where('payment_reference_number', $orderInfo)->first();
                     $payment = Payment::where('reference_number', $orderInfo)->first();
                     //dd($booking->email);
                     //                        Mail::send('emails/online-payment', array(
                     //                            'payment' => $payment,
                     //                            'booking' => $booking
                     //                        ), function ($message) use ($booking) {
                     //                            $message->subject('Online Payment Receipt : ' . $booking->reference_number)
                     //                                ->from('*****@*****.**', 'SriLankaHotels.Travel')
                     //                                ->bcc('*****@*****.**')
                     //                                ->to('*****@*****.**');
                     //                        });
                     Mail::send('emails/online-payment', array('booking' => $booking, 'payment' => $payment), function ($message) use($booking, $payment) {
                         $message->subject('Payment : ' . $payment->reference_number)->from('*****@*****.**', 'SriLankaHotels.Travel')->to($booking->email, $booking->booking_name)->bcc('*****@*****.**', 'Admin');
                     });
                     Session::flash('global', 'Thank you for paying online. </br> We have emailed you the online payment invoice');
                     // return View::make('pages.message');
                 }
                 Session::flash('global', 'Sorry Your Payment was unsuccessful!');
                 //  return View::make('pages.message');
             }
             if (substr_count($orderInfo, 'AP') != 0) {
                 if ($txnResponseCode == 0) {
                     $mybooking = 0;
                     $payment = DB::table('payments')->where('HSBC_payment_id', $merchTxnRef)->update(array('my_booking' => $mybooking));
                     $booking = Booking::where('payment_reference_number', $orderInfo)->first();
                     $this->sendBookingEmails($booking);
                 }
             }
             $url = "http://srilankahotels.travel/message";
             header("Location: {$url}");
             exit;
         } else {
             die("An error occurred. Please contact administrator");
         }
     } else {
         header("Location:index.php");
         exit;
     }
 }
Exemplo n.º 3
0
 /**
  * Store a newly created payment in storage.
  *
  * @return Response
  */
 public function store()
 {
     $data = Input::all();
     $user_id = Auth::id();
     $validator = Validator::make(Input::all(), array('amount' => 'required|numeric'));
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     /**
      * Payments are starting from "BK" numbers
      */
     if ($x = Payment::find(Payment::max('id'))) {
         $y = (int) substr($x->reference_number, 2);
         $data['reference_number'] = 'BK' . ++$y;
     } else {
         $data['reference_number'] = 'BK10000000';
     }
     $data['agent_id'] = User::getAgentOfUser(Auth::id());
     if (Entrust::hasRole('Agent')) {
         $agent_id = $data['agent_id']->user_id;
         $name = User::where('id', $user_id)->first()->first_name . ' ' . User::where('id', $user_id)->first()->last_name;
         $email = User::where('id', $user_id)->first()->email;
         $phone = Agent::where('user_id', $user_id)->first()->phone;
         $amount = Input::get('amount');
         $details = Input::get('details');
         $data = array('details' => $name, 'ip_address' => $_SERVER['REMOTE_ADDR'], 'amount' => $amount, 'payment_status' => 0, 'my_booking' => 2);
         $reserv_id = Payment::create($data);
         $data_tab_HSBC_payment = array('currency' => 'USD');
         $tab_HSBC_payment_id = HsbcPayment::create($data_tab_HSBC_payment);
         $stamp = strtotime("now");
         $payment_id = Payment::orderBy('created_at', 'desc')->first()->id;
         $orderid = "{$stamp}" . 'AP' . "{$payment_id}";
         $last_res_resid = str_replace(".", "", $orderid);
         $hsbc_id = HsbcPayment::orderBy('created_at', 'desc')->first()->id;
         $hsbc_payment_id_pre = "{$stamp}" . 'HSBC' . "{$hsbc_id}";
         $hsbc_payment_id = str_replace(".", "", $hsbc_payment_id_pre);
         if ($last_res_resid) {
             $payment = DB::table('payments')->where('id', $payment_id)->update(array('reference_number' => $last_res_resid, 'HSBC_payment_id' => $hsbc_payment_id));
             $data_tab_HSBC_payment = DB::table('hsbc_payments')->where('id', $hsbc_id)->update(array('HSBC_payment_id' => $hsbc_payment_id));
             $client = array('booking_name' => $name, 'email' => $email, 'phone' => $phone, 'remarks' => $details, 'val' => 0, 'payment_reference_number' => $last_res_resid);
             $client_payment_id = Booking::create($client);
         }
         $currency = 'USD';
         $x = $amount * 1.037;
         $total_price_all_hsbc = round($x, 2) * 100;
         //dd($hsbc_payment_id . '/' . $currency . '/' . $total_price_all_hsbc . '/' . $last_res_resid);
         HsbcPayment::goto_hsbc_gateway($hsbc_payment_id, $currency, $total_price_all_hsbc, $last_res_resid);
         //  return $this->storeAllDataAndSendEmails();
     }
     //Payment::create($data);
     return Redirect::route('accounts.payments.index');
 }