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;
 }
Пример #2
0
 $ack = strtoupper($response['ACK']);
 if ('SUCCESS' == $ack || 'SUCCESSWITHWARNING' == $ack) {
     // Wait to make sure the transaction is a success before creating the account
     if ($createAccount) {
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Creating account after successful PayPal transaction");
         $account->save();
     }
     // Create Recurring Payment Profile if a subscription has been sold
     $profileResponse = array('ACK' => 'SKIPPED');
     if ($cartItem = Cart66Session::get('Cart66Cart')->getPayPalSubscriptionItem()) {
         $planIndex = Cart66Session::get('Cart66Cart')->getPayPalSubscriptionIndex();
         $plan = new Cart66PayPalSubscription($cartItem->getPayPalSubscriptionId());
         $profileResponse = $pp->CreateRecurringPaymentsProfile($token, $cartItem, $planIndex);
         if ('FAILURE' != strtoupper($profileResponse['ACK'])) {
             $paypalPaymentProfileId = $profileResponse['PROFILEID'];
             if (Cart66Common::isLoggedIn() && $account->isPayPalAccount()) {
                 // Expire the current subscription and attach a new subscription
                 $account->cancelSubscription('Your subscription has been canceled because you changed to a new subscription.', true);
             }
             $activeUntil = $plan->getStartTimeFormula();
             $account->attachPayPalSubscription($details, $paypalPaymentProfileId, $plan, $activeUntil);
         }
     } elseif ($cartItem = Cart66Session::get('Cart66Cart')->getMembershipProductItem()) {
         Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Got membership product from the cart after a PayPal transaction.");
         $product = new Cart66Product($cartItem->getProductId());
         $account->attachMembershipProduct($product, $details['FIRSTNAME'], $details['LASTNAME']);
     }
     // Save the order
     if ('FAILURE' != strtoupper($profileResponse['ACK'])) {
         $token = Cart66Common::postVal('token');
         $payerId = Cart66Common::postVal('PayerID');