Ejemplo n.º 1
0
 public function postPayment()
 {
     $data = array();
     if (is_array(Input::get('room_id'))) {
         foreach (Input::get('room_id') as $key => $val) {
             $data[$key] = array('am_id' => Input::get('am_id.' . $key), 'rooms' => $val);
         }
     }
     $data2 = array();
     if (is_array(Input::get('add_Am'))) {
         foreach (Input::get('add_Am') as $key => $val) {
             $data2[$key] = array('am_id' => Input::get('am_id.' . $key), 'rooms' => $val);
         }
     }
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $name = Input::get('packname');
     $price = Input::get('amount');
     $input_dFrom = Input::get('package_datefrom');
     $input_dTo = Input::get('package_dateto');
     $input_nPax = Input::get('num_pax');
     $input_fName = Input::get('fullN');
     $postData = new Reservation();
     $postData->dataInsertPost($name, $price, $input_dFrom, $input_dTo, $input_nPax, $input_fName, json_encode($data), 'PayPal', json_encode($data2));
     $item_1 = new Item();
     $item_1->setName($name)->setCurrency('PHP')->setQuantity('1')->setPrice(intval($price));
     // unit price
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems(array($item_1));
     $amount = new Amount();
     $amount->setCurrency('PHP')->setTotal(intval($price));
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Your transaction description');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status'));
     //        $redirect_urls->setReturnUrl(URL::to('/dashboard/accommodation'))
     //            ->setCancelUrl(URL::to('/dashboard/accommodation'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (PayPal\Exception\PayPalConnectionException $e) {
         echo $e->getData();
         // This will print a JSON which has specific details about the error.
         exit;
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         return json_encode(['url' => $redirect_url]);
     }
     return Redirect::route('dashboard.packages.accommodation')->with('error', 'Unknown error occurred');
 }
Ejemplo n.º 2
0
 public function uploadBankReceipt()
 {
     if (Input::hasFile('uploadReceipt')) {
         $data = array();
         if (is_array(Input::get('room_id'))) {
             foreach (Input::get('room_id') as $key => $val) {
                 $data[$key] = array('am_id' => Input::get('am_id.' . $key), 'rooms' => $val);
             }
         }
         $data2 = array();
         if (is_array(Input::get('add_Am'))) {
             foreach (Input::get('add_Am') as $key => $val) {
                 $data2[$key] = array('am_id' => Input::get('am_id.' . $key), 'rooms' => $val);
             }
         }
         $name = Input::get('packname');
         $price = Input::get('amount');
         $input_dFrom = Input::get('package_datefrom');
         $input_dTo = Input::get('package_dateto');
         $input_nPax = Input::get('num_pax');
         $input_fName = Input::get('fullN');
         $postData = new Reservation();
         $postData->dataInsertPost($name, $price, $input_dFrom, $input_dTo, $input_nPax, $input_fName, json_encode($data), 'Bank', json_encode($data2));
         $lastInsert = DB::getPdo()->lastInsertId();
         $files = Input::file('uploadReceipt');
         $i = 1;
         foreach ($files as $file) {
             try {
                 $path = public_path() . '\\uploads\\bank_deposit\\';
                 $extension = $file->getClientOriginalExtension();
                 $filename = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
                 $dateNow = date('Ymd_His');
                 $new_filename = Auth::user()->id . '_' . $filename . '_' . $i . '.' . $extension;
                 $upload_success = $file->move($path, $new_filename);
             } catch (Exception $ex) {
                 $path = public_path() . '/uploads/bank_deposit/';
                 $extension = $file->getClientOriginalExtension();
                 $filename = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
                 $dateNow = date('Ymd_His');
                 $new_filename = Auth::user()->id . '_' . $filename . '_' . $i . '.' . $extension;
                 $upload_success = $file->move($path, $new_filename);
             }
             $insertVal = array('image_fieldvalue' => $lastInsert, 'image_name' => $new_filename);
             $this->GlobalModel->insertModel('tbl_images', $insertVal);
             $i++;
         }
         $data = array('refNumber' => str_pad($lastInsert, 10, "0", STR_PAD_LEFT), 'package' => $name, 'amount' => '₱' . number_format($price, 2), 'paymentMethod' => 'Bank Deposit', 'status' => 1);
         try {
             Mail::send('emails.user.transactionReservation', $data, function ($message) use($data) {
                 $message->from('*****@*****.**', 'El Sitio Filipino');
                 $message->to(Auth::user()->user_email, Auth::user()->user_fname . ' ' . Auth::user()->user_lname)->subject('El Sitio Filipino Transaction Details');
             });
         } catch (Exception $ex) {
             dd($ex->getMessage());
         }
         return Response::json($data);
     }
 }