google place api controller updated

This commit is contained in:
Hritikkk9
2024-07-12 19:17:19 +05:30
parent 65096a5c61
commit 563246bd54
4 changed files with 87 additions and 10 deletions

View File

@@ -85,7 +85,7 @@ class SubscriptionController extends Controller
} catch (\Exception $e) {
Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage(), ['exception' => $e]);
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'));
}
}

View File

@@ -6,6 +6,7 @@ use Illuminate\Support\Facades\Session;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Tymon\JWTAuth\Facades\JWTAuth;
use GuzzleHttp\Client;
/**
* Created By : sayli raut
@@ -168,17 +169,82 @@ if (!function_exists('readRestHeaderToken')) {
if (!function_exists('generateOTP')) {
function generateOTP()
{
// Define the length of the OTP
$otpLength = 4;
function generateOTP()
{
// Define the length of the OTP
$otpLength = 4;
// Generate a random OTP with $otpLength digits
$otp = '';
for ($i = 0; $i < $otpLength; $i++) {
$otp .= rand(0, 9);
// Generate a random OTP with $otpLength digits
$otp = '';
for ($i = 0; $i < $otpLength; $i++) {
$otp .= rand(0, 9);
}
return $otp;
}
return $otp;
}
}
/**
* Created by : Hritik RD
* Created at : 12 July 2024
* Use : To Get Opening hours of Restaurant By NAME based on Google Maps using Google Places APIs
*/
if (!function_exists('getOpeningHoursOfRestaurant')) {
function getOpeningHoursOfRestaurant($restaurantName)
{
$googlePlaceApiKey = config('constants.googlePlaces.api_key'); // Your webhook secret key
// dd($googlePlaceApiKey);
$client = new Client();
$url = 'https://maps.googleapis.com/maps/api/place/findplacefromtext/json';
$response = $client->get($url, [
'query' => [
'fields' => 'place_id',
'input' => $restaurantName,
'inputtype' => 'textquery',
'key' => $googlePlaceApiKey
]
]);
$placeData = json_decode($response->getBody(), true);
if (isset($placeData['candidates'][0]['place_id'])) {
$placeId = $placeData['candidates'][0]['place_id'];
// return $placeId;
} else {
$placeId = "N/A";
// return response()->json($placeId);
return $placeId;
}
// $placeId = 'ChIJT3dpYcy35zsRLxY5KTTMqhU'; // You can also pass this as a parameter if needed
$client = new Client();
$url = 'https://maps.googleapis.com/maps/api/place/details/json';
$response = $client->get($url, [
'query' => [
'fields' => 'name,rating,formatted_phone_number,opening_hours',
'place_id' => $placeId,
'key' => $googlePlaceApiKey
]
]);
$data = json_decode($response->getBody(), true);
if (isset($data['result']['opening_hours']['weekday_text'])) {
$hours = $data['result']['opening_hours']['weekday_text'];
// return response()->json(['place_id' => $placeId]);
} else {
$hours = "N/A";
}
return $hours ;
// dd($data);
// return response()->json($data);
}
}

View File

@@ -43,6 +43,7 @@ class RestaurantApiServices
->where('restaurant_xid', $restaurant['id'])
->exists();
$restaurant['is_favourite'] = $isFavourite;
// $restaurant['operating_hours'] = getOpeningHoursOfRestaurant($restaurant['name']);// will update later
}
return jsonResponseWithSuccessMessage(__('auth.data_fetched_successfully'), $restaurants, 200);
@@ -120,6 +121,8 @@ class RestaurantApiServices
->where('restaurant_xid', $rest->id)
->exists();
$rest->is_favourite = $isFavourite;
$redeem = RedeemRestaurant::where('iam_principal_xid', $customerIamId)
->where('manage_restaurants_xid', $rest->id)
@@ -131,6 +134,10 @@ class RestaurantApiServices
// $timeIntervalHours = $Timeinterval->time_hours;
$restTimeHours = $restTime->time_hours;
//this below code is updated by hritik on 12-07-2024 by adding restaurant opening hours dynamically from Google
// $rest->operating_hours = getOpeningHoursOfRestaurant($rest->name); //will update later
// $greaterTime = max($timeIntervalHours, $restTimeHours);

View File

@@ -21,5 +21,9 @@ return [
'stripe_secret_key' => env('STRIPE_SECRET'),
'webhook_secret' => env('STRIPE_WEBHOOK_SECRET'),
],
'googlePlaces'=>[
'api_key'=>env('GOOGLE_PLACE_API_KEY')
]
];