/**
  * Return the Spreedly url to manage the subscription or the
  * PayPal url to cancel the subscription. 
  * If the visitor is not logged in, return false.
  * You can pass in text for the link and a custom return URL
  * 
  * $attr = array(
  *   text => 'The link text for the subscription management link'
  *   return => 'Customize the return url for the spreedly page'
  * )
  * 
  * @return string Spreedly subscription management URL
  */
 public function accountInfo($attrs)
 {
     if (Cart66Common::isLoggedIn()) {
         $data = array();
         $account = new Cart66Account(Cart66Session::get('Cart66AccountId'));
         if (isset($_POST['cart66-task']) && $_POST['cart66-task'] == 'account-update') {
             $login = $_POST['login'];
             if ($login['password'] == $login['password2']) {
                 $account->firstName = $login['first_name'];
                 $account->lastName = $login['last_name'];
                 $account->email = $login['email'];
                 $account->password = empty($login['password']) ? $account->password : md5($login['password']);
                 $account->username = $login['username'];
                 $errors = $account->validate();
                 if (count($errors) == 0) {
                     $account->save();
                     if ($account->isSpreedlyAccount()) {
                         SpreedlySubscriber::updateRemoteAccount($account->id, array('email' => $account->email));
                     }
                     $data['message'] = 'Your account is updated';
                     Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Account was updated: " . print_r($account->getData, true));
                 } else {
                     $data['errors'] = $account->getErrors();
                     Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Account validation failed: " . print_r($data['errors'], true));
                 }
             } else {
                 $data['errors'] = "Account not updated. The passwords entered did not match";
             }
         }
         $data['account'] = $account;
         $data['url'] = false;
         if ($account->isSpreedlyAccount()) {
             $accountSub = $account->getCurrentAccountSubscription();
             $text = isset($attrs['text']) ? $attrs['text'] : 'Manage your subscription.';
             $returnUrl = isset($attrs['return']) ? $attrs['return'] : null;
             $url = $accountSub->getSubscriptionManagementLink($returnUrl);
             $data['url'] = $url;
             $data['text'] = $text;
         }
         $view = Cart66Common::getView('views/account-info.php', $data);
         return $view;
     } else {
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Trying to view account subscription short code but account holder is not logged into Cart66.");
     }
 }
예제 #2
0
             } else {
                 // Set the subscriber token in the session for repeat attempts to create the subscription
                 Cart66Session::set('Cart66SubscriberToken', $account->subscriberToken);
             }
             if (count($errors)) {
                 try {
                     Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Unable to process order: " . print_r($errors, true));
                     throw new Cart66Exception(__('Your order could not be processed for the following reasons:', 'cart66'), 66500);
                 } catch (Cart66Exception $e) {
                     $exception = Cart66Exception::exceptionMessages($e->getCode(), $e->getMessage(), $errors);
                     echo Cart66Common::getView('views/error-messages.php', $exception);
                 }
             }
         }
     } else {
         $errors = $account->getErrors();
         if (count($errors)) {
             try {
                 Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Unable to process order: " . print_r($errors, true));
                 throw new Cart66Exception(__('Your order could not be processed for the following reasons:', 'cart66'), 66500);
             } catch (Cart66Exception $e) {
                 $exception = Cart66Exception::exceptionMessages($e->getCode(), $e->getMessage(), $errors);
                 echo Cart66Common::getView('views/error-messages.php', $exception);
             }
         }
         $jqErrors = $account->getJqErrors();
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Account validation failed. " . print_r($errors, true));
     }
 }
 // ===========================
 // = End Spreedly Processing =