/**
  * Handle the event.
  *
  * @param  Event  $event
  * @return void
  */
 public function handle(Event $event)
 {
     $payment = Payment::findOrFail($event->transactionDetail['transaction_id']);
     if ($event instanceof \GoProp\Events\PaymentCompletedEvent) {
         switch ($event->transactionDetail['method']) {
             case MyShortCart::getMachineName():
                 if ($event->transactionDetail['status'] == 'success') {
                     if (isset($event->transactionDetail['payment_channel'])) {
                     } else {
                         $payment->order->update(['status' => Order::STATUS_PENDING]);
                         $payment->update(['status' => Payment::STATUS_PAID, 'amount' => $event->transactionDetail['amount'], 'received_at' => Carbon::now()->toDateTimeString()]);
                         Session::set('payment_redirect_to', route('frontend.property.success', ['id' => $payment->order->property->id]));
                     }
                 }
                 break;
         }
     } elseif ($event instanceof \GoProp\Events\PaymentCancelledEvent) {
         Session::set('payment_redirect_to', route('frontend.property.review', ['id' => $payment->order->property->id]));
     } elseif ($event instanceof \GoProp\Events\PaymentFailedEvent) {
         Session::set('payment_redirect_to', route('frontend.property.review', ['id' => $payment->order->property->id]));
     }
 }
 /**
  * Get the validation rules that apply to the request.
  *
  * @return array
  */
 public function rules()
 {
     $rules = [];
     $routeName = $this->route()->getName();
     if ($this->route('id')) {
         $property = Property::findOrFail($this->route('id'));
     } else {
         $property = new Property();
     }
     if (in_array($routeName, ['frontend.property.create.process', 'frontend.property.edit.process'])) {
         $rules = $this->getCreateRules($property);
     } elseif (in_array($routeName, ['frontend.property.details.process'])) {
         $rules = $this->getDetailRules($property);
     } elseif (in_array($routeName, ['frontend.property.map.process'])) {
         $rules['latitude'] = 'required_if:point_map,1';
         $rules['longitude'] = 'required_if:point_map,1';
     } elseif (in_array($routeName, ['frontend.property.packages.process'])) {
         $allowedPackages = implode(',', Package::lists('id')->toArray());
         $rules['action'] = 'required';
         foreach ($this->input('action', []) as $idx => $action) {
             $rules['action.' . $idx] = 'in:' . $allowedPackages;
             $package = Package::findOrFail($action);
             $allowedFeatures = implode(',', $package->features->lists('id')->toArray());
             foreach ($this->input('features.' . $package->id, []) as $featureIdx => $feature) {
                 $rules['features.' . $package->id . '.' . $featureIdx] = 'in:' . $allowedFeatures;
             }
         }
     } elseif (in_array($routeName, ['frontend.property.review.process'])) {
         $allowedPaymentMethods = array_keys(Payment::getPaymentMethods(null, TRUE));
         $allowedPaymentMethods = implode(',', $allowedPaymentMethods);
         if ($this->input('action') == 'purchase') {
             $rules['agree_tc'] = 'required';
             $rules['payment_method'] = 'required|in:' . $allowedPaymentMethods;
         }
     }
     return $rules;
 }
 public function postPropertyOrderReview(PropertyFormRequest $request, $id)
 {
     $user = Auth::user();
     $property = Property::findOrFail($id);
     if ($request->input('action') == 'purchase') {
         $order = $property->getCartOrder();
         $payment_method = Payment::getPaymentMethods($request->input('payment_method'), TRUE);
         $payment = new Payment(['total_amount' => $order->total_amount, 'payment_method' => $payment_method['machine_name'], 'status' => Payment::STATUS_UNPAID]);
         $payment->user()->associate($user);
         $payment->order()->associate($order);
         $payment->save();
         $order->generateOrderNumber();
         $order->save();
         switch ($payment_method['machine_name']) {
             case Payment::METHOD_DOKU_CREDIT_CARD:
                 return redirect()->route('frontend.property.payment', ['id' => $property->id]);
                 break;
             default:
                 $order->status = Order::STATUS_PENDING;
                 $order->save();
                 return redirect()->route('frontend.property.success', ['id' => $property->id]);
                 break;
         }
     } elseif ($request->input('action') == 'change_package') {
         return redirect()->route('frontend.property.packages', ['id' => $property->id]);
     }
 }