458 lines
16 KiB
PHP
458 lines
16 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
use App\Libraries\CywareLibrary;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Helpers\HttpStatusCode;
|
|
use App\Libraries\ParameterHelper;
|
|
use App\Http\Requests\MobileSignupFormValidation;
|
|
use App\Http\Requests\MobileSignupIDNumberValidation;
|
|
use App\Http\Resources\MobileUserProfileResource;
|
|
use App\Contracts\LoyaltyCardResourceInterface;
|
|
use App\Contracts\CardTypeResourceInterface;
|
|
use App\Contracts\PersonalDetailsResourceInterface;
|
|
use App\Contracts\UserResourceInterface;
|
|
use App\Contracts\MobileAnalyticsResourceInterface;
|
|
use App\Contracts\LcardActionLogsInterface;
|
|
use App\Contracts\SignUpAPICallsInterface;
|
|
use App\Http\Resources\LoyaltyCardSignUpResource;
|
|
use App\Http\Resources\LoyaltyCardSignUpCMSResource;
|
|
use App\Libraries\StaticContents;
|
|
|
|
|
|
use PHPMailer\PHPMailer\PHPMailer;
|
|
use PHPMailer\PHPMailer\Exception;
|
|
|
|
class SignUpController extends Controller
|
|
{
|
|
const MODULE = 'SIGNUP';
|
|
|
|
protected $format;
|
|
|
|
protected $module;
|
|
|
|
protected $model;
|
|
|
|
protected $loyaltyCard;
|
|
|
|
protected $cardtype;
|
|
|
|
protected $personalDetails;
|
|
|
|
protected $user;
|
|
|
|
protected $mobile_usage;
|
|
|
|
protected $signupAPICalls;
|
|
|
|
public function __construct(LoyaltyCardResourceInterface $loyaltyCard,
|
|
HttpStatusCode $httpStatusCode,
|
|
CardTypeResourceInterface $cardtype,
|
|
PersonalDetailsResourceInterface $personalDetails,
|
|
UserResourceInterface $user,
|
|
MobileAnalyticsResourceInterface $mobile_usage,
|
|
LcardActionLogsInterface $lcard_logs,
|
|
SignUpAPICallsInterface $signupAPICalls)
|
|
{
|
|
$this->loyaltyCard = $loyaltyCard;
|
|
$this->cardtype = $cardtype;
|
|
$this->personalDetails = $personalDetails;
|
|
$this->mobile_usage = $mobile_usage;
|
|
$this->user = $user;
|
|
$this->lcard_logs = $lcard_logs;
|
|
$this->signupAPICalls = $signupAPICalls;
|
|
$this->format = $httpStatusCode;
|
|
$this->module = "SignUp";
|
|
$this->model = "LoyaltyCardSignUp";
|
|
}
|
|
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
|
|
/*
|
|
NOTE: THIS FEATURE IS FROM THE INITIAL PLAN FOR CR1
|
|
*/
|
|
// public function index(Request $request)
|
|
// {
|
|
// $params = [
|
|
// 'search' => ($request->has('_search') ? $request->get('_search') : NULL),
|
|
// 'page_size' => ($request->has('page_size') ? $request->get('page_size') : 10),
|
|
// 'page' => ($request->has('page') ? $request->get('page') : 10),
|
|
// 'sorting' => ParameterHelper::prepareSortingParameter($request),
|
|
// 'status' => ($request->has('status') ? $request->status : NULL),
|
|
// ];
|
|
|
|
// if(count($params['status']))
|
|
// {
|
|
// foreach ($params['status'] as $key => $value) {
|
|
// $params['status'][$key] = StaticContents::loyalty_card_signup_status($value,true);
|
|
// }
|
|
// }
|
|
|
|
// $list = $this->signup->listing($params);
|
|
|
|
// // dd($list);
|
|
|
|
// if(count($list))
|
|
// {
|
|
// $additionals = $this->format->success("Success",[],false);
|
|
// $data = LoyaltyCardSignUpCMSResource::collection($list)->additional($additionals);
|
|
// return $data->response()->setStatusCode(200);
|
|
// }
|
|
// else
|
|
// {
|
|
// return $this->format->success("No records found",[]);
|
|
// }
|
|
// }
|
|
|
|
public function check_id_number(MobileSignupIDNumberValidation $request)
|
|
{
|
|
$card_details = $this->cardtype->getByField(['cardtype_uuid' => $request->cardtype_uuid]);
|
|
|
|
if(count($card_details) > 0)
|
|
{
|
|
$card_details = $card_details[0];
|
|
if($card_details->id_number == 1)
|
|
{
|
|
$cyware = new CywareLibrary();
|
|
$cyware->setCardTypeCode($card_details->code);
|
|
$cyware->setIDNumber($request->id_number);
|
|
$cyware->state_id_entry();
|
|
|
|
if(isset($cyware->response['result']))
|
|
{
|
|
|
|
// NOTE : cyware returns sql:success for unused and used id numbers
|
|
|
|
if($cyware->response['status_code'] == "200" && $cyware->response['message'] == "success" && $cyware->response['result'] == "Valid ID Number")
|
|
{
|
|
return $this->format->mobile_success($cyware->response['result'],[]);
|
|
}
|
|
else
|
|
{
|
|
return $this->format->mobile_error($cyware->response['result'],[]);
|
|
}
|
|
}
|
|
else
|
|
return $this->format->mobile_error($cyware->response['message'],[]);
|
|
|
|
}
|
|
else
|
|
{
|
|
return $this->format->mobile_success('Card Type doesn\'t require ID Number');
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return $this->format->mobile_error('Card Type doesn\'t exists');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* Accessed by MOBILE
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
/*
|
|
NOTE: THIS FEATURE IS FROM THE INITIAL PLAN FOR CR1
|
|
*/
|
|
public function store(MobileSignupFormValidation $request)
|
|
{
|
|
$card_details = $this->cardtype->getByField(['cardtype_uuid' => $request->cardtype_uuid]);
|
|
if(count($card_details) > 0)
|
|
{
|
|
$card_details = $card_details[0];
|
|
$user_id = env("USER_ID_PRE_IDENTIFIER", '').date('Ymd').($this->signupAPICalls->count() + 1);
|
|
$signup_api_id = $this->signupAPICalls->log($user_id);
|
|
|
|
$cyware = new CywareLibrary();
|
|
$cyware->setCardTypeCode($card_details->code);
|
|
$cyware->setIDNumber($request->id_number);
|
|
$cyware->setFirstName($request->firstname);
|
|
$cyware->setLastName($request->lastname);
|
|
$cyware->setBirthday(date('Ymd',strtotime($request->birthdate)));
|
|
$mobile = strlen($request->mobile) == 12 ? $request->mobile : '63'.$request->mobile;
|
|
$cyware->setMobile($mobile);
|
|
$cyware->setEmail($request->email);
|
|
$cyware->setUserID($user_id);
|
|
$cyware->state_app_entry();
|
|
|
|
if($cyware->response['status_code'] == "200" && $cyware->response['message'] == "success")
|
|
{
|
|
// save on personal details
|
|
$pd_id = $this->personalDetails->store_signup($request);
|
|
|
|
// save on loyalty card
|
|
$lcard_det = $this->loyaltyCard->store_signup($pd_id,(object)[
|
|
'card_number' => $cyware->response['card_number'],
|
|
'pin' => $cyware->response['pin'],
|
|
'birthdate' => $request->birthdate,
|
|
'mobile' => $mobile,
|
|
'email' => $request->email,
|
|
'card_id' => $card_details->cardtype_id
|
|
]);
|
|
|
|
// log user in
|
|
$this->user->store_member((object)[
|
|
'first_name' => $request->firstname,
|
|
'last_name' => $request->lastname,
|
|
'card_number' => $cyware->response['card_number'],
|
|
'birthdate' => $request->birthdate,
|
|
]);
|
|
|
|
$this->mobile_usage->add_active();
|
|
$this->signupAPICalls->success($signup_api_id,$lcard_det['lcard_id']);
|
|
|
|
if(Auth::attempt([ 'username' => $cyware->response['card_number'], 'password' => $request->birthdate ]))
|
|
{
|
|
$getuserDetails = $this->loyaltyCard->show($lcard_det['lcard_uuid'],['personalDetails','codeVehicleOwn','codeCivilStatus','codeGender','codeCardType','codeCity','codeFuelType']);
|
|
$data = new MobileUserProfileResource($getuserDetails);
|
|
$userDetails = null;
|
|
if($data != null){
|
|
$userDetails = $data->toArray($getuserDetails);
|
|
|
|
}
|
|
|
|
$user = Auth::user();
|
|
$success['is_valid'] = 1;
|
|
// $success['lcard_uuid'] = $lcard_det['lcard_uuid'];
|
|
// $success['birthdate'] = $request->birthdate;
|
|
// $success['mobile'] = $request->mobile;
|
|
// $success['card_number'] = $cyware->response['card_number'];
|
|
// $success['user_id'] = $user['id'];
|
|
|
|
// ---------------------------------------------------------------- new login start
|
|
|
|
$data = [
|
|
'grant_type' => 'password',
|
|
'client_id' => env("PASSPORT_ADMIN_CLIENT_ID", 2),
|
|
'client_secret' => env("PASSPORT_ADMIN_CLIENT_SECRET", "test"),
|
|
'username' => $cyware->response['card_number'],
|
|
'password' => $request->birthdate,
|
|
'scope' => ''
|
|
];
|
|
|
|
$request = Request::create('/oauth/token', 'POST', $data);
|
|
$result = app()->handle($request)->getContent();
|
|
$result = json_decode($result);
|
|
|
|
$success['token'] = $result->access_token;
|
|
$userDetails['customer_number'] = $cyware->response['customer_number'];
|
|
$success['userDetails'] = $userDetails;
|
|
// ---------------------------------------------------------------- new login end
|
|
|
|
$this->lcard_logs->log($lcard_det['lcard_id'],'SIGNUP','LOGIN','Member successfully signs up');
|
|
return $this->format->mobile_success('Success',$success);
|
|
}
|
|
}
|
|
else
|
|
return $this->format->mobile_error($cyware->response['message']);
|
|
}
|
|
else
|
|
{
|
|
return $this->format->mobile_error('Card Type doesn\'t exists');
|
|
}
|
|
}
|
|
|
|
// public function store(MobileSignupFormValidation $request)
|
|
// {
|
|
// $uuid = $this->signup->store($request);
|
|
|
|
// return $this->format->mobile_success('Success',[
|
|
// 'lcard_s_uuid' => $uuid,
|
|
// ]);
|
|
// }
|
|
|
|
/*
|
|
NOTE: THIS FEATURE IS FROM THE INITIAL PLAN FOR CR1
|
|
*/
|
|
// public function upload(Request $request)
|
|
// {
|
|
// if($this->signup->upload_document($request))
|
|
// return $this->format->mobile_success('Successfully Updated');
|
|
// else
|
|
// return $this->format->mobile_errror('Something went wrong');
|
|
// }
|
|
|
|
/*
|
|
NOTE: THIS FEATURE IS FROM THE INITIAL PLAN FOR CR1
|
|
*/
|
|
// public function signupSubmit($uuid)
|
|
// {
|
|
// // check if there's already a reference number
|
|
// $details = $this->signup->getByField([
|
|
// 'lcard_s_uuid' => $uuid
|
|
// ]);
|
|
|
|
// if($details)
|
|
// {
|
|
// if($details[0]->ref_no == '')
|
|
// {
|
|
// // create reference number
|
|
// $count = $this->signup->count_between(date('Y-m-d 00:00:00'), date('Y-m-d 23:59:59'));
|
|
// $ref_no = 'REF-'.date('Ymd').'-'.str_pad($count, 5, "0", STR_PAD_LEFT);
|
|
|
|
|
|
// // send email to Super Admin -- TODO!
|
|
|
|
// if($this->signup->assign_ref_no($uuid,$ref_no))
|
|
// return $this->format->mobile_success('Success',['ref_no' => $ref_no]);
|
|
// else
|
|
// return $this->format->mobile_errror('Something went wrong');
|
|
// }
|
|
// else
|
|
// return $this->format->mobile_success('Success',['ref_no' => $details[0]->ref_no]);
|
|
// }
|
|
// else
|
|
// return $this->format->mobile_errror('User does not exists');
|
|
// }
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
|
|
/*
|
|
NOTE: THIS FEATURE IS FROM THE INITIAL PLAN FOR CR1
|
|
*/
|
|
// public function show($uuid)
|
|
// {
|
|
// $details = $this->signup->getByField(['lcard_s_uuid' => $uuid],['codeCardType','idNumberType']);
|
|
|
|
// if($details)
|
|
// {
|
|
// $additionals = $this->format->success("Success",[],false);
|
|
// $data = (new LoyaltyCardSignUpCMSResource($details[0]))->additional($additionals);
|
|
// return $data->response()->setStatusCode(200);
|
|
// }
|
|
// else
|
|
// return $this->format->notFound();
|
|
// }
|
|
|
|
/*
|
|
NOTE: THIS FEATURE IS FROM THE INITIAL PLAN FOR CR1
|
|
*/
|
|
// public function review($uuid)
|
|
// {
|
|
// $details = $this->signup->getByField(['lcard_s_uuid' => $uuid],['codeCardType','idNumberType']);
|
|
|
|
// if($details->count())
|
|
// {
|
|
// $additionals = $this->format->mobile_success("Success",[],false);
|
|
// $data = (new LoyaltyCardSignUpResource($details[0]))->additional($additionals);
|
|
// return $data->response()->setStatusCode(200);
|
|
// }
|
|
// else
|
|
// return $this->format->mobile_error('User not found');
|
|
// }
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/*
|
|
NOTE: THIS FEATURE IS FROM THE INITIAL PLAN FOR CR1
|
|
*/
|
|
// public function reject(Request $request)
|
|
// {
|
|
// // reject application
|
|
|
|
// // replace mark ups on SELECTED template
|
|
|
|
// // sms and email
|
|
// }
|
|
|
|
/*
|
|
NOTE: THIS FEATURE IS FROM THE INITIAL PLAN FOR CR1
|
|
*/
|
|
// public function approve($uuid)
|
|
// {
|
|
// // submit to cyware
|
|
|
|
// // if okay -- approve application
|
|
|
|
// // replace mark ups on FIXED approve template
|
|
|
|
// // sms and email
|
|
|
|
// // return token
|
|
// }
|
|
|
|
/*
|
|
NOTE: THIS FEATURE IS FROM THE INITIAL PLAN FOR CR1
|
|
*/
|
|
// public function test()
|
|
// {
|
|
// $mail = new PHPMailer(true);
|
|
|
|
// try {
|
|
|
|
// $mail->SMTPDebug = 2; // Enable verbose debug output
|
|
// $mail->isSMTP(); // Set mailer to use SMTP
|
|
// // $mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
|
|
// $mail->Host = 'smtp.gmail.com';
|
|
// $mail->SMTPAuth = true; // Enable SMTP authentication
|
|
// $mail->Username = 'yondutesting@gmail.com'; // SMTP username
|
|
// $mail->Password = 'myY0nduP@ssword01'; // SMTP password
|
|
// $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
|
|
// $mail->Port = 587; // TCP port to connect to
|
|
|
|
// }
|
|
|
|
// echo "here";
|
|
// }
|
|
|
|
}
|