public function cancelPayPalSubscription($attrs) { $link = ''; if (Cart66Common::isLoggedIn()) { $account = new Cart66Account(Cart66Session::get('Cart66AccountId')); if ($account->isPayPalAccount()) { // Look for account cancelation request if (isset($_GET['cart66-task']) && $_GET['cart66-task'] == 'CancelRecurringPaymentsProfile') { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Caught task: CancelPaymentsProfileStatus"); $sub = new Cart66AccountSubscription($account->getCurrentAccountSubscriptionId()); $profileId = $sub->paypalBillingProfileId; $note = "Your subscription has been canceled per your request."; $action = "Cancel"; $pp = new Cart66PayPalPro(); $pp->ManageRecurringPaymentsProfileStatus($profileId, $action, $note); $url = str_replace('cart66-task=CancelRecurringPaymentsProfile', '', Cart66Common::getCurrentPageUrl()); $link = "We sent a cancelation request to PayPal. It may take a minute or two for the cancelation process to complete and for your account status to be changed."; } elseif ($subId = $account->getCurrentAccountSubscriptionId()) { $sub = new Cart66AccountSubscription($subId); if ($sub->status == 'active') { $url = $sub->getSubscriptionManagementLink(); $text = isset($attrs['text']) ? $attrs['text'] : 'Cancel your subscription'; $link = "<a id='Cart66CancelPayPalSubscription' href=\"{$url}\">{$text}</a>"; } else { $link = "Your account is {$sub->status} but will remain active until " . date(get_option('date_format'), strtotime($sub->activeUntil)); } } } } Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Cancel paypal account link for logged in user: {$link}"); return $link; }
/** * Cancel remote PayPal subscription and set local status to canceled. * If expire is set to true, also change the active until date to today. * * @param string $note The note to send to PayPal describing the reason for cancelation * @param boolean $expire If true, change the active_until date to today */ public function cancelPayPalSubscription($note = 'Your subscription has been canceled per your request.', $expire = false) { if ($this->id > 0) { $pp = new Cart66PayPalPro(); $profileId = $this->paypalBillingProfileId; $pp->ManageRecurringPaymentsProfileStatus($profileId, 'Cancel', $note); $this->active = 0; $this->status = 'canceled'; if ($expire) { $this->activeUntil = date('Y-m-d 00:00:00', Cart66Common::localTs()); } $this->save(); } }