public function paymentAction()
 {
     $request = $this->getRequest();
     if ($request->isPost()) {
         $subscriptionsession = new Container('subscriptionsession');
         $session = new Container('frontend');
         $bookingModel = new Bookings();
         $trans = new Transactions();
         $model = new Practitioners();
         $common = new Common();
         $consumer = new Consumers();
         $api_url = $this->getServiceLocator()->get('config')['api_url']['value'];
         if ($request->getPost('usesavedcard') !== '1') {
             $data['name'] = $request->getPost('name_on_card');
             $data['email'] = $request->getPost('emailid');
             $card_type = $request->getPost('card_type');
             $data['card_no'] = $request->getPost('card_no');
             $data['month'] = $request->getPost('month');
             $data['year'] = $request->getPost('year');
             $data['cvv_no'] = $request->getPost('cvv_no');
             $data['amount'] = $subscriptionsession->serviceprice;
             $data['rememberme'] = $request->getPost('rememberme');
             $data['use_for_renew'] = $request->getPost('use_for_renew');
             $data['currency'] = $subscriptionsession->currency;
             $result = $trans->processPayment($this->getServiceLocator()->get('Config'), $data);
         } else {
             $savedCard_details = $common->getUserCardDetails($api_url, array('user_id' => $session->userid));
             $cardDetails = end($savedCard_details);
             /* get saved card details : statr */
             $details = $trans->getcarddetails($this->getServiceLocator()->get('Config'), $cardDetails['creditCardDetails_token']);
             if (is_object($details) && isset($details->last4) && isset($details->cardType)) {
                 $data['card_no'] = $details->last4;
                 if ($details->cardType == "Visa") {
                     $card_type = 1;
                 } else {
                     if ($details->cardType == "MasterCard") {
                         $card_type = 2;
                     } else {
                         if ($details->cardType == "American Express") {
                             $card_type = 3;
                         }
                     }
                 }
             }
             /* get saved card details : statr */
             $data['customerDetails_id'] = $cardDetails['customerDetails_id'];
             $data['paymentMethodToken'] = $cardDetails['creditCardDetails_token'];
             $data['amount'] = $subscriptionsession->serviceprice;
             $data['currency'] = $subscriptionsession->currency;
             $result = $trans->processPayment($this->getServiceLocator()->get('Config'), $data, '1');
         }
         if ($result['status'] == 1) {
             // save user card details
             if ($data['rememberme'] == 1 || $data['use_for_renew'] == "1") {
                 $usersCardDetails = array();
                 $usersCardDetails['user_id'] = $session->userid;
                 $usersCardDetails['creditCardDetails_token'] = $result['creditCardDetails_token'];
                 $usersCardDetails['customerDetails_id'] = $result['customerDetails_id'];
                 $usersCardDetails['use_for_renew'] = $data['use_for_renew'] == 1 || $data['use_for_renew'] == "1" ? 1 : 0;
                 $usersCardDetails['card_expiration_hash'] = md5($data['month'] . '-' . $data['year']);
                 //$response = $bookingModel->addUsersCardDetails($api_url, $usersCardDetails);
                 $response = $trans->updateCard($this->getServiceLocator()->get('Config'), $usersCardDetails);
             }
             $subscriptionData = array();
             $subscriptionData['subscription_duration_id'] = $subscriptionsession->subscription_duration_id;
             $subscriptionData['payment_status_id'] = 7;
             $subscriptionData['site_commision'] = "0";
             $subscriptionData['status_id'] = 1;
             $subscriptionData['user_id'] = $session->userid;
             $subscriptionData['invoice_total'] = str_replace(array('USD$', 'CAD$', '$'), array('', '', ''), $subscriptionsession->serviceprice);
             $subscriptionData['created_by'] = $session->userid;
             $subscriptionData['invoice_status'] = 1;
             $subscriptionData['amount'] = str_replace(array('USD$', 'CAD$', '$'), array('', '', ''), $subscriptionsession->serviceprice);
             $subscriptionData['currency'] = $subscriptionsession->currency;
             $subscriptionData['payment_date'] = date('Y-m-d H:i:s');
             $subscriptionData['amount_paid'] = $subscriptionsession->serviceprice;
             $subscriptionData['transaction_id'] = $result['transaction_id'];
             $subscriptionData['payment_instrument_no'] = strlen($data['card_no']) > 4 ? substr($data['card_no'], strlen($data['card_no']) - 4, 4) : $data['card_no'];
             $subscriptionData['payment_method_id'] = $card_type;
             $subscriptionData['payment_status'] = 7;
             $subscriptionData['subscription_start_date'] = date('Y-m-d');
             $subscriptionData['sale_type'] = 1;
             /* 1 for subscription */
             $subscriptionData['subscription_end_date'] = $subscriptionsession->subscription_end_date;
             //$subscriptionData['user_card_id'] = $result['user_card_id'];
             $response = $bookingModel->addBooking($api_url, $subscriptionData);
             if ($response['status'] == 1 && isset($response['id'])) {
                 /* Send email code starts here */
                 $common = new Common();
                 if ($template = $common->emailTemplate($api_url, 11)) {
                     //$sp_details = $model->getSPDetails($api_url, $bookingsession->sp_id);
                     //$user_details = $consumer->getConsumerdetails($api_url, $session->userid);
                     $user_details = $model->getSPDetails($api_url, $session->userid);
                     $user_details['address'] = json_decode($user_details['address'][0], true);
                     $user_details['contact'] = json_decode($user_details['contact'][0], true);
                     $data = $bookingModel->getBookings($api_url, '', '', '', '', '', '', $response['id'], 'subscription');
                     $view = new viewModel(array('booking_details' => $data['results'], 'user_details' => $user_details));
                     $view->setTemplate('application/membership/printinvoice.phtml');
                     $printData = $this->getServiceLocator()->get('viewrenderer')->render($view);
                     // Store in PDF format
                     $dompdf = new \DOMPDF();
                     $dompdf->load_html($printData);
                     $dompdf->render();
                     $output = $dompdf->output();
                     $attachment = new MimePart($output);
                     $attachment->type = 'application/pdf';
                     $attachment->filename = 'invoice.pdf';
                     $attachment->encoding = \Zend\Mime\Mime::ENCODING_BASE64;
                     $attachment->disposition = \Zend\Mime\Mime::DISPOSITION_ATTACHMENT;
                     $mail = new Message();
                     $transport = new \Zend\Mail\Transport\Sendmail();
                     $html = new MimePart(preg_replace('/{{user_name}}/i', '<strong>' . $user_details['first_name'] . ' ' . $user_details['last_name'] . '</strong>', $template['content']));
                     $html->type = "text/html";
                     $body = new MimeMessage();
                     $body->setParts(array($html, $attachment));
                     $mail->setBody($body)->setFrom($template['fromEmail'], 'Ovessence')->addTo($user_details['email'], '')->setSubject($template['subject']);
                     $transport->send($mail);
                     /* Send email code ends here */
                 }
                 // unset all sessions
                 $subscriptionsession->offsetUnset('currency');
                 $subscriptionsession->offsetUnset('serviceprice');
                 $subscriptionsession->offsetUnset('subscription_duration_id');
                 $subscriptionsession->offsetUnset('subscription_end_date');
                 echo json_encode(array('status' => '1', 'msg' => 'Subscription updated successfully. <br /> Redirecting to invoice page..!!', 'subscription_id' => $response['id']));
             } else {
                 echo json_encode(array('status' => '0', 'msg' => 'Transaction completed successfully with Transaction Id <strong>' . $result['transaction_id'] . '</strong>. <br /> Failed to complete your request. Please contact to site admin..!!', 'errors' => $response['data']));
             }
         } else {
             echo json_encode($result);
         }
     }
     exit;
 }
Example #2
0
 public function autorenewcodeAction($api_url, $common, $detail)
 {
     $data = array('user_id' => $detail['user_id'], 'use_for_renew' => 1);
     $getCardDetails = $common->getUserCardDetails($api_url, $data);
     $card = end($getCardDetails);
     // Start:-- Get card details
     if ($card['creditCardDetails_token'] != '' && $card['customerDetails_id'] != '') {
         $bookingModel = new Bookings();
         $trans = new Transactions();
         $model = new Practitioners();
         $transaction['amount'] = $detail['price'];
         //$details['price'];
         $transaction['creditCardDetails_token'] = $card['creditCardDetails_token'];
         //$getCardDetails['creditCardDetails_token'];
         $transaction['customerDetails_id'] = $card['customerDetails_id'];
         //$getCardDetails['customerDetails_id'];
         $result = $trans->processPayment($this->getServiceLocator()->get('Config'), $transaction, 1);
         $user_details = $model->getSPDetails($api_url, $detail['user_id']);
         // getting use email permissions
         $subscriptionDetails = $common->getSubscriptiondetails($api_url, $detail['user_id'], true);
         // getting service provider subscription details
         $userFeatures = $common->getFeatures($api_url, $detail['user_id']);
         // If transaction done
         if ($result['status'] == 1) {
             $sendMail = 0;
             // Not send mail
             // Start :- Get subscription end date
             if (isset($detail['duration_in'])) {
                 if ($detail['duration_in'] == "1") {
                     // move subs date $selected['duration'] year ahed
                     $new_expireDate = date('Y-m-d', strtotime("+" . $detail['duration'] . " year", strtotime($detail['subscription_end_date'])));
                 } else {
                     if ($detail['duration_in'] == "2") {
                         // move subs date $selected['duration'] month ahed
                         $new_expireDate = date('Y-m-d', strtotime("+" . $detail['duration'] . " month", strtotime($detail['subscription_end_date'])));
                     } else {
                         if ($detail['duration_in'] == "3") {
                             // move subs date $selected['duration'] month ahed
                             $new_expireDate = date('Y-m-d', strtotime("+" . $detail['duration'] . " days", strtotime($detail['subscription_end_date'])));
                         } else {
                             // do nothing
                         }
                     }
                 }
             }
             // End :- Get subscription end date
             $subscriptionData = array();
             $subscriptionData['subscription_duration_id'] = $detail['subscription_duration_id'];
             $subscriptionData['payment_status_id'] = 7;
             $subscriptionData['site_commision'] = "0";
             $subscriptionData['status_id'] = 1;
             $subscriptionData['user_id'] = $detail['user_id'];
             $subscriptionData['invoice_total'] = $detail['price'];
             $subscriptionData['created_by'] = $detail['user_id'];
             $subscriptionData['invoice_status'] = 1;
             $subscriptionData['amount'] = $detail['price'];
             $subscriptionData['currency'] = $detail['currency'];
             $subscriptionData['payment_date'] = date('Y-m-d H:i:s');
             $subscriptionData['amount_paid'] = $detail['price'];
             $subscriptionData['transaction_id'] = $result['transaction_id'];
             $subscriptionData['payment_instrument_no'] = '5100';
             $subscriptionData['payment_method_id'] = '1';
             $subscriptionData['payment_status'] = 7;
             $subscriptionData['subscription_start_date'] = date('Y-m-d');
             $subscriptionData['sale_type'] = 1;
             $subscriptionData['subscription_end_date'] = $new_expireDate;
             $response = $bookingModel->addBooking($api_url, $subscriptionData);
             if ($response['status'] == 1 && isset($response['id'])) {
                 $user_details['address'] = json_decode($user_details['address'][0], true);
                 $user_details['contact'] = json_decode($user_details['contact'][0], true);
                 $data = $bookingModel->getBookings($api_url, '', '', '', '', '', '', $response['id'], 'subscription');
                 $view = new viewModel(array('booking_details' => $data['results'], 'user_details' => $user_details));
                 $view->setTemplate('application/membership/printinvoice.phtml');
                 $printData = $this->getServiceLocator()->get('viewrenderer')->render($view);
                 // Store in PDF format
                 $dompdf = new \DOMPDF();
                 $dompdf->load_html($printData);
                 $dompdf->render();
                 $output = $dompdf->output();
                 $attachment = new MimePart($output);
                 $attachment->type = 'application/pdf';
                 $attachment->filename = 'invoice.pdf';
                 $attachment->encoding = \Zend\Mime\Mime::ENCODING_BASE64;
                 $attachment->disposition = \Zend\Mime\Mime::DISPOSITION_ATTACHMENT;
                 $patterns = array('/{{user_name}}/i');
                 $replaces = array('<strong>' . $user_details['first_name'] . ' ' . $user_details['last_name'] . '</strong>');
                 if (isset($subscriptionDetails['features']) && is_array($subscriptionDetails['features']) && in_array(11, $subscriptionDetails['features']) || $userFeatures['email'] == 1) {
                     $common->sendMail($api_url, $user_details['email'], '', 11, '', $patterns, $replaces, $attachment);
                 }
             }
         } else {
             /* Make entry in failed payment history (pi21jan) */
             $check_failedpayArr = array('user_id' => $detail['user_id'], 'date' => date('Y-m-d', strtotime('-3 days')));
             $res = $common->check_failed_payment_history($api_url, $check_failedpayArr);
             if ($res) {
                 // there is a failed payment in last three days then set the subscription to basic one
                 $ongoing_subscription = $common->getSubscriptiondetails($api_url, $detail['user_id']);
                 $common->addSubscription($api_url, array('user_id' => $detail['user_id'], 'id' => $ongoing_subscription[0]['id']));
                 $delete_arr = array('user_id' => $detail['user_id']);
                 $common->deletefailedpayment($api_url, $delete_arr);
             } else {
                 $failed_payment_data = array('user_id' => $detail['user_id'], 'sale_type' => '1', 'instrument_no' => '', 'date' => date('Y-m-d H:i:s'));
                 $common->setfailedpayment($api_url, $failed_payment_data);
             }
             /* Failed payment code ends here */
             $consumer = new Consumers();
             // Start :- Get admin email id
             $res = $consumer->getConsumerdetails($api_url, 1);
             if (count($res) > 0) {
                 $adminEmailId = $res['email'];
             }
             // End :- Get admin email id
             $pattern = array('/{{user_name}}/i', '/{{subscription_name}}/i', '/{{error_message}}/i');
             $replace = array('<strong>' . $user_details['first_name'] . ' ' . $user_details['last_name'] . '</strong>', $detail['subscription_name'], '<strong>Transaction failed with message :- </strong>' . $result['msg']);
             if (isset($subscriptionDetails['features']) && is_array($subscriptionDetails['features']) && in_array(11, $subscriptionDetails['features']) || $userFeatures['email'] == 1) {
                 $common->sendMail($api_url, $user_details['email'], '', 19, '', $pattern, $replace, '', $adminEmailId);
             }
         }
     } else {
         /* Make entry in failed payment history (pi21jan) */
         $check_failedpayArr = array('user_id' => $detail['user_id'], 'date' => date('Y-m-d', strtotime('-3 days')));
         $res = $common->check_failed_payment_history($api_url, $check_failedpayArr);
         if ($res) {
             // there is a failed payment in last three days then set the subscription to basic one
             $ongoing_subscription = $common->getSubscriptiondetails($api_url, $detail['user_id']);
             $common->addSubscription($api_url, array('user_id' => $detail['user_id'], 'id' => $ongoing_subscription[0]['id']));
             $delete_arr = array('user_id' => $detail['user_id']);
             $common->deletefailedpayment($api_url, $delete_arr);
         } else {
             $failed_payment_data = array('user_id' => $detail['user_id'], 'sale_type' => '1', 'instrument_no' => '', 'date' => date('Y-m-d H:i:s'));
             $common->setfailedpayment($api_url, $failed_payment_data);
         }
         /* Failed payment code ends here */
     }
     // End:-- Get card details
 }
 public function settingsAction()
 {
     $auth = new FrontEndAuth();
     if (!$auth->hasIdentity(3)) {
         return $this->redirect()->toUrl('/login');
     }
     $session = new Container('frontend');
     $common = new Common();
     $api = new Api();
     $api_url = $this->getServiceLocator()->get('config')['api_url']['value'];
     $featureData = $common->getFeatures($api_url, $session->userid);
     $subscriptionData = $this->getSpsubscription($session->userid, $api, $api_url);
     $result_newsletter = $common->chkNewsletter($api_url);
     $unsubscribe_reasons = $common->getUnsubscribereason($api_url);
     $model = new Practitioners();
     $notifications = $model->getNotifications($api_url);
     $sp_details = $model->getSPDetails($api_url, $session->userid);
     $form = new SPChangePasswordForm();
     $form->get('submit')->setValue('Add');
     $request = $this->getRequest();
     if ($this->getRequest()->isXmlHttpRequest()) {
         $request = $this->getRequest();
         $error = false;
         $request->getPost('action') != '' ? $action = $request->getPost('action') : ($action = '');
         if ($action == "change_password") {
             if (preg_match('/^.*(?=.{6,})(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\\s).*$/', $request->getPost('Pass'))) {
                 $request->getPost('old_pass') != '' ? $old_pass = $request->getPost('old_pass') : ($old_pass = '');
                 $request->getPost('Pass') != '' ? $Pass = $request->getPost('Pass') : ($Pass = '');
                 $request->getPost('confirm_password') != '' ? $confirm_password = $request->getPost('confirm_password') : ($confirm_password = '');
                 if ($old_pass != '' && $Pass != '' && $confirm_password != '') {
                     if ($Pass == $confirm_password) {
                         $data = array('op' => 'changepassword', 'old_password' => md5($old_pass), 'new_password' => md5($Pass), 'user_id' => $session->userid);
                         $url = $api_url . "/api/useractivity/";
                         $res = $api->curl($url, $data, "POST");
                         if ($res->getStatusCode() == 200) {
                             $msg = "Success!! Password changed sucessfully";
                         } else {
                             if ($res->getStatusCode() == 404) {
                                 $error = true;
                                 $msg = "Error!! Old password is not correct";
                             } else {
                                 $error = true;
                                 $msg = "Error!! Password could not be updated";
                             }
                         }
                     } else {
                         // Password and confirm password do not match
                         $error = true;
                         $msg = "Error!! Confirm password do not match";
                     }
                 } else {
                     $error = true;
                     $msg = "Error!! Invalid form data";
                 }
             } else {
                 $error = true;
                 $msg = "Password must be at least 6 characters and must contain at least one lower case letter, one upper case letter, one digit and one special character.";
             }
             echo json_encode(array('error' => $error, 'msg' => $msg));
             exit;
         } else {
             if ($action == "change_features") {
                 $request->getPost('feature_email') != '' ? $feature_email = $request->getPost('feature_email') : ($feature_email = '');
                 $request->getPost('feature_sms') != '' ? $feature_sms = $request->getPost('feature_sms') : ($feature_sms = '');
                 $request->getPost('feature_chat') != '' ? $feature_chat = $request->getPost('feature_chat') : ($feature_chat = '');
                 $request->getPost('feature_table_id') != '' ? $feature_table_id = $request->getPost('feature_table_id') : ($feature_table_id = '');
                 $data = array('email' => $feature_email, 'sms' => $feature_sms, 'chat' => $feature_chat, 'user_id' => $session->userid);
                 $data['id'] = $featureData['id'];
                 if ($common->addFeature($api_url, $data)) {
                     $msg = "Feature setting updated successfully";
                 } else {
                     $error = true;
                     $msg = "Feature setting updated successfully";
                 }
                 echo json_encode(array('error' => $error, 'msg' => $msg));
                 exit;
             } else {
                 if ($action == "newletter-chk") {
                     $request->getPost('newletter_chk') != '' ? $newletter_chk = $request->getPost('newletter_chk') : ($newletter_chk = '');
                     $data = array('user_id' => $session->userid, 'newsletter' => $newletter_chk);
                     if (isset($featureData['id'])) {
                         // update
                         $url = $api_url . '/api/userfeaturesetting/' . $featureData['id'] . '/';
                         $res = $api->curlUpdate($url, $data, "PUT");
                     } else {
                         $url = $api_url . '/api/userfeaturesetting/';
                         $res = $api->curlUpdate($url, $data, "POST");
                     }
                     if ($res) {
                         $msg = "Feature setting updated successfully";
                     } else {
                         $error = true;
                         $msg = "Feature setting updated successfully";
                     }
                     echo json_encode(array('error' => $error, 'msg' => $msg));
                     exit;
                 } else {
                     if ($action == "auto-renewal") {
                         $autorenew = $request->getPost('auto_renewal') != '' ? $request->getPost('auto_renewal') : '0';
                         $subscription_id = $request->getPost('subscription_id') != '' ? $request->getPost('subscription_id') : '';
                         $result = $common->autorenew($api_url, $subscription_id, $autorenew);
                         echo json_encode($result);
                         exit;
                     } else {
                         if ($action == "close-acc") {
                             $reason_id = $request->getPost('reason_id') != '' ? $request->getPost('reason_id') : '';
                             $other_reason = $request->getPost('other_reason') != '' ? $request->getPost('other_reason') : '';
                             if ($reason_id !== '') {
                                 $result = $common->isaccountRemovable($api_url);
                                 if (!$result) {
                                     $error = true;
                                     $msg = "Sorry!! you cannot deactivate your account untill you clear all your pending bookings.";
                                 } else {
                                     if ($reason_id == 5 && $other_reason == '') {
                                         $error = true;
                                         $msg = "Please provide other reason in the text area";
                                     } else {
                                         $result = $common->closeAccount($api_url, $reason_id, $other_reason);
                                         if ($result) {
                                             // close acc here
                                             $msg = "You account has been deactivated successfully..you will be logged out in 5 seconds";
                                         } else {
                                             // error acc could not be closed
                                             $error = true;
                                             $msg = "Some Error occured , Could not close your account , please try after some time";
                                         }
                                     }
                                 }
                             } else {
                                 $error = true;
                                 $msg = "Please provide us a reason to close your account";
                             }
                             echo json_encode(array('error' => $error, 'msg' => $msg));
                             exit;
                         } else {
                             if ($action == "unsubscribe") {
                                 $subscription_id = $request->getPost('subscription_id') != '' ? $request->getPost('subscription_id') : '';
                                 $result = $common->unsubscribeMembership($api_url, $subscription_id);
                                 if ($result) {
                                     $msg = "Unsubscribed Successfully";
                                 } else {
                                     $error = true;
                                     $msg = "Error, could not unsubscribe";
                                 }
                                 echo json_encode(array('error' => $error, 'msg' => $msg));
                                 exit;
                             } else {
                                 if ($action == "update_card") {
                                     $trans = new Transactions();
                                     echo json_encode($trans->updateCard($this->getServiceLocator()->get('config'), $request->getPost('card_data')));
                                     exit;
                                 } else {
                                     $error = true;
                                     $msg = "Invalid request";
                                     echo json_encode(array('error' => $error, 'msg' => $msg));
                                     exit;
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     // getting banner for this page
     $banners = $common->getBanner($api_url, 4);
     return new ViewModel(array('form' => $form, 'featureData' => $featureData, 'subscriptionData' => $subscriptionData, 'notifications' => $notifications, 'avtar_url' => $sp_details['avtar_url'], 'first_name' => $sp_details['first_name'], 'last_name' => $sp_details['last_name'], 'newsletter_chk' => $result_newsletter, 'reasonsList' => $unsubscribe_reasons, 'card_details' => $common->getUserCardDetails($api_url, array('user_id' => $session->userid)), 'banners' => $banners));
 }
 public function paymentAction()
 {
     $request = $this->getRequest();
     if ($request->isPost()) {
         $bookingsession = new Container('bookingsession');
         $session = new Container('frontend');
         $bookingModel = new Bookings();
         $trans = new Transactions();
         $model = new Practitioners();
         $consumer = new Consumers();
         $common = new Common();
         $api_url = $this->getServiceLocator()->get('config')['api_url']['value'];
         $data['name'] = $request->getPost('name_on_card');
         $data['email'] = $request->getPost('emailid');
         $card_type = $request->getPost('card_type');
         $data['card_no'] = $request->getPost('card_no');
         $data['month'] = $request->getPost('month');
         $data['year'] = $request->getPost('year');
         $data['cvv_no'] = $request->getPost('cvv_no');
         $data['amount'] = $bookingsession->price;
         $data['currency'] = $bookingsession->currency;
         $result = $trans->processPayment($this->getServiceLocator()->get('Config'), $data);
         if ($result['status'] == 1) {
             //if (1 == 1) {
             $bookingData = array();
             $bookingData['transaction_id'] = $result['transaction_id'];
             $bookingData['service_provider_id'] = $bookingsession->sp_id;
             $bookingData['user_id'] = $session->userid;
             $bookingData['service_provider_service_id'] = $bookingsession->durationid;
             //$bookingData['booked_date'] = $bookingsession->servicedate;
             $bookingData['booked_date'] = date('Y-m-d H:i:s', strtotime(str_replace('/', '-', $bookingsession->servicedate)));
             $bookingData['booking_status'] = 5;
             $bookingData['payment_status'] = 7;
             $bookingData['status_id'] = 1;
             $bookingData['sale_type'] = 3;
             $bookingData['currency'] = $bookingsession->currency;
             $bookingData['amount'] = str_replace(array('USD$', 'CAD$', 'USD ', 'CAD ', 'USD', 'CAD', '$'), array('', '', '', '', '', '', ''), $bookingsession->serviceprice);
             // as suggested by kanhaiya sir on 1-8-2014
             $bookingData['site_commision'] = $data['amount'];
             $bookingData['invoice_total'] = str_replace(array('USD$', 'CAD$', 'USD ', 'CAD ', 'USD', 'CAD', '$'), array('', '', '', '', '', '', ''), $bookingsession->serviceprice);
             // as suggested by kanhaiya sir on 1-8-2014
             $bookingData['invoice_status'] = 1;
             $bookingData['payment_status_id'] = 7;
             $bookingData['amount_paid'] = $data['amount'];
             $bookingData['payment_date'] = date('Y-m-d H:i:s');
             $bookingData['payment_instrument_no'] = substr($data['card_no'], strlen($data['card_no']) - 4, 4);
             $bookingData['payment_method_id'] = $card_type;
             $bookingData['created_by'] = $session->userid;
             $bookingData['service_address_id'] = $bookingsession->locationid;
             //print_r($bookingData); exit;
             $response = $bookingModel->addBooking($api_url, $bookingData);
             if ($response['status'] == 1 && isset($response['id'])) {
                 //if (1==1) {
                 /* Generate attachment code starts here*/
                 $sp_details = $model->getSPDetails($api_url, $bookingsession->sp_id);
                 $sp_details['contact'] = json_decode($sp_details['contact'][0], true);
                 $user_details = $consumer->getConsumerdetails($api_url, $session->userid);
                 $user_details['address'] = json_decode($user_details['address'][0], true);
                 $user_details['contact'] = json_decode($user_details['contact'][0], true);
                 $data = $bookingModel->getBookings($api_url, '', $session->userid, '', '', '', '', $response['id']);
                 $service_rendering_address = $data['results'][0]['service_address_id'] != '' && $data['results'][0]['service_address_id'] != 'None' ? $common->address($api_url, $data['results'][0]['service_address_id']) : 'Not Available';
                 $view = new viewModel(array('booking_details' => $data['results'], 'user_details' => $user_details, 'service_rendering_address' => $service_rendering_address, 'service_rendering_details' => $sp_details));
                 $view->setTemplate('application/booking/printinvoice.phtml');
                 $printData = $this->getServiceLocator()->get('viewrenderer')->render($view);
                 // Store in PDF format
                 $dompdf = new \DOMPDF();
                 $dompdf->load_html($printData);
                 $dompdf->render();
                 $output = $dompdf->output();
                 $attachment = new MimePart($output);
                 $attachment->type = 'application/pdf';
                 $attachment->filename = 'invoice.pdf';
                 $attachment->encoding = \Zend\Mime\Mime::ENCODING_BASE64;
                 $attachment->disposition = \Zend\Mime\Mime::DISPOSITION_ATTACHMENT;
                 /* Generate attachment code ends here*/
                 /* Send email code starts here */
                 $common = $this->getServiceLocator()->get('Application\\Model\\Common');
                 $pattern = array('/{{user_name}}/i');
                 $userreplace = array('<strong>' . $user_details['first_name'] . ' ' . $user_details['last_name'] . '</strong>');
                 $spreplace = array('<strong>' . $sp_details['first_name'] . ' ' . $sp_details['last_name'] . '</strong>');
                 $common->sendMail($api_url, $user_details['email'], '', 9, '', $pattern, $userreplace, $attachment);
                 $subscriptionDetails = $common->getSubscriptiondetails($api_url, $bookingData['service_provider_id'], true);
                 // getting service provider subscription details
                 $userFeatures = $common->getFeatures($api_url, $bookingData['service_provider_id']);
                 if (isset($subscriptionDetails['features']) && is_array($subscriptionDetails['features']) && in_array(11, $subscriptionDetails['features']) && $userFeatures['email'] == 1) {
                     $common->sendMail($api_url, $sp_details['email'], '', 10, '', $pattern, $spreplace);
                 }
                 if (isset($subscriptionDetails['features']) && is_array($subscriptionDetails['features']) && in_array(12, $subscriptionDetails['features']) && $userFeatures['sms'] == 1) {
                     $common->sendMsg($sp_details['contact']['phone_number'], 1, '', $pattern, array($sp_details['first_name'] . ' ' . $sp_details['last_name']));
                 }
                 /* Send email code ends here */
                 // unset all sessions
                 $bookingsession->offsetUnset('sp_id');
                 $bookingsession->offsetUnset('user_id');
                 $bookingsession->offsetUnset('price');
                 $bookingsession->offsetUnset('locationid');
                 $bookingsession->offsetUnset('serviceid');
                 $bookingsession->offsetUnset('durationid');
                 $bookingsession->offsetUnset('servicedate');
                 $bookingsession->offsetUnset('serviceprice');
                 echo json_encode(array('status' => '1', 'msg' => 'Booking successfully completed. <br /> Redirecting to invoice page..!!', 'booking_id' => $response['id']));
             } else {
                 echo json_encode(array('status' => '0', 'msg' => 'Transaction completed successfully with Transaction Id <strong>' . $result['transaction_id'] . '</strong>. <br /> Failed to book your request. Please contact to site admin..!!', 'errors' => $response['data']));
             }
         } else {
             echo json_encode($result);
         }
     }
     exit;
 }