public function actionBullingInformation() { $this->pageName = "billing"; // if (!Yii::app()->request->isPostRequest) { // $this->redirect(basePath('')); // } if (Yii::app()->user->isGuest) { Yii::app()->request->redirect(basePath('')); } // if (UserAccessTable::checkUser2PropertyAccess(Yii::app()->user->getState('id'), Yii::app()->user->getState('propertyId'), UserAccessTable::OWNER)) { // $this->redirect(basePath('')); // ; // } $model = new PayPalPaymentModel(); $model->setAttributes($_POST); $model->validate(); $errors = $model->getErrors(); if (count($errors) > 0) { $this->render('index', array('errors' => $errors, 'bull' => $model->attributes, 'countries' => $this->getCountries(), 'provinces' => $this->getProvinces())); return; } $userApi = sharedkeyApi::create('usersAPI'); $userApi->addParams(array('email' => Yii::app()->user->getState('email'), 'format' => 'json')); $property = Properties::model()->findByPk(Yii::app()->user->getState('propertyId')); $byEmail = json_decode($userApi->byEmail('get')); $userData = (array) $byEmail->data; $userData['prop_name'] = $property ? $property->property_name : ""; $response = PayPalHelper::createBullingRequest($model, $userData); if (!$response->status) { $errors['0'] = $response->errorMessage; $this->render('index', array('errors' => $errors, 'countries' => $this->getCountries(), 'provinces' => $this->getProvinces())); return; } //activate property $property->isdeactivated = 0; $property->trialPeriodStartDate = null; $property->edt = new CDbExpression('NOW()'); $property->save(); //update property Admin $user2property = User2property::model()->findByAttributes(array('propertyId' => $property->getAttribute('id'), 'access' => UserAccessTable::OWNER)); if ($user2property->getAttribute('userId') != Yii::app()->user->getState('id')) { //need update property admin $user2property->access = UserAccessTable::FULL_ACCESS; $user2property->save(); //find current payer link and set it to Admin mode $u2p = User2property::model()->findByAttributes(array('userId' => Yii::app()->user->getState('id'), 'propertyId' => $property->getAttribute('id'))); $u2p->access = UserAccessTable::OWNER; $u2p->save(); } $this->redirect(basePath('app/gallery')); }
public function actionAddpropertysubmit() { if (Yii::app()->user->isGuest) { Yii::app()->request->redirect(basePath('')); } $errors = array(); $inputData = $_POST; $formModel = new addPropertyModel(); $formModel->setAttributes($inputData); $formModel->validate(); $errors = $formModel->getErrors(); $inputData['deleted'] = 0; $userData = array(); $paypalModel = new PayPalPaymentModel(); if (count($errors) == 0) { //add property first tab valid, we can try validate Bulling Information $paypalModel->setAttributes($_POST); $paypalModel->validate(); $errors = $paypalModel->getErrors(); if (count($errors) == 0) { //send paypal request $propIds = $this->addProperty($inputData); $userApi = sharedkeyApi::create('usersAPI'); $userApi->addParams(array('email' => Yii::app()->user->getState('email'), 'format' => 'json')); $byEmail = json_decode($userApi->byEmail('get')); $userData = (array) $byEmail->data; $userData['property_id'] = $propIds['newId']; $userData['prop_name'] = $inputData['property_name']; YII::app()->user->setState("addPropertyEmailed", true); $response = PayPalHelper::createBullingRequest($paypalModel, (array) $userData); if (!$response->status) { $this->deletePropertyById($propIds); $errors['PayPaL'] = array(); array_push($errors['PayPaL'], $response->errorMessage); } } } if (count($errors) == 0) { $this->layout = "emailmaster"; $emailBody = $this->render("../emails/newPropertyEmail", array('fullname' => $userData['firstname'] . ' ' . $userData['lastname'], 'propName' => $userData['prop_name'], 'reneweDate' => date('F m, Y', strtotime('+1 year'))), true); MailHelper::send($emailBody, "SharedKey.com - New Property Added to Your Account", array($userData['email'])); Yii::app()->request->redirect(basePath('app/gallery')); } else { $this->layout = "account"; $this->render('/app/addproperty', array('errors' => $errors, 'prop' => $formModel->attributes, 'bull' => $paypalModel->attributes, 'countries' => $this->getCountries(), 'provinces' => $this->getProvinces())); } }
public function actionSignUp() { $data = $this->getSignUpData(); $errors = $this->signUpValidation($data); if ($data['PP_TRIAL'] != 'YES') { $paypalModel = new PayPalPaymentModel(); if (empty($errors)) { $paypalModel->setAttributes($_POST); $paypalModel->validate(); $errors = $paypalModel->getErrors(); } } if (empty($errors)) { //registration $userApi = sharedkeyApi::create('usersAPI'); $verificationToken = uniqid(); $data['verificationToken'] = $verificationToken; $data['status'] = 0; $userApi->addParams($data); $signup = $userApi->signUp('create'); $signup = json_decode($signup); if ($signup->result == false) { $this->redirect(basePath('signup')); } else { $userApi = sharedkeyApi::create('usersAPI'); $userApi->addParams(array('email' => $data['email'], 'password' => $data['password'], 'format' => 'json')); $byEmail = json_decode($userApi->byEmail('get')); $userData = $byEmail->data; if ($data['PP_TRIAL'] != 'YES') { //send paypal request $response = PayPalHelper::createBullingRequest($paypalModel, (array) $userData); if (!$response->status) { $this->clearDataAfterSignUpByEmail($data['email']); $errors['paypal_error'] = $response->errorMessage; //show errors $this->setFlashErrors($errors); $this->setFlashData($data); $this->redirect(basePath('signup')); } } $this->layout = "emailmaster"; $message = $this->render('../emails/newuseremail', array('token' => $verificationToken, 'url' => Yii::app()->params['domain'] . '/activeuser', 'email' => $data['email'], 'password' => $data['password'], 'fullname' => $data['firstname'] . ' ' . $data['lastname']), true); MailHelper::send($message, "Welcome to SharedKey", array($data['email'])); //$identity->authenticate(); //Yii::app()->user->login($identity); Yii::app()->user->setState('new_email', $data['email']); $this->redirect(basePath('activateusermessage')); } } else { $this->clearDataAfterSignUpByEmail($data['email']); //show errors $this->setFlashErrors($errors); $this->setFlashData($data); $this->redirect(basePath('signup')); } }