public function process_shortcode($args = array(), $content = '')
 {
     extract(wp_parse_args($args, $this->_defaults_to_args()));
     global $post, $current_user, $appointments;
     if ('Payment for SERVICE' == $item_name && (isset($appointments->options["percent_deposit"]) && $appointments->options["percent_deposit"] || isset($appointments->options["fixed_deposit"]) && $appointments->options["fixed_deposit"])) {
         $item_name = __('Deposit for SERVICE', 'appointments');
     }
     $item_name = apply_filters('app_paypal_item_name', $item_name);
     // Let's be on the safe side and select the default currency
     if (empty($appointments->options['currency'])) {
         $appointments->options['currency'] = 'USD';
     }
     if (!isset($appointments->options["return"]) || !($return = get_permalink($appointments->options["return"]))) {
         $return = get_permalink($post->ID);
     }
     // Never let an undefined page, just in case
     if (!$return) {
         $return = home_url();
     }
     $return = apply_filters('app_paypal_return', $return);
     $cancel_return = apply_filters('app_paypal_cancel_return', get_option('home'));
     $form = '';
     $form .= '<div class="appointments-paypal">';
     if ($appointments->options['mode'] == 'live') {
         $form .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">';
     } else {
         $form .= '<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">';
     }
     $form .= '<input type="hidden" name="business" value="' . esc_attr($appointments->options['merchant_email']) . '" />';
     $form .= '<input type="hidden" name="cmd" value="_xclick">';
     $form .= '<input type="hidden" class="app_item_name" name="item_name" value="' . $item_name . '" />';
     $form .= '<input type="hidden" name="no_shipping" value="1" />';
     $form .= '<input type="hidden" name="currency_code" value="' . $appointments->options['currency'] . '" />';
     $form .= '<input type="hidden" name="return" value="' . $return . '" />';
     $form .= '<input type="hidden" name="cancel_return" value="' . $cancel_return . '" />';
     $form .= '<input type="hidden" name="notify_url" value="' . admin_url('admin-ajax.php?action=app_paypal_ipn') . '" />';
     $form .= '<input type="hidden" name="src" value="0" />';
     $form .= '<input class="app_custom" type="hidden" name="custom" value="" />';
     $form .= '<input class="app_amount" type="hidden" name="amount" value="" />';
     $form .= '<input class="app_submit_btn';
     // Add a class if user not logged in. May be required for addons.
     if (!is_user_logged_in()) {
         $form .= ' app_not_loggedin';
     }
     $display_currency = App_Template::get_currency_symbol($appointments->options["currency"]);
     $form .= '" type="submit" name="submit_btn" value="' . str_replace(array("CURRENCY"), array($display_currency), $button_text) . '" />';
     // They say Paypal uses this for tracking. I would prefer to remove it if it is not mandatory.
     $form .= '<img style="display:none" alt="" border="0" width="1" height="1" src="https://www.paypal.com/en_US/i/scr/pixel.gif" />';
     $form = apply_filters('app_paypal_additional_fields', $form, $appointments->location, $appointments->service, $appointments->worker);
     $form .= '</form>';
     $form .= '</div>';
     return $form;
 }
Exemplo n.º 2
0
 /**
  * Check and return necessary fields to the front end
  * @return json object
  */
 function pre_confirmation()
 {
     $values = explode(":", $_POST["value"]);
     $location = $values[0];
     $service = $values[1];
     $worker = $values[2];
     $start = $values[3];
     $end = $values[4];
     $post_id = $values[5];
     // A little trick to pass correct lsw variables to the get_price, is_busy and get_capacity functions
     $_REQUEST["app_location_id"] = $location;
     $_REQUEST["app_service_id"] = $service;
     $_REQUEST["app_provider_id"] = $worker;
     $this->get_lsw();
     // Alright, so before we go further, let's check if we can
     if (!is_user_logged_in() && (!empty($this->options['login_required']) && 'yes' == $this->options['login_required'])) {
         die(json_encode(array('error' => __('You need to login to make an appointment.', 'appointments'))));
     }
     $price = $this->get_price();
     // It is possible to apply special discounts
     $price = apply_filters('app_display_amount', $price, $service, $worker);
     $price = apply_filters('app_pre_confirmation_price', $price, $service, $worker, $start, $end);
     $display_currency = !empty($this->options["currency"]) ? App_Template::get_currency_symbol($this->options["currency"]) : App_Template::get_currency_symbol('USD');
     global $wpdb;
     if ($this->is_busy($start, $end, $this->get_capacity())) {
         die(json_encode(array("error" => apply_filters('app_booked_message', __('We are sorry, but this time slot is no longer available. Please refresh the page and try another time slot. Thank you.', 'appointments')))));
     }
     $service_obj = $this->get_service($service);
     $service = '<label><span>' . __('Service name: ', 'appointments') . '</span>' . apply_filters('app_confirmation_service', stripslashes($service_obj->name), $service_obj->name) . '</label>';
     $start = '<label><span>' . __('Date and time: ', 'appointments') . '</span>' . apply_filters('app_confirmation_start', date_i18n($this->datetime_format, $start), $start) . '</label>';
     $end = '<label><span>' . __('Lasts (approx): ', 'appointments') . '</span>' . apply_filters('app_confirmation_lasts', $service_obj->duration . " " . __('minutes', 'appointments'), $service_obj->duration) . '</label>';
     if ($price > 0) {
         $price = '<label><span>' . __('Price: ', 'appointments') . '</span>' . apply_filters('app_confirmation_price', $price . " " . $display_currency, $price) . '</label>';
     } else {
         $price = 0;
     }
     if ($worker) {
         $worker = '<label><span>' . __('Service provider: ', 'appointments') . '</span>' . apply_filters('app_confirmation_worker', stripslashes($this->get_worker_name($worker)), $worker) . '</label>';
     } else {
         $worker = '';
     }
     if ($this->options["ask_name"]) {
         $ask_name = "ask";
     } else {
         $ask_name = "";
     }
     if ($this->options["ask_email"]) {
         $ask_email = "ask";
     } else {
         $ask_email = "";
     }
     if ($this->options["ask_phone"]) {
         $ask_phone = "ask";
     } else {
         $ask_phone = "";
     }
     if ($this->options["ask_address"]) {
         $ask_address = "ask";
     } else {
         $ask_address = "";
     }
     if ($this->options["ask_city"]) {
         $ask_city = "ask";
     } else {
         $ask_city = "";
     }
     if ($this->options["ask_note"]) {
         $ask_note = "ask";
     } else {
         $ask_note = "";
     }
     if (isset($this->options["gcal"]) && 'yes' == $this->options["gcal"]) {
         $ask_gcal = "ask";
     } else {
         $ask_gcal = "";
     }
     $reply_array = array('service' => $service, 'worker' => $worker, 'start' => $start, 'end' => $end, 'price' => $price, 'name' => $ask_name, 'email' => $ask_email, 'phone' => $ask_phone, 'address' => $ask_address, 'city' => $ask_city, 'note' => $ask_note, 'gcal' => $ask_gcal);
     $reply_array = apply_filters('app_pre_confirmation_reply', $reply_array);
     die(json_encode($reply_array));
 }