コード例 #1
0
 public function checkoutAction()
 {
     $auth = new FrontEndAuth();
     if (!$auth->hasIdentity(3)) {
         return $this->redirect()->toUrl('/login');
     }
     $id = $this->params()->fromRoute('id');
     if ($id == '') {
         $this->redirect()->toRoute('membership');
     }
     $subscriptionsession = new Container('subscriptionsession');
     $session = new Container('frontend');
     $api = new Api();
     $api_url = $this->getServiceLocator()->get('Config')['api_url']['value'];
     $model_practitioner = new Practitioners();
     $common = new Common();
     $selected_subscription = $model_practitioner->getSubscription($api_url, $id);
     $ongoing_subscription = $common->getSubscriptiondetails($api_url);
     //echo "<pre>";print_r($ongoing_subscription);die;
     /* check if there is a saved card : start */
     $savedCard_details = $common->getUserCardDetails($api_url, array('user_id' => $session->userid));
     /* check if there is a saved card : end */
     $subscription_id = $this->getSubscriptionid($api_url);
     if ($id == '1') {
         if ($common->addSubscription($api_url, array('user_id' => $session->userid, 'id' => $ongoing_subscription[0]['id']))) {
             $this->flashMessenger()->addSuccessMessage("Basic subscription activated on your account..!!");
             return $this->redirect()->toRoute('practitioner', array('action' => 'dashboard'));
         } else {
             $this->flashMessenger()->addErrorMessage("Failed to activate basic subscription..!!");
             return $this->redirect()->toRoute('membership');
         }
     }
     $ongoingSubs_endDate = 'NA';
     $ongoingsubs_name = 'NA';
     $total_amount = 'NA';
     $new_expireDate = 'NA';
     $selectedSubs_name = 'NA';
     $subscription_duration_id = 'NA';
     $selectedCurrency = $model_practitioner->getcurrency($api_url, $this->getRequest()->getServer('REMOTE_ADDR'));
     if ($id == $subscription_id) {
         /* same subscription now renew */
         $checkout_type = "renew";
         if (count($selected_subscription) > 0) {
             if (count($ongoing_subscription) > 0) {
                 !empty($ongoing_subscription[0]['subscription_end_date']) ? $ongoingSubs_endDate = $ongoing_subscription[0]['subscription_end_date'] : '';
                 $ongoing_duration = json_decode($ongoing_subscription[0]['subscription_duration'], true);
                 if (count($ongoing_duration) > 0) {
                     $ongoingsubs_name = $ongoing_duration['subscription_name'];
                 }
             } else {
                 $ongoingSubs_endDate = date('Y-m-d');
             }
             $selected = json_decode($selected_subscription['duration'][0], true);
             if (count($selected) > 0) {
                 $total_amount = $selected['price'];
                 $selectedSubs_name = $selected['subscription_name'];
                 $subscription_duration_id = $selected['id'];
                 if (isset($selected['duration_in'])) {
                     if ($selected['duration_in'] == "1") {
                         // move subs date $selected['duration'] year ahed
                         $new_expireDate = date('Y-m-d', strtotime("+" . $selected['duration'] . " year", strtotime($ongoingSubs_endDate)));
                     } else {
                         if ($selected['duration_in'] == "2") {
                             // move subs date $selected['duration'] month ahed
                             $new_expireDate = date('Y-m-d', strtotime("+" . $selected['duration'] . " month", strtotime($ongoingSubs_endDate)));
                         } else {
                             if ($selected['duration_in'] == "3") {
                                 // move subs date $selected['duration'] month ahed
                                 $new_expireDate = date('Y-m-d', strtotime("+" . $selected['duration'] . " days", strtotime($ongoingSubs_endDate)));
                             } else {
                                 // do nothing
                             }
                         }
                     }
                 }
             }
         }
     } else {
         /* new subscription */
         $checkout_type = "new";
         if (count($selected_subscription) > 0) {
             if (count($ongoing_subscription) > 0) {
                 !empty($ongoing_subscription[0]['subscription_end_date']) ? $ongoingSubs_endDate = $ongoing_subscription[0]['subscription_end_date'] : '';
                 $ongoing_duration = json_decode($ongoing_subscription[0]['subscription_duration'], true);
                 if (count($ongoing_duration) > 0) {
                     $ongoingsubs_name = $ongoing_duration['subscription_name'];
                 }
             }
             $selected = json_decode($selected_subscription['duration'][0], true);
             if (count($selected) > 0) {
                 $total_amount = $selected['price'];
                 $selectedSubs_name = $selected['subscription_name'];
                 $subscription_duration_id = $selected['id'];
                 if (isset($selected['duration_in'])) {
                     if ($selected['duration_in'] == "1") {
                         // move subs date $selected['duration'] year ahed
                         $new_expireDate = date('Y-m-d', strtotime("+" . $selected['duration'] . " year", strtotime(date('Y-m-d'))));
                     } else {
                         if ($selected['duration_in'] == "2") {
                             // move subs date $selected['duration'] month ahed
                             $new_expireDate = date('Y-m-d', strtotime("+" . $selected['duration'] . " month", strtotime(date('Y-m-d'))));
                         } else {
                             if ($selected['duration_in'] == "3") {
                                 // move subs date $selected['duration'] month ahed
                                 $new_expireDate = date('Y-m-d', strtotime("+" . $selected['duration'] . " days", strtotime(date('Y-m-d'))));
                             } else {
                                 // do nothing
                             }
                         }
                     }
                 }
             }
         }
     }
     //echo $new_expireDate;die;
     $subscriptionsession->serviceprice = $total_amount;
     $subscriptionsession->subscription_duration_id = $subscription_duration_id;
     $subscriptionsession->currency = $selectedCurrency;
     $subscriptionsession->subscription_end_date = $new_expireDate;
     $form = new CheckoutForm($this->getServiceLocator()->get('config')['payment_methods']);
     $session = new Container('frontend');
     $form->get('name_on_card')->setValue($session->first_name . ' ' . $session->last_name);
     $form->get('emailid')->setValue($session->email);
     $banners = $common->getBanner($api_url, 14);
     return new ViewModel(array('form' => $form, 'errorMsgs' => $this->flashMessenger()->getCurrentErrorMessages(), 'checkout_type' => $checkout_type, 'ongoingSubs_endDate' => $ongoingSubs_endDate, 'ongoingsubs_name' => $ongoingsubs_name, 'total_amount' => $total_amount, 'new_expireDate' => $new_expireDate, 'selectedSubs_name' => $selectedSubs_name, 'selectedCurrency' => $selectedCurrency, 'banners' => $banners, 'savedCard_details' => end($savedCard_details), 'merchant_id' => $this->getServiceLocator()->get('Config')['payment_gateway']['merchant_id']));
 }
コード例 #2
0
 public function indexAction()
 {
     $fb_login = new Container('facebook');
     $google_login = new Container('google');
     $linkedin_login = new Container('linkedin');
     $social_media_id = '';
     if (isset($fb_login->social_id)) {
         $common_object = $fb_login;
         $social_media_id = $fb_login->social_id;
     }
     if (isset($google_login->social_id)) {
         $common_object = $google_login;
         $social_media_id = $google_login->social_id;
     }
     if (isset($linkedin_login->social_id)) {
         $common_object = $linkedin_login;
         $social_media_id = $linkedin_login->social_id;
     }
     $api = new Api();
     $auth = new FrontEndAuth();
     $session = new Container('frontend');
     $loginError = "";
     $redirectUrl = array('controller' => 'index');
     if ($auth->hasIdentity()) {
         //$redirectUrl = array('controller'=>'index');
         //$redirectUrl = array('controller'=>'login', 'action' => 'dashboard');
         return $this->redirect()->toRoute(null, $redirectUrl);
     }
     //var_dump($session->user_name); die;
     $common = new Common();
     $form = new LoginForm();
     $register_form = new RegisterForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         //die('hello');
         $register = new Register();
         $register_form->setInputFilter($register->getInputFilter());
         $data = $request->getPost()->toArray();
         $register_form->setData($data);
         //$validation_result = json_decode($this->passwordValidation($data['confirm_password']), true);
         if ($register_form->isValid()) {
             $loginError = $validation_result['msg'];
             //if(!$validation_result['error']){
             $loginError = '';
             unset($data['confirm_password'], $data['register_submit']);
             //die('hello');
             $api_url = $this->getServiceLocator()->get('Config')['api_url']['value'];
             $url = $api_url . "/api/users/";
             $data['op'] = 'register';
             $data['social_media_id'] = $social_media_id;
             $data['status_id'] = $data['user_type_id'] == 4 ? 9 : 5;
             $res = $api->curl($url, $data, "POST");
             if ($res->getStatusCode() == 201) {
                 $content = json_decode($res->getBody(), true);
                 $common->addChatAccount($this->getServiceLocator()->get('Config')['chatpath']['url'], $content, $data, $request);
                 // Creating account for live chat
                 $newsletter = $content['user_type_id'] == 3 ? 1 : 4;
                 $common->addFeature($api_url, array('user_id' => $content['id'], 'email' => 1, 'sms' => 1, 'chat' => 0, 'newsletter' => $newsletter));
                 // Adding user feature setting
                 $common->sendMail($api_url, $content['email'], '', 21, '', array('/{{user_name}}/i'), array($content['first_name'] . ' ' . $content['last_name']));
                 $session->userid = $content['id'];
                 $session->first_name = $content['first_name'];
                 $session->last_name = $content['last_name'];
                 $session->email = $content['email'];
                 $session->user_name = $content['user_name'];
                 $session->user_type_id = $content['user_type_id'];
                 $session->user_data = $content;
                 // adding default subscription
                 if ($session->user_type_id == 3) {
                     $common->addSubscription($api_url, array('user_id' => $session->userid));
                 }
                 $auth->wordpress_create_user($session->user_name, $session->email, $data['confirm_password']);
                 $auth->wordpress_login($session->user_name);
                 $bookingData = new Container('bookingData');
                 //var_dump($res); die;
                 //return ($session->user_type_id == 4) ? $this->redirect()->toRoute('consumer', array('action' => 'dashboard')) : $this->redirect()->toRoute('practitioner', array('action' => 'dashboard'));
                 if (isset($bookingData->bookingData)) {
                     return $this->redirect()->toRoute('booking', array('action' => 'schedule', 'id' => $bookingData->sp));
                 } else {
                     if ($this->getRequest()->getQuery('lasturl') != '') {
                         return $this->redirect()->toUrl($this->getRequest()->getQuery('lasturl'));
                     } else {
                         return $session->user_type_id == 4 ? $this->redirect()->toRoute('consumer', array('action' => 'dashboard')) : $this->redirect()->toRoute('practitioner', array('action' => 'dashboard'));
                     }
                 }
                 //return $this->redirect()->toRoute(null, $redirectUrl);
             } else {
                 $errors = json_decode($res->getBody(), true);
                 foreach ($errors as $key => $value) {
                     if (isset($value[0])) {
                         $register_form->setMessages(array($key => array($value[0])));
                     }
                 }
                 $this->errors = $register_form->getMessages();
                 // added by Ritesh to get error messages
             }
             //var_dump($errors); die;
             //}// validation condition
         } else {
             $this->errors = $register_form->getMessages();
         }
     }
     $view = new ViewModel(array('form' => $form, 'register_form' => $register_form, 'loginError' => $loginError, 'fb_login' => $common_object, 'errors' => $this->errors));
     $view->setTemplate('application/login/index.phtml');
     return $view;
 }