public static function accountsPage() { $data = array(); if (CART66_PRO) { $data['plan'] = new Cart66AccountSubscription(); $data['activeUntil'] = ''; $account = new Cart66Account(); if (isset($_REQUEST['cart66-action']) && $_REQUEST['cart66-action'] == 'delete_account') { // Look for delete request if (isset($_REQUEST['accountId']) && is_numeric($_REQUEST['accountId'])) { $account = new Cart66Account($_REQUEST['accountId']); $account->deleteMe(); $account->clear(); } } elseif (isset($_REQUEST['accountId']) && is_numeric($_REQUEST['accountId'])) { if (isset($_REQUEST['opt_out'])) { $account = new Cart66Account(); $account->load($_REQUEST['accountId']); $data = array('opt_out' => $_REQUEST['opt_out']); $account->setData($data); $account->save(); $account->clear(); } // Look in query string for account id $account = new Cart66Account(); $account->load($_REQUEST['accountId']); $id = $account->getCurrentAccountSubscriptionId(true); $data['plan'] = new Cart66AccountSubscription($id); // Return even if plan is expired if (date('Y', strtotime($data['plan']->activeUntil)) <= 1970) { $data['activeUntil'] = ''; } else { $data['activeUntil'] = date('m/d/Y', strtotime($data['plan']->activeUntil)); } } if ($_SERVER['REQUEST_METHOD'] == 'POST' && Cart66Common::postVal('cart66-action') == 'save account') { $acctData = $_POST['account']; // Format or unset password if (empty($acctData['password'])) { unset($acctData['password']); } else { $acctData['password'] = md5($acctData['password']); } // Strip HTML tags on notes field $acctData['notes'] = strip_tags($acctData['notes'], '<a><strong><em>'); $planData = $_POST['plan']; $planData['active_until'] = date('Y-m-d 00:00:00', strtotime($planData['active_until'])); // Updating an existing account if ($acctData['id'] > 0) { $account = new Cart66Account($acctData['id']); $account->setData($acctData); $account_errors = $account->validate(); $sub = new Cart66AccountSubscription($planData['id']); if ($planData['product_id'] != 'spreedly_subscription') { $sub->setData($planData); $subscription_product = new Cart66Product($sub->product_id); $sub->subscription_plan_name = $subscription_product->name; $sub->feature_level = $subscription_product->feature_level; $sub->subscriber_token = ''; } else { unset($planData['product_id']); $sub->setData($planData); } $subscription_errors = $sub->validate(); $errors = array_merge($account_errors, $subscription_errors); if (count($errors) == 0) { $account->save(); $sub->save(); $account->clear(); $sub->clear(); } else { $data['errors'] = $errors; $data['plan'] = $sub; $data['activeUntil'] = date('m/d/Y', strtotime($sub->activeUntil)); } } else { // Creating a new account $account = new Cart66Account(); $account->setData($acctData); $account_errors = $account->validate(); if (count($account_errors) == 0) { $sub = new Cart66AccountSubscription(); $sub->setData($planData); $subscription_errors = $sub->validate(); if (count($subscription_errors) == 0) { $account->save(); $sub->billingFirstName = $account->firstName; $sub->billingLastName = $account->lastName; $sub->billingInterval = 'Manual'; $sub->account_id = $account->id; $subscription_product = new Cart66Product($sub->product_id); $sub->subscription_plan_name = $subscription_product->name; $sub->feature_level = $subscription_product->feature_level; $sub->save(); $account->clear(); $data['just_saved'] = true; } else { $data['errors'] = $subscription_errors; } } else { $data['errors'] = $account_errors; } } } $data['url'] = Cart66Common::replaceQueryString('page=cart66-accounts'); $data['account'] = $account; } $view = Cart66Common::getView('admin/accounts.php', $data); echo $view; }
/** * 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."); } }
$exception = Cart66Exception::exceptionMessages($e->getCode(), $e->getMessage(), array(__("You must wait ", "cart66") . Cart66Session::get('Cart66CheckoutThrottle')->getTimeRemaining() . __(" more seconds before trying to checkout again.", "cart66"))); echo Cart66Common::getView('views/error-messages.php', $exception); $errors[] = ""; // Add an error so that the transaction will not be processed } } // Charge credit card for one time transaction using Authorize.net API if (count($errors) == 0 && !Cart66Session::get('Cart66InventoryWarning')) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] start working on charging the credit card"); // ============================= // = Start Spreedly Processing = // ============================= if (Cart66Session::get('Cart66Cart')->hasSpreedlySubscriptions()) { $accountErrors = $account->validate(); if (count($accountErrors) == 0) { $account->save(); // Save account data locally which will create an account id and/or update local values Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Account data validated and saved for account id: " . $account->id); try { $spreedlyCard = new SpreedlyCreditCard(); $spreedlyCard->hydrateFromCheckout(); $subscriptionId = Cart66Session::get('Cart66Cart')->getSpreedlySubscriptionId(); $productId = Cart66Session::get('Cart66Cart')->getSpreedlyProductId(); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] About to create a new spreedly account subscription: Account ID: {$account->id} | Subscription ID: {$subscriptionId}"); $accountSubscription = new Cart66AccountSubscription(); $accountSubscription->createSpreedlySubscription($account->id, $subscriptionId, $productId, $spreedlyCard); } catch (SpreedlyException $e) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Failed to checkout: " . $e->getCode() . ' ' . $e->getMessage()); $errors['spreedly failed'] = $e->getMessage(); $accountSubscription->refresh(); if (empty($accountSubscription->subscriberToken)) {