Example #1
0
 /**
  * Unregisters a given plugin from the current Craft license.
  *
  * @string $pluginHandle The plugin handle that should be unregistered
  *
  * @return EtModel
  */
 public function unregisterPlugin($pluginHandle)
 {
     $et = new Et(static::UnregisterPlugin);
     $et->setData(array('pluginHandle' => $pluginHandle));
     $etResponse = $et->phoneHome();
     if (!empty($etResponse->data['success'])) {
         // Remove our record of the license key
         craft()->plugins->setPluginLicenseKey($pluginHandle, null);
     }
     return $etResponse;
 }
 public function phoneHome()
 {
     $et = new Et(static::SecondStarToTheRight);
     $et->phoneHome();
 }
 /**
  * Attempts to purchase an edition upgrade.
  *
  * @param UpgradePurchaseModel $model
  *
  * @return bool
  */
 public function purchaseUpgrade(UpgradePurchaseModel $model)
 {
     if ($model->validate()) {
         $et = new Et(static::PurchaseUpgrade);
         $et->setData($model);
         $etResponse = $et->phoneHome();
         if (!empty($etResponse->data['success'])) {
             // Success! Let's get this sucker installed.
             craft()->setEdition($model->edition);
             return true;
         } else {
             // Did they at least say why?
             if (!empty($etResponse->errors)) {
                 switch ($etResponse->errors[0]) {
                     // Validation errors
                     case 'edition_doesnt_exist':
                         $error = Craft::t('The selected edition doesn’t exist anymore.');
                         break;
                     case 'invalid_license_key':
                         $error = Craft::t('Your license key is invalid.');
                         break;
                     case 'license_has_edition':
                         $error = Craft::t('Your Craft license already has this edition.');
                         break;
                     case 'price_mismatch':
                         $error = Craft::t('The cost of this edition just changed.');
                         break;
                     case 'unknown_error':
                         $error = Craft::t('An unknown error occurred.');
                         break;
                         // Stripe errors
                     // Stripe errors
                     case 'incorrect_number':
                         $error = Craft::t('The card number is incorrect.');
                         break;
                     case 'invalid_number':
                         $error = Craft::t('The card number is invalid.');
                         break;
                     case 'invalid_expiry_month':
                         $error = Craft::t('The expiration month is invalid.');
                         break;
                     case 'invalid_expiry_year':
                         $error = Craft::t('The expiration year is invalid.');
                         break;
                     case 'invalid_cvc':
                         $error = Craft::t('The security code is invalid.');
                         break;
                     case 'incorrect_cvc':
                         $error = Craft::t('The security code is incorrect.');
                         break;
                     case 'expired_card':
                         $error = Craft::t('Your card has expired.');
                         break;
                     case 'card_declined':
                         $error = Craft::t('Your card was declined.');
                         break;
                     case 'processing_error':
                         $error = Craft::t('An error occurred while processing your card.');
                         break;
                     default:
                         $error = $etResponse->errors[0];
                 }
             } else {
                 // Something terrible must have happened!
                 $error = Craft::t('Craft is unable to purchase an edition upgrade at this time.');
             }
             $model->addError('response', $error);
         }
     }
     return false;
 }
Example #4
0
 /**
  * @param TryPackageModel $model
  * @return bool
  */
 public function tryPackage(TryPackageModel $model)
 {
     $et = new Et(static::StartPackageTrial);
     $et->setData($model);
     $etResponse = $et->phoneHome();
     if (!empty($etResponse->data['success'])) {
         // Install the package.
         if (!Craft::hasPackage($model->packageHandle)) {
             Craft::installPackage($model->packageHandle);
         }
         return true;
     } else {
         // Did they at least say why?
         if (!empty($etResponse->errors)) {
             switch ($etResponse->errors[0]) {
                 // Validation errors
                 case 'package_doesnt_exist':
                     $error = Craft::t('The selected package doesn’t exist anymore.');
                     break;
                 case 'cannot_trial_package':
                     $error = Craft::t('Your license key is invalid.');
                     break;
                 default:
                     $error = $etResponse->errors[0];
             }
         } else {
             // Something terrible must have happened!
             $error = Craft::t('Craft is unable to trial packages at this time.');
         }
         $model->addError('response', $error);
     }
     return false;
 }