<?php
namespace App\Http\Controllers\User;
use App\Constants\PaymentGatewayConst;
use Exception;
use Illuminate\Http\Request;
use App\Http\Helpers\Response;
use App\Models\MerchantApiKey;
use App\Models\MerchantDetails;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
class MerchantDetailsController extends Controller
{
/**
* Method for view index page
* @return view
*/
public function index(){
$page_title = "Merchant Details";
$user = User::with(['merchant_api_keys','merchant_details'])->where('id',auth()->user()->id)->first();
return view('user.sections.merchant-details.index',compact(
'page_title',
'user',
));
}
/**
* Method for update merchant details information
* @param $id
* @param Illuminate\Http\Request $request
*/
public function update(Request $request,$id){
$data = MerchantDetails::where('user_id',$id)->first();
if(!$data){
$image_validate_roles = 'required|image';
}else{
$image_validate_roles = 'nullable|image';
}
$validator = Validator::make($request->all(),[
'merchant_name' => 'required|string',
'image' => $image_validate_roles
]);
if($validator->fails()) return back()->withErrors($validator)->withInput($request->all());
if (!$data) {
$data = new MerchantDetails();
$data->user_id = auth()->user()->id;
$data->merchant_id = "MI" . generate_random_number(10);
}
if(MerchantDetails::whereNot('id',$data->id)->where('merchant_id',$data->merchat_id)->exists()){
throw ValidationException::withMessages([
'name' => "Merchant already exists!",
]);
}
if ($request->hasFile("image")) {
$image = $this->imageValidate($request, "image", $data->image ?? null);
$data->image = $image;
}
$data->merchant_name = $request->merchant_name;
try {
$data->save();
} catch (Exception $e) {
return back()->with(['error' => ['Something went wrong! Please try again.']]);
}
return back()->with(['success' => ['Information Updated.']]);
}
/**
* Method for update payment configuartion information
* @param $user_id
* @param Illuminate\Http\Request $request
*/
public function paymentConfiguartionUpdate(Request $request,$user_id){
$validator = Validator::make($request->all(),[
'secret_key' => 'required|string'
]);
if($validator->fails()){
return back()->withErrors($validator)->withInput($request->all());
}
$validated = $validator->validate();
$data = MerchantDetails::where('user_id',$user_id)->first();
if (!$data) {
$data = new MerchantDetails();
$data->user_id = auth()->user()->id;
}
$data->payment_gateway = [
'payment_method' => PaymentGatewayConst::STRIPE,
'stripe_secret_key' => $request->secret_key,
];
try{
$data->save();
}catch(Exception $e){
return back()->with(['error' => ['Something went wrong! Please try again.']]);
}
return back()->with(['success' => ['Payment Gateway configuration successfully.']]);
}
/**
* Method for statusUpdate
*/
public function statusUpdate(Request $request){
$validator = Validator::make($request->all(),[
'status' => 'required',
'data_target' => 'required|string',
]);
if ($validator->stopOnFirstFailure()->fails()) {
return Response::error($validator->errors()->all(),null,400);
}
$validated = $validator->validate();
$merchant_api_key = MerchantApiKey::where('id',$validated['data_target'])->first();
if (!$merchant_api_key) {
$error = ['error' => [__('Merchant api key not found!')]];
return Response::error($error, null, 404);
}
try{
$merchant_api_key->update([
'env' => $validated['status'],
]);
}catch(Exception $e){
$error = ['error' => [__('Something went wrong!. Please try again.')]];
return Response::error($error, null, 500);
}
$success = ['success' => [__('Environment updated successfully!')]];
return Response::success($success, null, 200);
}
/**
* Method for validate request image if have
* @param object $request
* @param string $input_name
* @param string $old_image
* @return boolean|string $upload
*/
public function imageValidate($request,$input_name,$old_image) {
if($request->hasFile($input_name)) {
$image_validated = Validator::make($request->only($input_name),[
$input_name => "image|mimes:png,jpg,webp,jpeg,svg",
])->validate();
$image = get_files_from_fileholder($request,$input_name);
$upload = upload_files_from_path_dynamic($image,'merchant-details',$old_image);
return $upload;
}
return false;
}
}
Service Section
Discover how our services are designed to enhance your NFC Pay experience with convenience, security, and innovative solutions. From managing transactions to secure payments, we are dedicated to providing seamless support every step of the way.
Easily save your credit and debit card details within our app for quick and secure transactions. This feature ensures that your payment information is protected with advanced encryption and can be used for future purchases with just a tap.
Transfer funds quickly and securely between users with our streamlined money transfer service. Simply select the recipient, enter the amount, and authorize the transaction for instant, hassle-free transfers.
Activate your merchant account effortlessly to start receiving payments. Our intuitive setup process ensures that you can begin accepting transactions smoothly, helping your business thrive with minimal setup time.
Keep track of all your transactions in real time through our app. Monitor payment statuses, view transaction history, and manage your account efficiently, ensuring complete control over your financial activities.
Our dedicated support team is available to assist you with any queries or issues. Whether you need help with setting up your account or resolving transaction-related questions, we’re here to provide prompt and reliable assistance.