validate($request, [ 'id_transaction' => 'required', 'id_bank' => 'required', 'is_verified' => 'required|boolean' ]); $transaction = UsersBankingAccountVerification::where('id_transaction', $request->id_transaction)->first(); if (!$transaction) return $this->errorResponse(trans('errors.transaction_not_exist')); if ($transaction->was_treated) return $this->errorResponse(trans('errors.treated_demand')); if ($transaction->id_bank_country != $request->id_bank) return $this->errorResponse(trans('errors.not_authorized_to_process_request')); $transaction->is_verified = $request->is_verified; $user = User::where('user_code', $transaction->user_code)->first(); if (!$user) return $this->errorResponse(trans('errors.unexpected_error')); if ($request->is_verified) { $user->iban = $transaction->iban; $user->id_bank_country = $transaction->id_bank_country; $user->save(); } $transaction->was_treated = true; $transaction->save(); if($request->is_verified){ $identification = Identification::where('id_user',$user->id)->first(); $owner = isset($identification) ? $identification->lastname.' '.$identification->firstname : $user->lastname.' '.$user->firstname; $network_bank = NetworksOperator::where('id_network', $transaction->id_network )->where('id_operator_country', $request->id_bank)->first(); $bank = isset($network_bank) ? $network_bank->operators_country->operator->nom : 'n/a'; $country = isset($network_bank) ? $network_bank->network->country->name : 'n/a'; $message = trans('messages.successful_bank_account_attachment_message', ['iban' => $transaction->iban, 'owner' => $owner , 'bank' => $bank , 'country' => $country ]); $this->sendMail($user->email, trans('messages.successful_bank_account_attachment'), $message); }else{ $this->sendMail($user->email, trans('messages.failed_bank_account_attachment'), trans('messages.failed_bank_account_attachment_message')); } return $this->successResponse(trans('messages.success_treated_demand')); } }