function process(&$order)
 {
     //check for initial payment
     if (floatval($order->InitialPayment) == 0) {
         //just subscribe
         return $this->subscribe($order);
     } else {
         //charge then subscribe
         if ($this->charge($order)) {
             if (pmpro_isLevelRecurring($order->membership_level)) {
                 if ($this->subscribe($order)) {
                     //yay!
                     return true;
                 } else {
                     //try to refund initial charge
                     return false;
                 }
             } else {
                 //only a one time charge
                 $order->status = "success";
                 //saved on checkout page
                 return true;
             }
         } else {
             if (empty($order->error)) {
                 $order->error = __("Unknown error: Initial payment failed.", "pmpro");
             }
             return false;
         }
     }
 }
 function process(&$order)
 {
     if (pmpro_isLevelRecurring($order->membership_level)) {
         $order->ProfileStartDate = date("Y-m-d", strtotime("+ " . $order->BillingFrequency . " " . $order->BillingPeriod)) . "T0:0:0";
         $order->ProfileStartDate = apply_filters("pmpro_profile_start_date", $order->ProfileStartDate, $order);
         return $this->subscribe($order);
     } else {
         return $this->charge($order);
     }
 }
 function process(&$order)
 {
     if (floatval($order->InitialPayment) == 0) {
         //auth first, then process
         $authorization_id = $this->authorize($order);
         if ($authorization_id) {
             $this->void($order, $authorization_id);
             $order->ProfileStartDate = date("Y-m-d", strtotime("+ " . $order->BillingFrequency . " " . $order->BillingPeriod, current_time("timestamp"))) . "T0:0:0";
             $order->ProfileStartDate = apply_filters("pmpro_profile_start_date", $order->ProfileStartDate, $order);
             return $this->subscribe($order);
         } else {
             if (empty($order->error)) {
                 $order->error = __("Unknown error: Authorization failed.", "pmpro");
             }
             return false;
         }
     } else {
         //charge first payment
         if ($this->charge($order)) {
             //setup recurring billing
             if (pmpro_isLevelRecurring($order->membership_level)) {
                 $order->ProfileStartDate = date("Y-m-d", strtotime("+ " . $order->BillingFrequency . " " . $order->BillingPeriod, current_time("timestamp"))) . "T0:0:0";
                 $order->ProfileStartDate = apply_filters("pmpro_profile_start_date", $order->ProfileStartDate, $order);
                 if ($this->subscribe($order)) {
                     return true;
                 } else {
                     if ($this->void($order, $order->payment_transaction_id)) {
                         if (empty($order->error)) {
                             $order->error = __("Unknown error: Payment failed.", "pmpro");
                         }
                     } else {
                         if (empty($order->error)) {
                             $order->error = __("Unknown error: Payment failed.", "pmpro");
                         }
                         $order->error .= " " . __("A partial payment was made that we could not refund. Please contact the site owner immediately to correct this.", "pmpro");
                     }
                     return false;
                 }
             } else {
                 //only a one time charge
                 $order->status = "success";
                 //saved on checkout page
                 $order->saveOrder();
                 return true;
             }
         }
     }
 }
Example #4
0
File: billing.php Project: 6226/wp
        ?>
:</strong> <?php 
        echo $level->billing_limit . ' ' . sornot($level->cycle_period, $level->billing_limit);
        ?>
</li>
		<?php 
    }
    ?>
		
		</ul>
	<?php 
}
?>

<?php 
if (pmpro_isLevelRecurring($level)) {
    ?>
	<?php 
    if ($show_paypal_link) {
        ?>
		
		<p><?php 
        _e('Your payment subscription is managed by PayPal. Please <a href="http://www.paypal.com">login to PayPal here</a> to update your billing information.', 'pmpro');
        ?>
</p>
		
	<?php 
    } else {
        ?>
	
		<form class="pmpro_form" action="<?php 
 function cancel(&$order)
 {
     // If recurring, stop the recurring payment
     if (pmpro_isLevelRecurring($order->membership_level)) {
         $params['sale_id'] = $order->payment_transaction_id;
         $result = Twocheckout_Sale::stop($params);
         // Stop the recurring billing
         // Successfully cancelled
         if (isset($result['response_code']) && $result['response_code'] === 'OK') {
             $order->updateStatus("cancelled");
             return true;
         } else {
             $order->status = "error";
             $order->errorcode = $result->getCode();
             $order->error = $result->getMessage();
             return false;
         }
     }
     return $order;
 }
</a>
                        -->
                        <a class="pmpro_btn pmpro_btn-select change-subscription" href="<?php 
            echo "/billing/subscription-checkout?level=" . $level->id;
            ?>
"><?php 
            _e('Select Plan', 'pmpro');
            ?>
</a>
                    <?php 
        } elseif ($current_level) {
            ?>
      
                        <?php 
            //if it's a one-time-payment level, offer a link to renew
            if (!pmpro_isLevelRecurring($current_user->membership_level) && !empty($current_user->membership_level->enddate)) {
                ?>
                            <a class="pmpro_btn pmpro_btn-select renew" href="<?php 
                echo pmpro_url("checkout", "?level=" . $level->id, "https");
                ?>
"><?php 
                _e('Renew', 'pmpro');
                ?>
</a>
                            <?php 
            } else {
                ?>
                            <a class="pmpro_btn disabled your-current-level" href="<?php 
                echo pmpro_url("account");
                ?>
"><?php 
Example #7
0
                	
			<a class="pmpro_btn pmpro_btn-select" href="<?php 
        echo pmpro_url("checkout", "?level=" . $level->id, "https");
        ?>
"><?php 
        _e('Select', 'pmpro');
        ?>
</a>
		<?php 
    } elseif ($current_level) {
        ?>
      
			
			<?php 
        //if it's a one-time-payment level, offer a link to renew
        if (!pmpro_isLevelRecurring($current_user->membership_level)) {
            ?>
					<a class="pmpro_btn pmpro_btn-select" href="<?php 
            echo pmpro_url("checkout", "?level=" . $level->id, "https");
            ?>
"><?php 
            _e('Renew', 'pmpro');
            ?>
</a>
				<?php 
        } else {
            ?>
					<a class="pmpro_btn disabled" href="<?php 
            echo pmpro_url("account");
            ?>
"><?php 
Example #8
0
						
			foreach($levels as $level)
			{			
		?>
		<tr class="<?php if(!$level->allow_signups) { ?>pmpro_gray<?php } ?> <?php if(!pmpro_checkLevelForStripeCompatibility($level) || !pmpro_checkLevelForBraintreeCompatibility($level) || !pmpro_checkLevelForPayflowCompatibility($level)) { ?>pmpro_error<?php } ?>">			
			<td><?php echo $level->id?></td>
			<td><?php echo $level->name?></td>
			<td>
				<?php if(pmpro_isLevelFree($level)) { ?>
					FREE
				<?php } else { ?>
					<?php echo $pmpro_currency_symbol?><?php echo $level->initial_payment?>
				<?php } ?>
			</td>
			<td>
				<?php if(!pmpro_isLevelRecurring($level)) { ?>
					--
				<?php } else { ?>						
					<?php echo $pmpro_currency_symbol?><?php echo $level->billing_amount?> every <?php echo $level->cycle_number.' '.sornot($level->cycle_period,$level->cycle_number)?>
					
					<?php if($level->billing_limit) { ?>(for <?php echo $level->billing_limit?> <?php echo sornot($level->cycle_period,$level->billing_limit)?>)<?php } ?>
					
				<?php } ?>
			</td>				
			<td>
				<?php if(!pmpro_isLevelTrial($level)) { ?>
					--
				<?php } else { ?>		
					<?php echo $pmpro_currency_symbol?><?php echo $level->trial_amount?> for <?php echo $level->trial_limit?> <?php echo sornot("payment",$level->trial_limit)?>
				<?php } ?>
			</td>
 function sendToMigs(&$order)
 {
     global $pmpro_currency;
     //$order_id = $order->code;
     //taxes on initial amount
     $initial_payment = $order->InitialPayment;
     $initial_payment_tax = $order->getTaxForPrice($initial_payment);
     $initial_payment = round((double) $initial_payment + (double) $initial_payment_tax, 2);
     $details = '';
     //taxes on the amount (NOT CURRENTLY USED)
     $amount = $order->PaymentAmount;
     $amount_tax = $order->getTaxForPrice($amount);
     $amount = round((double) $amount + (double) $amount_tax, 2);
     // Recurring membership
     if (pmpro_isLevelRecurring($order->membership_level)) {
         $amount = number_format($initial_payment - $amount, 2, ".", "");
         //negative amount for lower initial payments
         $recurring_payment = number_format($order->membership_level->billing_amount, 2, ".", "");
         $recurring_payment_tax = number_format($order->getTaxForPrice($recurring_payment), 2, ".", "");
         $recurring_payment = number_format(round((double) $recurring_payment + (double) $recurring_payment_tax, 2), 2, ".", "");
         $amount = number_format($recurring_payment, 2, ".", "");
         $details = $order->BillingFrequency == 1 ? $order->BillingFrequency . ' ' . $order->BillingPeriod : $order->BillingFrequency . ' ' . $order->BillingPeriod . 's';
         if (property_exists($order, 'TotalBillingCycles')) {
             $details = $order->BillingFrequency * $order->TotalBillingCycles . ' ' . $order->BillingPeriod;
         } else {
             $details = 'Forever';
         }
     } else {
         $amount = number_format($initial_payment, 2, ".", "");
     }
     if (!empty($order->TrialBillingPeriod)) {
         $trial_amount = $order->TrialAmount;
         $trial_tax = $order->getTaxForPrice($trial_amount);
         $trial_amount = pmpro_formatPrice(round((double) $trial_amount + (double) $trial_tax, 2), false, false);
         $amount = $trial_amount;
         // Negative trial amount
     }
     global $pmpro_level;
     //create a code for the order
     if (empty($order->code)) {
         $order->code = $order->getRandomCode();
     }
     //what amount to charge?
     $amount = $order->InitialPayment;
     //tax
     $order->subtotal = $amount;
     $tax = $order->getTax(true);
     $amount = round((double) $order->subtotal + (double) $tax, 2);
     //create a customer
     //$result = $this->getCustomer($order);
     /*if(empty($result))
     		{
     			//failed to create customer
     			return false;
     		}*/
     //charge
     try {
         $order_id = $order->code;
         $order_amount = 100 * $amount;
         $md5Hash = pmpro_getOption("securehashe");
         /* Make sure user entered MIGS url, otherwise use the default one */
         if (trim($this->service_host) == "" || $this->service_host == null) {
             $this->service_host = "https://migs.mastercard.com.au/vpcpay";
         }
         $service_host = $this->service_host . "?";
         $rurl = admin_url("admin-ajax.php") . "?action=migspaymenthandler";
         //$rurl='https://nibaya.com/ccc/wp-content/plugins/pmpro-example-gateway/classes/paymenthandler.php?';
         //$rurl = pmpro_url("confirmation", "?level=" . $order->membership_level);
         $user_ID = get_current_user_id();
         $DigitalOrder = array("vpc_Version" => "1", "vpc_Command" => "pay", "vpc_AccessCode" => pmpro_getOption("accescodee"), "vpc_MerchTxnRef" => $order_id . '_' . date("Y-m-d"), "vpc_Merchant" => pmpro_getOption("merchantide"), "vpc_OrderInfo" => $order_id . '_' . date("Y-m-d"), "vpc_Amount" => $order_amount, "vpc_Locale" => "en", "vpc_ReturnURL" => $rurl . '&level=1');
         ksort($DigitalOrder);
         foreach ($DigitalOrder as $key => $value) {
             if (strlen($value) > 0) {
                 if ($appendAmp == 0) {
                     $service_host .= urlencode($key) . '=' . urlencode($value);
                     $appendAmp = 1;
                 } else {
                     $service_host .= '&' . urlencode($key) . "=" . urlencode($value);
                 }
                 $md5Hash .= $value;
             }
         }
         $service_host .= "&vpc_SecureHash=" . strtoupper(md5($md5Hash));
         //$order->saveOrder();
         //echo $service_host;
         header("Location:" . $service_host);
         exit;
     } catch (Exception $e) {
         //$order->status = "error";
         $order->errorcode = true;
         $order->error = "Error: " . $e->getMessage();
         $order->shorterror = $order->error;
         return false;
     }
     //$order->saveOrder();
     //echo $service_host;
     //header("Location:".$service_host);
     //exit();
     // Demo mode?
     // if(empty($order->gateway_environment))
     // $gateway_environment = pmpro_getOption("gateway_environment");
     // else
     // $gateway_environment = $order->gateway_environment;
     // if("sandbox" === $gateway_environment || "beta-sandbox" === $gateway_environment)
     // {
     // Migs::sandbox(true);
     // $tco_args['demo'] = 'Y';
     // }
     // else
     // Migs::sandbox(false);
     // Trial?
     //li_#_startup_fee	Any start up fees for the product or service. Can be negative to provide discounted first installment pricing, but cannot equal or surpass the product price.
     //redirect to 2checkout
 }
function getLevels()
{
    global $current_user;
    if ($current_user->ID) {
        $current_user->membership_level = pmpro_getMembershipLevelForUser($current_user->ID);
    }
    //is there a default level to redirect to?
    if (defined("PMPRO_DEFAULT_LEVEL")) {
        $default_level = intval(PMPRO_DEFAULT_LEVEL);
    } else {
        $default_level = false;
    }
    if ($default_level) {
        wp_redirect(pmpro_url("checkout", "?level=" . $default_level));
        exit;
    }
    global $wpdb, $pmpro_msg, $pmpro_msgt;
    if (isset($_REQUEST['msg'])) {
        if ($_REQUEST['msg'] == 1) {
            $pmpro_msg = __('Your membership status has been updated - Thank you!', 'pmpro');
        } else {
            $pmpro_msg = __('Sorry, your request could not be completed - please try again in a few moments.', 'pmpro');
            $pmpro_msgt = "pmpro_error";
        }
    } else {
        $pmpro_msg = false;
    }
    global $pmpro_levels;
    $pmpro_levels = pmpro_getAllLevels(false, true);
    $pmpro_levels = apply_filters("pmpro_levels_array", $pmpro_levels);
    if ($pmpro_msg) {
        ?>
        <div class="pmpro_message <?php 
        echo $pmpro_msgt;
        ?>
"><?php 
        echo $pmpro_msg;
        ?>
</div>
        <?php 
    }
    ?>

    <div id="main" class="site-main clr">
        <div id="membership-wrapper"> 
            <?php 
    $count = 0;
    $count_levels = count($pmpro_levels);
    $tmp = 0;
    foreach ($pmpro_levels as $level) {
        if (isset($current_user->membership_level->ID)) {
            $current_level = $current_user->membership_level->ID == $level->id;
        } else {
            $current_level = false;
        }
        ?>

                <?php 
        $last = $count_levels - $tmp;
        ?>
  
                <?php 
        $tmp = $tmp + 1;
        ?>

                <div class="box-level <?php 
        if ($count++ % 2 == 0) {
            ?>
odd<?php 
        } else {
            ?>
 even<?php 
        }
        if ($current_level == $level) {
            ?>
 active<?php 
        }
        if ($last == 2 || $last == 1) {
            ?>
 last-box<?php 
        }
        ?>
">
                    <h1><?php 
        echo $current_level ? "<strong>{$level->name}</strong>" : $level->name;
        ?>
</h1>
                    <div class="copy">
                        <?php 
        if (pmpro_isLevelFree($level)) {
            $cost_text = "<strong>Free</strong>";
        } else {
            $cost_text = pmpro_getLevelCost($level, true, true);
        }
        $expiration_text = pmpro_getLevelExpiration($level);
        if (!empty($cost_text) && !empty($expiration_text)) {
            echo $cost_text . "<br />" . $expiration_text;
        } elseif (!empty($cost_text)) {
            echo $cost_text;
        } elseif (!empty($expiration_text)) {
            echo $expiration_text;
        }
        ?>
                    </div>
                    <div class="links">
                        <?php 
        if (empty($current_user->membership_level->ID)) {
            ?>
                            <a class="pmpro_btn pmpro_btn-select sign-up" href="<?php 
            echo pmpro_url("checkout", "?level=" . $level->id, "https");
            ?>
"><?php 
            _e('Sign Up', 'pmpro');
            ?>
</a>
                        <?php 
        } elseif (!$current_level) {
            ?>
     
                            <!--
                            <a class="pmpro_btn pmpro_btn-select" href="<?php 
            //echo pmpro_url("checkout", "?level=" . $level->id, "https")
            ?>
"><?php 
            //_e('Change Subscription', 'pmpro');
            ?>
</a>
                            -->
                            <a class="pmpro_btn pmpro_btn-select change-subscription" href="<?php 
            echo "/billing/subscription-checkout?level=" . $level->id;
            ?>
"><?php 
            _e('Change Subscription', 'pmpro');
            ?>
</a>
                        <?php 
        } elseif ($current_level) {
            ?>
      
                            <?php 
            //if it's a one-time-payment level, offer a link to renew
            if (!pmpro_isLevelRecurring($current_user->membership_level) && !empty($current_user->membership_level->enddate)) {
                ?>
                                <a class="pmpro_btn pmpro_btn-select renew" href="<?php 
                echo pmpro_url("checkout", "?level=" . $level->id, "https");
                ?>
"><?php 
                _e('Renew', 'pmpro');
                ?>
</a>
                                <?php 
            } else {
                ?>
                                <a class="pmpro_btn disabled your-current-level" href="<?php 
                echo pmpro_url("account");
                ?>
"><?php 
                _e('Your&nbsp;Current&nbsp;Level', 'pmpro');
                ?>
</a>
                                <?php 
            }
            ?>
                        <?php 
        }
        ?>
                    </div>
                </div>
                <?php 
    }
    ?>
            <div class="clear clearfix"></div>
            <nav id="nav-below" class="navigation" role="navigation">
                <div class="nav-previous alignleft">
                    <?php 
    if (!empty($current_user->membership_level->ID)) {
        ?>
                        <!--
                            <a href="<?php 
        echo pmpro_url("account");
        ?>
"><?php 
        _e('&larr; Return to Your Account', 'pmpro');
        ?>
</a>
                        -->
                    <?php 
    } else {
        ?>
                        <a href="<?php 
        echo home_url();
        ?>
"><?php 
        _e('&larr; Return to Home', 'pmpro');
        ?>
</a>
                    <?php 
    }
    ?>
                </div>
            </nav>
        </div>
    </div>    

    <?php 
}
Example #11
0
function memberlite_levels_shortcode($atts, $content = null, $code = "")
{
    // $atts    ::= array of attributes
    // $content ::= text within enclosing form of shortcode element
    // $code    ::= the shortcode found, when == callback name
    // examples: [memberlite_levels levels="1,2,3" layout="table" hightlight="2" description="false" checkout_button="Register Now"]
    extract(shortcode_atts(array('account_button' => 'Your Level', 'back_link' => '1', 'checkout_button' => 'Select', 'compare' => NULL, 'description' => '1', 'discount_code' => NULL, 'expiration' => '1', 'highlight' => NULL, 'layout' => 'div', 'levels' => NULL, 'more_button' => NULL, 'price' => 'short', 'renew_button' => 'Renew'), $atts));
    global $wpdb, $pmpro_msg, $pmpro_msgt, $current_user, $pmpro_currency_symbol, $pmpro_all_levels, $pmpro_visible_levels, $current_user, $membership_levels;
    //turn 0's into falses
    if ($back_link === "0" || $back_link === "false" || $back_link === "no") {
        $back_link = false;
    } else {
        $back_link = true;
    }
    if ($compare === "0" || $compare === "false" || $compare === "no") {
        $compare = false;
    } else {
        $compareitems = explode(";", $compare);
    }
    if ($description === "0" || $description === "false" || $description === "no") {
        $description = false;
    } else {
        $description = true;
    }
    if ($expiration === "0" || $expiration === "false" || $expiration === "no") {
        $expiration = false;
    } else {
        $expiration = true;
    }
    if ($more_button === "0" || $more_button === "false" || $more_button === "no" || empty($more_button)) {
        $more_button = false;
    } elseif ($more_button === "1" || $more_button === "true" || $more_button === "yes") {
        $more_button = "Read More";
    }
    if ($price === "0" || $price === "false" || $price === "hide") {
        $show_price = false;
    } else {
        $show_price = true;
    }
    if (function_exists('pmpro_getAllLevels')) {
        ob_start();
        //make sure pmpro_levels has all levels
        if (!isset($pmpro_all_levels)) {
            $pmpro_all_levels = pmpro_getAllLevels(true, true);
        }
        if (!isset($pmpro_visible_levels)) {
            $pmpro_visible_levels = pmpro_getAllLevels(false, true);
        }
        if ($pmpro_msg) {
            ?>
			<div class="pmpro_message <?php 
            echo $pmpro_msgt;
            ?>
"><?php 
            echo $pmpro_msg;
            ?>
</div>
			<?php 
        }
        $pmpro_levels_filtered = array();
        if (!empty($levels)) {
            $levels_order = explode(",", $levels);
            //loop through $levels_order array and pull levels from $levels
            foreach ($levels_order as $level_id) {
                foreach ($pmpro_all_levels as $level) {
                    if ($level->id == $level_id) {
                        $pmpro_levels_filtered[$level->id] = $level;
                        break;
                    }
                }
            }
        } else {
            $pmpro_levels_filtered = $pmpro_visible_levels;
        }
        $pmpro_levels_filtered = apply_filters("pmpro_levels_array", $pmpro_levels_filtered);
        $numeric_levels_array = array_values($pmpro_levels_filtered);
        //update per discount code
        if (!empty($discount_code) && !empty($pmpro_levels_filtered)) {
            foreach ($pmpro_levels_filtered as $level_id => $level) {
                //check code for this level and update if applicable
                if (pmpro_checkDiscountCode($discount_code, $level->id)) {
                    $sqlQuery = "SELECT l.id, cl.*, l.name, l.description, l.allow_signups FROM {$wpdb->pmpro_discount_codes_levels} cl LEFT JOIN {$wpdb->pmpro_membership_levels} l ON cl.level_id = l.id LEFT JOIN {$wpdb->pmpro_discount_codes} dc ON dc.id = cl.code_id WHERE dc.code = '" . $discount_code . "' AND cl.level_id = '" . (int) $level->id . "' LIMIT 1";
                    $pmpro_levels_filtered[$level_id] = $wpdb->get_row($sqlQuery);
                    $pmpro_levels_filtered[$level_id]->base_level = $level;
                }
            }
        }
        if ($layout == 'table') {
            ?>
			<table id="pmpro_levels" class="pmpro_levels-table">
			<thead>
			  <tr>
				<th><?php 
            _e('Level', 'pmpro');
            ?>
</th>
				<?php 
            if (!empty($show_price)) {
                ?>
					<th><?php 
                _e('Price', 'pmpro');
                ?>
</th>	
				<?php 
            }
            ?>
				<?php 
            if (!empty($expiration)) {
                ?>
					<th><?php 
                _e('Expiration', 'pmpro');
                ?>
</th>
				<?php 
            }
            ?>
				<th>&nbsp;</th>
			  </tr>
			</thead>
			<tbody>
			<?php 
            $count = 0;
            foreach ($pmpro_levels_filtered as $level) {
                if (isset($current_user->membership_level->ID)) {
                    $current_level = $current_user->membership_level->ID == $level->id;
                } else {
                    $current_level = false;
                }
                ?>
				<tr class="<?php 
                if ($current_level) {
                    echo 'pmpro_level-current ';
                }
                if ($highlight == $level->id) {
                    echo 'pmpro_level-highlight ';
                }
                ?>
">
					<td>
						<h2><?php 
                echo $level->name;
                ?>
</h2>
						<?php 
                if (!empty($description)) {
                    echo wpautop($level->description);
                }
                ?>
						<?php 
                $level_page = memberlite_getLevelLandingPage($level->id);
                if (!empty($level_page)) {
                    ?>
								<p><a href="<?php 
                    echo get_permalink($level_page->ID);
                    ?>
"><?php 
                    echo $more_button;
                    ?>
</a></p>
								<?php 
                }
                ?>
					</td>
					<?php 
                if (!empty($show_price)) {
                    ?>
					<td>
						<?php 
                    if ($price === 'full') {
                        echo memberlite_getLevelCost($level, true, false);
                    } else {
                        echo memberlite_getLevelCost($level, true, true);
                    }
                    ?>
					</td>
					<?php 
                }
                ?>
					<?php 
                if (!empty($expiration)) {
                    ?>
							<td>
							<?php 
                    $level_expiration = pmpro_getLevelExpiration($level);
                    if (empty($level_expiration)) {
                        _e('Membership Never Expires.', 'pmpro');
                    } else {
                        echo $level_expiration;
                    }
                    ?>
							</td>
							<?php 
                }
                ?>
					<td>
					<?php 
                if (empty($current_user->membership_level->ID)) {
                    ?>
						<a class="pmpro_btn pmpro_btn-select" href="<?php 
                    echo pmpro_url("checkout", "?level=" . $level->id, "https");
                    ?>
"><?php 
                    echo $checkout_button;
                    ?>
</a>
					<?php 
                } elseif (!$current_level) {
                    ?>
                	
						<a class="pmpro_btn pmpro_btn-select" href="<?php 
                    echo pmpro_url("checkout", "?level=" . $level->id, "https");
                    ?>
"><?php 
                    echo $checkout_button;
                    ?>
</a>
					<?php 
                } elseif ($current_level) {
                    ?>
      
						
						<?php 
                    //if it's a one-time-payment level, offer a link to renew
                    if (!pmpro_isLevelRecurring($current_user->membership_level) && !empty($current_user->membership_level->enddate)) {
                        ?>
								<a class="pmpro_btn pmpro_btn-select" href="<?php 
                        echo pmpro_url("checkout", "?level=" . $level->id, "https");
                        ?>
"><?php 
                        echo $renew_button;
                        ?>
</a>
							<?php 
                    } else {
                        ?>
								<a class="pmpro_btn disabled" href="<?php 
                        echo pmpro_url("account");
                        ?>
"><?php 
                        echo $account_button;
                        ?>
</a>
							<?php 
                    }
                    ?>
						
					<?php 
                }
                ?>
					</td>
				</tr>
				<?php 
            }
            ?>
			</tbody>
			</table>
			<?php 
        } elseif ($layout == 'compare_table') {
            ?>
			<table id="pmpro_levels" class="pmpro_levels-compare_table">
				<thead>
					<tr>
						<th><?php 
            _e('Level', 'pmpro');
            ?>
</th>
						<?php 
            $count = 0;
            foreach ($pmpro_levels_filtered as $level) {
                ?>
								<th class="<?php 
                if ($current_level) {
                    echo 'pmpro_level-current ';
                }
                if ($highlight == $level->id) {
                    echo 'pmpro_level-highlight ';
                }
                ?>
">
									<h2><?php 
                echo $level->name;
                ?>
</h2>
								</th>
								<?php 
            }
            ?>
					</tr>
					<?php 
            if (!empty($show_price)) {
                ?>
					<tr>
						<th><?php 
                _e('Price', 'pmpro');
                ?>
</th>
						<?php 
                foreach ($pmpro_levels_filtered as $level) {
                    ?>
								<th class="<?php 
                    if ($current_level) {
                        echo 'pmpro_level-current ';
                    }
                    if ($highlight == $level->id) {
                        echo 'pmpro_level-highlight ';
                    }
                    ?>
">
									<h1 class="primary">
									<?php 
                    if ($price === 'full') {
                        echo memberlite_getLevelCost($level, true, false);
                    } else {
                        echo memberlite_getLevelCost($level, true, true);
                    }
                    ?>
									</h1>
								</th>
								<?php 
                }
                ?>
					</tr>
					<?php 
            }
            ?>
					<?php 
            if (!empty($expiration)) {
                ?>
					<tr>
						<th><?php 
                _e('Expiration', 'pmpro');
                ?>
</th>
						<?php 
                foreach ($pmpro_levels_filtered as $level) {
                    ?>
								<th class="muted <?php 
                    if ($current_level) {
                        echo 'pmpro_level-current ';
                    }
                    if ($highlight == $level->id) {
                        echo 'pmpro_level-highlight ';
                    }
                    ?>
">
									<?php 
                    $level_expiration = pmpro_getLevelExpiration($level);
                    if (empty($level_expiration)) {
                        _e('Membership Never Expires.', 'pmpro');
                    } else {
                        echo $level_expiration;
                    }
                    ?>
								</th>
								<?php 
                }
                ?>
					</tr>
					<?php 
            }
            ?>
					<tr>
						<th>&nbsp;</th>
						<?php 
            foreach ($pmpro_levels_filtered as $level) {
                ?>
								<th class="<?php 
                if ($current_level) {
                    echo 'pmpro_level-current ';
                }
                if ($highlight == $level->id) {
                    echo 'pmpro_level-highlight ';
                }
                ?>
">
								<?php 
                if (empty($current_user->membership_level->ID)) {
                    ?>
									<a class="pmpro_btn pmpro_btn-select" href="<?php 
                    echo pmpro_url("checkout", "?level=" . $level->id, "https");
                    ?>
"><?php 
                    echo $checkout_button;
                    ?>
</a>
								<?php 
                } elseif (!$current_level) {
                    ?>
                	
									<a class="pmpro_btn pmpro_btn-select" href="<?php 
                    echo pmpro_url("checkout", "?level=" . $level->id, "https");
                    ?>
"><?php 
                    echo $checkout_button;
                    ?>
</a>
								<?php 
                } elseif ($current_level) {
                    ?>
      									
									<?php 
                    //if it's a one-time-payment level, offer a link to renew
                    if (!pmpro_isLevelRecurring($current_user->membership_level) && !empty($current_user->membership_level->enddate)) {
                        ?>
											<a class="pmpro_btn pmpro_btn-select" href="<?php 
                        echo pmpro_url("checkout", "?level=" . $level->id, "https");
                        ?>
"><?php 
                        echo $renew_button;
                        ?>
</a>
										<?php 
                    } else {
                        ?>
											<a class="pmpro_btn disabled" href="<?php 
                        echo pmpro_url("account");
                        ?>
"><?php 
                        echo $account_button;
                        ?>
</a>
										<?php 
                    }
                    ?>
									
								<?php 
                }
                ?>
								</th>
								<?php 
            }
            ?>
					</tr>
				</thead>
				<tbody>
					<?php 
            if (!empty($compareitems)) {
                //var_dump($compareitems);
                foreach ($compareitems as $compareitem) {
                    ?>
							<tr>
							<?php 
                    $count = -1;
                    $compareitem_values = explode(",", $compareitem);
                    foreach ($compareitem_values as $compareitem_value) {
                        if ($count > 0 && !empty($numeric_levels_array[$count])) {
                            $level = $numeric_levels_array[$count];
                        } else {
                            $level = NULL;
                        }
                        $count++;
                        ?>
									<td class="<?php 
                        if ($current_level) {
                            echo 'pmpro_level-current ';
                        }
                        if (!empty($level) && $highlight == $level->id) {
                            echo 'pmpro_level-highlight ';
                        }
                        ?>
">
										<?php 
                        if ($compareitem_value == '1') {
                            echo '<i class="fa fa-check fa-2x success"></i>';
                        } elseif ($compareitem_value == '0') {
                            echo '<i class="fa fa-minus muted"></i>';
                        } else {
                            echo $compareitem_value;
                        }
                        ?>
									</td>
									<?php 
                    }
                    ?>
							</tr>
							<?php 
                }
            }
            ?>
				</tbody>
				<tfoot>
					<tr>
						<td>&nbsp;</td>
						<?php 
            foreach ($pmpro_levels_filtered as $level) {
                ?>
								<td class="<?php 
                if ($current_level) {
                    echo 'pmpro_level-current ';
                }
                if (!empty($level) && $highlight == $level->id) {
                    echo 'pmpro_level-highlight ';
                }
                ?>
">
								<?php 
                if (empty($current_user->membership_level->ID)) {
                    ?>
									<a class="pmpro_btn pmpro_btn-select" href="<?php 
                    echo pmpro_url("checkout", "?level=" . $level->id, "https");
                    ?>
"><?php 
                    echo $checkout_button;
                    ?>
</a>
								<?php 
                } elseif (!$current_level) {
                    ?>
                	
									<a class="pmpro_btn pmpro_btn-select" href="<?php 
                    echo pmpro_url("checkout", "?level=" . $level->id, "https");
                    ?>
"><?php 
                    echo $checkout_button;
                    ?>
</a>
								<?php 
                } elseif ($current_level) {
                    ?>
      									
									<?php 
                    //if it's a one-time-payment level, offer a link to renew
                    if (!pmpro_isLevelRecurring($current_user->membership_level) && !empty($current_user->membership_level->enddate)) {
                        ?>
											<a class="pmpro_btn pmpro_btn-select" href="<?php 
                        echo pmpro_url("checkout", "?level=" . $level->id, "https");
                        ?>
"><?php 
                        echo $renew_button;
                        ?>
</a>
										<?php 
                    } else {
                        ?>
											<a class="pmpro_btn disabled" href="<?php 
                        echo pmpro_url("account");
                        ?>
"><?php 
                        echo $account_button;
                        ?>
</a>
										<?php 
                    }
                    ?>
									
								<?php 
                }
                ?>
								</td>
								<?php 
            }
            ?>
					</tr>
					<?php 
            if (!empty($expiration)) {
                ?>
					<tr>
						<td><?php 
                _e('Expiration', 'pmpro');
                ?>
</td>
						<?php 
                foreach ($pmpro_levels_filtered as $level) {
                    ?>
								<td class="muted <?php 
                    if ($current_level) {
                        echo 'pmpro_level-current ';
                    }
                    if ($highlight == $level->id) {
                        echo 'pmpro_level-highlight ';
                    }
                    ?>
">
									<?php 
                    $level_expiration = pmpro_getLevelExpiration($level);
                    if (empty($level_expiration)) {
                        _e('Membership Never Expires.', 'pmpro');
                    } else {
                        echo $level_expiration;
                    }
                    ?>
								</td>
								<?php 
                }
                ?>
					</tr>
					<?php 
            }
            ?>
					
					<?php 
            if (!empty($more_button)) {
                ?>
					<tr>
						<td><?php 
                _e('More Information', 'pmpro');
                ?>
</td>
						<?php 
                $count = 0;
                foreach ($pmpro_levels_filtered as $level) {
                    ?>
								<td class="<?php 
                    if ($current_level) {
                        echo 'pmpro_level-current ';
                    }
                    if (!empty($level) && $highlight == $level->id) {
                        echo 'pmpro_level-highlight ';
                    }
                    ?>
">
									<?php 
                    $level_page = memberlite_getLevelLandingPage($level->id);
                    if (!empty($level_page)) {
                        ?>
											<a href="<?php 
                        echo get_permalink($level_page->ID);
                        ?>
"><?php 
                        echo $more_button;
                        ?>
</a>
											<?php 
                    }
                    ?>
								</td>
								<?php 
                }
                ?>
					</tr>
					<?php 
            }
            ?>
					
				</tfoot>
			</table>	
			<?php 
        } else {
            ?>
			<div id="pmpro_levels" class="pmpro_levels-<?php 
            echo $layout;
            ?>
 row">
			<?php 
            $count = 0;
            foreach ($pmpro_levels_filtered as $level) {
                $count++;
                if (isset($current_user->membership_level->ID)) {
                    $current_level = $current_user->membership_level->ID == $level->id;
                } else {
                    $current_level = false;
                }
                ?>
				<div class="medium-<?php 
                if ($layout == 'div' || empty($layout)) {
                    echo '12';
                } elseif ($layout == '2col') {
                    echo '6';
                } elseif ($layout == '3col') {
                    echo '4';
                } elseif ($layout == '4col') {
                    echo '3';
                } else {
                    if (count($pmpro_levels) > 1) {
                        echo '12';
                    }
                }
                //if($count == 1 || ($layout == 'div' || empty($layout))) { echo '12'; }
                ?>
 columns">
				<div class="hentry post <?php 
                if ($current_level) {
                    echo 'pmpro_level-current ';
                }
                if ($highlight == $level->id) {
                    echo 'pmpro_level-highlight ';
                }
                ?>
">
					<h2><?php 
                echo $level->name;
                ?>
</h2>
					<?php 
                if ((!empty($description) || !empty($more_button)) && ($layout == 'div' || $layout == '2col' || empty($layout))) {
                    ?>
						<div class="entry-content">
							<?php 
                    echo wpautop($level->description);
                    ?>
							<?php 
                    $level_page = memberlite_getLevelLandingPage($level->id);
                    if (!empty($level_page)) {
                        ?>
									<p><a href="<?php 
                        echo get_permalink($level_page->ID);
                        ?>
"><?php 
                        echo $more_button;
                        ?>
</a></p>
									<?php 
                    }
                    ?>
						</div>
					<?php 
                }
                ?>
					<?php 
                if ($layout == 'div' || $layout == '2col' || empty($layout)) {
                    ?>
						<footer class="entry-footer">	
						<?php 
                    if (empty($current_user->membership_level->ID)) {
                        ?>
								<a class="pmpro_btn pmpro_btn-select <?php 
                        if ($layout == 'div' || $layout == '2col' || empty($layout)) {
                            echo 'alignright';
                        }
                        ?>
" href="<?php 
                        echo pmpro_url("checkout", "?level=" . $level->id, "https");
                        ?>
"><?php 
                        echo $checkout_button;
                        ?>
</a>
								<?php 
                    } elseif (!$current_level) {
                        ?>
                	
								<a class="pmpro_btn pmpro_btn-select <?php 
                        if ($layout == 'div' || $layout == '2col' || empty($layout)) {
                            echo 'alignright';
                        }
                        ?>
" href="<?php 
                        echo pmpro_url("checkout", "?level=" . $level->id, "https");
                        ?>
"><?php 
                        echo $checkout_button;
                        ?>
</a>
								<?php 
                    } elseif ($current_level) {
                        //if it's a one-time-payment level, offer a link to renew
                        if (!pmpro_isLevelRecurring($current_user->membership_level) && !empty($current_user->membership_level->enddate)) {
                            ?>
									<a class="pmpro_btn pmpro_btn-select <?php 
                            if ($layout == 'div' || $layout == '2col' || empty($layout)) {
                                echo 'alignright';
                            }
                            ?>
" href="<?php 
                            echo pmpro_url("checkout", "?level=" . $level->id, "https");
                            ?>
"><?php 
                            echo $renew_button;
                            ?>
</a>
									<?php 
                        } else {
                            ?>
									<a class="pmpro_btn disabled <?php 
                            if ($layout == 'div' || $layout == '2col' || empty($layout)) {
                                echo 'alignright';
                            }
                            ?>
" href="<?php 
                            echo pmpro_url("account");
                            ?>
"><?php 
                            echo $account_button;
                            ?>
</a>
									<?php 
                        }
                    }
                    ?>
						
						<?php 
                    if (!empty($show_price)) {
                        ?>
								<p class="pmpro_level-price">
								<?php 
                        if (pmpro_isLevelFree($level)) {
                            if (!empty($expiration)) {
                                ?>
											<strong><?php 
                                _e('Free.', 'pmpro');
                                ?>
</strong>
											<?php 
                            } else {
                                ?>
											<strong><?php 
                                _e('Free', 'pmpro');
                                ?>
</strong>
											<?php 
                            }
                        } elseif ($price === 'full') {
                            echo memberlite_getLevelCost($level, true, false);
                        } else {
                            echo memberlite_getLevelCost($level, true, true);
                        }
                        ?>
								</p>
								<?php 
                    }
                    ?>
		
						<?php 
                    if (!empty($expiration)) {
                        $level_expiration = pmpro_getLevelExpiration($level);
                        if (empty($level_expiration)) {
                            _e('Membership Never Expires.', 'pmpro');
                        } else {
                            echo $level_expiration;
                        }
                    }
                    ?>
						<?php 
                    if ($layout == 'div' || $layout == '2col' || empty($layout)) {
                        echo '<div class="clear"></div>';
                    }
                    ?>
						</footer> <!-- .entry-footer -->
						<?php 
                } else {
                    //This is a column-type div layout
                    ?>
							<div class="entry-content">
								<?php 
                    if (!empty($show_price)) {
                        ?>
										<p class="pmpro_level-price">
										<?php 
                        if ($price === 'full') {
                            echo memberlite_getLevelCost($level, true, false);
                        } else {
                            echo memberlite_getLevelCost($level, true, true);
                        }
                        ?>
										</p>
										<?php 
                    }
                    ?>
								
								<p class="pmpro_level-select"><?php 
                    if (empty($current_user->membership_level->ID)) {
                        ?>
										<a class="pmpro_btn pmpro_btn-select" href="<?php 
                        echo pmpro_url("checkout", "?level=" . $level->id, "https");
                        ?>
"><?php 
                        echo $checkout_button;
                        ?>
</a>
										<?php 
                    } elseif (!$current_level) {
                        ?>
                	
										<a class="pmpro_btn pmpro_btn-select" href="<?php 
                        echo pmpro_url("checkout", "?level=" . $level->id, "https");
                        ?>
"><?php 
                        echo $checkout_button;
                        ?>
</a>
										<?php 
                    } elseif ($current_level) {
                        //if it's a one-time-payment level, offer a link to renew
                        if (!pmpro_isLevelRecurring($current_user->membership_level) && !empty($current_user->membership_level->enddate)) {
                            ?>
											<a class="pmpro_btn pmpro_btn-select" href="<?php 
                            echo pmpro_url("checkout", "?level=" . $level->id, "https");
                            ?>
"><?php 
                            echo $renew_button;
                            ?>
</a>
											<?php 
                        } else {
                            ?>
											<a class="pmpro_btn disabled" href="<?php 
                            echo pmpro_url("account");
                            ?>
"><?php 
                            echo $account_button;
                            ?>
</a>
											<?php 
                        }
                    }
                    ?>
</p>

								<?php 
                    if (!empty($description)) {
                        echo wpautop($level->description);
                    }
                    ?>
								
								<?php 
                    $level_page = memberlite_getLevelLandingPage($level->id);
                    if (!empty($level_page)) {
                        ?>
										<p><a href="<?php 
                        echo get_permalink($level_page->ID);
                        ?>
"><?php 
                        echo $more_button;
                        ?>
</a></p>
										<?php 
                    }
                    ?>
						</div> <!-- .entry-content -->		
						<?php 
                    if (!empty($expiration)) {
                        echo '<footer class="entry-footer pmpro_level-expiration">';
                        $level_expiration = pmpro_getLevelExpiration($level);
                        if (empty($level_expiration)) {
                            _e('Membership Never Expires.', 'pmpro');
                        } else {
                            echo $level_expiration;
                        }
                        echo '</footer>';
                    }
                    ?>

							<?php 
                }
                ?>
				</div></div>
				<?php 
            }
            ?>
			</div> <!-- #pmpro_levels, .row -->
			<?php 
        }
        //end else if no layout specified, use 'div'
        ?>
			
		<?php 
        if (!is_page_template('templates/interstitial.php') && !empty($back_link)) {
            ?>
 
		<nav id="nav-below" class="navigation" role="navigation">
			<div class="nav-previous alignleft">
				<?php 
            if (!empty($current_user->membership_level->ID)) {
                ?>
					<a href="<?php 
                echo pmpro_url("account");
                ?>
"><?php 
                _e('&larr; Return to Your Account', 'pmpro');
                ?>
</a>
				<?php 
            } else {
                ?>
					<a href="<?php 
                echo home_url();
                ?>
"><?php 
                _e('&larr; Return to Home', 'pmpro');
                ?>
</a>
				<?php 
            }
            ?>
			</div>
		</nav>	
		<?php 
        }
        ?>
		
		<?php 
        $temp_content = ob_get_contents();
        ob_end_clean();
        return $temp_content;
    }
}
function pmpropbc_isMemberPending($user_id)
{
    global $pmpropbc_pending_member_cache;
    //check the cache first
    if (isset($pmpropbc_pending_member_cache[$user_id])) {
        return $pmpropbc_pending_member_cache[$user_id];
    }
    //no cache, assume they aren't pending
    $pmpropbc_pending_member_cache[$user_id] = false;
    //check their last order
    $order = new MemberOrder();
    $order->getLastMemberOrder($user_id, NULL);
    //NULL here means any status
    if (!empty($order)) {
        if ($order->status == "pending") {
            //for recurring levels, we should check if there is an older successful order
            $membership_level = pmpro_getMembershipLevelForUser($user_id);
            if (pmpro_isLevelRecurring($membership_level)) {
                //unless the previous order has status success and we are still within the grace period
                $paid_order = new MemberOrder();
                $paid_order->getLastMemberOrder($user_id, 'success', $order->membership_id);
                if (!empty($paid_order) && !empty($paid_order->id)) {
                    //how long ago is too long?
                    $options = pmpropbc_getOptions($membership_level->id);
                    $cutoff = strtotime("- " . $membership_level->cycle_number . " " . $membership_level->cycle_period, current_time("timestamp")) - $options['cancel_days'] * 3600 * 24;
                    //too long ago?
                    if ($paid_order->timestamp < $cutoff) {
                        $pmpropbc_pending_member_cache[$user_id] = true;
                    } else {
                        $pmpropbc_pending_member_cache[$user_id] = false;
                    }
                } else {
                    //no previous order, this must be the first
                    $pmpropbc_pending_member_cache[$user_id] = true;
                }
            } else {
                //one time payment, so only interested in the last payment
                $pmpropbc_pending_member_cache[$user_id] = true;
            }
        }
    }
    return $pmpropbc_pending_member_cache[$user_id];
}
function pmpro_shortcode_account($atts, $content = null, $code = "")
{
    global $wpdb, $pmpro_msg, $pmpro_msgt, $pmpro_levels, $current_user, $levels;
    // $atts    ::= array of attributes
    // $content ::= text within enclosing form of shortcode element
    // $code    ::= the shortcode found, when == callback name
    // examples: [pmpro_account] [pmpro_account sections="membership,profile"/]
    extract(shortcode_atts(array('section' => '', 'sections' => 'membership,profile,invoices,links'), $atts));
    //did they use 'section' instead of 'sections'?
    if (!empty($section)) {
        $sections = $section;
    }
    //Extract the user-defined sections for the shortcode
    $sections = array_map('trim', explode(",", $sections));
    ob_start();
    //if a member is logged in, show them some info here (1. past invoices. 2. billing information with button to update.)
    if (pmpro_hasMembershipLevel()) {
        $ssorder = new MemberOrder();
        $ssorder->getLastMemberOrder();
        $mylevels = pmpro_getMembershipLevelsForUser();
        $pmpro_levels = pmpro_getAllLevels(false, true);
        // just to be sure - include only the ones that allow signups
        $invoices = $wpdb->get_results("SELECT *, UNIX_TIMESTAMP(timestamp) as timestamp FROM {$wpdb->pmpro_membership_orders} WHERE user_id = '{$current_user->ID}' AND status NOT IN('refunded', 'review', 'token', 'error') ORDER BY timestamp DESC LIMIT 6");
        ?>
	
	<div id="pmpro_account">		
		<?php 
        if (in_array('membership', $sections) || in_array('memberships', $sections)) {
            ?>
			<div id="pmpro_account-membership" class="pmpro_box">
				
				<h3><?php 
            _e("My Memberships", "pmpro");
            ?>
</h3>
				<table width="100%" cellpadding="0" cellspacing="0" border="0">
					<thead>
						<tr>
							<th><?php 
            _e("Level", "pmpro");
            ?>
</th>
							<th><?php 
            _e("Billing", "pmpro");
            ?>
</th>
							<th><?php 
            _e("Expiration", "pmpro");
            ?>
</th>
						</tr>
					</thead>
					<tbody>
						<?php 
            foreach ($mylevels as $level) {
                ?>
						<tr>
							<td class="pmpro_account-membership-levelname">
								<?php 
                echo $level->name;
                ?>
								<div class="pmpro_actionlinks">
									<?php 
                do_action("pmpro_member_action_links_before");
                ?>
									
									<?php 
                if (array_key_exists($level->id, $pmpro_levels) && pmpro_isLevelExpiringSoon($level)) {
                    ?>
										<a href="<?php 
                    echo pmpro_url("checkout", "?level=" . $level->id, "https");
                    ?>
"><?php 
                    _e("Renew", "pmpro");
                    ?>
</a>
									<?php 
                }
                ?>

									<?php 
                if (isset($ssorder->status) && $ssorder->status == "success" && (isset($ssorder->gateway) && in_array($ssorder->gateway, array("authorizenet", "paypal", "stripe", "braintree", "payflow", "cybersource"))) && pmpro_isLevelRecurring($level)) {
                    ?>
										<a href="<?php 
                    echo pmpro_url("billing", "", "https");
                    ?>
"><?php 
                    _e("Update Billing Info", "pmpro");
                    ?>
</a>
									<?php 
                }
                ?>
									
									<?php 
                //To do: Only show CHANGE link if this level is in a group that has upgrade/downgrade rules
                if (count($pmpro_levels) > 1 && !defined("PMPRO_DEFAULT_LEVEL")) {
                    ?>
										<a href="<?php 
                    echo pmpro_url("levels");
                    ?>
"><?php 
                    _e("Change", "pmpro");
                    ?>
</a>
									<?php 
                }
                ?>
									<a href="<?php 
                echo pmpro_url("cancel", "?levelstocancel=" . $level->id);
                ?>
"><?php 
                _e("Cancel", "pmpro");
                ?>
</a>
									<?php 
                do_action("pmpro_member_action_links_after");
                ?>
								</div> <!-- end pmpro_actionlinks -->
							</td>
							<td class="pmpro_account-membership-levelfee">
								<p><?php 
                echo pmpro_getLevelCost($level, true, true);
                ?>
</p>
							</td>
							<td class="pmpro_account-membership-expiration">
							<?php 
                if ($level->enddate) {
                    echo date_i18n(get_option('date_format'), $level->enddate);
                } else {
                    echo "---";
                }
                ?>
							</td>
						</tr>
						<?php 
            }
            ?>
					</tbody>
				</table>
				<?php 
            //Todo: If there are multiple levels defined that aren't all in the same group defined as upgrades/downgrades
            ?>
				<div class="pmpro_actionlinks">
					<a href="<?php 
            echo pmpro_url("levels");
            ?>
"><?php 
            _e("View all Membership Options", "pmpro");
            ?>
</a>
				</div>

			</div> <!-- end pmpro_account-membership -->
		<?php 
        }
        ?>
		
		<?php 
        if (in_array('profile', $sections)) {
            ?>
			<div id="pmpro_account-profile" class="pmpro_box">	
				<?php 
            wp_get_current_user();
            ?>
 
				<h3><?php 
            _e("My Account", "pmpro");
            ?>
</h3>
				<?php 
            if ($current_user->user_firstname) {
                ?>
					<p><?php 
                echo $current_user->user_firstname;
                ?>
 <?php 
                echo $current_user->user_lastname;
                ?>
</p>
				<?php 
            }
            ?>
				<ul>
					<?php 
            do_action('pmpro_account_bullets_top');
            ?>
					<li><strong><?php 
            _e("Username", "pmpro");
            ?>
:</strong> <?php 
            echo $current_user->user_login;
            ?>
</li>
					<li><strong><?php 
            _e("Email", "pmpro");
            ?>
:</strong> <?php 
            echo $current_user->user_email;
            ?>
</li>
					<?php 
            do_action('pmpro_account_bullets_bottom');
            ?>
				</ul>
				<div class="pmpro_actionlinks">
					<a href="<?php 
            echo admin_url('profile.php');
            ?>
"><?php 
            _e("Edit Profile", "pmpro");
            ?>
</a>
					<a href="<?php 
            echo admin_url('profile.php');
            ?>
"><?php 
            _e('Change Password', 'pmpro');
            ?>
</a>
				</div>
			</div> <!-- end pmpro_account-profile -->
		<?php 
        }
        ?>
	
		<?php 
        if (in_array('invoices', $sections) && !empty($invoices)) {
            ?>
		
		<div id="pmpro_account-invoices" class="pmpro_box">
			<h3><?php 
            _e("Past Invoices", "pmpro");
            ?>
</h3>
			<table width="100%" cellpadding="0" cellspacing="0" border="0">
				<thead>
					<tr>
						<th><?php 
            _e("Date", "pmpro");
            ?>
</th>
						<th><?php 
            _e("Level", "pmpro");
            ?>
</th>
						<th><?php 
            _e("Amount", "pmpro");
            ?>
</th>
					</tr>
				</thead>
				<tbody>
				<?php 
            $count = 0;
            foreach ($invoices as $invoice) {
                if ($count++ > 4) {
                    break;
                }
                //get an member order object
                $invoice_id = $invoice->id;
                $invoice = new MemberOrder();
                $invoice->getMemberOrderByID($invoice_id);
                $invoice->getMembershipLevel();
                ?>
						<tr id="pmpro_account-invoice-<?php 
                echo $invoice->code;
                ?>
">
							<td><a href="<?php 
                echo pmpro_url("invoice", "?invoice=" . $invoice->code);
                ?>
"><?php 
                echo date_i18n(get_option("date_format"), $invoice->timestamp);
                ?>
</td>
							<td><?php 
                if (!empty($invoice->membership_level)) {
                    echo $invoice->membership_level->name;
                } else {
                    echo __("N/A", "pmpro");
                }
                ?>
</td>
							<td><?php 
                echo pmpro_formatPrice($invoice->total);
                ?>
</td>
						</tr>
						<?php 
            }
            ?>
				</tbody>
			</table>						
			<?php 
            if ($count == 6) {
                ?>
				<div class="pmpro_actionlinks"><a href="<?php 
                echo pmpro_url("invoice");
                ?>
"><?php 
                _e("View All Invoices", "pmpro");
                ?>
</a></div>
			<?php 
            }
            ?>
		</div> <!-- end pmpro_account-invoices -->
		<?php 
        }
        ?>
		
		<?php 
        if (in_array('links', $sections) && (has_filter('pmpro_member_links_top') || has_filter('pmpro_member_links_bottom'))) {
            ?>
		<div id="pmpro_account-links" class="pmpro_box">
			<h3><?php 
            _e("Member Links", "pmpro");
            ?>
</h3>
			<ul>
				<?php 
            do_action("pmpro_member_links_top");
            ?>
				
				<?php 
            do_action("pmpro_member_links_bottom");
            ?>
			</ul>
		</div> <!-- end pmpro_account-links -->		
		<?php 
        }
        ?>
	</div> <!-- end pmpro_account -->		
	<?php 
    }
    $content = ob_get_contents();
    ob_end_clean();
    return $content;
}
Example #14
0
										}
									  ?>
									</select>
									<br /><small>The amount to be billed one cycle after the initial payment.</small>									
								</td>
							</tr>                                        
							
							<tr class="recurring_info" <?php if(!pmpro_isLevelRecurring($level)) {?>style="display: none;"<?php } ?>>
								<th scope="row" valign="top"><label for="billing_limit">Billing Cycle Limit:</label></th>
								<td>
									<input name="billing_limit[]" type="text" size="20" value="<?php echo $level->billing_limit?>" />
									<br /><small>The <strong>total</strong> number of billing cycles for this level, including the trial period (if applicable). Set to zero if membership is indefinite.</small>
								</td>
							</tr>            								
			
							<tr class="recurring_info" <?php if (!pmpro_isLevelRecurring($level)) echo "style='display:none;'";?>>
								<th scope="row" valign="top"><label>Custom Trial:</label></th>
								<td><input id="custom_trial_<?php echo $level->id?>" name="custom_trial[]" type="checkbox" value="<?php echo $level->id?>" <?php if ( pmpro_isLevelTrial($level) ) { echo "checked='checked'"; } ?> onclick="if(jQuery(this).attr('checked')) jQuery(this).parent().parent().siblings('.trial_info').show();	else jQuery(this).parent().parent().siblings('.trial_info').hide();" /> Check to add a custom trial period.</td>
							</tr>
			
							<tr class="trial_info recurring_info" <?php if (!pmpro_isLevelTrial($level)) echo "style='display:none;'";?>>
								<th scope="row" valign="top"><label for="trial_amount">Trial Billing Amount:</label></th>
								<td>
									<?php echo $pmpro_currency_symbol?><input name="trial_amount[]" type="text" size="20" value="<?php echo str_replace("\"", "&quot;", stripslashes($level->trial_amount))?>" />
									<small>for the first</small>
									<input name="trial_limit[]" type="text" size="10" value="<?php echo str_replace("\"", "&quot;", stripslashes($level->trial_limit))?>" />
									<small>subscription payments.</small>																			
								</td>
							</tr>
							
							<tr>
		function process(&$order)
		{
			//clean up a couple values
			$order->payment_type = "Check";
			$order->CardType = "";
			$order->cardtype = "";
			
			//check for initial payment
			if(floatval($order->InitialPayment) == 0)
			{
				//auth first, then process
				if($this->authorize($order))
				{						
					$this->void($order);										
					if(!pmpro_isLevelTrial($order->membership_level))
					{
						//subscription will start today with a 1 period trial
						$order->ProfileStartDate = date("Y-m-d") . "T0:0:0";
						$order->TrialBillingPeriod = $order->BillingPeriod;
						$order->TrialBillingFrequency = $order->BillingFrequency;													
						$order->TrialBillingCycles = 1;
						$order->TrialAmount = 0;
						
						//add a billing cycle to make up for the trial, if applicable
						if(!empty($order->TotalBillingCycles))
							$order->TotalBillingCycles++;
					}
					elseif($order->InitialPayment == 0 && $order->TrialAmount == 0)
					{
						//it has a trial, but the amount is the same as the initial payment, so we can squeeze it in there
						$order->ProfileStartDate = date("Y-m-d") . "T0:0:0";														
						$order->TrialBillingCycles++;
						
						//add a billing cycle to make up for the trial, if applicable
						if($order->TotalBillingCycles)
							$order->TotalBillingCycles++;
					}
					else
					{
						//add a period to the start date to account for the initial payment
						$order->ProfileStartDate = date("Y-m-d", strtotime("+ " . $order->BillingFrequency . " " . $order->BillingPeriod)) . "T0:0:0";				
					}
					
					$order->ProfileStartDate = apply_filters("pmpro_profile_start_date", $order->ProfileStartDate, $order);
					return $this->subscribe($order);
				}
				else
				{
					if(empty($order->error))
						$order->error = "Unknown error: Authorization failed.";
					return false;
				}
			}
			else
			{
				//charge first payment
				if($this->charge($order))
				{							
					//setup recurring billing					
					if(pmpro_isLevelRecurring($order->membership_level))
					{						
						if(!pmpro_isLevelTrial($order->membership_level))
						{
							//subscription will start today with a 1 period trial
							$order->ProfileStartDate = date("Y-m-d") . "T0:0:0";
							$order->TrialBillingPeriod = $order->BillingPeriod;
							$order->TrialBillingFrequency = $order->BillingFrequency;													
							$order->TrialBillingCycles = 1;
							$order->TrialAmount = 0;
							
							//add a billing cycle to make up for the trial, if applicable
							if(!empty($order->TotalBillingCycles))
								$order->TotalBillingCycles++;
						}
						elseif($order->InitialPayment == 0 && $order->TrialAmount == 0)
						{
							//it has a trial, but the amount is the same as the initial payment, so we can squeeze it in there
							$order->ProfileStartDate = date("Y-m-d") . "T0:0:0";														
							$order->TrialBillingCycles++;
							
							//add a billing cycle to make up for the trial, if applicable
							if(!empty($order->TotalBillingCycles))
								$order->TotalBillingCycles++;
						}
						else
						{
							//add a period to the start date to account for the initial payment
							$order->ProfileStartDate = date("Y-m-d", strtotime("+ " . $this->BillingFrequency . " " . $this->BillingPeriod)) . "T0:0:0";				
						}
						
						$order->ProfileStartDate = apply_filters("pmpro_profile_start_date", $order->ProfileStartDate, $order);
						if($this->subscribe($order))
						{
							return true;
						}
						else
						{
							if($this->void($order))
							{
								if(!$order->error)
									$order->error = "Unknown error: Payment failed.";							
							}
							else
							{
								if(!$order->error)
									$order->error = "Unknown error: Payment failed.";
								
								$order->error .= " A partial payment was made that we could not void. Please contact the site owner immediately to correct this.";
							}
							
							return false;								
						}
					}
					else
					{
						//only a one time charge
						$order->status = apply_filters("pmpro_check_status_after_checkout", "success");	//saved on checkout page											
						return true;
					}
				}
				else
				{
					if(empty($order->error))
						$order->error = "Unknown error: Payment failed.";
					
					return false;
				}	
			}	
		}
 function sendToTwocheckout(&$order)
 {
     global $pmpro_currency;
     $tco_args = array('sid' => pmpro_getOption("twocheckout_accountnumber"), 'mode' => '2CO', 'li_0_type' => 'product', 'li_0_name' => substr($order->membership_level->name . " at " . get_bloginfo("name"), 0, 127), 'li_0_quantity' => 1, 'li_0_tangible' => 'N', 'li_0_product_id' => $order->code, 'merchant_order_id' => $order->code, 'currency_code' => $pmpro_currency, 'pay_method' => 'CC', 'purchase_step' => 'billing-information', 'x_receipt_link_url' => admin_url("admin-ajax.php") . "?action=twocheckout-ins");
     //taxes on initial amount
     $initial_payment = $order->InitialPayment;
     $initial_payment_tax = $order->getTaxForPrice($initial_payment);
     $initial_payment = round((double) $initial_payment + (double) $initial_payment_tax, 2);
     //taxes on the amount (NOT CURRENTLY USED)
     $amount = $order->PaymentAmount;
     $amount_tax = $order->getTaxForPrice($amount);
     $amount = round((double) $amount + (double) $amount_tax, 2);
     // Recurring membership
     if (pmpro_isLevelRecurring($order->membership_level)) {
         $tco_args['li_0_startup_fee'] = number_format($initial_payment - $amount, 2, ".", "");
         //negative amount for lower initial payments
         $recurring_payment = number_format($order->membership_level->billing_amount, 2, ".", "");
         $recurring_payment_tax = number_format($order->getTaxForPrice($recurring_payment), 2, ".", "");
         $recurring_payment = number_format(round((double) $recurring_payment + (double) $recurring_payment_tax, 2), 2, ".", "");
         $tco_args['li_0_price'] = number_format($recurring_payment, 2, ".", "");
         $tco_args['li_0_recurrence'] = $order->BillingFrequency == 1 ? $order->BillingFrequency . ' ' . $order->BillingPeriod : $order->BillingFrequency . ' ' . $order->BillingPeriod . 's';
         if (property_exists($order, 'TotalBillingCycles')) {
             $tco_args['li_0_duration'] = $order->BillingFrequency * $order->TotalBillingCycles . ' ' . $order->BillingPeriod;
         } else {
             $tco_args['li_0_duration'] = 'Forever';
         }
     } else {
         $tco_args['li_0_price'] = number_format($initial_payment, 2, ".", "");
     }
     // Demo mode?
     if (empty($order->gateway_environment)) {
         $gateway_environment = pmpro_getOption("gateway_environment");
     } else {
         $gateway_environment = $order->gateway_environment;
     }
     if ("sandbox" === $gateway_environment || "beta-sandbox" === $gateway_environment) {
         Twocheckout::sandbox(true);
         $tco_args['demo'] = 'Y';
     } else {
         Twocheckout::sandbox(false);
     }
     // Trial?
     //li_#_startup_fee	Any start up fees for the product or service. Can be negative to provide discounted first installment pricing, but cannot equal or surpass the product price.
     if (!empty($order->TrialBillingPeriod)) {
         $trial_amount = $order->TrialAmount;
         $trial_tax = $order->getTaxForPrice($trial_amount);
         $trial_amount = pmpro_formatPrice(round((double) $trial_amount + (double) $trial_tax, 2), false, false);
         $tco_args['li_0_startup_fee'] = $trial_amount;
         // Negative trial amount
     }
     $ptpStr = '';
     foreach ($tco_args as $key => $value) {
         reset($tco_args);
         // Used to verify whether or not we're on the first argument
         $ptpStr .= $key == key($tco_args) ? '?' . $key . '=' . urlencode($value) : '&' . $key . '=' . urlencode($value);
     }
     //anything modders might add
     $additional_parameters = apply_filters('pmpro_twocheckout_return_url_parameters', array());
     if (!empty($additional_parameters)) {
         foreach ($additional_parameters as $key => $value) {
             $ptpStr .= "&" . urlencode($key) . "=" . urlencode($value);
         }
     }
     $ptpStr = apply_filters('pmpro_twocheckout_ptpstr', $ptpStr, $order);
     ///useful for debugging
     ///echo str_replace("&", "&<br />", $ptpStr);
     ///exit;
     //figure out gateway environment and URL to use
     if ($gateway_environment == "live") {
         $host = "www.2checkout.com";
     } else {
         $host = "sandbox.2checkout.com";
     }
     $tco_url = 'https://' . $host . '/checkout/purchase' . $ptpStr;
     //redirect to 2checkout
     wp_redirect($tco_url);
     exit;
 }
 function sendToPayPal(&$order)
 {
     global $pmpro_currency;
     //taxes on initial amount
     $initial_payment = $order->InitialPayment;
     $initial_payment_tax = $order->getTaxForPrice($initial_payment);
     $initial_payment = round((double) $initial_payment + (double) $initial_payment_tax, 2);
     //taxes on the amount
     $amount = $order->PaymentAmount;
     $amount_tax = $order->getTaxForPrice($amount);
     $amount = round((double) $amount + (double) $amount_tax, 2);
     //build PayPal Redirect
     $environment = pmpro_getOption("gateway_environment");
     if ("sandbox" === $environment || "beta-sandbox" === $environment) {
         $paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr?business=" . urlencode(pmpro_getOption("gateway_email"));
     } else {
         $paypal_url = "https://www.paypal.com/cgi-bin/webscr?business=" . urlencode(pmpro_getOption("gateway_email"));
     }
     if (pmpro_isLevelRecurring($order->membership_level)) {
         //convert billing period
         if ($order->BillingPeriod == "Day") {
             $period = "D";
         } elseif ($order->BillingPeriod == "Week") {
             $period = "W";
         } elseif ($order->BillingPeriod == "Month") {
             $period = "M";
         } elseif ($order->BillingPeriod == "Year") {
             $period = "Y";
         } else {
             $order->error = "Invalid billing period: " . $order->BillingPeriod;
             $order->shorterror = "Invalid billing period: " . $order->BillingPeriod;
             return false;
         }
         //other args
         $paypal_args = array('cmd' => '_xclick-subscriptions', 'a1' => number_format($initial_payment, 2), 'p1' => $order->BillingFrequency, 't1' => $period, 'a3' => number_format($amount, 2), 'p3' => $order->BillingFrequency, 't3' => $period, 'item_name' => substr($order->membership_level->name . " at " . get_bloginfo("name"), 0, 127), 'email' => $order->Email, 'no_shipping' => '1', 'shipping' => '0', 'no_note' => '1', 'currency_code' => $pmpro_currency, 'item_number' => $order->code, 'charset' => get_bloginfo('charset'), 'rm' => '2', 'return' => pmpro_url("confirmation", "?level=" . $order->membership_level->id), 'notify_url' => admin_url("admin-ajax.php") . "?action=ipnhandler", 'src' => '1', 'sra' => '1', 'bn' => PAYPAL_BN_CODE);
         //trial?
         /*
         	Note here that the TrialBillingCycles value is being ignored. PayPal Standard only offers 1 payment during each trial period.
         */
         if (!empty($order->TrialBillingPeriod)) {
             //if a1 and a2 are 0, let's just combine them. PayPal doesn't like a2 = 0.
             if ($paypal_args['a1'] == 0 && $order->TrialAmount == 0) {
                 $paypal_args['p1'] = $paypal_args['p1'] + $order->TrialBillingFrequency;
             } else {
                 $trial_amount = $order->TrialAmount;
                 $trial_tax = $order->getTaxForPrice($trial_amount);
                 $trial_amount = round((double) $trial_amount + (double) $trial_tax, 2);
                 $paypal_args['a2'] = $trial_amount;
                 $paypal_args['p2'] = $order->TrialBillingFrequency;
                 $paypal_args['t2'] = $period;
             }
         } else {
             //we can try to work in any change in ProfileStartDate
             $psd = date("Y-m-d", strtotime("+ " . $order->BillingFrequency . " " . $order->BillingPeriod, current_time("timestamp"))) . "T0:0:0";
             $adjusted_psd = apply_filters("pmpro_profile_start_date", $psd, $order);
             if ($psd != $adjusted_psd) {
                 //someone is trying to push the start date back
                 $adjusted_psd_time = strtotime($adjusted_psd, current_time("timestamp"));
                 $seconds_til_psd = $adjusted_psd_time - current_time('timestamp');
                 $days_til_psd = floor($seconds_til_psd / (60 * 60 * 24));
                 //push back trial one by days_til_psd
                 if ($days_til_psd > 90) {
                     //we need to convert to weeks, because PayPal limits t1 to 90 days
                     $weeks_til_psd = round($days_til_psd / 7);
                     $paypal_args['p1'] = $weeks_til_psd;
                     $paypal_args['t1'] = "W";
                 } elseif ($days_til_psd > 0) {
                     //use days
                     $paypal_args['p1'] = $days_til_psd;
                     $paypal_args['t1'] = "D";
                 }
             }
         }
         //billing limit?
         if (!empty($order->TotalBillingCycles)) {
             if (!empty($trial_amount)) {
                 $srt = intval($order->TotalBillingCycles) - 1;
                 //subtract one for the trial period
             } else {
                 $srt = intval($order->TotalBillingCycles);
             }
             //srt must be at least 2 or the subscription is not "recurring" according to paypal
             if ($srt > 1) {
                 $paypal_args['srt'] = $srt;
             } else {
                 $paypal_args['src'] = '0';
             }
         } else {
             $paypal_args['srt'] = '0';
         }
         //indefinite subscription
     } else {
         //other args
         $paypal_args = array('cmd' => '_xclick', 'amount' => number_format($initial_payment, 2), 'item_name' => substr($order->membership_level->name . " at " . get_bloginfo("name"), 0, 127), 'email' => $order->Email, 'no_shipping' => '1', 'shipping' => '0', 'no_note' => '1', 'currency_code' => $pmpro_currency, 'item_number' => $order->code, 'charset' => get_bloginfo('charset'), 'rm' => '2', 'return' => pmpro_url("confirmation", "?level=" . $order->membership_level->id), 'notify_url' => admin_url("admin-ajax.php") . "?action=ipnhandler", 'bn' => PAYPAL_BN_CODE);
     }
     $nvpStr = "";
     foreach ($paypal_args as $key => $value) {
         $nvpStr .= "&" . $key . "=" . urlencode($value);
     }
     //anything modders might add
     $additional_parameters = apply_filters("pmpro_paypal_express_return_url_parameters", array());
     if (!empty($additional_parameters)) {
         foreach ($additional_parameters as $key => $value) {
             $nvpStr .= urlencode("&" . $key . "=" . $value);
         }
     }
     $account_optional = apply_filters('pmpro_paypal_account_optional', true);
     if ($account_optional) {
         $nvpStr .= '&SOLUTIONTYPE=Sole&LANDINGPAGE=Billing';
     }
     $nvpStr = apply_filters("pmpro_paypal_standard_nvpstr", $nvpStr, $order);
     //redirect to paypal
     $paypal_url .= $nvpStr;
     //wp_die(str_replace("&", "<br />", $paypal_url));
     wp_redirect($paypal_url);
     exit;
 }
Example #18
0
	  else
	  	  $current_level = false;
	?>
	<tr class="<?php if($count++ % 2 == 0) { ?>odd<?php } ?><?php if($current_level == $level) { ?> active<?php } ?>">
		<td><?php echo $current_level ? "<strong>{$level->name}</strong>" : $level->name?></td>
		<td>
			<?php if(pmpro_isLevelFree($level)) { ?>
				<strong>Free</strong>
			<?php } else { ?>
				<?php echo $pmpro_currency_symbol?><?php echo $level->initial_payment?>
			<?php } ?>
		</td>
		<td>
		<?php if(pmpro_isLevelFree($level)) { ?>
			<strong>Free</strong>
		<?php } elseif(pmpro_isLevelRecurring($level)) { ?>
			<strong><?php echo $pmpro_currency_symbol?><?php echo $level->billing_amount?></strong>
			<?php if($level->cycle_number == '1') { ?>
				per <?php echo sornot($level->cycle_period,$level->cycle_number)?>
			<?php } else { ?>
				every <?php echo $level->cycle_number.' '.sornot($level->cycle_period,$level->cycle_number)?>
			<?php } ?>
		<?php } else { ?>
			N/A
		<?php } ?>
		</td>		
		<td>
		<?php
		  if (pmpro_isLevelTrial($level)) 
		  {			
			?>