/** * Insert or update refunds models in DB * @param $payload */ public function refundsNeedaDatabase($payload) { foreach ($payload as $refund) { $payload['data']['object'] = $refund; $payload['type'] = null; if (!is_null(Refund::where('uuid', $refund['id'])->first())) { (new Refund())->updateEntity(Refund::where('uuid', $refund['id'])->first(), $payload); } else { Refund::create((new Refund())->buildAttributesFromStripe($payload['data']['object'])); } } }
/** * Création d'une demande de remboursement en DB */ public function refunds(Request $request, Guard $auth) { $this->validate($request, ['amount' => 'required|min:1|numeric', 'content' => 'required|min:10']); $amount = $request->get('amount'); $content = $request->get('content'); if (DB::table('refunds')->where('playerid', $auth->user()->arma)->where('status', 0)->first()) { return redirect(action('PlayersController@index'))->with('error', 'Vous avez déjà une demande de remboursement en attente'); } $player = DB::table('players')->where('playerid', $auth->user()->arma)->first(); $refunds = new Refund(); $refunds->playerid = $auth->user()->arma; $refunds->name = $player->name; $refunds->amount = $amount; $refunds->content = $content; $refunds->status = 0; $refunds->save(); return redirect(action('PlayersController@index'))->with('success', 'La demande de remboursement à bien été envoyer'); }