public function update($id) { $today = date("Y-m-d H:i:s"); $i = Input::all(); $bookingRemarks = ''; $addition = 0; $deduction = 0; if ($i['savethis'] == true) { $addition -= $i['price_addition']; $deduction += $i['price_deduction']; } $booking = Booking::where('id', $id)->with('reservedRoom.room.roomDetails')->first(); //$booking = ReservedRoom::where('id', $id)->with('room.roomDetails')->first(); $old_status = $booking->status; $current_price = $booking->price; $current_price += $addition + $deduction; if (!empty($booking)) { $booking->status = $i['status']; if ($i['status'] == 5) { $booking->cancelled_at = $today; $booking->paid = 0; $booking->price = 0; $booking->cancelled_remarks = $i['cancelled_remarks']; } else { if ($i['status'] == 1) { $booking->paid = $i['paid']; } else { //$booking->paid=0; $booking->price = $current_price; $booking->cancelled_remarks = ''; $booking->cancelled_at = '0000-00-00 00:00:00'; } } if ($booking->save()) { if ($i['savethis'] == true) { $newBookingRemarks = new BookingRemarksHistory(); $newBookingRemarks->additional = $addition; $newBookingRemarks->deduction = $deduction; $newBookingRemarks->remarks = $i['bookingremarks']; $newBookingRemarks->booking_id = $id; $newBookingRemarks->save(); } $roomReserved = ReservedRoom::where('booking_id', $booking->id)->get(); foreach ($roomReserved as $rr) { $rr->status = $i['status']; $rr->save(); } $a = new Activity(); $a->actor = Auth::id(); $a->location = 3; $a->logs = 'Updated booking ID of:' . $booking->id . ' by ' . $booking->firstname . ' ' . $booking->lastname . ' from ' . $this->bookingStatus($old_status) . ' to ' . $this->bookingStatus($booking->status); //before to after status. $a->save(); return $booking; } else { return '0'; //means failed } } }
public function getPaymentStatus() { // Get the payment ID before session clear $payment_id = Session::get('paypal_payment_id'); // clear the session payment ID Session::forget('paypal_payment_id'); if (empty(Input::get('PayerID')) || empty(Input::get('token'))) { return Redirect::route('original.route')->with('error', 'Payment failed'); } $payment = Payment::get($payment_id, $this->_api_context); // PaymentExecution object includes information necessary // to execute a PayPal account payment. // The payer_id is added to the request query parameters // when the user is redirected from paypal back to your site $execution = new PaymentExecution(); $execution->setPayerId(Input::get('PayerID')); //Execute the payment $result = $payment->execute($execution, $this->_api_context); /*echo '<pre>';print_r($result);echo '</pre>';exit; // DEBUG RESULT, remove it later*/ if ($result->getState() == 'approved') { // payment made // $tax = null; $total_price = null; $i = []; $i['checkin'] = Session::get('reservation')['checkin'] . '12:00:00'; $i['checkout'] = Session::get('reservation')['checkout'] . '11:59:00'; $customerinformation = Session::get('reservation.customerinformation'); $count = 0; //for test $count1 = 0; //for test $booked_room = []; //all picked rooms from available rooms $new_booking = new Booking(); $new_booking->firstname = $customerinformation['firstname']; $new_booking->lastname = $customerinformation['lastname']; $new_booking->address = $customerinformation['address']; $new_booking->contact_number = $customerinformation['contact_no']; $new_booking->email_address = $customerinformation['email']; $new_booking->check_in = $i['checkin']; $new_booking->check_out = $i['checkout']; $new_booking->payment_type = 'paypal'; $new_booking->paypal_paymentId = Input::get('PayerID'); $new_booking->save(); if (Session::has('hasMembershipDiscount')) { $booking_remarks = new BookingRemarksHistory(); $booking_remarks->remarks = "Membership Discount"; $booking_remarks->deduction = Session::get('hasMembershipDiscount'); $booking_remarks->booking_id = $new_booking->id; $booking_remarks->save(); Session::forget('hasMembershipDiscount'); } if (Session::has('hasCouponDiscount')) { $booking_remarks = new BookingRemarksHistory(); $booking_remarks->remarks = "Coupon Discount"; $booking_remarks->deduction = Session::get('hasCouponDiscount'); $booking_remarks->booking_id = $new_booking->id; $booking_remarks->save(); Session::forget('hasCouponDiscount'); } foreach (Session::get('reservation')['reservation_room'] as $rooms) { $count++; $room_id = $rooms['room_details']['id']; $available_rooms = []; $room_qty = RoomQty::with(array('roomPrice', 'roomReserved' => function ($query) use($i, $room_id) { $query->where(function ($query2) use($i, $room_id) { $query2->whereBetween('check_in', array($i['checkin'], $i['checkout']))->orWhereBetween('check_out', array($i['checkin'], $i['checkout']))->orWhereRaw('"' . $i["checkin"] . '" between check_in and check_out')->orWhereRaw('"' . $i["checkout"] . '" between check_in and check_out'); })->where(function ($query3) { $query3->where('status', '!=', 5)->orWhere('status', '!=', 3); }); }))->where('room_id', $room_id)->where('status', 1)->get(); foreach ($room_qty as $available) { if ($available->roomReserved == '[]') { array_push($available_rooms, $available); } } for ($counter = 0; $counter < $rooms['quantity']; $counter++) { array_push($booked_room, $available_rooms[$counter]); } } $total = 0; if (!empty($booked_room)) { foreach ($booked_room as $b) { $roomprice = $b->roomPrice->price * Session::get('reservation.nights'); $total += $b->roomPrice->price * Session::get('reservation.nights'); //$roomprice+=$tax; //$total = $total + $tax; $reserveRoom = new ReservedRoom(); $reserveRoom->booking_id = $new_booking->id; $reserveRoom->room_id = $b->id; $reserveRoom->room_type = $b->room_id; $reserveRoom->price = $roomprice; $reserveRoom->check_in = $i['checkin']; $reserveRoom->check_out = $i['checkout']; $reserveRoom->status = 1; $reserveRoom->firstname = $customerinformation['firstname']; $reserveRoom->lastname = $customerinformation['lastname']; $reserveRoom->address = $customerinformation['address']; $reserveRoom->contact_number = $customerinformation['contact_no']; $reserveRoom->email_address = $customerinformation['email']; $reserveRoom->save(); } } //$tax = $total * 0.12; //$total = $total + $tax; $new_booking->price = Session::get('total_price'); $new_booking->paid = Session::get('total_price'); $new_booking->status = 1; $date = date('Ymd'); $code = strtolower(Str::random(5) . $date); $new_booking->code = $code; $new_booking->save(); Session::forget('reservation'); Session::forget('total_price'); return Redirect::to('booking/step5')->with('code', $code); } return 'error in payment'; }