Proven Expertise
Our team brings years of experience in the digital payments industry to provide reliable services.
<?php
namespace App\Http\Controllers\Api\V1\User;
use Exception;
use App\Models\User;
use App\Models\UserWallet;
use App\Models\Transaction;
use Jenssegers\Agent\Agent;
use Illuminate\Http\Request;
use App\Constants\GlobalConst;
use App\Http\Helpers\Response;
use App\Models\Admin\Currency;
use App\Models\UserNotification;
use Illuminate\Support\Facades\DB;
use App\Models\Admin\BasicSettings;
use App\Http\Controllers\Controller;
use App\Constants\PaymentGatewayConst;
use App\Models\Admin\TransactionSetting;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Notification;
use App\Notifications\User\TransferMoneyNotification;
use App\Notifications\User\TransferMoneyReceivedNotification;
class TransferMoneyController extends Controller
{
/**
* Method for get transfer money information
* @return response
*/
public function info(){
$base_currency = Currency::default();
$user_wallet = UserWallet::auth()->first();
$transaction_settings = TransactionSetting::where('slug',GlobalConst::TRANSFER_MONEY)->get()->map(function($data){
return [
'title' => $data->title,
'fixed_charge' => get_amount($data->fixed_charge),
'percent_charge'=> get_amount($data->percent_charge),
'min_limit' => get_amount($data->min_limit),
'max_limit' => get_amount($data->max_limit),
];
})->first();
$transactions = Transaction::auth()->where('type',PaymentGatewayConst::TYPETRANSFERMONEY)->get()->map(function($data){
if($data->attribute == PaymentGatewayConst::SEND){
$receiver_name = $data->details->receiver->fullname;
$receiver_email = $data->details->receiver->email;
return [
'type' => $data->type,
'trx_id' => $data->trx_id,
'receiver_name' => $receiver_name,
'receiver_email' => $receiver_email,
'request_amount' => get_amount($data->request_amount),
'fixed_charge' => get_amount($data->fixed_charge),
'percent_charge' => get_amount($data->percent_charge),
'total_charge' => get_amount($data->total_charge),
'total_payable' => get_amount($data->total_payable),
'request_currency' => $data->request_currency,
'remark' => $data->remark,
'attribute' => $data->attribute,
'status' => $data->stringStatus->value,
];
}else{
$sender_name = $data->details->sender->fullname;
$sender_email = $data->details->sender->email;
return [
'type' => $data->type,
'trx_id' => $data->trx_id,
'sender_name' => $sender_name,
'sender_email' => $sender_email,
'request_amount' => get_amount($data->request_amount),
'fixed_charge' => get_amount($data->fixed_charge),
'percent_charge' => get_amount($data->percent_charge),
'total_charge' => get_amount($data->total_charge),
'total_payable' => get_amount($data->total_payable),
'request_currency' => $data->request_currency,
'remark' => $data->remark,
'attribute' => $data->attribute,
'status' => $data->stringStatus->value,
];
}
});
$currency_image_paths = [
'base_url' => url("/"),
'path_location' => files_asset_path_basename("currency-flag"),
'default_image' => files_asset_path_basename("currency-flag"),
];
return Response::success(['Transfer money fetch successfully.'],[
'base_currency' => $base_currency->code,
'rate' => get_amount($base_currency->rate),
'flag' => $base_currency->flag,
'currency_image_paths' => $currency_image_paths,
'wallet' => [
'code' => $user_wallet->currency->code,
'balance' => get_amount($user_wallet->balance),
],
'transaction_settings' => $transaction_settings,
'transactions' => $transactions
],200);
}
/**
* Method for check the user data
* @param Illuminate\Http\Request $request
*/
public function checkUser(Request $request){
$validator = Validator::make($request->all(),[
'email' => 'required|email',
]);
if($validator->fails()) return Response::error($validator->errors()->all(),[]);
$validated = $validator->validate();
$user = User::where('email',$validated['email'])->first();
if(!$user){
return Response::error(['Sorry! User not found.'],[],400);
}
if(auth()->user()->email == $validated['email']){
return Response::error(['Sorry! You can not transfer money to your own account.'],[],400);
}
$user_data = [
'name' => $user->fullname,
'email' => $user->email,
'image' => $user->image
];
$image_paths = [
'base_url' => url("/"),
'path_location' => files_asset_path_basename("user-profile"),
'default_image' => files_asset_path_basename("profile-default"),
];
return Response::success(['Valid user for transfer money.'],[
'user' => $user_data,
'image_paths' => $image_paths
],200);
}
/**
* Method for confirm transfer money request
* @param Illuminate\Http\Request $request
*/
public function confirm(Request $request){
$validator = Validator::make($request->all(),[
'amount' => 'required|numeric',
'email' => 'required|email',
'remark' => 'nullable'
]);
if($validator->fails()) return Response::error($validator->errors()->all(),[]);
$validated = $validator->validate();
if(auth()->user()->email == $validated['email']){
return Response::error(['Sorry! You can not transfer money to your own account.'],[],400);
}
$user_wallet = UserWallet::auth()->first();
if(!$user_wallet) return Response::error(['Sorry! Wallet not found.'],[],400);
$amount = $validated['amount'];
$receiver = User::with(['wallet'])->where('email',$validated['email'])->first();
if(!$receiver) return Response::error(['Sorry! Receiver not found.'],[],400);
$transaction_settings = TransactionSetting::where('slug',GlobalConst::TRANSFER_MONEY)->first();
if(!$transaction_settings) return Response::error(['Sorry! Transaction charges not found.'],[],400);
if($user_wallet->balance < $amount){
return Response::error(['Sorry! Insufficient balance.'],[],400);
}
$basic_settings = BasicSettings::first();
$fixed_charge = $transaction_settings->fixed_charge;
$percent_charge = ($amount * $transaction_settings->percent_charge) / 100;
$total_charge = $fixed_charge + $percent_charge;
$payable_amount = $amount + $total_charge;
if($transaction_settings->min_limit > $payable_amount || $transaction_settings->max_limit < $payable_amount){
return Response::error(['Please follow the transaction limit.'],[],400);
}
if($user_wallet->balance < $payable_amount){
return Response::error(['Sorry! Insufficient balance.'],[],400);
}
if(isset($validated['remark']) == '' || isset($validated['remark']) == null){
$remark = null;
}else{
$remark = $validated['remark'];
}
try{
// for sender
$transaction = $this->insertSenderRecord($amount,$user_wallet,$receiver,$fixed_charge,$percent_charge,$total_charge,$payable_amount,$remark);
$this->transactionDevice($transaction);
$this->userNotification($transaction,$amount,$receiver);
if($basic_settings->email_notification){
try{
Notification::route('mail',auth()->user()->email)->notify(new TransferMoneyNotification($amount,$receiver,$payable_amount));
}catch(Exception $e){}
}
// for receiver
$receiver_transaction = $this->insertReceiverRecord($amount,$user_wallet,$receiver,$fixed_charge,$percent_charge,$total_charge,$payable_amount,$remark);
$this->userReceiverNotification($receiver_transaction,$amount,$receiver);
if($basic_settings->email_notification){
try{
Notification::route('mail',$receiver->email)->notify(new TransferMoneyReceivedNotification($amount,$receiver));
}catch(Exception $e){}
}
}catch(Exception $e){
return Response::error(['Something went wrong! Please try again.'],[],400);
}
$transaction_data = Transaction::where('id',$transaction)->first();
$image_paths = [
'base_url' => url("/"),
'path_location' => files_asset_path_basename("user-profile"),
'default_image' => files_asset_path_basename("profile-default"),
];
return Response::success(['Successfully transferred money.'],[
'currency' => $transaction_data->request_currency,
'request_amount' => floatval($transaction_data->request_amount),
'total_charge' => floatval($transaction_data->total_charge),
'total_payable' => floatval($transaction_data->total_payable),
'receiver_name' => $transaction_data->details->receiver->fullname,
'receiver_email' => $transaction_data->details->receiver->email,
'status' => $transaction_data->stringStatus->value,
'receiver_image' => $receiver->image,
'image_paths' => $image_paths
],200);
}
//insert transaction data
function insertSenderRecord($amount,$user_wallet,$receiver,$fixed_charge,$percent_charge,$total_charge,$payable_amount,$remark){
$available_balance = $user_wallet->balance - $payable_amount;
DB::beginTransaction();
try{
$trx_id = generateTrxString("transactions","trx_id","TM",8);
$id = DB::table('transactions')->insertGetId([
'trx_id' => $trx_id,
'user_id' => auth()->user()->id,
'user_wallet_id' => $user_wallet->id,
'type' => PaymentGatewayConst::TYPETRANSFERMONEY,
'request_amount' => $amount,
'fixed_charge' => $fixed_charge,
'percent_charge' => $percent_charge,
'total_charge' => $total_charge,
'total_payable' => $payable_amount,
'request_currency' => get_default_currency_code(),
'available_balance' => $available_balance,
'payment_currency' => get_default_currency_code(),
'remark' => ucwords(remove_special_char("Transfer Money"," ")) . " Send to" . " " . $receiver->email,
'details' => json_encode(['remark' => $remark,'receiver' => [
'fullname' => $receiver->fullname,
'email' => $receiver->email
]]),
'attribute' => PaymentGatewayConst::SEND,
'status' => PaymentGatewayConst::STATUSSUCCESS,
'created_at' => now()
]);
$this->updateSenderWalletBalance($user_wallet,$payable_amount);
DB::commit();
}catch(Exception $e){
DB::rollBack();
return Response::error(['Something went wrong! Please try again.'],[],400);
}
return $id;
}
// update sender wallet balance
function updateSenderWalletBalance($user_wallet,$amount){
$user_wallet->update([
'balance' => $user_wallet->balance - $amount,
]);
}
// save the transaction device information
function transactionDevice($id){
$client_ip = request()->ip() ?? false;
$location = geoip()->getLocation($client_ip);
$agent = new Agent();
$mac = "";
DB::beginTransaction();
try{
DB::table("transaction_devices")->insert([
'transaction_id'=> $id,
'ip' => $client_ip,
'mac' => $mac,
'city' => $location['city'] ?? "",
'country' => $location['country'] ?? "",
'longitude' => $location['lon'] ?? "",
'latitude' => $location['lat'] ?? "",
'timezone' => $location['timezone'] ?? "",
'browser' => $agent->browser() ?? "",
'os' => $agent->platform() ?? "",
]);
DB::commit();
}catch(Exception $e) {
DB::rollBack();
return Response::error(['Something went wrong! Please try again.'],[],400);
}
}
//user notification
public function userNotification($id,$amount,$receiver){
UserNotification::create([
'user_id' => auth()->user()->id,
'transaction_id' => $id,
'details' => [
'title' => 'Transfer Money to ' .$receiver->email,
'amount' => floatval($amount),
'currency' => get_default_currency_code(),
'message' => "Successfully Send."
],
]);
}
//insert transaction data
function insertReceiverRecord($amount,$user_wallet,$receiver,$fixed_charge,$percent_charge,$total_charge,$payable_amount,$remark){
$available_balance = $receiver->wallet->balance + $amount;
DB::beginTransaction();
try{
$trx_id = generateTrxString("transactions","trx_id","TM",8);
$id = DB::table('transactions')->insertGetId([
'trx_id' => $trx_id,
'user_id' => $receiver->id,
'user_wallet_id' => $receiver->wallet->id,
'type' => PaymentGatewayConst::TYPETRANSFERMONEY,
'request_amount' => $amount,
'fixed_charge' => $fixed_charge,
'percent_charge' => $percent_charge,
'total_charge' => $total_charge,
'total_payable' => $payable_amount,
'request_currency' => get_default_currency_code(),
'available_balance' => $available_balance,
'payment_currency' => get_default_currency_code(),
'remark' => ucwords(remove_special_char("Received Money"," ")) . " From" . " " . auth()->user()->email,
'details' => json_encode(['remark' => $remark,'sender' => [
'fullname' => auth()->user()->fullname,
'email' => auth()->user()->email
]]),
'attribute' => PaymentGatewayConst::RECEIVED,
'status' => PaymentGatewayConst::STATUSSUCCESS,
'created_at' => now()
]);
$this->updateReceiverWalletBalance($receiver,$amount);
DB::commit();
}catch(Exception $e){
DB::rollBack();
return Response::error(['Something went wrong! Please try again.'],[],400);
}
return $id;
}
//update receiver wallet balance
function updateReceiverWalletBalance($receiver,$amount){
$update_balance = $receiver->wallet->balance + $amount;
$receiver->wallet->update([
'balance' => $update_balance,
]);
}
//user notification
public function userReceiverNotification($id,$amount,$receiver){
UserNotification::create([
'user_id' => $receiver->id,
'transaction_id' => $id,
'details' => [
'title' => 'Received Money From ' .auth()->user()->email,
'amount' => floatval($amount),
'currency' => get_default_currency_code(),
'message' => "Successfully Received."
],
]);
}
}
How it Works
Getting started with NFC Pay is simple and quick. Register your account, add your cards, and you're ready to make payments in no time. Whether you're paying at a store, sending money to a friend, or managing your merchant transactions, NFC Pay makes it easy and secure.
Download the NFC Pay app and sign up with your email or phone number. Complete the registration process by verifying your identity, and set up your secure PIN to protect your account.
Link your debit or credit cards to your NFC Pay wallet. Simply scan your card or enter the details manually, and you’re set to load funds, shop, and pay with ease.
To pay, simply tap your phone or scan the QR code at checkout. You can also transfer money to other users with a few taps. Enjoy fast, contactless payments with top-notch security.
Security System
NFC Pay prioritizes your security with advanced features that safeguard every transaction. From SMS or email verification to end-to-end encryption, we've implemented robust measures to ensure your data is always protected. Our security systems are designed to prevent unauthorized access and provide you with a safe and reliable payment experience.
Receive instant alerts for every transaction to keep track of your account activities.
Verify your identity through our Know Your Customer process to prevent fraud and enhance security.
Dramatically supply transparent backward deliverables before caward comp internal or "organic" sources.
All your data and transactions are encrypted, ensuring that your sensitive information remains private.
Monitor unusual activity patterns to detect and prevent suspicious behavior in real-time.
Why Choice Us
With NFC Pay, you get a trusted platform backed by proven expertise and a commitment to quality. We put our customers first, offering innovative solutions tailored to your needs, ensuring every transaction is secure, swift, and seamless.
Our team brings years of experience in the digital payments industry to provide reliable services.
We prioritize excellence, ensuring that every aspect of our platform meets the highest standards.
Your needs drive our solutions, and we are dedicated to delivering a superior user experience.
We continuously evolve, integrating the latest technologies to enhance your payment experience.
Testimonial Section
Hear from our users who trust NFC Pay for their everyday transactions. Our commitment to security, ease of use, and exceptional service shines through in their experiences. See why our clients choose NFC Pay for their payment needs and how it has transformed the way they manage their finances.
App Section
Unlock the full potential of NFC Pay by downloading our app, designed to bring secure, swift, and smart transactions to your fingertips. Whether you're paying at a store, transferring money to friends, or managing your business payments, the NFC Pay app makes it effortless. Available on both iOS and Android, it's your all-in-one solution for convenient and reliable digital payments. Download now and experience the future of payments!