unioil-loyalty-app/app/Http/Controllers/API/SharedTreatsController.php

99 lines
2.8 KiB
PHP
Executable File

<?php
namespace App\Http\Controllers\API;
use App\Contracts\LcardActionLogsInterface;
use App\Helpers\CurrentUserHelper;
use App\SharedTreats;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Uri;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Libraries\ParameterHelper;
use App\Helpers\HttpStatusCode;
use Illuminate\Support\Facades\Config;
class SharedTreatsController extends Controller
{
public $shared_treats;
public $admin_logs;
protected $format;
protected $url_encryption;
protected $url_gateway;
private $lcard_logs;
const MODULE = 'SHAREDTREATS';
public function __construct(HttpStatusCode $httpStatusCode, LcardActionLogsInterface $lcard_logs)
{
$this->format = $httpStatusCode;
$this->lcard_logs = $lcard_logs;
$this->module = "SharedTreats";
$this->model = "SharedTreats";
$this->url_encryption = Config::get('app.sharedtreatsEncryption');
$this->url_gateway = Config::get('app.sharedtreatsGateway');
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$return = [];
$member_details = CurrentUserHelper::get_currentMember();
if (empty($member_details->card_number)){
return $this->format->mobile_error('Something went wrong');
}
if (empty($member_details->mobile)){
return $this->format->mobile_error('Something went wrong');
}
if(!$this->checkMobileNumber($member_details->mobile)){
return $this->format->mobile_error('Something went wrong');
}
$card = $member_details->card_number."/1";
$data = $this->create_request($card);
$encrypted_uuid = $data->result_value;
$data = $this->create_request($member_details->mobile);
$encrypted_mobile = $data->result_value;
$return['site'] = $this->url_gateway.$encrypted_uuid."/".$encrypted_mobile;
$this->lcard_logs->log("0",'SHAREDTREATS','VIEW');
return $this->format->mobile_success('Shared Treats',$return);
}
public function checkMobileNumber($mobileNumber)
{
if (mb_substr($mobileNumber, 0, 2) == "63"){
return $mobileNumber;
}elseif(mb_substr($mobileNumber, 0, 2) == "09" ){
return "63".substr($mobileNumber, -10);
}elseif(mb_substr($mobileNumber, 0, 1) == "9"){
return "63".substr($mobileNumber, -10);
}else{
return false;
}
}
public function create_request($params)
{
$url = $this->url_encryption ;
$this->uri = new Uri($url.$params);
$client = new Client();
$response = $client->request('GET', $this->uri,[]);
return json_decode($response->getBody()->getContents()) ;
}
}