first commit

This commit is contained in:
ExtraNetwork
2026-05-12 17:04:54 +03:00
commit e5c4b6aa13
1425 changed files with 284735 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,109 @@
<?php
namespace App\Http\Controllers\BookingEngine\V1;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
Abstract class BookingEngineBaseController
{
protected $cachePrefix = 'enwAPISearch:';
protected $cacheExpireTime = 30;
public function __construct()
{
}
public function setCacheDataWithSearchKey($searchKey, $dataArray)
{
$searchKeyPrefix = $this->cachePrefix . $searchKey;
Cache::put($searchKeyPrefix, $dataArray, $this->cacheExpireTime * 60);//5 min, 300 ttl, 600 10 dk
if (Cache::has($searchKeyPrefix)) {
return true;
} else {
return false;
}
}
public function getCacheDataWithSearchKey($searchKey)
{
$cacheData = [];
$searchKeyPrefix = $this->cachePrefix . $searchKey;
if (Cache::has($searchKeyPrefix)) {
$cacheData = Cache::get($searchKeyPrefix);
}
return $cacheData;
}
public function rateKeyCodeDecode($rateKeyCode)
{
$rateKeyCodeExplode = explode('-', $rateKeyCode);
$data = [
'propertyId' => $rateKeyCodeExplode[0],
'channelId' => $rateKeyCodeExplode[1],
'availabilityTypeId' => $rateKeyCodeExplode[2],
'roomId' => $rateKeyCodeExplode[3],
'rateMappingId' => $rateKeyCodeExplode[4],
'roomOccupancyCode' => $rateKeyCodeExplode[5],
'checkInDate' => Carbon::parse($rateKeyCodeExplode[6])->format('Y-m-d'),
'checkOutDate' => Carbon::parse($rateKeyCodeExplode[7])->format('Y-m-d'),
'cancellationPolicyId' => $rateKeyCodeExplode[8],
'paymentTypeId' => $rateKeyCodeExplode[9],
];
return $data;
}
public function getDateByDay($dates = [])
{
$dateByDay = [];
$diffInDays = Carbon::parse($dates['checkIn'])->floatDiffInDays(Carbon::parse($dates['checkOut']));
for ($i = 0; $i < $diffInDays; $i++) {
$dateByDay[] = Carbon::parse($dates['checkIn'])->addDay($i)->format('Y-m-d');
}
return $dateByDay;
}
public function getRoomsByOccupancies($rooms = [])
{
$roomsByOccupancies = [];
foreach ($rooms as $roomOrder => $room) {
$roomKey = [];
$roomKey[] = str_repeat('A', $room['adults']);
if ($room['children'] > 0) {
foreach ($room['age'] as $childAge) {
$roomKey[] = 'C' . $childAge;
}
}
$roomKey = implode($roomKey, '');
$roomsByOccupancies[$roomKey]['rooms'][] = $roomOrder;
$roomsByOccupancies[$roomKey]['roomCount'] = count($roomsByOccupancies[$roomKey]['rooms']);
$roomsByOccupancies[$roomKey]['occupancy'] = intval($room['adults'] + $room['children']);
$roomsByOccupancies[$roomKey]['adultCount'] = $room['adults'];
$roomsByOccupancies[$roomKey]['childCount'] = $room['children'];
$roomsByOccupancies[$roomKey]['childAges'] = fillOnUndefined($room, 'age', []);
$roomsByOccupancies[$roomKey]['occupancyCode'] = str_repeat('A', $room['adults']) . str_repeat('C', $room['children']);
}
return $roomsByOccupancies;
}
}

View File

@@ -0,0 +1,489 @@
<?php
namespace App\Http\Controllers\BookingEngine\V1;
use App\Core\Service\BookingService;
use App\Core\Service\BookingRoomService;
use App\Core\Service\BookingRoomPaxService;
use App\Core\Service\BookingContactService;
use App\Core\Service\BookingPaymentService;
use App\Core\Service\PropertyRoomAvailabilityService;
use App\Core\Service\PropertyChannelMappingService;
use App\Core\Service\PropertyPaymentService;
use App\Core\Service\NewBookingMailService;
use App\Core\Service\PropertyService;
use App\Core\Service\LanguageService;
use App\Core\Service\ManualPaymentMailService;
use Carbon\Carbon;
use Illuminate\Http\Request;
use App;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Config;
use Exception;
use App\Exceptions\ApiErrorException;
use phpDocumentor\Reflection\Types\Collection;
class PaymentLinkController extends BookingEngineBaseController
{
private $request;
private $newBookingMailService;
private $propertyPaymentService;
private $propertyService;
private $languageService;
private $manualPaymentMailService;
public function __construct(
Request $request,
PropertyPaymentService $propertyPaymentService,
PropertyService $propertyService,
LanguageService $languageService,
ManualPaymentMailService $manualPaymentMailService,
PropertyChannelMappingService $propertyChannelMappingService
)
{
$this->request = $request;
$this->propertyPaymentService = $propertyPaymentService;
$this->propertyService = $propertyService;
$this->languageService = $languageService;
$this->manualPaymentMailService = $manualPaymentMailService;
$this->propertyChannelMappingService = $propertyChannelMappingService;
}
public function paymentLinkDetail(Request $request, $orderCode)
{
$response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500];
try {
$paymentDetailParam = [
'criteria' => [
['field' => 'order_id', 'condition' => '=', 'value' => $orderCode],
['field' => 'transaction_type', 'condition' => '=', 'value' => 'LNK'],
['field' => 'status', 'condition' => '=', 'value' => 5],
],
'with' => ['relatedTransactions', 'paymentTypeMapping.paymentType'],
'firstRow' => true
];
$paymentDetail = $this->propertyPaymentService->selectPaymentTransaction($paymentDetailParam);
if ($paymentDetail['status'] != 'success' || empty($paymentDetail['data'])) {
throw new ApiErrorException(lang('Payment not found'));
}
$paymentDetail = $paymentDetail['data'];
if ($paymentDetail['status'] != 5) {
throw new ApiErrorException(lang('Payment not link status'));
}
$paymentDetail['is_payed'] = false;
if (!empty($paymentDetail['related_transactions'])) {
$relatedTransactions = collect($paymentDetail['related_transactions']);
if ($relatedTransactions->where('status', 1)->count() > 0) {
$paymentDetail['is_payed'] = true;
}
}
$propertyId = $paymentDetail['property_id'];
$propertyParam = [
'criteria' => [
['field' => 'id', 'condition' => '=', 'value' => $propertyId],
],
'with' => ['propertyBrand', 'propertyContact'],
'firstRow' => true
];
$getProperty = $this->propertyService->select($propertyParam);
if ($getProperty['status'] != "success") {
throw new ApiErrorException($getProperty['message']);
}
$property = $getProperty['data'];
$property['property_brand']['logo_url'] = $property['property_brand'] ? Config::get('app.imageUrl') . '/property-photos/' . $property['id'] . "/logo/" . $property['property_brand']['logo_name'] . '_250x250.' . $property['property_brand']['logo_file_ext'] : null;
$property['property_contact']['social_media_addresses'] = json_decode($property['property_contact']['social_media_addresses'], 1);
$availableLanguageRequest = [
'criteria' => [
['field' => 'status', 'condition' => '=', 'value' => 1],
['field' => 'is_application', 'condition' => '=', 'value' => 1],
['field' => 'is_published', 'condition' => '=', 'value' => 1]
],
];
$availableLanguages = $this->languageService->select($availableLanguageRequest, ['code', 'name', 'language_key']);
$availableLanguages = Collect($availableLanguages['data'])->keyBy('code')->all();
//contract_file
$property['contract_file'] = null;
$channelMappingRequest = [
'criteria' => [
['field' => 'property_id', 'condition' => '=', 'value' => $property['id']],
['field' => 'channel_id', 'condition' => '=', 'value' => 1],
['field' => 'status', 'condition' => '=', 'value' => 1],
],
'firstRow' => 1
];
$channelMapping = $this->propertyChannelMappingService->select($channelMappingRequest, ['id', 'contract_file', 'currency_code']);
if ($channelMapping['status'] == 'success' && !empty($channelMapping['data'])) {
$property['contract_file'] = Config::get('app.propertyFilesUrl') . $channelMapping['data']['contract_file'];
}
//contract_file
$responseData = [
'payment_detail' => $paymentDetail,
'property_detail' => $property,
'available_languages' => $availableLanguages,
];
$response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $responseData];
} catch (ApiErrorException $e) {
$response['message'] = implode(', ', $e->getMessageArr());
$response['statusCode'] = 400;
} catch (Exception $e) {
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
Log::error($message);
$response['message'] = $e->getMessage();
$response['statusCode'] = 500;
}
return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']);
}
public function paymentLinkInitialize(Request $request)
{
$response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500];
try {
if (is_null($this->request->getContent())) {
throw new ApiErrorException(lang('Parameter Error.'));
}
$params = json_decode($this->request->getContent(), 1);
$orderCode = $params['orderCode'];
$paymentDetailParam = [
'criteria' => [
['field' => 'order_id', 'condition' => '=', 'value' => $orderCode],
['field' => 'transaction_type', 'condition' => '=', 'value' => 'LNK'],
['field' => 'status', 'condition' => '=', 'value' => 5],
],
'firstRow' => true
];
$paymentDetail = $this->propertyPaymentService->selectPaymentTransaction($paymentDetailParam);
if ($paymentDetail['status'] != 'success' || empty($paymentDetail['data'])) {
throw new ApiErrorException(lang('Payment not found'));
}
$paymentDetail = $paymentDetail['data'];
if ($paymentDetail['status'] != 5) {
throw new ApiErrorException(lang('Payment not link status'));
}
$paymentStatusCheckParam = [
'criteria' => [
['field' => 'order_id', 'condition' => '=', 'value' => $orderCode],
['field' => 'transaction_type', 'condition' => '=', 'value' => 'LNK'],
['field' => 'status', 'condition' => '=', 'value' => 1],
],
'firstRow' => true
];
$paymentStatusCheck = $this->propertyPaymentService->selectPaymentTransaction($paymentStatusCheckParam);
if ($paymentStatusCheck['status'] == 'success' && !empty($paymentStatusCheck['data'])) {
throw new ApiErrorException(lang('Previously paid transaction'));
}
DB::beginTransaction();
$initializePaymentParam = [
'propertyId' => $paymentDetail['property_id'],
'orderId' => $paymentDetail['order_id'],
'installment' => 0,
'amount' => (double)$paymentDetail['amount'],
'currency' => $paymentDetail['currency'],
'type' => 'LNK',
'preferredPaymentTypeId' => $paymentDetail['payment_type_mapping_id'],
'responseUrl' => $params['responseUrl'],
'creditCard' => [
'name' => $params['creditCard']['cardHolder'],
'number' => $params['creditCard']['cardNumber'],
'month' => $params['creditCard']['cardExpireMonth'],
'year' => $params['creditCard']['cardExpireYear'],
'cvv' => $params['creditCard']['cardCvv'],
]
];
$initializePayment = $this->propertyPaymentService->initializePayment($initializePaymentParam);
if (!$initializePayment['status']) {
throw new ApiErrorException(lang($initializePayment['message']));
}
$responseData = [
'orderCode' => $paymentDetail['order_id'],
'paymentCode' => $initializePayment['data']['paymentCode'],
];
if (isset($initializePayment['data']['redirectUrl'])) {
$responseData['redirectUrl'] = $initializePayment['data']['redirectUrl'];
}
$response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $responseData];
} catch (ApiErrorException $e) {
$response['message'] = implode(', ', $e->getMessageArr());
$response['statusCode'] = 400;
} catch (Exception $e) {
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
Log::error($message);
$response['message'] = $e->getMessage();
$response['statusCode'] = 500;
}
if ($response['status']) {
DB::commit();
} else {
DB::rollBack();
}
return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']);
}
public function paymentLinkConfirm(Request $request)
{
$response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500];
try {
if (is_null($this->request->getContent())) {
throw new ApiErrorException(lang('Parameter Error.'));
}
$params = json_decode($this->request->getContent(), 1);
$orderCode = $params['orderCode'];
$paymentCode = $params['paymentCode'];
$paymentDetailParam = [
'criteria' => [
['field' => 'order_id', 'condition' => '=', 'value' => $orderCode],
['field' => 'code', 'condition' => '=', 'value' => $paymentCode],
['field' => 'transaction_type', 'condition' => '=', 'value' => 'LNK'],
['field' => 'status', 'condition' => '=', 'value' => 1],
],
'firstRow' => true
];
$paymentDetail = $this->propertyPaymentService->selectPaymentTransaction($paymentDetailParam);
if ($paymentDetail['status'] != 'success' || empty($paymentDetail['data'])) {
throw new ApiErrorException(lang('Payment not confirmed'));
}
$paymentDetailParam = [
'orderCode' => $orderCode,
'language_code' => isset($params['language_code']) ? $params['language_code'] : 'en'
];
$this->manualPaymentMailService->process($paymentDetailParam);
$response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => []];
} catch (ApiErrorException $e) {
$response['message'] = implode(', ', $e->getMessageArr());
$response['statusCode'] = 400;
} catch (Exception $e) {
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
Log::error($message);
$response['message'] = $e->getMessage();
$response['statusCode'] = 500;
}
return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']);
}
public function createManualPaymentForm(Request $request)
{
$response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500];
try {
if (is_null($this->request->getContent())) {
throw new ApiErrorException(lang('Parameter Error.'));
}
$params = $this->request->params;
$createPaymentLink = $this->propertyPaymentService->createManualPaymentForm($params);
if ($createPaymentLink['status'] != "success") {
throw new ApiErrorException($createPaymentLink['message']);
}
$response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $createPaymentLink['data']];
} catch (ApiErrorException $e) {
$response['message'] = implode(', ', $e->getMessageArr());
} catch (Exception $e) {
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
Log::error($message);
$response['message'] = $e->getMessage();
}
return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']);
}
public function createManualPayment(Request $request)
{
$response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500];
try {
if (is_null($this->request->getContent())) {
throw new ApiErrorException(lang('Parameter Error.'));
}
$params = $this->request->params;
$params['user_id'] = $request->credentials->user_id;
$createPaymentLink = $this->propertyPaymentService->createManualPayment($params);
if ($createPaymentLink['status'] != "success") {
throw new ApiErrorException($createPaymentLink['message']);
}
$response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $createPaymentLink['data']];
} catch (ApiErrorException $e) {
$response['message'] = implode(', ', $e->getMessageArr());
} catch (Exception $e) {
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
Log::error($message);
$response['message'] = $e->getMessage();
}
return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']);
}
public function editManualPaymentForm(Request $request)
{
$response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500];
try {
if (is_null($this->request->getContent())) {
throw new ApiErrorException(lang('Parameter Error.'));
}
$params = $this->request->params;
$createPaymentLink = $this->propertyPaymentService->editManualPaymentForm($params);
if ($createPaymentLink['status'] != "success") {
throw new ApiErrorException($createPaymentLink['message']);
}
$response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $createPaymentLink['data']];
} catch (ApiErrorException $e) {
$response['message'] = implode(', ', $e->getMessageArr());
} catch (Exception $e) {
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
Log::error($message);
$response['message'] = $e->getMessage();
}
return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']);
}
public function updateManualPayment(Request $request)
{
$response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500];
try {
if (is_null($this->request->getContent())) {
throw new ApiErrorException(lang('Parameter Error.'));
}
$params = $this->request->params;
$createPaymentLink = $this->propertyPaymentService->updateManualPayment($params);
if ($createPaymentLink['status'] != "success") {
throw new ApiErrorException($createPaymentLink['message']);
}
$response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $createPaymentLink['data']];
} catch (ApiErrorException $e) {
$response['message'] = implode(', ', $e->getMessageArr());
} catch (Exception $e) {
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
Log::error($message);
$response['message'] = $e->getMessage();
}
return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']);
}
public function getManualPayment(Request $request)
{
$response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500];
try {
if (is_null($this->request->getContent())) {
throw new ApiErrorException(lang('Parameter Error.'));
}
$params = $this->request->params;
$createPaymentLink = $this->propertyPaymentService->getManualPayment($params);
if ($createPaymentLink['status'] != "success") {
throw new ApiErrorException($createPaymentLink['message']);
}
$response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $createPaymentLink['data']];
} catch (ApiErrorException $e) {
$response['message'] = implode(', ', $e->getMessageArr());
} catch (Exception $e) {
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
Log::error($message);
$response['message'] = $e->getMessage();
}
return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']);
}
}

View File

@@ -0,0 +1,357 @@
<?php
namespace App\Http\Controllers\BookingEngine\V1;
use App\Core\Service\CurrencyService;
use App\Core\Service\FindCountryCodeService;
use App\Core\Service\GeneralTimezoneService;
use App\Core\Service\LanguageService;
use App\Core\Service\PropertyBookingEngineService;
use App\Core\Service\PropertyChannelMappingService;
use App\Core\Service\PropertyGroupService;
use App\Exceptions\ApiErrorException;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
class PropertyBookingEngineController extends Controller
{
private $propertyBookingEngineService;
private $propertyChannelMappingService;
private $languageService;
public function __construct(
PropertyBookingEngineService $propertyBookingEngineService,
LanguageService $languageService,
PropertyChannelMappingService $propertyChannelMappingService,
CurrencyService $currencyService,
PropertyGroupService $propertyGroupService,
FindCountryCodeService $findCountryCodeService,
GeneralTimezoneService $generalTimezoneService
)
{
$this->propertyBookingEngineService = $propertyBookingEngineService;
$this->languageService = $languageService;
$this->propertyChannelMappingService = $propertyChannelMappingService;
$this->currencyService = $currencyService;
$this->propertyGroupService = $propertyGroupService;
$this->findCountryCodeService = $findCountryCodeService;
$this->generalTimezoneService = $generalTimezoneService;
}
public function checkProperty(Request $request)
{
$response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500];
try {
if (is_null($request->getContent())) {
throw new ApiErrorException(lang('Parameter Error.'));
}
$params = $request->params;
$propertyRequest = [
'criteria' => [
['field' => 'token', 'condition' => '=', 'value' => $params['token']],
],
'with' => ['channel',
'property.propertyBookingEngineGroupMapping.propertyGroup.propertyGroupMapping.property.propertyBookingEngineToken',
'property.propertyBookingEngineGroupMapping.propertyGroup.propertyGroupMapping.property.propertyWeb',
'propertyWeb', 'propertyChannelMapping.channelTax', 'propertyWebComponent',
'property.propertyAdditionalInfos'
],
'firstRow' => 1
];
$propertyBookingEngine = $this->propertyBookingEngineService->select($propertyRequest, ['id', 'property_id', 'channel_id', 'token', 'parameters']);
if ($propertyBookingEngine['status'] != 'success') {
throw new ApiErrorException($propertyBookingEngine['message']);
}
if (!$propertyBookingEngine['data']) {
throw new ApiErrorException('General error ...');
}
$propertyBookingEngine = $propertyBookingEngine['data'];
$availableLanguageRequest = [
'criteria' => [
['field' => 'status', 'condition' => '=', 'value' => 1],
['field' => 'is_application', 'condition' => '=', 'value' => 1],
['field' => 'is_published', 'condition' => '=', 'value' => 1]
]
];
$availableLanguages = $this->languageService->select($availableLanguageRequest, ['code', 'name', 'language_key']);
$languageCodes = [];
foreach ($availableLanguages['data'] as $language) {
$languageCodes[$language['code']] = $language;
}
$properBookingEngineMapping = [];
if (isset($propertyBookingEngine['parametersArray']['property_group_id'])) {
$propertyGroupRequest = [
'criteria' => [
['field' => 'status', 'condition' => '=', 'value' => 1],
['field' => 'type', 'condition' => '=', 'value' => 'BEN'],
['field' => 'id', 'condition' => '=', 'value' => $propertyBookingEngine['parametersArray']['property_group_id']]
],
'with' => ['propertyGroupMapping'],
'firstRow' => true,
];
$propertyGroup = $this->propertyGroupService->select($propertyGroupRequest);
$propertyGroup = $propertyGroup['status'] == 'success' && !empty($propertyGroup['data']) ? $propertyGroup['data']['property_group_mapping'] : [];
$propertyGroupPropertyIds = collect($propertyGroup)->pluck('property_id')->toArray();
$propertyGroupBookingEngineRequest = [
'criteria' => [
['field' => 'status', 'condition' => '=', 'value' => 1],
['field' => 'channel_id', 'condition' => '=', 'value' => $propertyBookingEngine['channel_id']],
],
'with' => ['property.propertyBookingEngineGroupMapping.propertyGroup.propertyGroupMapping.property.propertyBookingEngineToken'],
'whereIn' => [
['field' => 'property_id', 'value' => $propertyGroupPropertyIds]
]
];
$propertyGroupBookingEngine = $this->propertyBookingEngineService->select($propertyGroupBookingEngineRequest);
if ($propertyGroupBookingEngine['status'] == 'success') {
foreach ($propertyGroupBookingEngine['data'] as $bookingEngine) {
$properBookingEngineMapping[] = [
'property_id' => $bookingEngine['property_id'],
'name' => $bookingEngine['property']['name'],
'token' => $bookingEngine['token'],
'order_number' => count($properBookingEngineMapping)
];
}
}
}
if ($propertyBookingEngine['channel_id'] == 1) {
$propertyBookingEngineGroupMapping = $propertyBookingEngine['property']['property_booking_engine_group_mapping'];
foreach ($propertyBookingEngineGroupMapping as $beGroupMapping) {
$group = $beGroupMapping['property_group'];
if ($group['type'] == 'MYW') {
$groupProperties = $group['property_group_mapping'];
foreach ($groupProperties as $groupProperty) {
if (isset($groupProperty['property']['property_booking_engine_token'])) {
$arrayItem = [
'property_id' => $groupProperty['property_id'],
'name' => $groupProperty['property']['name'],
'token' => $groupProperty['property']['property_booking_engine_token']['token'],
'order_number' => $groupProperty['order_number']
];
$arrayItem['web'] = null;
if (!empty($groupProperty['property']['property_web'])) {
if ($groupProperty['property']['property_web']['status'] && $groupProperty['property']['property_web']['is_published']) {
$arrayItem['web'] = $groupProperty['property']['property_web']['webProtocolUrl'];
}
}
$properBookingEngineMapping[] = $arrayItem;
}
}
}
}
}
if (count($properBookingEngineMapping) > 1) {
array_multisort(array_column($properBookingEngineMapping, 'order_number'), SORT_ASC, $properBookingEngineMapping);
}
$channelMappingRequest = [
'criteria' => [
['field' => 'property_id', 'condition' => '=', 'value' => $propertyBookingEngine['property_id']],
['field' => 'channel_id', 'condition' => '=', 'value' => $propertyBookingEngine['channel_id']],
['field' => 'status', 'condition' => '=', 'value' => 1],
],
'firstRow' => 1
];
$channelMapping = $this->propertyChannelMappingService->select($channelMappingRequest, ['id', 'contract_file', 'currency_code']);
if ($channelMapping['status'] != 'success') {
throw new ApiErrorException($channelMapping['message']);
}
$channelDefaultCurrencyCode = $channelMapping['data']['currency_code'];
//IP Bases Pricing Channel Manipulation
if (isset($params['ipAddress']) && !empty($params['ipAddress']) && fillOnUndefined($params, 'referrer') != 'google') {
// Find Country Code with IP
$ipResponse = $this->findCountryCodeService->findCountryWithIpAddress($params['ipAddress']);
if ($ipResponse['status'] == 'success') {
$propertyChannelMappingParam = [
'criteria' => [
['field' => 'property_id', 'condition' => '=', 'value' => $propertyBookingEngine['property_id']],
['field' => 'status', 'condition' => '=', 'value' => 1],
],
'with' => ['channel'],
];
$propertyChannelMapping = $this->propertyChannelMappingService->select($propertyChannelMappingParam);
$ipCountryCode = isset($ipResponse['data']['code']) ? $ipResponse['data']['code'] : 'tr';
if ($propertyChannelMapping['status'] == 'success') {
$propertyChannelMappingCollect = collect($propertyChannelMapping['data']);
$countryChannel = $propertyChannelMappingCollect
->where('channel.channel_category_id', 3)
->where('channel.country_code', $ipCountryCode)
->where('channel.parent_id', 1)
->first();
if (!empty($countryChannel)) {
$channelDefaultCurrencyCode = $countryChannel['currency_code'];
}
//countryCodeGroup
if (empty($countryChannel)) {
$countryChannelGroup = $propertyChannelMappingCollect
->where('channel.channel_category_id', 3)
->where('channel.country_code', 'group')
->where('channel.parent_id', 1)
->toArray();
if (!empty($countryChannelGroup)) {
foreach ($countryChannelGroup as $country) {
if (!empty($country['channel']['country_code_group'])) {
if (in_array($ipCountryCode, $country['channel']['countryCodeGroupArray'])) {
$channelDefaultCurrencyCode = $country['currency_code'];
break;
}
}
}
}
}
//countryCodeGroup
}
}
//channelToken Manipulation
}
$exchangeCurrencyRates = $this->currencyService->exchangeCurrencyRates($channelDefaultCurrencyCode);
$exchangeCurrencyRateList = [];
$exchangeCurrencyAvailable = ['EUR', 'USD', 'TRY', 'GBP', 'GEL', 'MAD', 'AZN'];
if ($exchangeCurrencyRates['status'] == 'success') {
foreach ($exchangeCurrencyRates['data'] as $currencyRate) {
if (!in_array($currencyRate['exc_currency_code'], $exchangeCurrencyAvailable)) {
continue;
}
$currencyKey = $currencyRate['currency_code'] . '-' . $currencyRate['exc_currency_code'];
$exchangeCurrencyRateList[$currencyKey] = [
'currency_code' => $currencyRate['currency_code'],
'exc_currency_code' => $currencyRate['exc_currency_code'],
'rate' => moneyFourFormatDecimal($currencyRate['rate']),
];
}
}
$contractFileUrl = NULL;
if (!empty($channelMapping['data']['contract_file'])) {
$contractFileUrl = Config::get('app.propertyFilesUrl') . $channelMapping['data']['contract_file'];
}
$channelTax = null;
$taxOptions = Config::get('app.taxOptions');
if (!empty($propertyBookingEngine['property_channel_mapping']['channel_tax_id'])) {
$channelTax = [
'id' => $propertyBookingEngine['property_channel_mapping']['channel_tax']['id'],
'code' => $propertyBookingEngine['property_channel_mapping']['channel_tax']['code'],
'name' => $propertyBookingEngine['property_channel_mapping']['channel_tax']['name'],
'language_key' => $propertyBookingEngine['property_channel_mapping']['channel_tax']['language_key'],
'tax' => isset($taxOptions[$propertyBookingEngine['property']['country']]) ? $taxOptions[$propertyBookingEngine['property']['country']] : null
];
}
//PropertyWebComponent
$propertyWebComponent = null;
if ($propertyBookingEngine['property_web_component']) {
$propertyWebComponentSojernBookingEngine = collect($propertyBookingEngine['property_web_component'])
->where('component_id', 10)
->first();
if ($propertyWebComponentSojernBookingEngine) {
$propertyWebComponent['sojernbookingengine'] = $propertyWebComponentSojernBookingEngine['parameterArray'];
}
$propertyWebComponentClarityBookingEngine = collect($propertyBookingEngine['property_web_component'])
->where('component_id', 14)
->first();
if ($propertyWebComponentClarityBookingEngine) {
$propertyWebComponent['claritybookingengine'] = $propertyWebComponentClarityBookingEngine['parameterArray'];
}
}
$propertyTimeZoneDetail = null;
$timeZoneValue = collect($propertyBookingEngine['property']['property_additional_infos'])->where('additional_info_key_id', '13')->first();
if ($timeZoneValue) {
$generalTimezoneRepositoryCriteria = ['criteria' => [['field' => 'id', 'condition' => '=', 'value' => $timeZoneValue['value']],], 'firstRow' => true];
$propertyTimeZoneDetail = $this->generalTimezoneService->select($generalTimezoneRepositoryCriteria, ['location', 'action_type', 'hour', 'minute']);
if ($propertyTimeZoneDetail['status'] == 'success') {
$propertyTimeZoneDetail = $propertyTimeZoneDetail['data'];
}
}
$responseData = [
'property_id' => $propertyBookingEngine['property_id'],
'property_name' => $propertyBookingEngine['property']['name'],
'channel_id' => $propertyBookingEngine['channel_id'],
'channel_name' => $propertyBookingEngine['channel']['name'],
'channel_category_id' => $propertyBookingEngine['channel']['channel_category_id'],
'booking_engine_token' => $propertyBookingEngine['token'],
'channel_token' => $propertyBookingEngine['channel']['token'],
'channel_contact' => $propertyBookingEngine['channel']['contact'],
'default_language' => isset($propertyBookingEngine['property_web']['default_language']) ? $propertyBookingEngine['property_web']['default_language'] : null,
'default_currency' => $channelDefaultCurrencyCode,
'available_language_codes' => $languageCodes,
'property_booking_engine_mapping' => count($properBookingEngineMapping) > 0 ? $properBookingEngineMapping : null,
'contract_file_url' => $contractFileUrl,
'exchange_currency_rate' => $exchangeCurrencyRateList,
'booking_engine_parameters' => $propertyBookingEngine['parametersArray'],
'channel_tax' => $channelTax,
'property_web_component' => $propertyWebComponent,
'property_timezone' => $propertyTimeZoneDetail
];
$response = ['status' => 1, 'statusCode' => 200, 'message' => null, 'data' => $responseData];
} catch (ApiErrorException $e) {
$response['message'] = implode(', ', $e->getMessageArr());
$response['statusCode'] = 400;
} catch (Exception $e) {
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
Log::error($message);
$response['message'] = $e->getMessage();
$response['statusCode'] = 500;
}
return apiResponse($response['status'], $response['message'], $response['data'], $response['statusCode']);
}
}

File diff suppressed because it is too large Load Diff