Scalr_Billing::createSubscription PHP Method

createSubscription() public method

public createSubscription ( $package, $ccNumber, $ccExpMonth, $ccExpYear, $ccCvv, $fName = "", $lName = "", $postalCode = "" )
    public function createSubscription($package, $ccNumber, $ccExpMonth, $ccExpYear, $ccCvv, $fName = "", $lName = "", $postalCode = "")
    {
        if (!$this->subscriptionId) {
            if (!$this->customerId) {
                if ($fName == "" && $lName == "") {
                    $c = explode(" ", $this->account->getOwner()->fullname);
                    $fName = array_shift($c);
                    $lName = implode(" ", $c);
                }
                $clientInfo = array('email' => $this->account->getOwner()->getEmail(), 'org' => $this->account->name, 'first_name' => $fName, 'last_name' => $lName);
            } else {
                $clientInfo = false;
            }
            $subscription = $this->chargify->createSubscription($this->account->id, $package, $ccNumber, $ccExpMonth, $ccExpYear, $ccCvv, $clientInfo, $postalCode);
            $this->account->setSetting(self::SETTING_CGF_SID, $subscription['subscription']['id']);
            $this->account->setSetting(self::SETTING_CGF_CID, $subscription['subscription']['customer']['id']);
            $this->account->setSetting(self::SETTING_PACKAGE, $package);
            $this->account->status = Scalr_Account::STATUS_ACTIVE;
            $this->account->save();
            $this->setLimits($package);
            return true;
        } else {
            throw new Exception("Account already have subscription");
        }
    }

Usage Example

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");
     }
 }
All Usage Examples Of Scalr_Billing::createSubscription