createSubscription() public method

public createSubscription ( $package, $ccNumber, $ccExpMonth, $ccExpYear, $ccCvv, $fName = "", $lName = "", $postalCode = "" )
Example #1
0
 public function xChangePlanAction()
 {
     if (!$this->getParam('package')) {
         $this->response->failure("z");
     }
     if ($this->billing->package == $this->getParam('package')) {
         $this->response->success();
     }
     if ($this->getParam('package') == 'cancel') {
         if ($this->billing->subscriptionId) {
             $this->billing->cancelSubscription();
         }
         $this->response->success("Subscription cancelled: Scalr has STOPPED managing your instances.  You can reactivate your account at any time.");
         return;
     }
     if ($this->billing->subscriptionId) {
         $this->billing->changePackage($this->getParam('package'));
         $this->response->success("Subscription successfully updated");
     } else {
         if (!$this->getParam('postalCode')) {
             $this->response->failure("Billing postal code is required");
             exit;
         }
         $this->billing->createSubscription($this->getParam('package'), $this->getParam('ccNumber'), $this->getParam('ccExpMonth'), $this->getParam('ccExpYear'), $this->getParam('ccCvv'), $this->getParam('firstName'), $this->getParam('lastName'), $this->getParam('postalCode'));
         $this->response->success("Subscription successfully created");
     }
 }
Example #2
0
 public function xChangePlanAction()
 {
     if (!$this->getParam('package')) {
         $this->response->failure("z");
     }
     if ($this->billing->package == $this->getParam('package')) {
         $this->response->success();
     }
     if ($this->getParam('package') == 'cancel') {
         if ($this->billing->subscriptionId) {
             $this->billing->cancelSubscription();
         }
         $this->response->success("Your subscription has been cancelled, you will no longer be charged. Since your account was overdue, the cancellation is immediate and you will no longer be able to manage your infrastructure through Scalr, and all Scalr automation will cease.");
         return;
     }
     if ($this->billing->subscriptionId) {
         $this->billing->changePackage($this->getParam('package'));
         $this->response->success("Subscription successfully updated");
     } else {
         if (!$this->getParam('postalCode')) {
             $this->response->failure("Billing postal code is required");
             exit;
         }
         $this->billing->createSubscription($this->getParam('package'), $this->getParam('ccNumber'), $this->getParam('ccExpMonth'), $this->getParam('ccExpYear'), $this->getParam('ccCvv'), $this->getParam('firstName'), $this->getParam('lastName'), $this->getParam('postalCode'));
         $this->response->success("Subscription successfully created");
     }
 }
Example #3
0
 /**
  * @param string $name
  * @param string $org
  * @param $email
  * @param $password
  * @param string $agreeTerms
  * @param string $newBilling
  * @param string $country
  * @param string $phone
  * @param string $lastname
  * @param string $firstname
  * @param string $v
  * @param string $numServers
  */
 public function xCreateAccountAction($name = '', $org = '', $email, $password = '', $agreeTerms = '', $newBilling = '', $country = '', $phone = '', $lastname = '', $firstname = '', $v = '', $numServers = '')
 {
     if (!\Scalr::config('scalr.billing.enabled')) {
         exit;
     }
     $Validator = new Scalr_Validator();
     if ($v == 2) {
         if (!$firstname) {
             $err['firstname'] = _("First name required");
         }
         if (!$lastname) {
             $err['lastname'] = _("Last name required");
         }
         //if (!$org)
         //    $err['org'] = _("Organization required");
         $name = $firstname . " " . $lastname;
     } else {
         if (!$name) {
             $err['name'] = _("Account name required");
         }
     }
     if (!$password) {
         $password = $this->getCrypto()->sault(10);
     }
     if ($Validator->validateEmail($email, null, true) !== true) {
         $err['email'] = _("Invalid E-mail address");
     }
     if (strlen($password) < 6) {
         $err['password'] = _("Password should be longer than 6 chars");
     }
     // Check email
     $DBEmailCheck = $this->db->GetOne("SELECT COUNT(*) FROM account_users WHERE email=?", array($email));
     if ($DBEmailCheck > 0) {
         $err['email'] = _("E-mail already exists in database");
     }
     if (!$agreeTerms) {
         $err['agreeTerms'] = _("You need to agree with terms and conditions");
     }
     if (count($err) == 0) {
         $account = Scalr_Account::init();
         $account->name = $org ? $org : $name;
         $account->status = Scalr_Account::STATUS_ACTIVE;
         $account->save();
         $account->createEnvironment("Environment 1");
         $account->initializeAcl();
         $user = $account->createUser($email, $password, Scalr_Account_User::TYPE_ACCOUNT_OWNER);
         $user->fullname = $name;
         $user->save();
         if ($v == 2) {
             $user->setSetting('website.phone', $phone);
             $user->setSetting('website.country', $country);
             $user->setSetting('website.num_servers', $numServers);
         }
         /**
          * Limits
          */
         $url = Scalr::config('scalr.endpoint.scheme') . "://" . Scalr::config('scalr.endpoint.host');
         try {
             $billing = new Scalr_Billing();
             $billing->loadByAccount($account);
             $billing->createSubscription(Scalr_Billing::PAY_AS_YOU_GO, "", "", "", "");
             /*******************/
         } catch (Exception $e) {
             $account->delete();
             header("Location: {$url}/order/?error={$e->getMessage()}");
             exit;
         }
         if ($_COOKIE['__utmz']) {
             $gaParser = new Scalr_Service_GoogleAnalytics_Parser();
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_CONTENT] = $gaParser->campaignContent;
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_MEDIUM] = $gaParser->campaignMedium;
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_NAME] = $gaParser->campaignName;
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_SOURCE] = $gaParser->campaignSource;
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_TERM] = $gaParser->campaignTerm;
             $clientSettings[CLIENT_SETTINGS::GA_FIRST_VISIT] = $gaParser->firstVisit;
             $clientSettings[CLIENT_SETTINGS::GA_PREVIOUS_VISIT] = $gaParser->previousVisit;
             $clientSettings[CLIENT_SETTINGS::GA_TIMES_VISITED] = $gaParser->timesVisited;
         }
         $clientSettings[CLIENT_SETTINGS::RSS_LOGIN] = $email;
         $clientSettings[CLIENT_SETTINGS::RSS_PASSWORD] = $this->getCrypto()->sault(10);
         foreach ($clientSettings as $k => $v) {
             $account->setSetting($k, $v);
         }
         try {
             $this->db->Execute("INSERT INTO default_records SELECT null, '{$account->id}', rtype, ttl, rpriority, rvalue, rkey FROM default_records WHERE clientid='0'");
         } catch (Exception $e) {
         }
         $clientinfo = array('fullname' => $name, 'firstname' => $firstname ? $firstname : $name, 'email' => $email, 'password' => $password);
         //Sends welcome email
         $this->getContainer()->mailer->setFrom('*****@*****.**', 'Scalr')->setHtml()->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/welcome.html.php', array('firstName' => htmlspecialchars($clientinfo['firstname']), 'password' => htmlspecialchars($clientinfo['password']), "siteUrl" => htmlspecialchars($url), "wikiUrl" => htmlspecialchars(\Scalr::config('scalr.ui.wiki_url')), "supportUrl" => htmlspecialchars(\Scalr::config('scalr.ui.support_url')), "isUrl" => preg_match('/^http(s?):\\/\\//i', \Scalr::config('scalr.ui.support_url'))), $email);
         $user->getAccount()->setSetting(Scalr_Account::SETTING_IS_TRIAL, 1);
         //AutoLogin
         $user->updateLastLogin();
         Scalr_Session::create($user->getId());
         Scalr_Session::keepSession();
         $this->response->setRedirect("{$url}/thanks.html");
     } else {
         $errors = array_values($err);
         $error = $errors[0];
         $this->response->setRedirect("{$url}/order/?error={$error}");
     }
 }
Example #4
0
 /**
  * @param string  $name
  * @param string  $org
  * @param string  $email
  * @param RawData $password
  * @param string  $agreeTerms
  * @param string  $newBilling
  * @param string  $country
  * @param string  $phone
  * @param string  $lastname
  * @param string  $firstname
  * @param string  $v
  * @param string  $numServers
  */
 public function xCreateAccountAction($name = '', $org = '', $email = '', RawData $password = null, $agreeTerms = '', $newBilling = '', $country = '', $phone = '', $lastname = '', $firstname = '', $v = '', $numServers = '', $beta = 0)
 {
     if (!\Scalr::config('scalr.billing.enabled')) {
         header("HTTP/1.0 403 Forbidden");
         exit;
     }
     $validator = new Validator();
     if ($v == 2) {
         $validator->validate($firstname, "firstname", Validator::NOEMPTY, [], "First name is required");
         $validator->validate($lastname, "lastname", Validator::NOEMPTY, [], "Last name is required");
         $name = $firstname . " " . $lastname;
     } else {
         $validator->validate($name, "name", Validator::NOEMPTY, [], "Account name is required");
     }
     if ($password == '') {
         $password = \Scalr::GenerateSecurePassword(User::PASSWORD_ADMIN_LENGTH);
     }
     $validator->validate($email, "email", Validator::EMAIL);
     $validator->validate($password, "password", Validator::PASSWORD, ['admin']);
     $validator->addErrorIf($this->db->GetOne("SELECT EXISTS(SELECT * FROM account_users WHERE email = ?)", [$email]), "email", "E-mail already exists in the database");
     $validator->validate($agreeTerms, "agreeTerms", Validator::NOEMPTY, [], "You haven't accepted terms and conditions");
     $errors = $validator->getErrors(true);
     if (empty($errors)) {
         $account = Scalr_Account::init();
         $account->name = $org ? $org : $name;
         $account->status = Scalr_Account::STATUS_ACTIVE;
         $account->save();
         $user = $account->createUser($email, $password, Scalr_Account_User::TYPE_ACCOUNT_OWNER);
         $user->fullname = $name;
         $user->save();
         if ($this->getContainer()->analytics->enabled) {
             $analytics = $this->getContainer()->analytics;
             //Default Cost Center should be assigned
             $cc = $analytics->ccs->get($analytics->usage->autoCostCentre());
             //Assigns account with Cost Center
             $accountCcEntity = new AccountCostCenterEntity($account->id, $cc->ccId);
             $accountCcEntity->save();
         }
         //Creates Environment. It will be associated with the Cost Center itself.
         $account->createEnvironment("Environment 1");
         $account->initializeAcl();
         if ($v == 2) {
             $user->setSetting('website.phone', $phone);
             $user->setSetting('website.country', $country);
             $user->setSetting('website.num_servers', $numServers);
         }
         /**
          * Limits
          */
         $url = Scalr::config('scalr.endpoint.scheme') . "://" . Scalr::config('scalr.endpoint.host');
         try {
             $billing = new Scalr_Billing();
             $billing->loadByAccount($account);
             $billing->createSubscription(Scalr_Billing::PAY_AS_YOU_GO, "", "", "", "");
         } catch (Exception $e) {
             $account->delete();
             header("Location: {$url}/order/?error={$e->getMessage()}");
             exit;
         }
         if ($_COOKIE['__utmz']) {
             $gaParser = new Scalr_Service_GoogleAnalytics_Parser();
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_CONTENT] = $gaParser->campaignContent;
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_MEDIUM] = $gaParser->campaignMedium;
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_NAME] = $gaParser->campaignName;
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_SOURCE] = $gaParser->campaignSource;
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_TERM] = $gaParser->campaignTerm;
             $clientSettings[CLIENT_SETTINGS::GA_FIRST_VISIT] = $gaParser->firstVisit;
             $clientSettings[CLIENT_SETTINGS::GA_PREVIOUS_VISIT] = $gaParser->previousVisit;
             $clientSettings[CLIENT_SETTINGS::GA_TIMES_VISITED] = $gaParser->timesVisited;
         }
         if (!empty($clientSettings)) {
             foreach ($clientSettings as $k => $v) {
                 $account->setSetting($k, $v);
             }
         }
         try {
             $this->db->Execute("\n                    INSERT INTO default_records\n                    SELECT null, '{$account->id}', rtype, ttl, rpriority, rvalue, rkey\n                    FROM default_records\n                    WHERE clientid='0'\n                ");
         } catch (Exception $e) {
         }
         $clientinfo = array('fullname' => $name, 'firstname' => $firstname ? $firstname : $name, 'email' => $email, 'password' => $password);
         //Sends welcome email
         $this->getContainer()->mailer->setFrom('*****@*****.**', 'Scalr')->setHtml()->sendTemplate(SCALR_TEMPLATES_PATH . '/emails/welcome.html.php', array('firstName' => htmlspecialchars($clientinfo['firstname']), 'password' => htmlspecialchars($clientinfo['password']), "siteUrl" => htmlspecialchars($url), "wikiUrl" => htmlspecialchars(\Scalr::config('scalr.ui.wiki_url')), "supportUrl" => htmlspecialchars(\Scalr::config('scalr.ui.support_url')), "isUrl" => preg_match('/^http(s?):\\/\\//i', \Scalr::config('scalr.ui.support_url'))), $email);
         $user->getAccount()->setSetting(Scalr_Account::SETTING_IS_TRIAL, 1);
         //AutoLogin
         $user->updateLastLogin();
         Scalr_Session::create($user->getId());
         Scalr_Session::keepSession();
         if ($beta != 1) {
             $this->response->setRedirect("{$url}/thanks.html");
         } else {
             $this->response->data(array('accountId' => $user->getAccountId()));
         }
     } else {
         if ($beta == 1) {
             header("HTTP/1.0 400 Bad request");
             print json_encode($errors);
             exit;
         } else {
             $error = array_values($errors)[0];
             $this->response->setRedirect("{$url}/order/?error={$error}");
         }
     }
 }
Example #5
0
 public function xCreateAccountAction()
 {
     global $Mailer;
     //FIXME:
     if (!class_exists("Scalr_Billing")) {
         exit;
     }
     $this->request->defineParams(array('name', 'org', 'email', 'password', 'agreeTerms', 'newBilling', 'country', 'phone', 'lastname', 'firstname', 'v', 'numServers'));
     $Validator = new Validator();
     if ($this->getParam('v') == 2) {
         if (!$this->getParam('firstname')) {
             $err['firstname'] = _("First name required");
         }
         if (!$this->getParam('lastname')) {
             $err['lastname'] = _("Last name required");
         }
         if (!$this->getParam('org')) {
             $err['org'] = _("Organization required");
         }
         $name = $this->getParam('firstname') . " " . $this->getParam('lastname');
     } else {
         if (!$this->getParam('name')) {
             $err['name'] = _("Account name required");
         }
         $name = $this->getParam("name");
     }
     $password = $this->getParam('password');
     if (!$password) {
         $password = $this->getCrypto()->sault(10);
     }
     if (!$Validator->IsEmail($this->getParam('email'))) {
         $err['email'] = _("Invalid E-mail address");
     }
     if (strlen($password) < 6) {
         $err['password'] = _("Password should be longer than 6 chars");
     }
     // Check email
     $DBEmailCheck = $this->db->GetOne("SELECT COUNT(*) FROM account_users WHERE email=?", array($this->getParam('email')));
     if ($DBEmailCheck > 0) {
         $err['email'] = _("E-mail already exists in database");
     }
     if (!$this->getParam('agreeTerms')) {
         $err['agreeTerms'] = _("You need to agree with terms and conditions");
     }
     if (count($err) == 0) {
         $account = Scalr_Account::init();
         $account->name = $this->getParam("org") ? $this->getParam("org") : $name;
         $account->status = Scalr_Account::STATUS_ACTIVE;
         $account->save();
         $account->createEnvironment("default", true);
         $user = $account->createUser($this->getParam('email'), $password, Scalr_Account_User::TYPE_ACCOUNT_OWNER);
         $user->fullname = $name;
         $user->save();
         if ($this->getParam('v') == 2) {
             $user->setSetting('website.phone', $this->getParam('phone'));
             $user->setSetting('website.country', $this->getParam('country'));
             $user->setSetting('website.num_servers', $this->getParam('numServers'));
         }
         /**
          * Limits
          */
         try {
             $billing = new Scalr_Billing();
             $billing->loadByAccount($account);
             $billing->createSubscription(Scalr_Billing::PACKAGE_SEED, "", "", "", "");
             /*******************/
         } catch (Exception $e) {
             $account->delete();
             header("Location: https://scalr.net/order/?error={$e->getMessage()}");
             exit;
         }
         if ($_COOKIE['__utmz']) {
             $gaParser = new Scalr_Service_GoogleAnalytics_Parser();
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_CONTENT] = $gaParser->campaignContent;
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_MEDIUM] = $gaParser->campaignMedium;
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_NAME] = $gaParser->campaignName;
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_SOURCE] = $gaParser->campaignSource;
             $clientSettings[CLIENT_SETTINGS::GA_CAMPAIGN_TERM] = $gaParser->campaignTerm;
             $clientSettings[CLIENT_SETTINGS::GA_FIRST_VISIT] = $gaParser->firstVisit;
             $clientSettings[CLIENT_SETTINGS::GA_PREVIOUS_VISIT] = $gaParser->previousVisit;
             $clientSettings[CLIENT_SETTINGS::GA_TIMES_VISITED] = $gaParser->timesVisited;
         }
         $clientSettings[CLIENT_SETTINGS::RSS_LOGIN] = $this->getParam('email');
         $clientSettings[CLIENT_SETTINGS::RSS_PASSWORD] = $this->getCrypto()->sault(10);
         foreach ($clientSettings as $k => $v) {
             $account->setSetting($k, $v);
         }
         try {
             $this->db->Execute("INSERT INTO default_records SELECT null, '{$account->id}', rtype, ttl, rpriority, rvalue, rkey FROM default_records WHERE clientid='0'");
         } catch (Exception $e) {
         }
         $clientinfo = array('fullname' => $name, 'firstname' => $this->getParam('firstname') ? $this->getParam('firstname') : $name, 'email' => $this->getParam('email'), 'password' => $password);
         $mailer = new PHPMailer();
         $mailer->Subject = 'Welcome to the Scalr revolution!';
         $mailer->From = '*****@*****.**';
         $mailer->FromName = 'Scalr';
         $mailer->AddAddress($this->getParam('email'));
         $mailer->IsHTML(true);
         $mailer->Body = @file_get_contents(dirname(__FILE__) . '/../../../../templates/en_US/emails/welcome.html');
         $mailer->Body = str_replace(array('{{FirstName}}', '{{Password}}'), array($clientinfo['firstname'], $clientinfo['password']), $mailer->Body);
         $mailer->Send();
         /*
         // Send welcome E-mail
         $Mailer->ClearAddresses();
         $Mailer->From 		='*****@*****.**';
         $res = $Mailer->Send("emails/welcome.eml",
         	array("client" => $clientinfo, "site_url" => "http://{$_SERVER['HTTP_HOST']}"),
         	$this->getParam('email'),
         	''
         );
         */
         $user->getAccount()->setSetting(Scalr_Account::SETTING_IS_TRIAL, 1);
         //AutoLogin
         $user->updateLastLogin();
         Scalr_Session::create($user->getId());
         Scalr_Session::keepSession();
         header("Location: http://scalr.net/thanks.html");
     } else {
         $errors = array_values($err);
         $error = $errors[0];
         header("Location: https://scalr.net/order/?error={$error}");
         //$this->response->failure();
         //$this->response->data(array('errors' => $err));
     }
     exit;
 }