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;
             }
         }
     }
 }
 /**
  * 4. Render fourth step.
  *
  * @return string JSON
  */
 public function executeRenderPayment()
 {
     $response = null;
     $userData = new AB_UserBookingData($this->getParameter('form_id'));
     if ($userData->load()) {
         $payment_disabled = AB_BookingConfiguration::isPaymentDisabled();
         if ($userData->getServicePrice() <= 0) {
             $payment_disabled = true;
         }
         if ($payment_disabled == false) {
             $this->form_id = $this->getParameter('form_id');
             $this->info_text = $this->_prepareInfoText(get_option('ab_appearance_text_info_fourth_step'), $userData);
             $this->info_text_coupon = $this->_prepareInfoText(get_option('ab_appearance_text_info_coupon'), $userData);
             $service = $userData->getService();
             $price = $userData->getFinalServicePrice();
             // Create a paypal object.
             $paypal = new AB_PayPal();
             $product = new stdClass();
             $product->name = $service->get('title');
             $product->desc = $service->getTitleWithDuration();
             $product->price = $price;
             $product->qty = $userData->get('number_of_persons');
             $paypal->addProduct($product);
             // Get the products information from the $_POST and create the Product objects.
             $this->paypal = $paypal;
             $this->_prepareProgressTracker(4, $price);
             // Set response.
             $response = array('status' => 'success', 'disabled' => false, 'html' => $this->render('4_payment', array('userData' => $userData, 'paypal_status' => $userData->extractPayPalStatus()), false));
         } else {
             $response = array('status' => 'success', 'disabled' => true);
         }
     } else {
         $response = array('status' => 'error', 'error' => __('Session error.', 'bookly'));
     }
     // Output JSON response.
     wp_send_json($response);
 }