public function paypalExpressCheckout() { $form_id = $this->getParameter('form_id'); if ($form_id) { // create a paypal object $paypal = new AB_PayPal(); $userData = new AB_UserBookingData($form_id); $userData->load(); if ($userData->get('service_id')) { $service = $userData->getService(); // get the products information from the $_POST and create the Product objects $product = new stdClass(); $product->name = $service->get('title'); $product->desc = $service->getTitleWithDuration(); $product->price = $userData->getFinalServicePrice(); $product->qty = $userData->get('number_of_persons'); $paypal->addProduct($product); // and send the payment request try { $paypal->send_EC_Request($form_id); } catch (Exception $e) { $userData->setPayPalStatus('error', $this->getParameter('error_msg')); @wp_redirect(remove_query_arg(array('action', 'token', 'PayerID'), AB_Utils::getCurrentPageURL())); exit; } } } }
/** * Check if booking time is still available * Return TRUE if time is available * * @return bool */ public function checkBookingTime() { /** @var WPDB $wpdb */ global $wpdb; $booked_datetime = $this->userData->get('appointment_datetime'); $endDate = new DateTime($booked_datetime); $endDate->modify("+ {$this->userData->getService()->get('duration')} sec"); $query = $wpdb->prepare("SELECT `a`.*, `ss`.`capacity`, SUM(`ca`.`number_of_persons`) AS `total_number_of_persons`\n FROM `" . AB_CustomerAppointment::getTableName() . "` `ca`\n LEFT JOIN `" . AB_Appointment::getTableName() . "` `a` ON `a`.`id` = `ca`.`appointment_id`\n LEFT JOIN `" . AB_StaffService::getTableName() . "` `ss` ON `ss`.`staff_id` = `a`.`staff_id` AND `ss`.`service_id` = `a`.`service_id`\n WHERE `a`.`staff_id` = %d\n GROUP BY `a`.`start_date` , `a`.`staff_id` , `a`.`service_id`\n HAVING\n (`a`.`start_date` = %s AND `service_id` = %d AND `total_number_of_persons` >= `capacity`) OR\n (`a`.`start_date` = %s AND `service_id` <> %d) OR\n (`a`.`start_date` > %s AND `a`.`end_date` <= %s) OR\n (`a`.`start_date` < %s AND `a`.`end_date` > %s) OR\n (`a`.`start_date` < %s AND `a`.`end_date` > %s)\n LIMIT 1", $this->userData->getStaffId(), $booked_datetime, $this->userData->get('service_id'), $booked_datetime, $this->userData->get('service_id'), $booked_datetime, $endDate->format('Y-m-d H:i:s'), $endDate->format('Y-m-d H:i:s'), $endDate->format('Y-m-d H:i:s'), $booked_datetime, $booked_datetime); return !(bool) $wpdb->get_row($query); }
/** * Render info text into a variable. * * @param string $text * @param AB_UserBookingData $userData * @param int $preset_price * * @return string */ private function _prepareInfoText($text, $userData, $preset_price = null) { if (empty($this->replacement)) { $service = $userData->getService(); $category_name = $service->getCategoryName(); $staff_name = $userData->getStaffName(); $price = $preset_price === null ? $userData->getServicePrice() : $preset_price; $number_of_persons = $userData->get('number_of_persons'); $service_date = AB_DateTimeUtils::formatDate($userData->get('appointment_datetime')); if (get_option('ab_settings_use_client_time_zone')) { $service_time = AB_DateTimeUtils::formatTime(AB_DateTimeUtils::applyTimeZoneOffset($userData->get('appointment_datetime'), $userData->get('time_zone_offset'))); } else { $service_time = AB_DateTimeUtils::formatTime($userData->get('appointment_datetime')); } $this->replacement = array('[[STAFF_NAME]]' => '<b>' . $staff_name . '</b>', '[[SERVICE_NAME]]' => '<b>' . $service->get('title') . '</b>', '[[CATEGORY_NAME]]' => '<b>' . $category_name . '</b>', '[[NUMBER_OF_PERSONS]]' => '<b>' . $number_of_persons . '</b>', '[[SERVICE_TIME]]' => '<b>' . $service_time . '</b>', '[[SERVICE_DATE]]' => '<b>' . $service_date . '</b>', '[[SERVICE_PRICE]]' => '<b>' . AB_Utils::formatPrice($price) . '</b>', '[[TOTAL_PRICE]]' => '<b>' . AB_Utils::formatPrice($price * $number_of_persons) . '</b>', '[[LOGIN_FORM]]' => get_current_user_id() == 0 ? $this->render('_login_form', array(), false) : ''); } return strtr(nl2br($text), $this->replacement); }