Advertisement
Guest User

Untitled

a guest
Feb 14th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 51.57 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers\Front;
  4.  
  5. use App\Http\Controllers\FrontController;
  6. use Carbon\Carbon;
  7. use Auth;
  8. use DB;
  9. use Response;
  10. use Mail;
  11.  
  12. use App\Models\Room;
  13. use App\Models\Hotel;
  14. use App\Models\Extra;
  15. use App\Models\Booking;
  16. use App\Models\Voucher;
  17. use App\Models\Promotion;
  18. use App\Models\BookingRoom;
  19. use App\Models\BookingExtra;
  20. use App\Models\GuestRequest;
  21. use App\Models\PurchasedVoucher;
  22. use App\Models\File;
  23. use App\Models\Feedback;
  24. use App\Models\Admin;
  25. use App\Models\MenuCategory;
  26. use App\Models\MenuItem;
  27.  
  28.  
  29. class IndexController extends FrontController
  30. {
  31. public function index() {
  32.  
  33. return $this->ShowView('index', array(
  34. ));
  35.  
  36. }
  37.  
  38. private function is_admin() {
  39. if( Auth::guard('admin')->user() && Auth::guard('admin')->user()->hotel_id ) {
  40. return Auth::guard('admin')->user()->hotel;
  41. }
  42.  
  43. return null;
  44. }
  45.  
  46. private function getHotel() {
  47. $admin_hotel = $this->is_admin();
  48. if( $admin_hotel ) {
  49. return $admin_hotel;
  50. }
  51.  
  52. if(session('hotel_id')) {
  53. return Hotel::find( session('hotel_id') );
  54. }
  55. $parse = parse_url( request()->server('HTTP_REFERER') );
  56. $domain = $this->get_domain( $parse['host'] );
  57. return Hotel::where('domain', 'LIKE', $domain)->first();
  58. }
  59.  
  60. public function chatbot() {
  61.  
  62. \App::setLocale( request('lang') );
  63.  
  64. $ret = array(
  65. 'success' => true,
  66. );
  67.  
  68. $hotel = $this->getHotel();
  69. if(!$hotel) {
  70. return Response::json( [
  71. 'success' => false,
  72. 'message' => 'Invalid Hotel',
  73. ] );
  74. } else if(!$hotel->disabled && !$this->is_admin()) {
  75. return Response::json( [
  76. 'success' => false,
  77. 'message' => 'Hotel Disabled',
  78. ] );
  79. }
  80.  
  81. $story = config('chatbot.stories.'.request('story'));
  82. $step = config('chatbot.stories.'.request('story').'.steps.'.request('step'));
  83. if( $story && $step ) {
  84. $ret = $step;
  85.  
  86. if( request('story')=='services' && (request('step')=='concierge' || request('step')=='start' ) ) {
  87. $file_fields = [
  88. 'hotel-map',
  89. 'rent-a-car',
  90. 'change',
  91. 'parking',
  92. 'activities',
  93. ];
  94.  
  95. foreach ($ret['controllers'] as $k => $controller) {
  96. if(in_array($controller['step'], $file_fields)) {
  97. $list = File::where('hotel_id', $hotel->id)->where('item_name', $controller['step'])->get();
  98. if($list->isEmpty()) {
  99. unset($ret['controllers'][$k]);
  100. }
  101. }
  102. }
  103.  
  104. } else if( request('story')=='room-service' && request('step')=='final' ) {
  105. $data = request('data');
  106.  
  107. $details = '';
  108. $list = $data['room-service']['confirm'];
  109. $menuItems = MenuItem::whereIn('id', array_keys($list))->get();
  110. foreach ($menuItems as $menuItem) {
  111. $details .= $list[$menuItem->id].'x '.$menuItem->name
  112. # code...
  113. }
  114.  
  115.  
  116. $detailsSteps = [
  117. 'housekeeping-other',
  118. 'maintenance-other',
  119. 'newspaper',
  120. ];
  121.  
  122. $details .= '<br/>'.$data['room-service']['comment']['comment'];
  123.  
  124. $gr = new GuestRequest;
  125. $gr->hotel_id = $hotel->id;
  126. $gr->item_name = 'room-service';
  127. $gr->room_number = $data['room-service']['guest-info']['room_number'];
  128. $gr->guest_name = $data['room-service']['guest-info']['name'];
  129. $gr->details = $details;
  130. $gr->save();
  131.  
  132. } else if( request('story')=='services' && request('step')=='done' ) {
  133.  
  134. $data = request('data');
  135.  
  136. if( isset( $data['services'][ $data['services']['start'] ] ) && !empty( $data['services']['guest-info'] ) ) {
  137.  
  138. $details = '';
  139. $service = $data['services'][ $data['services']['start'] ];
  140.  
  141. $detailsSteps = [
  142. 'housekeeping-other',
  143. 'maintenance-other',
  144. 'newspaper',
  145. ];
  146.  
  147. if( in_array($service, $detailsSteps)!==false ) {
  148. $details = $data['services'][$service];
  149. }
  150.  
  151. $gr = new GuestRequest;
  152. $gr->hotel_id = $hotel->id;
  153. $gr->item_name = $service;
  154. $gr->room_number = $data['services']['guest-info']['room_number'];
  155. $gr->guest_name = $data['services']['guest-info']['name'];
  156. $gr->details = $details;
  157. $gr->save();
  158.  
  159. }
  160. } else if( request('story')=='welcome' && (request('step')=='start' || request('step')=='start-again') ) {
  161. foreach ($ret['controllers'] as $k => $controller) {
  162. if(!in_array($controller['story'], $hotel->menu_buttons)) {
  163. unset($ret['controllers'][$k]);
  164. }
  165. }
  166.  
  167. } else if( request('story')=='checkin' && request('step')=='checkin-else' ) {
  168. $data = request('data');
  169. //dd($data);
  170.  
  171. $booking_id = $data['checkin']['start']['id'];
  172. $booking = Booking::find($booking_id);
  173.  
  174. $checkin = $data['checkin']['checkin-guests'];
  175. //dd($checkin, $booking->checkin_data);
  176. /*
  177. foreach ($checkin['guest_info'] as $gk => $gi) {
  178. foreach ($gi as $guest_num => $guest) {
  179. if(!empty($guest['checkin_email']) && empty($booking->checkin_data['guest_info'][$gk][$guest_num]['checkin_email'])) {
  180.  
  181. $subject = 'Вашата регистрация';
  182. $receiver = $guest['checkin_email'];
  183. Mail::send('emails.chekcin', [
  184. 'hotel_name' => $hotel->name,
  185. 'hotel_privacy_policy' => $hotel->privacy_policy,
  186. 'hotel_website' => $hotel->website,
  187. 'hotel_address' => $hotel->address,
  188. 'hotel_coordinates' => $hotel->coordinates,
  189. 'hotel_phone' => $hotel->phone,
  190. 'hotel_phone2' => $hotel->phone2,
  191. 'hotel_email' => $hotel->email,
  192. 'hotel_email2' => $hotel->email2,
  193.  
  194. ], function ($message) use ($subject, $receiver) {
  195. //$message->from($sender, $sender_name);
  196. $message->to( $receiver );
  197. $message->subject($subject);
  198. });
  199. }
  200. }
  201. }
  202. */
  203.  
  204. $booking->checkin_data = $checkin;
  205. $flat = array();
  206. array_walk_recursive($checkin,function($v) use (&$flat){ $flat[] = $v; });
  207.  
  208. //dd($data, $flat);
  209. $booking->checkin_status = array_search(null, $flat, true)!==false ? 'partial' : 'new';
  210. $booking->check_updated = Carbon::now();
  211. $booking->save();
  212.  
  213. //////
  214. } else if( request('story')=='feedback' && request('step')=='end' ) {
  215. $data = request('data');
  216.  
  217. $gr = new Feedback;
  218. $gr->hotel_id = $hotel->id;
  219. $gr->name = $data['feedback']['start']['name'];
  220. $gr->phone = $data['feedback']['start']['phone'];
  221. $gr->email = $data['feedback']['start']['email'];
  222. $gr->message = $data['feedback']['start']['message'];
  223. $gr->save();
  224. }
  225.  
  226.  
  227. foreach ($ret['controllers'] as $k => $controller) {
  228.  
  229. if($controller['type']=='vouchers') {
  230. $ret['controllers'][$k]['vouchers'] = Voucher::where('hotel_id', $hotel->id)->get();
  231. foreach ($ret['controllers'][$k]['vouchers'] as $rid => $r) {
  232. $rarr = $r->toArray();
  233. $rarr['image'] = $r->getImageUrl();
  234. $ret['controllers'][$k]['vouchers'][$rid] = $rarr;
  235. }
  236. } else if($controller['type']=='room-service' || $controller['type']=='room-service-confirm') {
  237. $ret['controllers'][$k]['menu'] = MenuCategory::with('items')->where('hotel_id', $hotel->id)->get();
  238. foreach ($ret['controllers'][$k]['menu'] as $rid => $r) {
  239. $rarr = $r->toArray();
  240. $ret['controllers'][$k]['menu'][$rid] = $rarr;
  241. }
  242.  
  243. } else if($controller['type']=='promos') {
  244. $ret['controllers'][$k]['promos'] = Promotion::where('hotel_id', $hotel->id)
  245. ->where('date_from', '<=', Carbon::now())
  246. ->where('to_date', '>=', Carbon::now())
  247. ->where('max_number_uses', '>=', 'times_used')
  248. ->get();
  249. foreach ($ret['controllers'][$k]['promos'] as $rid => $r) {
  250. $rarr = $r->toArray();
  251. $rarr['image'] = $r->getImageUrl();
  252. $ret['controllers'][$k]['promos'][$rid] = $rarr;
  253. }
  254. } else if($controller['type']=='rooms') {
  255. $ret['controllers'][$k]['rooms'] = Room::where('hotel_id', $hotel->id)->get();
  256. $prices = $hotel->getPricesForPeriod( request()->input('data.bookings.start'), request()->input('data.bookings.booking_out') );
  257. foreach ($ret['controllers'][$k]['rooms'] as $rid => $r) {
  258. if(!isset($prices[$r->id])) {
  259. unset( $ret['controllers'][$k]['rooms'][$rid] );
  260. continue;
  261. }
  262.  
  263. $rarr = $r->toArray();
  264. $rarr['image'] = $r->getImageUrl();
  265. $rarr['prices'] = $prices[$r->id];
  266. $ret['controllers'][$k]['rooms'][$rid] = $rarr;
  267. }
  268. } else if($controller['type']=='files') {
  269. $list = File::where('hotel_id', $hotel->id)->where('item_name', $controller['item'])->where('lang', \App::getLocale())->get();
  270. $ret['controllers'][$k]['files'] = [];
  271. foreach ($list as $file) {
  272. $ret['controllers'][$k]['files'][] = [
  273. 'url' => $file->getImageUrl(),
  274. 'thumb' => $file->getImageUrl(true),
  275. 'image' => $file->isImage(),
  276. 'file_name' => $file->file_name,
  277. ];
  278. }
  279. } else if($controller['type']=='calendar' && request('story')=='promos') {
  280. $data = request('data');
  281. $pid = $data['promos']['start']['id'];
  282. $promo = Promotion::find($pid);
  283. //dd($promo);
  284. $dates = [];
  285. $start = new Carbon($promo->date_from);
  286. $end = new Carbon($promo->to_date);
  287. $wdays = [
  288. 'monday','tuesday','wednesday','thursday','friday','saturday','sunday'
  289. ];
  290. while( $start->timestamp<=$end->timestamp ) {
  291. $weekday = $wdays[$start->dayOfWeek];
  292. if(in_array($weekday, $promo->days_of_week)) {
  293. $dates[] = $start->toDateString();
  294. } else {
  295. $ok = $promo->room->getPriceForPeriod( $start, $start->copy()->addDays($promo->days_number) );
  296. if(empty($ok)) {
  297. $dates[] = $start->toDateString();
  298. }
  299. }
  300.  
  301. $start->addDays(1);
  302. }
  303.  
  304. $ret['controllers'][$k]['unavailable'] = $dates;
  305. $ret['controllers'][$k]['start'] = $promo->date_from->toDateString();
  306. $ret['controllers'][$k]['end'] = $promo->to_date->toDateString();
  307. $ret['controllers'][$k]['duration'] = $promo->days_number;
  308.  
  309. } else if($controller['type']=='check-in') {
  310.  
  311. $data = request('data');
  312. $booking_id = $data['checkin']['start']['id'];
  313.  
  314. $booking = Booking::where('id', $booking_id)->where('hotel_id', $hotel->id)->whereIn('checkin_status', ['pending', 'partial'])->first();
  315. if(!empty( $booking )) {
  316. $ret['controllers'][$k]['rooms'] = [];
  317. $ret['controllers'][$k]['config'] = [
  318. 'rooms' => [],
  319. 'guests' => [],
  320. ];
  321.  
  322. $fields = [
  323. "checkin_name",
  324. "checkin_email",
  325. "checkin_phone",
  326. "checkin_address",
  327. "checkin_id",
  328. ];
  329.  
  330. foreach ($fields as $f) {
  331. if( $hotel->$f=='room' ) {
  332. $ret['controllers'][$k]['config']['rooms'][] = $f;
  333. } else if( $hotel->$f=='guest' ) {
  334. $ret['controllers'][$k]['config']['guests'][] = $f;
  335. }
  336. }
  337.  
  338.  
  339. foreach ($booking->rooms as $br) {
  340. $br_info = [
  341. 'guest_count' => $br->adults + $br->children + $br->infants,
  342. 'name' => $br->room->name
  343. ];
  344. $ret['controllers'][$k]['rooms'][] = $br_info;
  345. }
  346.  
  347. $ret['controllers'][$k]['info'] = $booking->checkin_data;
  348. }
  349.  
  350. } else if($controller['type']=='extras') {
  351. $ret['controllers'][$k]['items'] = Extra::where('hotel_id', $hotel->id)->get()->toArray();
  352. }
  353.  
  354. }
  355.  
  356.  
  357. $ret['nextvideo'] = null;
  358. if( count($ret['controllers'])==1 ) {
  359. $nextStory = !empty( current($ret['controllers'])['story'] ) ? current($ret['controllers'])['story'] : request('story');
  360. $nextStep = !empty( current($ret['controllers'])['step'] ) ? current($ret['controllers'])['step'] : 'start';
  361. $ret['nextvideo'] = config('chatbot.stories.'.$nextStory.'.steps.'.$nextStep.'.video');
  362. }
  363.  
  364. if(!empty($ret['video'])) {
  365. $ret['video'] = url('/front/video/LANGPLACEHOLDER/'.$ret['video'].'.mp4');
  366. }
  367. if(!empty($ret['nextvideo'])) {
  368. $ret['nextvideo'] = url('/front/video/LANGPLACEHOLDER/'.$ret['nextvideo'].'.mp4');
  369. }
  370. } else {
  371. $step = config('chatbot.stories.'.request('story').'.steps.'.request('step'));
  372. $ret['success'] = false;
  373. }
  374.  
  375. if( request()->input('config') ) {
  376. $ret['config'] = $hotel->toArray();
  377. $ret['config']['debug'] = $this->is_admin();
  378. $ret['config']['captcha_key'] = '6LfBlIoUAAAAAB88HAzexnaUAKrneEYZGSVVe_KD';
  379. $ret['config']['sentences'] = [
  380. 'adults' => [
  381. 'bg' => 'Възрастни',
  382. 'en' => 'Adults',
  383. ],
  384. 'children' => [
  385. 'bg' => 'Деца до '.$ret['config']['child_age'].'г.',
  386. 'en' => 'Children up to '.$ret['config']['child_age'].' y.o.',
  387. ],
  388. 'infants' => [
  389. 'bg' => 'Бебета до '.$ret['config']['infant_age'].'г.',
  390. 'en' => 'Babies up to '.$ret['config']['infant_age'].' y.o.',
  391. ],
  392. 'room_price' => [
  393. 'bg' => 'Цена за стаята',
  394. 'en' => 'Room price',
  395. ],
  396. 'remaining' => [
  397. 'bg' => 'остават',
  398. 'en' => 'remaining',
  399. ],
  400. 'room' => [
  401. 'bg' => 'Стая',
  402. 'en' => 'Room',
  403. ],
  404. 'guest' => [
  405. 'bg' => 'Гост',
  406. 'en' => 'Guest',
  407. ],
  408. 'id_documents' => [
  409. [
  410. 'bg' => 'Лична карта',
  411. 'en' => 'ID Card',
  412. ],
  413. [
  414. 'bg' => 'Международен паспорт',
  415. 'en' => 'International Passport',
  416. ]
  417. ],
  418. 'weights' => [
  419. 'ml' => [
  420. 'bg' => 'мл',
  421. 'en' => 'ml',
  422. ],
  423. 'gr' => [
  424. 'bg' => 'гр',
  425. 'en' => 'gr',
  426. ],
  427. 'pcs' => [
  428. 'bg' => 'бр',
  429. 'en' => 'pcs',
  430. ],
  431. ],
  432.  
  433.  
  434. 'checkin_address' => [
  435. 'bg' => 'Адрес',
  436. 'en' => 'Address',
  437. ],
  438. 'checkin_phone' => [
  439. 'bg' => 'Телефонен номер',
  440. 'en' => 'Phone number',
  441. ],
  442. 'checkin_email' => [
  443. 'bg' => 'Email адрес',
  444. 'en' => 'Email address',
  445. ],
  446. 'checkin_name' => [
  447. 'bg' => 'Име и Фамилия',
  448. 'en' => 'Names',
  449. ],
  450. 'checkin_id_id' => [
  451. 'bg' => 'Номер на документа',
  452. 'en' => 'Document Number',
  453. ],
  454. 'checkin_id_type' => [
  455. 'bg' => 'Документ за самоличност',
  456. 'en' => 'Type of document',
  457. ],
  458. 'checkin_id_nationality' => [
  459. 'bg' => 'Гражданство',
  460. 'en' => 'Nationality',
  461. ],
  462. 'not_bot' => [
  463. 'bg' => 'Моля, потвърдете, че не сте робот',
  464. 'en' => 'Please, prove you are not a robot',
  465. ],
  466. 'checkin-early' => [
  467. 'bg' => 'Ранно настаняване',
  468. 'en' => 'Early Check-in',
  469. ],
  470. 'checkout-late' => [
  471. 'bg' => 'Късно напускане',
  472. 'en' => 'Late Check-out',
  473. ],
  474. 'before' => [
  475. 'bg' => 'преди',
  476. 'en' => 'before',
  477. ],
  478. 'after' => [
  479. 'bg' => 'след',
  480. 'en' => 'after',
  481. ],
  482. 'total' => [
  483. 'bg' => 'Общо',
  484. 'en' => 'Total',
  485. ],
  486. ];
  487.  
  488. unset($ret['config']['payment_secret']);
  489. unset($ret['config']['payment_password']);
  490. }
  491.  
  492. return Response::json($ret);
  493.  
  494. }
  495.  
  496. public function pay() {
  497.  
  498. $ret = array(
  499. 'success' => true,
  500. );
  501.  
  502. $hotel = $this->getHotel();
  503. $input = request()->input();
  504.  
  505. //dd($input);
  506.  
  507. $type = null;
  508. $total = 0;
  509. $room_id = null;
  510. if(!empty($input['data']['bookings']['rooms'])) {
  511. $type = 'booking';
  512. $rooms = $input['data']['bookings']['rooms'];
  513. foreach ($rooms as $k => $room_info) {
  514. $room_id = $room_info['room_id'];
  515. $room = Room::find($room_info['room_id']);
  516. $prices = $room->getPriceForPeriod( request()->input('data.bookings.start'), request()->input('data.bookings.booking_out') );
  517.  
  518. $room_total = $room_info['adults']==1 ? $prices['base_double'] : $prices['base'];
  519. if($room_info['adults'] > $room->capacity) {
  520. $room_total += $prices['adult'] * ($room_info['adults'] - $room->capacity);
  521. }
  522. if($room_info['children'] > $room->capacity) {
  523. $room_total += $prices['child'] * ($room_info['children'] - $room->capacity);
  524. }
  525.  
  526. if($room_info['checkin']) {
  527. $room_total += $prices['extra_checkin'];
  528. }
  529. if($room_info['checkout']) {
  530. $room_total += $prices['extra_checkout'];
  531. }
  532.  
  533. $total += $room_total;
  534.  
  535. $rooms[$k]['name'] = $room->name;
  536. $rooms[$k]['price'] = $room_total;
  537. }
  538.  
  539. $extras = $input['data']['bookings']['extras'];
  540. $names = $input['data']['bookings']['names'];
  541. $date_in = request()->input('data.bookings.start');
  542. $date_out = request()->input('data.bookings.booking_out');
  543. $payment_token = request()->input('data.bookings.payment.token');
  544. $item_name = 'Резервация в Хотел '.$hotel->name;
  545.  
  546. } else if(!empty($input['data']['promos']['start'])) {
  547. $type = 'booking';
  548. $promo = Promotion::find($input['data']['promos']['start']['id']);
  549. $rooms = [];
  550. for($i=0;$i<$input['data']['promos']['start']['amount'];$i++) {
  551. $rooms[] = [
  552. "room_id" => $promo->room_id,
  553. "name" => $promo->room->name,
  554. "adults" => $promo->room->capacity,
  555. "children" => 0,
  556. "infants" => 0,
  557. "price" => $promo->discount_price
  558. ];
  559. }
  560. $total += $promo->discount_price*$input['data']['promos']['start']['amount'];
  561. $room_id = $promo->room_id;
  562.  
  563.  
  564. $extras = $input['data']['promos']['extras'];
  565. $names = $input['data']['promos']['names'];
  566. $date_in = request()->input('data.promos.checkin');
  567. $cin = new Carbon( request()->input('data.promos.checkin') );
  568. $date_out = $cin->addDays($promo->days_number)->toDateString();
  569. $payment_token = request()->input('data.promos.payment.token');
  570. $item_name = 'Промо Резервация в Хотел '.$hotel->name;
  571. } else if(!empty($input['data']['vouchers']['start'])) {
  572. $type = 'voucher';
  573. $voucher = Voucher::find($input['data']['vouchers']['start']);
  574. $total = $voucher->price;
  575. $names = $input['data']['vouchers']['names'];
  576. $payment_token = request()->input('data.vouchers.payment.token');
  577. $item_name = 'Подаръчен Ваучер от Хотел '.$hotel->name;
  578.  
  579. } else {
  580. return Response::json( [
  581. 'success' => false
  582. ] );;
  583. }
  584.  
  585.  
  586. if( $type=='booking' ) {
  587. foreach ($extras as $e_id => $amount) {
  588. if(intval( $amount )) {
  589. $extra = Extra::find($e_id);
  590. $total += intval( $amount ) * $extra->price;
  591. }
  592. }
  593. }
  594.  
  595.  
  596. try {
  597. if( $hotel->payment=='pay' ) {
  598. if($hotel->payment_method == 'stripe') {
  599. \Stripe\Stripe::setApiKey ( $hotel->payment_secret );
  600. \Stripe\Charge::create ( array (
  601. "amount" => $total*100,
  602. "currency" => $hotel->currency,
  603. "source" => $payment_token, // obtained with Stripe.js
  604. "description" => $item_name
  605. ) );
  606.  
  607. } else if($hotel->payment_method == 'paylane') {
  608. $paylaneClient = new PayLaneRestClient($hotel->payment_secret, $hotel->payment_password);
  609.  
  610. $card_params = array(
  611. 'sale' => array(
  612. 'amount' => $total,
  613. 'currency' => $hotel->currency,
  614. 'description' => $item_name
  615. ),
  616. 'customer' => array(
  617. 'email' => $names['email'],
  618. 'ip' => request()->ip(),
  619. ),
  620. 'card' => array(
  621. 'token' => $payment_token,
  622. ),
  623. );
  624.  
  625. try {
  626. $status = $paylaneClient->cardSaleByToken($card_params);
  627. } catch (Exception $e) {
  628. return Response::json( [
  629. 'success' => false,
  630. 'message' => $e->getMessage()
  631. ] );
  632. }
  633.  
  634. // checking transaction status example (optional):
  635. if ($paylaneClient->isSuccess()) {
  636. // $status['id_sale']
  637. // Cool
  638. } else {
  639. return Response::json( [
  640. 'success' => false,
  641. 'message' => $status['error']['error_description'].' ('.$status['error']['id_error'].' - '.$status['error']['error_number'].')'
  642. ] );
  643. }
  644.  
  645. }
  646. }
  647. } catch ( \Exception $e ) {
  648. return Response::json( [
  649. 'success' => false,
  650. 'message' => $e->getMessage()
  651. ] );
  652. }
  653.  
  654. $payment_id = null;
  655. if( $type=='booking' ) {
  656. $booking = new Booking;
  657. $booking->name = $names['name'];
  658. $booking->email = $names['email'];
  659. $booking->phone = $names['phone'];
  660. $booking->note = $names['note'];
  661. $booking->hotel_id = $hotel->id;
  662. $booking->room_id = $room_id;
  663. $booking->price = $total;
  664. $booking->check_in = $date_in;
  665. $booking->check_out = $date_out;
  666. $booking->payment_method = $hotel->payment_method;
  667. $booking->save();
  668.  
  669. $booking->setReservationId();
  670.  
  671. $payment_id = $booking->reservation_id;
  672.  
  673. foreach ($rooms as $room_info) {
  674. $booking_room = new BookingRoom;
  675. $booking_room->booking_id = $booking->id;
  676. $booking_room->room_id = $room_info['room_id'];
  677. $booking_room->adults = $room_info['adults'];
  678. $booking_room->children = $room_info['children'];
  679. $booking_room->infants = $room_info['infants'];
  680. $booking_room->checkin = $room_info['checkin'];
  681. $booking_room->checkout = $room_info['checkout'];
  682. $booking_room->save();
  683. }
  684. $extras_list = [];
  685. foreach ($extras as $e_id => $amount) {
  686. if(intval( $amount )) {
  687. $booking_extra = new BookingExtra;
  688. $booking_extra->booking_id = $booking->id;
  689. $booking_extra->extra_id = $e_id;
  690. $booking_extra->amount = $amount;
  691. $booking_extra->save();
  692.  
  693. $extra = Extra::find($e_id);
  694. $extras_list[] = [
  695. 'name' => $extra->name,
  696. 'amount' => $amount,
  697. 'price' => $extra->price,
  698. 'total' => $extra->price * intval($amount),
  699. ];
  700. }
  701. }
  702.  
  703.  
  704.  
  705. $start = new Carbon( $date_in );
  706. $duration = $start->diffInDays( new Carbon( $date_out ) );
  707.  
  708. $rooms_list_arr = [];
  709. $rooms_list = [];
  710. foreach ($rooms as $room) {
  711. if(!isset($rooms_list_arr[$room['name']])) {
  712. $rooms_list_arr[$room['name']] = 0;
  713. }
  714. $rooms_list_arr[$room['name']] ++;
  715. }
  716. foreach ($rooms_list_arr as $key => $value) {
  717. $rooms_list[] = $value.'x '.$key;
  718. }
  719. $rooms_list = implode(', ', $rooms_list);
  720.  
  721. $reservation_number = $booking->getReservationNumber();
  722.  
  723. $subject = 'Вашата резервация';
  724. $receiver = $booking->email;
  725. Mail::send('emails.booking', [
  726. 'hotel_name' => $hotel->name,
  727. 'hotel_privacy_policy' => $hotel->privacy_policy,
  728. 'hotel_website' => $hotel->website,
  729. 'hotel_address' => $hotel->address,
  730. 'hotel_coordinates' => $hotel->coordinates,
  731. 'hotel_phone' => $hotel->phone,
  732. 'hotel_phone2' => $hotel->phone2,
  733. 'hotel_email' => $hotel->email,
  734. 'hotel_email2' => $hotel->email2,
  735. 'name' => $booking->name,
  736. 'room_count' => count($rooms),
  737. 'duration' => $duration,
  738. 'check_in' => $date_in,
  739. 'check_out' => $date_out,
  740. 'rooms' => $rooms,
  741. 'extras' => $extras_list,
  742. 'currency' => $hotel->currency,
  743. 'total_price' => $total,
  744. 'rooms_list' => $rooms_list,
  745. 'reservation_number' => $reservation_number,
  746. ], function ($message) use ($subject, $receiver) {
  747. //$message->from($sender, $sender_name);
  748. $message->to( $receiver );
  749. $message->subject($subject);
  750. });
  751.  
  752. /*
  753. $notify = Admin::where('hotel_id', $hotel->id)->get();
  754. $notify_content = 'Току що получих нова резервация. Подробности можеш да видиш тук: http://eva.youpluswe.com/bookings';
  755. foreach ($notify as $nuser) {
  756. $admin_email = $nuser->email;
  757. Mail::raw($notify_content, function ($message) use ($admin_email) {
  758. $message->to($admin_email);
  759. $message->subject('Нова резервация');
  760. });
  761. }
  762. */
  763.  
  764. } else if( $type=='voucher' ) {
  765. $pvoucher = new PurchasedVoucher;
  766. $pvoucher->hotel_id = $hotel->id;
  767. $pvoucher->voucher_id = $voucher->id;
  768. $pvoucher->name = $names['name'];
  769. $pvoucher->price = $total;
  770. $pvoucher->display_name = $names['display_name'];
  771. $pvoucher->email = $names['email'];
  772. $pvoucher->phone = $names['phone'];
  773. $pvoucher->receiver_name = $names['receiver_name'];
  774. $pvoucher->message = $names['message'];
  775. $pvoucher->payment_method = $hotel->payment_method;
  776. $pvoucher->save();
  777.  
  778. $pvoucher->setReservationId();
  779. $pvoucher->generateImage();
  780.  
  781. $payment_id = $pvoucher->reservation_id;
  782.  
  783. $subject = 'Вашият ваучер';
  784. $receiver = $pvoucher->email;
  785. $duration = Carbon::now()->addMonths( $voucher->validity )->toDateString();
  786.  
  787. Mail::send('emails.voucher', [
  788. 'hotel_name' => $hotel->name,
  789. 'hotel_website' => $hotel->website,
  790. 'hotel_address' => $hotel->address,
  791. 'hotel_coordinates' => $hotel->coordinates,
  792. 'hotel_phone' => $hotel->phone,
  793. 'hotel_phone2' => $hotel->phone2,
  794. 'hotel_email' => $hotel->email,
  795. 'hotel_email2' => $hotel->email2,
  796.  
  797.  
  798. 'name' => $pvoucher->receiver_name,
  799. 'service_name' => $voucher->name,
  800. 'voucher_message' => $pvoucher->message,
  801. 'duration' => $duration,
  802. 'voucher_link' => $pvoucher->getImage(),
  803.  
  804. ], function ($message) use ($subject, $receiver) {
  805. //$message->from($sender, $sender_name);
  806. $message->to( $receiver );
  807. $message->subject($subject);
  808. });
  809.  
  810. }
  811.  
  812. return Response::json( [
  813. 'success' => true,
  814. 'total' => $total,
  815. 'id' => $payment_id
  816. ] );
  817. }
  818.  
  819. public function booking_id() {
  820.  
  821. $ret = array(
  822. 'success' => false,
  823. );
  824.  
  825. $hotel = $this->getHotel();
  826. if( request()->input('booking_id') ) {
  827. $bid = request()->input('booking_id');
  828. $bid = preg_replace("/[^0-9]/", "", $bid );
  829. $bid = ltrim($bid, '0');
  830. $booking = Booking::where('reservation_id', $bid)->where('hotel_id', $hotel->id)->first();
  831. if( $booking ) {
  832. $ret['success'] = true;
  833. $ret['booking'] = $booking->toArray();
  834. $ret['booking']['rooms'] = $booking->rooms->toArray();
  835. }
  836. }
  837.  
  838. return Response::json($ret);
  839. }
  840.  
  841. private function get_domain($domain, $debug = false)
  842. {
  843. $original = $domain = strtolower($domain);
  844. if (filter_var($domain, FILTER_VALIDATE_IP)) { return $domain; }
  845. $debug ? print('<strong style="color:green">&raquo;</strong> Parsing: '.$original) : false;
  846. $arr = array_slice(array_filter(explode('.', $domain, 4), function($value){
  847. return $value !== 'www';
  848. }), 0); //rebuild array indexes
  849. if (count($arr) > 2)
  850. {
  851. $count = count($arr);
  852. $_sub = explode('.', $count === 4 ? $arr[3] : $arr[2]);
  853. $debug ? print(" (parts count: {$count})") : false;
  854. if (count($_sub) === 2) // two level TLD
  855. {
  856. $removed = array_shift($arr);
  857. if ($count === 4) // got a subdomain acting as a domain
  858. {
  859. $removed = array_shift($arr);
  860. }
  861. $debug ? print("<br>\n" . '[*] Two level TLD: <strong>' . join('.', $_sub) . '</strong> ') : false;
  862. }
  863. elseif (count($_sub) === 1) // one level TLD
  864. {
  865. $removed = array_shift($arr); //remove the subdomain
  866. if (strlen($_sub[0]) === 2 && $count === 3) // TLD domain must be 2 letters
  867. {
  868. array_unshift($arr, $removed);
  869. }
  870. else
  871. {
  872. // non country TLD according to IANA
  873. $tlds = array(
  874. 'aero',
  875. 'arpa',
  876. 'asia',
  877. 'biz',
  878. 'cat',
  879. 'com',
  880. 'coop',
  881. 'edu',
  882. 'gov',
  883. 'info',
  884. 'jobs',
  885. 'mil',
  886. 'mobi',
  887. 'museum',
  888. 'name',
  889. 'net',
  890. 'org',
  891. 'post',
  892. 'pro',
  893. 'tel',
  894. 'travel',
  895. 'xxx',
  896. );
  897. if (count($arr) > 2 && in_array($_sub[0], $tlds) !== false) //special TLD don't have a country
  898. {
  899. array_shift($arr);
  900. }
  901. }
  902. $debug ? print("<br>\n" .'[*] One level TLD: <strong>'.join('.', $_sub).'</strong> ') : false;
  903. }
  904. else // more than 3 levels, something is wrong
  905. {
  906. for ($i = count($_sub); $i > 1; $i--)
  907. {
  908. $removed = array_shift($arr);
  909. }
  910. $debug ? print("<br>\n" . '[*] Three level TLD: <strong>' . join('.', $_sub) . '</strong> ') : false;
  911. }
  912. }
  913. elseif (count($arr) === 2)
  914. {
  915. $arr0 = array_shift($arr);
  916. if (strpos(join('.', $arr), '.') === false
  917. && in_array($arr[0], array('localhost','test','invalid')) === false) // not a reserved domain
  918. {
  919. $debug ? print("<br>\n" .'Seems invalid domain: <strong>'.join('.', $arr).'</strong> re-adding: <strong>'.$arr0.'</strong> ') : false;
  920. // seems invalid domain, restore it
  921. array_unshift($arr, $arr0);
  922. }
  923. }
  924. $debug ? print("<br>\n".'<strong style="color:gray">&laquo;</strong> Done parsing: <span style="color:red">' . $original . '</span> as <span style="color:blue">'. join('.', $arr) ."</span><br>\n") : false;
  925. return join('.', $arr);
  926. }
  927.  
  928. }
  929.  
  930.  
  931. /**
  932. * Client library for Paylane REST Server.
  933. * More info at http://devzone.paylane.com
  934. */
  935. class PayLaneRestClient
  936. {
  937. /**
  938. * @var string
  939. */
  940. protected $api_url = 'https://direct.paylane.com/rest/';
  941.  
  942. /**
  943. * @var string
  944. */
  945. protected $username = null, $password = null;
  946.  
  947. /**
  948. * @var array
  949. */
  950. protected $http_errors = array
  951. (
  952. 400 => '400 Bad Request',
  953. 401 => '401 Unauthorized',
  954. 500 => '500 Internal Server Error',
  955. 501 => '501 Not Implemented',
  956. 502 => '502 Bad Gateway',
  957. 503 => '503 Service Unavailable',
  958. 504 => '504 Gateway Timeout',
  959. );
  960.  
  961. /**
  962. * @var bool
  963. */
  964. protected $is_success = false;
  965.  
  966. /**
  967. * @var array
  968. */
  969. protected $allowed_request_methods = array(
  970. 'get',
  971. 'put',
  972. 'post',
  973. 'delete',
  974. );
  975.  
  976. /**
  977. * @var boolean
  978. */
  979. protected $ssl_verify = true;
  980.  
  981. /**
  982. * Constructor
  983. *
  984. * @param string $username Username
  985. * @param string $password Password
  986. */
  987. public function __construct($username, $password)
  988. {
  989. $this->username = $username;
  990. $this->password = $password;
  991.  
  992. $validate_params = array
  993. (
  994. false === extension_loaded('curl') => 'The curl extension must be loaded for using this class!',
  995. false === extension_loaded('json') => 'The json extension must be loaded for using this class!'
  996. );
  997. $this->checkForErrors($validate_params);
  998. }
  999.  
  1000. /**
  1001. * Set Api URL
  1002. *
  1003. * @param string $url Api URL
  1004. */
  1005. public function setUrl($url)
  1006. {
  1007. $this->api_url = $url;
  1008. }
  1009.  
  1010. /**
  1011. * Sets SSL verify
  1012. *
  1013. * @param bool $ssl_verify SSL verify
  1014. */
  1015. public function setSSLverify($ssl_verify)
  1016. {
  1017. $this->ssl_verify = $ssl_verify;
  1018. }
  1019.  
  1020. /**
  1021. * Request state getter
  1022. *
  1023. * @return bool
  1024. */
  1025. public function isSuccess()
  1026. {
  1027. return $this->is_success;
  1028. }
  1029.  
  1030. /**
  1031. * Performs card sale
  1032. *
  1033. * @param array $params Sale Params
  1034. * @return array
  1035. */
  1036. public function cardSale($params)
  1037. {
  1038. return $this->call(
  1039. 'cards/sale',
  1040. 'post',
  1041. $params
  1042. );
  1043. }
  1044.  
  1045. /**
  1046. * Performs card sale by token
  1047. *
  1048. * @param array $params Sale Params
  1049. * @return array
  1050. */
  1051. public function cardSaleByToken($params)
  1052. {
  1053. return $this->call(
  1054. 'cards/saleByToken',
  1055. 'post',
  1056. $params
  1057. );
  1058. }
  1059.  
  1060. /**
  1061. * Card authorization
  1062. *
  1063. * @param array $params Authorization params
  1064. * @return array
  1065. */
  1066. public function cardAuthorization($params)
  1067. {
  1068. return $this->call(
  1069. 'cards/authorization',
  1070. 'post',
  1071. $params
  1072. );
  1073. }
  1074.  
  1075. /**
  1076. * Card authorization by token
  1077. *
  1078. * @param array $params Authorization params
  1079. * @return array
  1080. */
  1081. public function cardAuthorizationByToken($params)
  1082. {
  1083. return $this->call(
  1084. 'cards/authorizationByToken',
  1085. 'post',
  1086. $params
  1087. );
  1088. }
  1089.  
  1090. /**
  1091. * PayPal authorization
  1092. *
  1093. * @param $params
  1094. * @return array
  1095. */
  1096. public function paypalAuthorization($params)
  1097. {
  1098. return $this->call(
  1099. 'paypal/authorization',
  1100. 'post',
  1101. $params
  1102. );
  1103. }
  1104.  
  1105. /**
  1106. * Performs capture from authorized card
  1107. *
  1108. * @param array $params Capture authorization params
  1109. * @return array
  1110. */
  1111. public function captureAuthorization($params)
  1112. {
  1113. return $this->call(
  1114. 'authorizations/capture',
  1115. 'post',
  1116. $params
  1117. );
  1118. }
  1119.  
  1120. /**
  1121. * Performs closing of card authorization, basing on authorization card ID
  1122. *
  1123. * @param array $params Close authorization params
  1124. * @return array
  1125. */
  1126. public function closeAuthorization($params)
  1127. {
  1128. return $this->call(
  1129. 'authorizations/close',
  1130. 'post',
  1131. $params
  1132. );
  1133. }
  1134.  
  1135. /**
  1136. * Performs refund
  1137. *
  1138. * @param array $params Refund params
  1139. * @return array
  1140. */
  1141. public function refund($params)
  1142. {
  1143. return $this->call(
  1144. 'refunds',
  1145. 'post',
  1146. $params
  1147. );
  1148. }
  1149.  
  1150. /**
  1151. * Get sale info
  1152. *
  1153. * @param array $params Get sale info params
  1154. * @return array
  1155. */
  1156. public function getSaleInfo($params)
  1157. {
  1158. return $this->call(
  1159. 'sales/info',
  1160. 'get',
  1161. $params
  1162. );
  1163. }
  1164.  
  1165. /**
  1166. * Get sale authorization info
  1167. *
  1168. * @param array $params Get sale authorization info params
  1169. * @return array
  1170. */
  1171. public function getAuthorizationInfo($params)
  1172. {
  1173. return $this->call(
  1174. 'authorizations/info',
  1175. 'get',
  1176. $params
  1177. );
  1178. }
  1179.  
  1180. /**
  1181. * Performs sale status check
  1182. *
  1183. * @param array $params Check sale status
  1184. * @return array
  1185. */
  1186. public function checkSaleStatus($params)
  1187. {
  1188. return $this->call(
  1189. 'sales/status',
  1190. 'get',
  1191. $params
  1192. );
  1193. }
  1194.  
  1195. /**
  1196. * Direct debit sale
  1197. *
  1198. * @param array $params Direct debit params
  1199. * @return array
  1200. */
  1201. public function directDebitSale($params)
  1202. {
  1203. return $this->call(
  1204. 'directdebits/sale',
  1205. 'post',
  1206. $params
  1207. );
  1208. }
  1209.  
  1210. /**
  1211. * Sofort sale
  1212. *
  1213. * @param array $params Sofort params
  1214. * @return array
  1215. */
  1216. public function sofortSale($params)
  1217. {
  1218. return $this->call(
  1219. 'sofort/sale',
  1220. 'post',
  1221. $params
  1222. );
  1223. }
  1224.  
  1225. /**
  1226. * iDeal sale
  1227. *
  1228. * @param $params iDeal transaction params
  1229. * @return array
  1230. */
  1231. public function idealSale($params)
  1232. {
  1233. return $this->call(
  1234. 'ideal/sale',
  1235. 'post',
  1236. $params
  1237. );
  1238. }
  1239.  
  1240. /**
  1241. * iDeal banks list
  1242. *
  1243. * @return array
  1244. */
  1245. public function idealBankCodes()
  1246. {
  1247. return $this->call(
  1248. 'ideal/bankcodes',
  1249. 'get',
  1250. array()
  1251. );
  1252. }
  1253.  
  1254. /**
  1255. * Bank transfer sale
  1256. *
  1257. * @param array $params Bank transfer sale params
  1258. * @return array
  1259. */
  1260. public function bankTransferSale($params)
  1261. {
  1262. return $this->call(
  1263. 'banktransfers/sale',
  1264. 'post',
  1265. $params
  1266. );
  1267. }
  1268.  
  1269. /**
  1270. * PayPal sale
  1271. *
  1272. * @param array $params Paypal sale params
  1273. * @return array
  1274. */
  1275. public function paypalSale($params)
  1276. {
  1277. return $this->call(
  1278. 'paypal/sale',
  1279. 'post',
  1280. $params
  1281. );
  1282. }
  1283.  
  1284. /**
  1285. * Cancels Paypal recurring profile
  1286. *
  1287. * @param array $params Paypal params
  1288. * @return array
  1289. */
  1290. public function paypalStopRecurring($params)
  1291. {
  1292. return $this->call('paypal/stopRecurring',
  1293. 'post',
  1294. $params
  1295. );
  1296. }
  1297.  
  1298. /**
  1299. * Performs resale by sale ID
  1300. *
  1301. * @param array $params Resale by sale params
  1302. * @return array
  1303. */
  1304. public function resaleBySale($params)
  1305. {
  1306. return $this->call(
  1307. 'resales/sale',
  1308. 'post',
  1309. $params
  1310. );
  1311. }
  1312.  
  1313. /**
  1314. * Performs resale by authorization ID
  1315. *
  1316. * @param array $params Resale by authorization params
  1317. * @return array
  1318. */
  1319. public function resaleByAuthorization($params)
  1320. {
  1321. return $this->call(
  1322. 'resales/authorization',
  1323. 'post',
  1324. $params
  1325. );
  1326. }
  1327.  
  1328. /**
  1329. * Checks if a card is enrolled in the 3D-Secure program.
  1330. *
  1331. * @param array $params Is card 3d secure params
  1332. * @return array
  1333. */
  1334. public function checkCard3DSecure($params)
  1335. {
  1336. return $this->call(
  1337. '3DSecure/checkCard',
  1338. 'get',
  1339. $params
  1340. );
  1341. }
  1342.  
  1343. /**
  1344. * Checks if a card is enrolled in the 3D-Secure program, based on the card's token.
  1345. *
  1346. * @param array $params Is card 3d secure params
  1347. * @return array
  1348. */
  1349. public function checkCard3DSecureByToken($params)
  1350. {
  1351. return $this->call(
  1352. '3DSecure/checkCardByToken',
  1353. 'get',
  1354. $params
  1355. );
  1356. }
  1357.  
  1358. /**
  1359. * Performs sale by ID 3d secure authorization
  1360. *
  1361. * @param array $params Sale by 3d secure authorization params
  1362. * @return array
  1363. */
  1364. public function saleBy3DSecureAuthorization($params)
  1365. {
  1366. return $this->call(
  1367. '3DSecure/authSale',
  1368. 'post',
  1369. $params
  1370. );
  1371. }
  1372.  
  1373. /**
  1374. * Perform check card
  1375. *
  1376. * @param array $params Check card params
  1377. * @return array
  1378. */
  1379. public function checkCard($params)
  1380. {
  1381. return $this->call(
  1382. 'cards/check',
  1383. 'get',
  1384. $params
  1385. );
  1386. }
  1387.  
  1388. /**
  1389. * Perform check card by token
  1390. *
  1391. * @param array $params Check card params
  1392. * @return array
  1393. */
  1394. public function checkCardByToken($params)
  1395. {
  1396. return $this->call(
  1397. 'cards/checkByToken',
  1398. 'get',
  1399. $params
  1400. );
  1401. }
  1402.  
  1403. /**
  1404. * Performs Apple Pay sale
  1405. *
  1406. * @param array $params Apple Pay sale params
  1407. * @return array
  1408. */
  1409. public function applePaySale(array $params)
  1410. {
  1411. return $this->call(
  1412. 'applepay/sale',
  1413. 'post',
  1414. $params
  1415. );
  1416. }
  1417.  
  1418. /**
  1419. * Performs Apple Pay authorization
  1420. *
  1421. * @param array $params Apple Pay authorization params
  1422. * @return array
  1423. */
  1424. public function applePayAuthorization(array $params)
  1425. {
  1426. return $this->call(
  1427. 'applepay/authorization',
  1428. 'post',
  1429. $params
  1430. );
  1431. }
  1432.  
  1433. /**
  1434. * Method responsible for preparing, setting state and returning answer from rest server
  1435. *
  1436. * @param string $method
  1437. * @param string $request
  1438. * @param array $params
  1439. * @return array
  1440. */
  1441. protected function call($method, $request, $params)
  1442. {
  1443. $this->is_success = false;
  1444.  
  1445. if (is_object($params))
  1446. {
  1447. $params = (array) $params;
  1448. }
  1449.  
  1450. $validate_params = array
  1451. (
  1452. false === is_string($method) => 'Method name must be string',
  1453. false === $this->checkRequestMethod($request) => 'Not allowed request method type',
  1454. );
  1455.  
  1456. $this->checkForErrors($validate_params);
  1457.  
  1458. $params_encoded = json_encode($params);
  1459.  
  1460. $response = $this->pushData($method, $request, $params_encoded);
  1461.  
  1462. $response = json_decode($response, true);
  1463.  
  1464. if (isset($response['success']) && $response['success'] === true)
  1465. {
  1466. $this->is_success = true;
  1467. }
  1468.  
  1469. return $response;
  1470. }
  1471.  
  1472. /**
  1473. * Checking error mechanism
  1474. *
  1475. * @param array $validate_params
  1476. * @throws \Exception
  1477. */
  1478. protected function checkForErrors($validate_params)
  1479. {
  1480. foreach ($validate_params as $key => $error)
  1481. {
  1482. if ($key)
  1483. {
  1484. throw new \Exception($error);
  1485. }
  1486. }
  1487. }
  1488.  
  1489. /**
  1490. * Check if method is allowed
  1491. *
  1492. * @param string $method_type
  1493. * @return bool
  1494. */
  1495. protected function checkRequestMethod($method_type)
  1496. {
  1497. $request_method = strtolower($method_type);
  1498.  
  1499. if(in_array($request_method, $this->allowed_request_methods))
  1500. {
  1501. return true;
  1502. }
  1503.  
  1504. return false;
  1505. }
  1506.  
  1507. /**
  1508. * Method responsible for pushing data to REST server
  1509. *
  1510. * @param string $method
  1511. * @param string $method_type
  1512. * @param string $request - JSON
  1513. * @return array
  1514. * @throws \Exception
  1515. */
  1516. protected function pushData($method, $method_type, $request)
  1517. {
  1518. $ch = curl_init();
  1519.  
  1520. curl_setopt($ch, CURLOPT_URL, $this->api_url . $method);
  1521. curl_setopt($ch, CURLOPT_POST, 1);
  1522. curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
  1523. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
  1524. curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
  1525. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, strtoupper($method_type));
  1526. curl_setopt($ch, CURLOPT_HTTPAUTH, 1);
  1527. curl_setopt($ch, CURLOPT_USERPWD, $this->username . ':' . $this->password);
  1528. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1529. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->ssl_verify);
  1530.  
  1531. $response = curl_exec($ch);
  1532.  
  1533. $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  1534.  
  1535. if (isset($this->http_errors[$http_code]))
  1536. {
  1537. throw new \Exception('Response Http Error - ' . $this->http_errors[$http_code]);
  1538. }
  1539.  
  1540. if (0 < curl_errno($ch))
  1541. {
  1542. throw new \Exception('Unable to connect to ' . $this->api_url . ' Error: ' . curl_error($ch));
  1543. }
  1544.  
  1545. curl_close($ch);
  1546.  
  1547. return $response;
  1548. }
  1549. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement