all(); $refund = RefundWorkflow::run($trasition, $refund, $request); $data = new RefundResource($refund); return $this->response->message(trans('messages.success.updated', ['Module' => trans('payment::refund.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('payment/refund/' . $refund->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('payment/refund/' . $refund->getRouteKey())) ->redirect(); } } /** * Get the refund and user for the workflow. * * @param PublicRequest $request * @param string $refund * @param string $user * * @return Response */ public function get(PublicRequest $request, $refund, $user) { if (!$request->hasValidSignature()) { abort(403, 'This url is expired!'); } $auth = Auth::guard()->getProvider()->getModel(); $user = $auth::findBySignedId($user); Auth::guard()->login($user); $refund = Refund::findBySignedId($refund); $transitions = $this->transitions($refund, $user); $user = user(); Auth::logout(); return $this->response->setMetaTitle(trans('payment::refund.name') . ' ' . trans('Approvals')) ->view('payment::public.refund.workflow') ->layout('mobile') ->data(compact('refund', 'user', 'transitions')) ->output(); } /** * Display the workflow form for the refund. * * @param PublicRequest $request * @param string $refund * @param string $user * * @return Response */ public function post(PublicRequest $request, $refund, $user) { if (!$request->hasValidSignature()) { abort(403, 'This url is expired!'); } $transition = $request->transition; $auth = Auth::guard()->getProvider()->getModel(); $user = $auth::findBySignedId($user); Auth::guard()->login($user); $refund = Refund::findBySignedId($refund); $user = user(); $refund = RefundWorkflow::run($transition, $refund, $request->all()); Auth::logout(); return response()->json( [ 'status' => 'success', 'url' => $request->url(), ] ); } private function transitions($refund, $user) { $transitions = []; foreach ($refund->workflow()->transitions($refund) as $key => $value) { $name = $value->getName(); $array['url'] = URL::temporarySignedRoute('litecms.refund.workflow', now()->addMinutes(3), [ 'guard' => 'admin', 'transition' => $name, 'refund' => $refund->getSignedId(now()->addMinutes(3)), 'user' => $user->getSignedId(now()->addMinutes(3)), 'trans' => 'en', ] ); $array['name'] = $name; $array['key'] = $name; $array['form'] = $refund->workflow()->form($value); $array['label'] = trans('payment::refund.workflow.' . $name); $transitions[] = $array; } return $transitions; } }