public function executeRenderPayment() { $form_id = $this->getParameter('form_id'); $response = null; if ($form_id) { $payment_disabled = AB_BookingConfiguration::isPaymentDisabled(); $this->userData = new AB_UserBookingData($form_id); $this->userData->load(); if ($this->userData->hasData()) { if ($this->userData->getServicePrice() <= 0) { $payment_disabled = true; } } if ($payment_disabled == false) { $this->form_id = $form_id; $this->info_text = nl2br(esc_html(get_option('ab_appearance_text_info_fourth_step'))); $this->info_text_coupon = $this->_prepareInfoText(4, $this->userData); if ($this->userData->hasData()) { $employee = new AB_Staff(); $employee->load($this->userData->getStaffId()); $service = new AB_Service(); $service->load($this->userData->getServiceId()); $price = $this->getWpdb()->get_var($this->getWpdb()->prepare(' SELECT price FROM ab_staff_service WHERE staff_id = %d AND service_id = %d', $employee->get('id'), $service->get('id'))); $this->_prepareProgressTracker(4, $price); // Set response. $response = array('status' => 'success', 'html' => $this->render('payment', array(), false)); } else { if (isset($_SESSION['tmp_booking_data'])) { $tmp_booking_data = AB_CommonUtils::getTemporaryBookingData(); if (!empty($tmp_booking_data)) { $tmp_form_id = $tmp_booking_data['form_id']; if (isset($_SESSION['appointment_booking'][$tmp_form_id]) && $_SESSION['appointment_booking'][$tmp_form_id]['cancelled'] === true) { $employee = new AB_Staff(); $employee->load($tmp_booking_data['staff_id'][0]); $service = new AB_Service(); $service->load($tmp_booking_data['service_id']); $price = $this->getWpdb()->get_var($this->getWpdb()->prepare(' SELECT price FROM ab_staff_service WHERE staff_id = %d AND service_id = %d', $employee->get('id'), $service->get('id'))); // create a paypal object $paypal = new PayPal(); $product = new stdClass(); $product->name = $service->get('title'); $product->desc = $service->getTitleWithDuration(); $product->price = $price; $product->qty = 1; $paypal->addProduct($product); // get the products information from the $_POST and create the Product objects $this->paypal = $paypal; $this->_prepareProgressTracker(4, $price); $error_msg = isset($_SESSION['appointment_booking'][$tmp_form_id]['paypal_error']) ? $_SESSION['appointment_booking'][$tmp_form_id]['paypal_error'] : ""; unset($_SESSION['appointment_booking'][$tmp_form_id]['paypal_error']); // Set response. $response = array('status' => 'success', 'html' => $this->render('payment', array('form_id' => $tmp_form_id, 'error_msg' => $error_msg), false)); } } } } } } // Output JSON response. if ($response === null) { $response = array('status' => 'no-data'); } header('Content-Type: application/json'); echo json_encode($response); exit(0); }
$objForm = new Form(); $token1 = $objForm->getPost('token'); if ($token2 == Login::string2hash($token1)) { // create order $objOrder = new Order(); if ($objOrder->createOrder()) { // populate order details $order = $objOrder->getOrder(); $items = $objOrder->getOrderItems(); if (!empty($order) && !empty($items)) { $objBasket = new Basket(); $objCatalogue = new Catalogue(); $objPayPal = new PayPal(); foreach ($items as $item) { $product = $objCatalogue->getProduct($item['product']); $objPayPal->addProduct($item['product'], $product['name'], $item['price'], $item['qty']); } $objPayPal->_tax_cart = $objBasket->_vat; // populate client's details $objUser = new User(); $user = $objUser->getUser($order['client']); if (!empty($user)) { // get user country record $objCountry = new Country(); $country = $objCountry->getCountry($user['country']); // pass client's details to the PayPal instance $objPayPal->_populate = array('address1' => $user['address_1'], 'address2' => $user['address_2'], 'city' => $user['town'], 'state' => $user['county'], 'zip' => $user['post_code'], 'country' => $country['code'], 'email' => $user['email'], 'first_name' => $user['first_name'], 'last_name' => $user['last_name']); // redirect client to PayPal echo $objPayPal->run($order['id']); } }