919 lines
33 KiB
PHP
919 lines
33 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Session;
|
|
use Illuminate\Http\Request;
|
|
use Carbon\Carbon;
|
|
use App\Models\security_question;
|
|
use App\Models\User;
|
|
use App\Models\user_profile;
|
|
use App\Models\AdminUser;
|
|
use App\Models\userotp;
|
|
use App\Models\Plan;
|
|
use App\Models\Subscription;
|
|
use App\Models\user_security_answer;
|
|
use App\Models\UserForgotPasswordPin;
|
|
use App\Models\UserLoginAudit;
|
|
use App\Models\KycDetailedStatus;
|
|
use App\Models\kycuserdetail;
|
|
use App\Models\BankDetails;
|
|
use App\Models\personalprofile;
|
|
use App\Models\GoalTracker;
|
|
use App\Models\familydetail;
|
|
use App\Mail\MyTestMail;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Razorpay\Api\Api;
|
|
use Lcobucci\JWT\Configuration;
|
|
use Lcobucci\JWT\Signer\Hmac\Sha256;
|
|
use Lcobucci\JWT\Signer\Key\InMemory;
|
|
|
|
class AuthService {
|
|
|
|
public function getSecurityQuestions() {
|
|
$getPost = DB::select(
|
|
'CALL get_all_security_questions()'
|
|
);
|
|
return response([
|
|
'data' => $getPost
|
|
], 200);
|
|
}
|
|
|
|
public function registernumber(Request $request) {
|
|
$attrs = $request->validate([
|
|
'mob_number' => 'required',
|
|
]);
|
|
|
|
$result = User::where("mob_number", $attrs['mob_number'])->exists();
|
|
if ($result) {
|
|
$isverified = User::where('mob_number', $attrs['mob_number'])->value('is_verify');
|
|
if ($isverified) {
|
|
return response([
|
|
'message' => "Number already exist"
|
|
], 201);
|
|
} else {
|
|
$number = User::where('mob_number', $request['mob_number'],)->first();
|
|
return response([
|
|
'token' => $number->createToken('secret')->plainTextToken
|
|
], 200);
|
|
}
|
|
} else {
|
|
|
|
$user = User::create([
|
|
'mob_number' => $attrs['mob_number'],
|
|
]);
|
|
return response([
|
|
'user' => $user,
|
|
'token' => $user->createToken('secret')->plainTextToken
|
|
], 200);
|
|
}
|
|
}
|
|
|
|
public function userRegistration(Request $request) {
|
|
$attrs = $request->validate([
|
|
'full_name' => 'required|string',
|
|
'email' => 'required|email',
|
|
'password' => 'required|min:6',
|
|
]);
|
|
$id = auth()->user()->id;
|
|
//create user
|
|
$user = User::where('id', $id)->update([
|
|
'full_name' => $attrs['full_name'],
|
|
'email' => $attrs['email'],
|
|
'password' => bcrypt($attrs['password']),
|
|
]);
|
|
|
|
// User::where('id', $id)->update(['is_verify' => 1]);
|
|
$email = DB::table('users')->where('id', '=', $id)->pluck('email');
|
|
$mobno = DB::table('users')->where('id', '=', $id)->pluck('mob_number');
|
|
$fullname = DB::table('users')->where('id', '=', $id)->pluck('full_name');
|
|
$this->sendmail($attrs['email'], $attrs['full_name'],);
|
|
//return user & token in response
|
|
return response()->json([
|
|
'email' => $email,
|
|
'number' => $mobno,
|
|
'fullname' => $fullname
|
|
]);
|
|
}
|
|
|
|
// get user details
|
|
public function user() {
|
|
return response([
|
|
'user' => auth()->user()
|
|
], 200);
|
|
}
|
|
|
|
public function sendmail($enteredemail, $fullname) {
|
|
$email = new \SendGrid\Mail\Mail();
|
|
$email->setFrom("info@piadvisors.in", "Pi Advisor");
|
|
$email->setSubject("Welcome");
|
|
$email->addTo($enteredemail, $fullname);
|
|
// $email->addContent("text/plain", "and easy to do anywhere, even with PHP");
|
|
$email->addContent(
|
|
"text/html", "<strong>This is Test Email </strong>"
|
|
);
|
|
$sendgrid = new \SendGrid("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");
|
|
try {
|
|
$response = $sendgrid->send($email);
|
|
// print $response->statusCode() . "\n";
|
|
// print_r($response->headers());
|
|
// print $response->body() . "\n";
|
|
} catch (Exception $e) {
|
|
echo 'Caught exception: ' . $e->getMessage() . "\n";
|
|
}
|
|
}
|
|
|
|
public function logout(Request $request) {
|
|
|
|
$request->user()->currentAccessToken()->delete();
|
|
return response()->json(['done' => true]);
|
|
}
|
|
|
|
public function sendsms(Request $request) {
|
|
|
|
$randomNumber = random_int(1000, 9999);
|
|
// print($randomNumber);
|
|
$userotp = new userotp();
|
|
$userotp->OTP = $randomNumber;
|
|
|
|
$mobile = $request->input('mob_number');
|
|
$id = User::where('mob_number', $mobile)->value('id');
|
|
|
|
$userobj = new User();
|
|
$userobj->id = $id;
|
|
|
|
$userobj->userotp()->save($userotp);
|
|
|
|
User::where('id', $id)->update(array('generated_otp' => $randomNumber));
|
|
|
|
$smstext = rawurlencode("Welcome to Investmentinbonds.com. Your One Time Password is $randomNumber -From Team of BON4EQUI");
|
|
$data = $this->localSMS($mobile, $smstext);
|
|
// $this->localsendsms();
|
|
if ($data) {
|
|
return response([
|
|
'status' => 'success',
|
|
'mobile_number' => $mobile,
|
|
], 200);
|
|
}
|
|
}
|
|
|
|
public function localsendsms($authId = null) {
|
|
|
|
|
|
$post_data = array(
|
|
'From' => '08047362550',
|
|
'To' => '09158874404',
|
|
'Body' => 'This is a test message powered by Exotel. Report abuse to +918088919888 -Exotel',
|
|
);
|
|
$api_key = "8ddf80e302d337c5fbc778dc6600eaf82e4cc1fc2846631f";
|
|
$api_token = "eac28164088558dcf855c66c5854ab644a9a334a3b6ff45d";
|
|
$exotel_sid = "supermoneyadvisors1";
|
|
#Replace <subdomain> with the region of your account
|
|
#<subdomain> of Singapore cluster is @api.exotel.com
|
|
#<subdomain> of Mumbai cluster is @api.in.exotel.com
|
|
$url = "https://" . $api_key . ":" . $api_token . "@api.in.exotel.in/v1/Accounts/" . $exotel_sid . "/Sms/send";
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_VERBOSE, 1);
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
|
|
$http_result = curl_exec($ch);
|
|
curl_close($ch);
|
|
print "Response = " . print_r($http_result);
|
|
}
|
|
|
|
public function localSMS($mobile, $smstext) {
|
|
|
|
$minuts = 30;
|
|
|
|
$url = "http://mobicomm.dove-sms.com//submitsms.jsp?user=Bon4equi&key=1a70c42b9bXX&mobile=+91" . $mobile . "&message=" . $smstext . "&senderid=BONEQU&accusage=1";
|
|
// Send the GET request with cURL to send SMS
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
$response = curl_exec($ch);
|
|
curl_close($ch);
|
|
// print($response);
|
|
return 1;
|
|
}
|
|
|
|
public function isverified() {
|
|
$userId = auth()->user()->id;
|
|
// $isverified = User::find($userId)->value('is_verify');
|
|
$isverified = User::where('id', $userId)->value('is_verify');
|
|
return response()->json([
|
|
'isVerified' => $isverified
|
|
]);
|
|
}
|
|
|
|
public function mobileExists(Request $request) {
|
|
|
|
$mobexist = User::where('mob_number', $request->number)->exists();
|
|
|
|
if ($mobexist) {
|
|
return response()->json([
|
|
'status' => "success",
|
|
'mob_exists' => 1
|
|
]);
|
|
} else {
|
|
return response()->json([
|
|
'status' => 'error',
|
|
'mob_exists' => 0
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function resetPassword(Request $request) {
|
|
$user = User::where('mob_number', $request->number)->update(['password' => bcrypt($request->password)]);
|
|
|
|
return response()->json([
|
|
'data' => $user
|
|
]);
|
|
}
|
|
|
|
public function getFingerPrintStatus() {
|
|
$userId = auth()->user()->id;
|
|
//$is_securityquestion = User::find($userId)->value('is_securityquestion');
|
|
$is_fingerprint = User::where('id', $userId)->value('isTouchIdEnable');
|
|
return response()->json([
|
|
'is_fignerprint' => $is_fingerprint
|
|
]);
|
|
}
|
|
|
|
public function postFingerPrintStatus() {
|
|
$userId = auth()->user()->id;
|
|
$data = User::where('id', $userId)->update(['isTouchIdEnable' => 1]);
|
|
return response([
|
|
'status' => 'success',
|
|
'user' => $data,
|
|
], 200);
|
|
}
|
|
|
|
public function check_pin_exist() {
|
|
$userId = auth()->user()->id;
|
|
// $pinexist = User::find($userId)->value('user_pin');
|
|
$pinexist = User::where('id', $userId)->value('user_pin');
|
|
if ($pinexist) {
|
|
return response()->json([
|
|
'pin_exists' => 1
|
|
]);
|
|
} else {
|
|
return response()->json([
|
|
'pin_exists' => 0
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function pin_match(Request $request) {
|
|
|
|
$userId = auth()->user()->id;
|
|
$attrs = $request->validate([
|
|
'pin' => 'required',
|
|
]);
|
|
$existingPin = User::where('id', $userId)->value('user_pin');
|
|
|
|
if ($existingPin == $attrs['pin']) {
|
|
return response()->json([
|
|
'status' => 'success',
|
|
'pin_matched' => 1
|
|
], 200);
|
|
} else {
|
|
return response()->json([
|
|
'status' => 'Pin does not match',
|
|
'pin_matched' => 0
|
|
], 201);
|
|
}
|
|
}
|
|
|
|
public function verifyotp(Request $request) {
|
|
$OTP = auth()->user()->generated_otp;
|
|
$userId = auth()->user()->id;
|
|
$userExist = User::find($userId);
|
|
|
|
$enteredOtp = $request->input('otp');
|
|
|
|
if ($OTP == $enteredOtp) {
|
|
if ($userExist) {
|
|
$userExist->generated_otp = null;
|
|
$userExist->save();
|
|
}
|
|
User::where('id', $userId)->update(['is_otpverify' => 1]);
|
|
|
|
return response()->json([
|
|
'error' => 0,
|
|
'is_otpverify' => 1,
|
|
'message' => "Your Number is Verified."
|
|
]);
|
|
} else {
|
|
return response()->json([
|
|
'error' => 1,
|
|
'message' => "OTP does not match."
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function verifyotpWithoutToken(Request $request) {
|
|
$mobileno = $request->input('mob_number');
|
|
$userId = User::where('mob_number', $mobileno)->value('id');
|
|
|
|
$OTP = userotp::where('user_id', $userId)->value('OTP');
|
|
$userotpId = userotp::where('user_id', $userId)->value('id');
|
|
$userExist = userotp::find($userotpId);
|
|
|
|
$enteredOtp = $request->input('otp');
|
|
|
|
if ($OTP == $enteredOtp) {
|
|
if ($userExist) {
|
|
// $userExist->OTP = null;
|
|
// $userExist->OTPFor = 0;
|
|
$userExist->delete();
|
|
}
|
|
return response()->json([
|
|
'error' => 0,
|
|
'message' => "Your Number is Verified."
|
|
]);
|
|
} else {
|
|
return response()->json([
|
|
'error' => 1,
|
|
'message' => "OTP does not match."
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function login(Request $request) {
|
|
// $this->validateLogin($request);
|
|
|
|
if ($this->attemptLogin($request)) {
|
|
|
|
return $this->successfulLogin($request);
|
|
}
|
|
return $this->failedLogin($request);
|
|
}
|
|
|
|
protected function validateLogin(Request $request) {
|
|
// $this->validate($request, [
|
|
// 'username' => 'required',
|
|
// 'password' => 'required',
|
|
// ]);
|
|
}
|
|
|
|
/**
|
|
* Attempt to log the user into the application.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return bool
|
|
*/
|
|
protected function attemptLogin(Request $request) {
|
|
//Try with email AND username fields
|
|
if (Auth::attempt([
|
|
'email' => $request['email'],
|
|
'password' => $request['password']
|
|
]) || Auth::attempt([
|
|
'mob_number' => $request['number'],
|
|
'password' => $request['password']
|
|
])) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
protected function successfulLogin(Request $request) {
|
|
$user = User::where('email', $request['email'],)->first();
|
|
$number = User::where('mob_number', $request['number'],)->first();
|
|
$loginauditobj = new UserLoginAudit();
|
|
$loginauditobj->isLoginSuccess = 1;
|
|
$user->userUserLoginAudit()->save($loginauditobj);
|
|
if (is_null($user)) {
|
|
return response([
|
|
'email' => $number['email'],
|
|
'number' => $number['mob_number'],
|
|
'fullname' => $number['full_name'],
|
|
'token' => $number->createToken('secret')->plainTextToken
|
|
], 200);
|
|
} else {
|
|
return response([
|
|
'email' => $user ['email'],
|
|
'number' => $user['mob_number'],
|
|
'fullname' => $user['full_name'],
|
|
'token' => $user->createToken('secret')->plainTextToken
|
|
], 200);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This is executed when the user fails to log in
|
|
*
|
|
* @var Request $request
|
|
* @return Reponse
|
|
*/
|
|
protected function failedLogin(Request $request) {
|
|
|
|
return response([
|
|
'message' => 'Invalid credentials.'
|
|
], 403);
|
|
}
|
|
|
|
public function security_answers(Request $request) {
|
|
|
|
$attrs = $request->validate([
|
|
'question_id_answers' => 'required',
|
|
]);
|
|
|
|
$userid = auth()->user()->id;
|
|
|
|
$input = [
|
|
'user_id' => $userid,
|
|
'question_id_answers' => $attrs['question_id_answers']
|
|
];
|
|
$data = user_security_answer::create($input);
|
|
// $data = user_security_answer::create([
|
|
// 'user_id' => $userid,
|
|
// 'question_id' => $attrs['question_id'],
|
|
// 'answer' => $attrs['answer'],
|
|
// ]);
|
|
User::where('id', $userid)->update(['is_securityquestion' => 1]);
|
|
return response([
|
|
'status' => 'success',
|
|
'user' => $data,
|
|
], 200);
|
|
}
|
|
|
|
public function resetPin() {
|
|
$userId = auth()->user()->id;
|
|
|
|
$mobile = User::where('id', $userId)->value('mob_number');
|
|
$randomNumber = random_int(1000, 9999);
|
|
//print($randomNumber);
|
|
User::where('id', $userId)->update(array('generated_otp' => $randomNumber));
|
|
|
|
$smstext = rawurlencode("Welcome to Investmentinbonds.com. Your One Time Password is $randomNumber -From Team of BON4EQUI");
|
|
$data = $this->localSMS($mobile, $smstext);
|
|
|
|
return response([
|
|
'status' => "success",
|
|
'mobile_number' => $mobile
|
|
], 200);
|
|
}
|
|
|
|
public function userforgotpasswordpin(Request $request) {
|
|
$userid = auth()->user()->id;
|
|
try {
|
|
$userforgotpasswordpin = new UserForgotPasswordPin();
|
|
$userforgotpasswordpin->oldPasswordPin = $request->oldPasswordPin;
|
|
$userforgotpasswordpin->newPasswordPin = $request->newPasswordPin;
|
|
$userobj = new User();
|
|
$userobj->id = $userid;
|
|
$userobj->userforgotpasswordpin()->save($userforgotpasswordpin);
|
|
User::where('id', $userid)->update([
|
|
'user_pin' => $request->newPasswordPin
|
|
]);
|
|
} catch (Exception $ex) {
|
|
return response([
|
|
'status' => "failed",
|
|
// 'token' => $user->createToken('secret')->plainTextToken
|
|
], 500);
|
|
}
|
|
return response([
|
|
'status' => "success",
|
|
// 'token' => $user->createToken('secret')->plainTextToken
|
|
], 200);
|
|
}
|
|
|
|
public function storeKycDetails(Request $req) {
|
|
$userid = auth()->user()->id;
|
|
$result = KycDetailedStatus::where("user_id", $userid)->exists();
|
|
if ($result) {
|
|
KycDetailedStatus::where('id', $userid)->update([
|
|
'requestID' => $req->requestid,
|
|
'status' => $req->status,
|
|
'customer_identifier' => $req->customer_identifier,
|
|
'transaction_id' => $req->transaction_id,
|
|
'reference_id' => $req->reference_id,
|
|
'customer_name' => $req->customer_name,
|
|
'expire_in_days' => $req->expire_in_days,
|
|
]);
|
|
} else {
|
|
$kycobj = new KycDetailedStatus ();
|
|
$kycobj->user_id = $userid;
|
|
$kycobj->requestID = $req->requestid;
|
|
$kycobj->status = $req->status;
|
|
$kycobj->customer_identifier = $req->customer_identifier;
|
|
$kycobj->reference_id = $req->reference_id;
|
|
$kycobj->transaction_id = $req->transaction_id;
|
|
$kycobj->customer_name = $req->customer_name;
|
|
$kycobj->expire_in_days = $req->expire_in_days;
|
|
$userobj = User::find($userid);
|
|
$userobj->KycDetailedStatus()->save($kycobj);
|
|
}
|
|
}
|
|
|
|
public function fetchKYCstatus() {
|
|
try {
|
|
$userid = auth()->user()->id;
|
|
// $kycstatus = DB::table('kyc_detailed_statuses')->orderBy('status', 'DESC')->first();
|
|
$kycstatus = KycDetailedStatus::where('id', $userid)->latest()->first();
|
|
|
|
return response([
|
|
'status' => $kycstatus,
|
|
], 200);
|
|
} catch (Exception $ex) {
|
|
return response([
|
|
'status' => "failed",
|
|
], 500);
|
|
}
|
|
}
|
|
|
|
public function storeBankDetails(Request $req) {
|
|
$userid = auth()->user()->id;
|
|
$result = BankDetails::where("user_id", $userid)->exists();
|
|
if ($result) {
|
|
BankDetails::where('id', $userid)->update([
|
|
'bankName' => $req->bankName,
|
|
'accountHolderName' => $req->accountHolderName,
|
|
'accountNumber' => $req->accountNumber,
|
|
'IFSC' => $req->IFSC
|
|
]);
|
|
} else {
|
|
try {
|
|
|
|
$bankobj = new BankDetails();
|
|
$bankobj->bankName = $req->bankName;
|
|
$bankobj->accountHolderName = $req->accountHolderName;
|
|
$bankobj->accountNumber = $req->accountNumber;
|
|
$bankobj->IFSC = $req->IFSC;
|
|
$userobj = User::find($userid);
|
|
$userobj->BankDetails()->save($bankobj);
|
|
// if ($kycstatus == "requested") {
|
|
//
|
|
// } else if ($kycstatus == "approval_pending") {
|
|
//
|
|
// } else if ($kycstatus == "requested") {
|
|
//
|
|
// }
|
|
return response([
|
|
'status' => "success",
|
|
], 200);
|
|
} catch (Exception $ex) {
|
|
return response([
|
|
'status' => "failed",
|
|
], 500);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getBankDetails() {
|
|
try {
|
|
$userid = auth()->user()->id;
|
|
$data = BankDetails::where('user_id', $userid,)->first();
|
|
|
|
return response([
|
|
'user' => $data,
|
|
// 'token' => $user->createToken('secret')->plainTextToken
|
|
], 200);
|
|
} catch (Exception $ex) {
|
|
return response([
|
|
'status' => "failed",
|
|
], 500);
|
|
}
|
|
}
|
|
|
|
public function storeBasicKycUserDetails(Request $req) {
|
|
$userid = auth()->user()->id;
|
|
$result = kycuserdetail::where("user_id", $userid)->exists();
|
|
$kyctableid = kycuserdetail::where('user_id', $userid,)->value('id');
|
|
|
|
if ($result) {
|
|
kycuserdetail::where('id', $kyctableid)->update([
|
|
'firstName' => $req->firstName,
|
|
'lastName' => $req->lastName,
|
|
'address' => $req->address,
|
|
'email' => $req->email,
|
|
'DOB' => $req->DOB,
|
|
'mob_number' => $req->mob_number,
|
|
'age' => $req->age,
|
|
'occupation' => $req->occupation,
|
|
'gender' => $req->gender,
|
|
'residential_status' => $req->residential_status,
|
|
'life_expectancy' => $req->life_expectancy,
|
|
]);
|
|
} else {
|
|
$kycobj = new kycuserdetail();
|
|
$kycobj->user_id = $userid;
|
|
$kycobj->firstName = $req->firstName;
|
|
$kycobj->lastName = $req->lastName;
|
|
$kycobj->address = $req->address;
|
|
$kycobj->email = $req->email;
|
|
$kycobj->pan_number = $req->pan_number;
|
|
$kycobj->DOB = $req->DOB;
|
|
$kycobj->mob_number = $req->mob_number;
|
|
$kycobj->age = $req->age;
|
|
$kycobj->occupation = $req->occupation;
|
|
$kycobj->gender = $req->gender;
|
|
$kycobj->residential_status = $req->residential_status;
|
|
$kycobj->life_expectancy = $req->life_expectancy;
|
|
$userobj = User::find($userid);
|
|
$userobj->kycuserdetail()->save($kycobj);
|
|
}
|
|
}
|
|
|
|
public function getBasicKycUserDetails() {
|
|
$userid = auth()->user()->id;
|
|
$data = kycuserdetail::where('user_id', $userid,)->first();
|
|
|
|
return response([
|
|
'user' => $data,
|
|
// 'token' => $user->createToken('secret')->plainTextToken
|
|
], 200);
|
|
}
|
|
|
|
public function storePersonalProfileDetails(Request $req) {
|
|
$userid = auth()->user()->id;
|
|
$result = personalprofile::where("user_id", $userid)->exists();
|
|
$kyctableid = personalprofile::where('user_id', $userid,)->value('id');
|
|
|
|
if ($result) {
|
|
personalprofile::where('id', $kyctableid)->update([
|
|
'fullname' => $req->fullname,
|
|
'mob_number' => $req->mob_number,
|
|
'email_id' => $req->email_id,
|
|
'dob' => $req->dob,
|
|
'occupation' => $req->occupation,
|
|
'address' => $req->address,
|
|
'city' => $req->city,
|
|
'state' => $req->state,
|
|
'pincode' => $req->pincode,
|
|
'aadhar_number' => $req->aadhar_number,
|
|
'pan_number' => $req->pan_number,
|
|
]);
|
|
} else {
|
|
$personalobj = new personalprofile();
|
|
$personalobj->user_id = $userid;
|
|
$personalobj->fullname = $req->fullname;
|
|
$personalobj->mob_number = $req->mob_number;
|
|
$personalobj->email_id = $req->email_id;
|
|
$personalobj->dob = $req->dob;
|
|
$personalobj->occupation = $req->occupation;
|
|
$personalobj->address = $req->address;
|
|
$personalobj->city = $req->city;
|
|
$personalobj->state = $req->state;
|
|
$personalobj->pincode = $req->pincode;
|
|
$personalobj->aadhar_number = $req->aadhar_number;
|
|
$personalobj->pan_number = $req->pan_number;
|
|
|
|
$userobj = User::find($userid);
|
|
$userobj->personalprofile()->save($personalobj);
|
|
}
|
|
}
|
|
|
|
public function getPersonalProfileDetails() {
|
|
$userid = auth()->user()->id;
|
|
$data = personalprofile::where('user_id', $userid,)->first();
|
|
|
|
return response([
|
|
'user' => $data,
|
|
// 'token' => $user->createToken('secret')->plainTextToken
|
|
], 200);
|
|
}
|
|
|
|
public function storeFamilyDetails(Request $req) {
|
|
$userid = auth()->user()->id;
|
|
$result = familydetail::where("user_id", $userid)->exists();
|
|
$kyctableid = familydetail::where('user_id', $userid,)->value('id');
|
|
|
|
if ($result) {
|
|
familydetail::where('id', $kyctableid)->update([
|
|
'Fathers_name' => $req->Fathers_name,
|
|
'fathers_occupation' => $req->fathers_occupation,
|
|
'fathers_dob' => $req->fathers_dob,
|
|
'fathers_age' => $req->fathers_age,
|
|
'Mothers_name' => $req->Mothers_name,
|
|
'mothers_occupation' => $req->mothers_occupation,
|
|
'mothers_age' => $req->mothers_age,
|
|
'mothers_dob' => $req->mothers_dob,
|
|
'Husband_wife_name' => $req->Husband_wife_name,
|
|
'Husband_wife_occupation' => $req->Husband_wife_occupation,
|
|
'Husband_wife_dob' => $req->Husband_wife_dob,
|
|
'Husband_wife_age' => $req->Husband_wife_age,
|
|
'children' => $req->children,
|
|
]);
|
|
} else {
|
|
$personalobj = new familydetail();
|
|
$personalobj->user_id = $userid;
|
|
$personalobj->Fathers_name = $req->Fathers_name;
|
|
$personalobj->fathers_occupation = $req->fathers_occupation;
|
|
$personalobj->fathers_dob = $req->fathers_dob;
|
|
$personalobj->fathers_age = $req->fathers_age;
|
|
$personalobj->Mothers_name = $req->Mothers_name;
|
|
$personalobj->mothers_occupation = $req->mothers_occupation;
|
|
$personalobj->mothers_age = $req->mothers_age;
|
|
$personalobj->mothers_dob = $req->mothers_dob;
|
|
$personalobj->Husband_wife_name = $req->Husband_wife_name;
|
|
$personalobj->Husband_wife_occupation = $req->Husband_wife_occupation;
|
|
$personalobj->Husband_wife_dob = $req->Husband_wife_dob;
|
|
$personalobj->Husband_wife_age = $req->Husband_wife_age;
|
|
$personalobj->children = $req->children;
|
|
$userobj = User::find($userid);
|
|
$userobj->familydetail()->save($personalobj);
|
|
}
|
|
}
|
|
|
|
public function getFamilyDetails() {
|
|
$userid = auth()->user()->id;
|
|
$data = familydetail::where('user_id', $userid,)->first();
|
|
|
|
return response([
|
|
'user' => $data,
|
|
// 'token' => $user->createToken('secret')->plainTextToken
|
|
], 200);
|
|
}
|
|
|
|
public function storeGoals(Request $req) {
|
|
$userid = auth()->user()->id;
|
|
$personalobj = new GoalTracker();
|
|
$personalobj->user_id = $userid;
|
|
$personalobj->type = $req->type;
|
|
$personalobj->amount = $req->amount;
|
|
$personalobj->duration = $req->duration;
|
|
|
|
$userobj = User::find($userid);
|
|
$userobj->GoalTracker()->save($personalobj);
|
|
}
|
|
|
|
public function user_pin(Request $request) {
|
|
|
|
$attrs = $request->validate([
|
|
'user_pin' => 'required',
|
|
]);
|
|
$userid = auth()->user()->id;
|
|
|
|
$data = User::where('id', $userid)->update([
|
|
'user_pin' => $attrs['user_pin'],
|
|
]);
|
|
return response([
|
|
'user' => $data,
|
|
// 'token' => $user->createToken('secret')->plainTextToken
|
|
], 200);
|
|
}
|
|
|
|
public function createorder(Request $request) {
|
|
$amount = $request->input('amount');
|
|
$api = new Api("rzp_test_ryPoiSUUJmfLXB", "wtLBbDf43iYaW84MQJSkKWfT");
|
|
$randomnumber = rand(100, 999);
|
|
$recepitno = "receipt_no $randomnumber";
|
|
$data = $api->order->create(['receipt' => $recepitno, 'amount' => $amount, 'currency' => 'INR']);
|
|
$text = json_encode($data->toArray());
|
|
$obj = json_decode($text);
|
|
|
|
return response()->json([
|
|
'data' => $obj,
|
|
], 200);
|
|
}
|
|
|
|
public function payment_verification(Request $request) {
|
|
$orderID = $request->input('orderID');
|
|
$paymentID = $request->input('paymentID');
|
|
$signature = $request->input('signature');
|
|
|
|
$generated_signature = hash_hmac('sha256', $orderID . "|" . $paymentID, "wtLBbDf43iYaW84MQJSkKWfT");
|
|
if ($generated_signature == $signature) {
|
|
return response()->json([
|
|
'data' => "success",
|
|
], 200);
|
|
} else {
|
|
return response()->json([
|
|
'data' => "failed",
|
|
], 200);
|
|
}
|
|
}
|
|
|
|
public function storeTransactionDetails(Request $request) {
|
|
//auth()->user()->id;
|
|
$paymentId = $request->input('paymentId');
|
|
$amount = $request->input('amount');
|
|
$currency = $request->input('currency');
|
|
|
|
try {
|
|
$userobj = User::find(2);
|
|
$subsobj = Subscription::find(3);
|
|
$transactionobj = new \App\Models\Transaction();
|
|
$transactionobj->paymentId = $request->paymentId;
|
|
$transactionobj->amount = $request->amount;
|
|
$transactionobj->currency = $request->currency;
|
|
$transactionobj->status = $request->status;
|
|
$transactionobj->order_id = $request->order_id;
|
|
$transactionobj->invoice_id = $request->invoice_id;
|
|
$transactionobj->payment_method = $request->payment_method;
|
|
$transactionobj->amount_refunded = $request->amount_refunded;
|
|
$transactionobj->refund_status = $request->refund_status;
|
|
$transactionobj->captured = $request->captured;
|
|
$transactionobj->description = $request->description;
|
|
$transactionobj->bank = $request->bank;
|
|
$transactionobj->wallet = $request->wallet;
|
|
$transactionobj->vpa = $request->vpa;
|
|
$transactionobj->error_code = $request->error_code;
|
|
$transactionobj->error_description = $request->error_description;
|
|
$transactionobj->error_source = $request->error_source;
|
|
$transactionobj->error_step = $request->error_step;
|
|
$transactionobj->error_reason = $request->error_reason;
|
|
$transactionobj->isSuccess = $request->isSuccess;
|
|
$transactionobj->reason = $request->reason;
|
|
|
|
$transactionobj->User()->associate($userobj)->save();
|
|
$transactionobj->Subscription()->associate($subsobj)->save();
|
|
return response()->json([
|
|
'data' => "success",
|
|
], 200);
|
|
} catch (Exception $ex) {
|
|
return response()->json([
|
|
'data' => "failed",
|
|
], 200);
|
|
}
|
|
}
|
|
|
|
public function createPlans(Request $request) {
|
|
try {
|
|
$planobj = new Plan();
|
|
$planobj->planName = $request->planName;
|
|
$planobj->description = $request->description;
|
|
$planobj->amount = $request->amount;
|
|
$planobj->PlanValidity = $request->PlanValidity;
|
|
$planobj->isActive = $request->isActive;
|
|
// $adminobj = new AdminUser();
|
|
// $adminobj->id = 2;
|
|
$adminobj = AdminUser::find(2);
|
|
$adminobj->Plan()->save($planobj);
|
|
return response([
|
|
'status' => "success",
|
|
// 'token' => $user->createToken('secret')->plainTextToken
|
|
], 200);
|
|
} catch (Exception $ex) {
|
|
return response([
|
|
'status' => "failed",
|
|
// 'token' => $user->createToken('secret')->plainTextToken
|
|
], 500);
|
|
}
|
|
}
|
|
|
|
public function storeSubscriptionPlan(Request $req) {
|
|
try {
|
|
//$userid = auth()->user()->id;
|
|
$subsobj = new Subscription();
|
|
|
|
$current = Carbon::now();
|
|
|
|
$planExpires = $current->addMonths(12);
|
|
$userobj = User::find(2);
|
|
$planobj = Plan::find(3);
|
|
$subsobj->planEndDate = $planExpires;
|
|
$subsobj->Plan()->associate($planobj)->save();
|
|
$subsobj->User()->associate($userobj)->save();
|
|
return response([
|
|
'status' => "success",
|
|
// 'token' => $user->createToken('secret')->plainTextToken
|
|
], 200);
|
|
} catch (Exception $ex) {
|
|
return response([
|
|
'status' => "failed",
|
|
// 'token' => $user->createToken('secret')->plainTextToken
|
|
], 500);
|
|
}
|
|
}
|
|
|
|
public function getSubscriptionWithDetails() {
|
|
return Subscription::find(1)->with('plan')->get();
|
|
}
|
|
|
|
public function password_reset(Request $request) {
|
|
$userid = auth()->user()->id;
|
|
$useremail = User::where('id', $userid,)->value('email');
|
|
//$password = $request->currentPassword;
|
|
if (Auth::attempt([
|
|
'email' => $useremail,
|
|
'password' => $request['password']
|
|
])) {
|
|
$attrs = $request->validate([
|
|
'new_password' => 'required',
|
|
]);
|
|
|
|
$data = User::where('id', $userid)->update([
|
|
'password' => $attrs['new_password'],
|
|
]);
|
|
return response([
|
|
'status' => "success",
|
|
// 'token' => $user->createToken('secret')->plainTextToken
|
|
], 200);
|
|
} else {
|
|
return response([
|
|
'status' => "failed",
|
|
// 'token' => $user->createToken('secret')->plainTextToken
|
|
], 500);
|
|
}
|
|
}
|
|
|
|
}
|