function pmpro_upgrade_1_8_9_3_ajax()
{
    global $wpdb;
    $debug = false;
    $run = true;
    //some vars
    $all_levels = pmpro_getAllLevels(true, true);
    //keeping track of which user we're working on
    $last_user_id = get_option('pmpro_upgrade_1_8_9_3_last_user_id', 0);
    //get all active users during the period where things may have been broken
    $user_ids = $wpdb->get_col("SELECT user_id FROM {$wpdb->pmpro_memberships_users} WHERE status = 'active' AND modified > '2016-05-19' AND user_id > {$last_user_id} ORDER BY user_id LIMIT 10");
    //track progress
    $first_load = get_transient('pmpro_updates_first_load');
    if ($first_load) {
        $total_users = $wpdb->get_var("SELECT COUNT(user_id) FROM {$wpdb->pmpro_memberships_users} WHERE status = 'active' AND modified > '2016-05-19' ORDER BY user_id");
        update_option('pmpro_upgrade_1_8_9_3_total', $total_users, 'no');
        $progress = 0;
    } else {
        $total_users = get_option('pmpro_upgrade_1_8_9_3_total', 0);
        $progress = get_option('pmpro_upgrade_1_8_9_3_progress', 0);
    }
    update_option('pmpro_upgrade_1_8_9_3_progress', $progress + count($user_ids), 'no');
    global $pmpro_updates_progress;
    if ($total_users > 0) {
        $pmpro_updates_progress = "[" . $progress . "/" . $total_users . "]";
    } else {
        $pmpro_updates_progress = "";
    }
    if (empty($user_ids)) {
        //done with this update
        pmpro_removeUpdate('pmpro_upgrade_1_8_9_3_ajax');
        delete_option('pmpro_upgrade_1_8_9_3_last_user_id');
        delete_option('pmpro_upgrade_1_8_9_3_total');
        delete_option('pmpro_upgrade_1_8_9_3_progress');
    } else {
        foreach ($user_ids as $user_id) {
            $last_user_id = $user_id;
            //keeping track of the last user we processed
            $user = get_userdata($user_id);
            //user not found for some reason
            if (empty($user)) {
                if ($debug) {
                    echo "User #" . $user_id . " not found.\n";
                }
                continue;
            }
            //get level
            $user->membership_level = pmpro_getMembershipLevelForUser($user->ID);
            //has a start and end date already
            if (!empty($user->membership_level->enddate) && !empty($user->membership_level->startdate)) {
                if ($debug) {
                    echo "User #" . $user_id . ", " . $user->user_email . " already has a start and end date.\n";
                }
                continue;
            }
            //get order
            $last_order = new MemberOrder();
            $last_order->getLastMemberOrder();
            /*
            	Figure out if this user should have been given an end date.
            	The level my have an end date.
            	They might have used a discount code.
            	They might be using the set-expiration-dates code.
            	They might have custom code setting the end date.
            
            	Let's setup some vars as if we are at checkout.
            	Then pass recreate the level with the pmpro_checkout_level filter.
            	And use the end date there if there is one.
            */
            global $pmpro_level, $discount_code, $discount_code_id;
            //level
            $level_id = $user->membership_level->id;
            $_REQUEST['level'] = $level_id;
            //gateway
            if (!empty($last_order) && !empty($last_order->gateway)) {
                $_REQUEST['gateway'] = $last_order->gateway;
            } else {
                $_REQUEST['gateway'] = pmpro_getGateway();
            }
            //discount code
            $discount_code_id = $user->membership_level->code_id;
            $discount_code = $wpdb->get_var("SELECT code FROM {$wpdb->pmpro_discount_codes} WHERE id = '" . $discount_code_id . "' LIMIT 1");
            //get level
            if (!empty($discount_code_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_level = $wpdb->get_row($sqlQuery);
                //if the discount code doesn't adjust the level, let's just get the straight level
                if (empty($pmpro_level)) {
                    $pmpro_level = $all_levels[$level_id];
                }
                //filter adjustments to the level
                $pmpro_level->code_id = $discount_code_id;
                $pmpro_level = apply_filters("pmpro_discount_code_level", $pmpro_level, $discount_code_id);
            }
            //no level yet, use default
            if (empty($pmpro_level)) {
                $pmpro_level = $all_levels[$level_id];
            }
            //no level for some reason
            if (empty($pmpro_level) && empty($pmpro_level->id)) {
                if ($debug) {
                    echo "No level found with ID #" . $level_id . " for user #" . $user_id . ", " . $user->user_email . ".\n";
                }
                continue;
            }
            //filter level
            $pmpro_level = apply_filters("pmpro_checkout_level", $pmpro_level);
            if ($debug) {
                echo "User #" . $user_id . ", " . $user->user_email . ". Fixing.\n";
            }
            //calculate and fix start date
            if (empty($user->membership_level->startdate)) {
                $startdate = $wpdb->get_var("SELECT modified FROM {$wpdb->pmpro_memberships_users} WHERE user_id = {$user_id} AND membership_id = {$level_id} AND status = 'active' LIMIT 1");
                //filter
                $filtered_startdate = apply_filters("pmpro_checkout_start_date", $startdate, $user_id, $pmpro_level);
                //only use filtered value if it's not 0
                if (!empty($filtered_startdate) && $filtered_startdate != '0000-00-00 00:00:00' && $filtered_startdate != "'0000-00-00 00:00:00'") {
                    $startdate = $filtered_startdate;
                }
                if ($debug) {
                    echo "- Adding startdate " . $startdate . ".\n";
                }
                if ($run) {
                    $sqlQuery = "UPDATE {$wpdb->pmpro_memberships_users} SET startdate = '" . esc_sql($startdate) . "' WHERE user_id = {$user_id} AND membership_id = {$level_id} AND status = 'active' LIMIT 1";
                    $wpdb->query($sqlQuery);
                }
            } else {
                $startdate = date_i18n("Y-m-d", $user->membership_level->startdate);
            }
            //calculate and fix the end date
            if (empty($user->membership_level->enddate)) {
                if (!empty($pmpro_level->expiration_number)) {
                    $enddate = date_i18n("Y-m-d", strtotime("+ " . $pmpro_level->expiration_number . " " . $pmpro_level->expiration_period, $last_order->timestamp));
                } else {
                    $enddate = "NULL";
                }
                $enddate = apply_filters("pmpro_checkout_end_date", $enddate, $user_id, $pmpro_level, $startdate);
                if (!empty($enddate) && $enddate != "NULL") {
                    if ($debug) {
                        echo "- Adding enddate " . $enddate . ".\n";
                    }
                    if ($run) {
                        $sqlQuery = "UPDATE {$wpdb->pmpro_memberships_users} SET enddate = '" . esc_sql($enddate) . "' WHERE user_id = {$user_id} AND membership_id = {$level_id} AND status = 'active' LIMIT 1";
                        $wpdb->query($sqlQuery);
                    }
                }
            }
            //clear vars for next pass
            $user_id = NULL;
            $level_id = NULL;
            $discount_code = NULL;
            $discount_code_id = NULL;
            $pmpro_level = NULL;
            $last_order = NULL;
            $startdate = NULL;
            $filtered_startdate = NULL;
            $enddate = NULL;
            echo "\n";
        }
        update_option('pmpro_upgrade_1_8_9_3_last_user_id', $last_user_id, 'no');
    }
}
function pmprodev_checkout_debug_email($level)
{
    global $pmprodev_options, $current_user, $wpdb;
    if (empty($pmprodev_options['checkout_debug_email'])) {
        return $level;
    }
    $email = new PMProEmail();
    if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
        $http = 'https://';
    } else {
        $http = 'http://';
    }
    $email->subject = sprintf('%s Checkout Page Debug Log', get_bloginfo('name'));
    $email->recipient = $pmprodev_options['checkout_debug_email'];
    $email->template = 'checkout_debug';
    $email->body = file_get_contents(plugin_dir_path(__FILE__) . '/email/checkout_debug.html');
    $email->data = array('sitename' => get_bloginfo('sitename'), 'checkout_url' => $http . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'submit' => print_r($_REQUEST['submit-checkout'], true), 'level' => print_r($level, true), 'user' => print_r($current_user->data, true), 'request' => print_r($_REQUEST, true));
    $order = new MemberOrder();
    $order->getLastMemberOrder($current_user->user_id);
    if (!empty($order)) {
        $email->data['order'] = print_r($order, true);
    }
    $email->sendEmail();
    return $level;
}
Esempio n. 3
0
function pmpro_cron_credit_card_expiring_warnings()
{
    global $wpdb;
    $next_month_date = date("Y-m-01", strtotime("+2 months"));
    $sqlQuery = "SELECT mu.user_id\n\t\t\t\t\t\tFROM  {$wpdb->pmpro_memberships_users} mu\n\t\t\t\t\t\t\tLEFT JOIN {$wpdb->usermeta} um1 ON mu.user_id = um1.user_id\n\t\t\t\t\t\t\t\tAND meta_key =  'pmpro_ExpirationMonth'\n\t\t\t\t\t\t\tLEFT JOIN {$wpdb->usermeta} um2 ON mu.user_id = um2.user_id\n\t\t\t\t\t\t\t\tAND um2.meta_key =  'pmpro_ExpirationYear'\n\t\t\t\t\t\t\tLEFT JOIN {$wpdb->usermeta} um3 ON mu.user_id = um3.user_id\n\t\t\t\t\t\t\t\tAND um3.meta_key = 'pmpro_credit_card_expiring_warning'\n\t\t\t\t\t\tWHERE mu.status =  'active'\n\t\t\t\t\t\t\tAND mu.cycle_number >0\n\t\t\t\t\t\t\tAND CONCAT(um2.meta_value, '-', um1.meta_value, '-01') < '" . $next_month_date . "'\n\t\t\t\t\t\t\tAND (um3.meta_value IS NULL OR CONCAT(um2.meta_value, '-', um1.meta_value, '-01') <> um3.meta_value)\n\t\t\t\t\t";
    $cc_expiring_user_ids = $wpdb->get_col($sqlQuery);
    if (!empty($cc_expiring_user_ids)) {
        require_once ABSPATH . 'wp-includes/pluggable.php';
        foreach ($cc_expiring_user_ids as $user_id) {
            //get user
            $euser = get_userdata($user_id);
            //make sure their level doesn't have a billing limit that's been reached
            $euser->membership_level = pmpro_getMembershipLevelForUser($euser->ID);
            if (!empty($euser->membership_level->billing_limit)) {
                /*
                	There is a billing limit on this level, skip for now. 
                	We should figure out how to tell if the limit has been reached
                	and if not, email the user about the expiring credit card.
                */
                continue;
            }
            //make sure they are using a credit card type billing method for their current membership level (check the last order)
            $last_order = new MemberOrder();
            $last_order->getLastMemberOrder($euser->ID);
            if (empty($last_order->accountnumber)) {
                continue;
            }
            //okay send them an email
            $send_email = apply_filters("pmpro_send_credit_card_expiring_email", true, $e->user_id);
            if ($send_email) {
                //send an email
                $pmproemail = new PMProEmail();
                $pmproemail->sendCreditCardExpiringEmail($euser);
                printf(__("Credit card expiring email sent to %s. ", "pmpro"), $euser->user_email);
            }
            //update user meta so we don't email them again
            update_user_meta($euser->ID, "pmpro_credit_card_expiring_warning", $euser->pmpro_ExpirationYear . "-" . $euser->pmpro_ExpirationMonth . "-01");
        }
    }
}
<?php

global $wpdb, $current_user, $pmpro_msg, $pmpro_msgt;
global $bfirstname, $blastname, $baddress1, $baddress2, $bcity, $bstate, $bzipcode, $bcountry, $bphone, $bemail, $bconfirmemail, $CardType, $AccountNumber, $ExpirationMonth, $ExpirationYear;
$gateway = pmpro_getOption("gateway");
//need to be secure?
global $besecure, $show_paypal_link;
$user_order = new MemberOrder();
$user_order->getLastMemberOrder();
if (empty($user_order->gateway)) {
    //no order
    $besecure = false;
} elseif ($user_order->gateway == "paypalexpress") {
    $besecure = pmpro_getOption("use_ssl");
    //still they might have website payments pro setup
    if ($gateway == "paypal") {
        //$besecure = true;
    } else {
        //$besecure = false;
        $show_paypal_link = true;
    }
} else {
    //$besecure = true;
    $besecure = pmpro_getOption("use_ssl");
}
//code for stripe
if ($gateway == "stripe") {
    //stripe js library
    wp_enqueue_script("stripe", "https://js.stripe.com/v1/", array(), "");
    //stripe js code for checkout
    function pmpro_stripe_javascript()
 /**
  * Filter pmpro_next_payment to get date via API if possible
  *
  * @since 1.8.5
  */
 static function pmpro_next_payment($timestamp, $user_id, $order_status)
 {
     //find the last order for this user
     if (!empty($user_id)) {
         //get last order
         $order = new MemberOrder();
         $order->getLastMemberOrder($user_id, $order_status);
         //check if this is a paypal express order with a subscription transaction id
         if (!empty($order->id) && !empty($order->subscription_transaction_id) && $order->gateway == "paypalexpress") {
             //get the subscription status
             $status = $order->getGatewaySubscriptionStatus();
             d($status);
             if (!empty($status) && !empty($status['NEXTBILLINGDATE'])) {
                 //found the next billing date at PayPal, going to use that
                 $timestamp = strtotime(urldecode($status['NEXTBILLINGDATE']), current_time('timestamp'));
             } elseif (!empty($status) && !empty($status['PROFILESTARTDATE']) && $order_status == "cancelled") {
                 //startdate is in the future and we cancelled so going to use that as the next payment date
                 $startdate_timestamp = strtotime(urldecode($status['PROFILESTARTDATE']), current_time('timestamp'));
                 if ($startdate_timestamp > current_time('timestamp')) {
                     $timestamp = $startdate_timestamp;
                 }
             }
         }
     }
     return $timestamp;
 }
function pmproppsc_admin_page()
{
    ?>
<div class="wrap">
<h2>PMPro Subscription Check</h2>
<?php 
    if (!empty($_REQUEST['pmpro_subscription_check']) && current_user_can("manage_options")) {
        global $wpdb;
        //get members
        if (!empty($_REQUEST['limit'])) {
            $limit = intval($_REQUEST['limit']);
        } else {
            $limit = 20;
        }
        if (!empty($_REQUEST['start'])) {
            $start = intval($_REQUEST['start']);
        } else {
            $start = 0;
        }
        //when using auto refresh get the last user id
        if (!empty($_REQUEST['autorefresh']) && empty($_REQUEST['restart'])) {
            $last_user_id = get_option("pmpro_subscription_check_last_user_id", 0);
        } else {
            $last_user_id = 0;
        }
        //get gateway
        $gateway = $_REQUEST['gateway'];
        if (!in_array($gateway, array_keys(pmpro_gateways()))) {
            wp_die('Invalid gateway selection.');
        }
        //when using auto refresh get the last user id
        if (!empty($_REQUEST['autorefresh']) && empty($_REQUEST['restart'])) {
            $last_user_id = get_option("pmpro_stripe_subscription_check_last_user_id", 0);
        } else {
            $last_user_id = 0;
        }
        $sqlQuery = "SELECT DISTINCT(user_id) FROM {$wpdb->pmpro_membership_orders} WHERE gateway = '" . esc_sql($gateway) . "' ";
        if (!empty($last_user_id)) {
            $sqlQuery .= "AND user_id > '" . $last_user_id . "' ";
        }
        $sqlQuery .= "ORDER BY user_id LIMIT {$start}, {$limit}";
        $user_ids = $wpdb->get_col($sqlQuery);
        $totalrows = $wpdb->get_var("SELECT COUNT(DISTINCT(user_id)) FROM {$wpdb->pmpro_membership_orders} WHERE gateway = '" . esc_sql($gateway) . "'");
        if (empty($_REQUEST['autorefresh'])) {
            echo "Checking users for orders " . $start . " to " . min(intval($start + $limit), $totalrows) . ". ";
            if ($totalrows > intval($start + $limit)) {
                $url = "?page=pmproppsc&pmpro_subscription_check=1&start=" . ($start + $limit) . "&limit=" . $limit . "&gateway=" . $gateway;
                echo '<a href="' . $url . '">Next ' . $limit . ' Results</a>';
            } else {
                echo "All done.";
            }
            echo "<hr />";
        }
        $allmembers = "";
        $requiresaction = "";
        foreach ($user_ids as $user_id) {
            $user = get_userdata($user_id);
            if (empty($user)) {
                $s = "User #" . $user_id . " has been deleted. ";
            } else {
                $s = "User #" . $user->ID . "(" . $user->user_email . ", " . $user->first_name . " " . $user->lat_name . ") ";
            }
            $level = pmpro_getMembershipLevelForUser($user_id);
            if (!empty($level) && empty($user)) {
                $s .= " Had level #" . $level->id . ". ";
                $level_id = $level->id;
            } elseif (!empty($level)) {
                $s .= " Has level #" . $level->id . ". ";
                $level_id = $level->id;
            } else {
                $s .= " Does not have a level. ";
                $level_id = "";
            }
            $order = new MemberOrder();
            $order->getLastMemberOrder($user_id, "");
            if (!empty($order->id)) {
                $s .= " Last order was #" . $order->id . ", status " . $order->status . ". ";
                //check status of order at gateway
                $details = $order->getGatewaySubscriptionStatus($order);
                if (empty($details)) {
                    $s .= " Couldn't get status from gateway. ";
                    echo "<span style='color: gray;'>" . $s . "</span>";
                    $allmembers .= "<span style='color: gray;'>" . $s . "</span>";
                } else {
                    if (!is_array($details)) {
                        $details = array('STATUS' => $details);
                    }
                    $s .= "Gateway Status is " . $details['STATUS'] . ". ";
                    //if gateway status is active, but local user has no level, cancel the gateway subscription
                    if (strtolower($details['STATUS']) == 'active' && $level_id != $order->membership_id) {
                        $s .= " But this user has level #" . $user_level_id . " and order is for #" . $order->membership_id . ". Will try to cancel at the gateway. ";
                        if (!empty($_REQUEST['mode'])) {
                            if ($order->cancel()) {
                                $s .= " Order cancelled.";
                                echo "<span style='color: green;'><strong>" . $s . "</strong></span>";
                            } else {
                                $s .= " Error cancelling order.";
                                echo "<span style='color: red;'><strong>" . $s . "</strong></span>";
                            }
                        } else {
                            echo "<span style='color: black;'><strong>" . $s . "</strong></span>";
                            $allmembers .= "<span style='color: black;'><strong>" . $s . "</strong></span>";
                            $requiresaction .= "<span style='color: black;'><strong>" . $s . "</strong></span><br />\n";
                        }
                    } elseif (!empty($user) && strtolower($details['STATUS']) != 'active' && $level_id == $order->membership_id) {
                        //if gateway status is not active, but local user has the level associated with this order, cancel the local membership
                        $s .= "Still has a #" . $level_id . " membership here. ";
                        if (!empty($_REQUEST['mode'])) {
                            //check if membership has an enddate
                            if (empty($level->enddate)) {
                                if (pmpro_changeMembershipLevel(0, $user->ID)) {
                                    $s .= " Membership cancelled.";
                                    echo "<span style='color: green;'><strong>" . $s . "</strong></span>";
                                } else {
                                    $s .= " Error cancelling membership.";
                                    echo "<span style='color: red;'><strong>" . $s . "</strong></span>";
                                }
                            } else {
                                $s .= " Membership is set to end on " . date(get_option('date_format'), $level->enddate) . ". Looks good!";
                                echo "<span style='color: gray;'><strong>" . $s . "</strong></span>";
                            }
                        } else {
                            echo "<span style='color: black;'><strong>" . $s . "</strong></span>";
                            $allmembers .= "<span style='color: black;'><strong>" . $s . "</strong></span>";
                            $requiresaction .= "<span style='color: black;'><strong>" . $s . "</strong></span><br />\n";
                        }
                    } elseif (empty($user)) {
                        $s .= "User was deleted so has no membership. Looks good! ";
                        echo "<span style='color: gray;'><strong>" . $s . "</strong></span>";
                        $allmembers .= "<span style='color: gray;'><strong>" . $s . "</strong></span>";
                    } else {
                        $s .= "Order is for level #" . $order->membership_id . ". User has level #" . $level_id . ". Looks good! ";
                        echo "<span style='color: gray;'><strong>" . $s . "</strong></span>";
                        $allmembers .= "<span style='color: gray;'><strong>" . $s . "</strong></span>";
                    }
                }
            } else {
                $s .= " Does not have an order. ";
                echo "<span style='color: gray;'><strong>" . $s . "</strong></span>";
                $allmembers .= "<span style='color: gray;'><strong>" . $s . "</strong></span>";
            }
            echo "<br />\n";
            $allmembers .= "<br />\n";
            $last_user_id = $user_id;
        }
        //update last user id if using auto refresh
        if (!empty($_REQUEST['autorefresh'])) {
            update_option("pmpro_subscription_check_last_user_id", $last_user_id);
            if (!empty($allmembers)) {
                //file
                $loghandle = fopen(dirname(__FILE__) . "/logs/allmembers.html", "a");
                fwrite($loghandle, $allmembers);
                fclose($loghandle);
            }
            if (!empty($requiresaction)) {
                //file
                $loghandle = fopen(dirname(__FILE__) . "/logs/requiresaction.html", "a");
                fwrite($loghandle, $requiresaction);
                fclose($loghandle);
            }
            if ($totalrows > intval($start) + intval($limit)) {
                echo "Continuing in 2 seconds...";
                ?>
				<script>
					setTimeout(function() {location.reload();}, 2000);
				</script>
				<?php 
            } else {
                echo "All done.";
            }
        }
        echo '<hr /><a href="?page=pmproppsc">&laquo; return to Subscription Check home</a>';
    } else {
        ?>
	<form method = "get">
		<p><strong>WARNING: Running this code could cancel subscriptions on the WP side or at your gateway. Use at your own risk.</strong></p>
		<p>Test mode will check the status of subscriptions, but won't cancel any memberships locally or cancel any subscription at the gateway. Live Mode will check the status of subscriptions and also cancel any membership locally if the gateway subscription was perviously cancelled and will cancel any gateway subscription for members that cancelled their membership in PMPro.</p>
		<input type="hidden" name="page" value ="pmproppsc" />
		<input type="hidden" name="pmpro_subscription_check" value="1">
		<input type="hidden" name="restart" value="1" />
		<select name="mode">
			<option value="0">Test Only</option>
			<option value="1">Live Mode</option>
		</select>
		<select name="gateway">
			<option value="paypal">PayPal (Standard, Express, WPP Legacy)</option>
			<option value="stripe">Stripe</option>
			<option value="authorizenet">Authorize.net</option>
		</select>
		<select name="autorefresh">
			<option value="0">Manual Refresh</option>
			<option value="1">Auto Refresh</option>
		</select>
		<select name="limit">
			<option value="5">5 at a time</option>
			<option value="10">10 at a time</option>
			<option value="20" selected="selected">20 at a time</option>
			<option value="30">30 at a time</option>
			<option value="40">40 at a time</option>
			<option value="50">50 at a time</option>
			<option value="100">100 at a time</option>
		</select>
		<input type="submit" value="Start Script" />
	</form>
	<?php 
    }
    ?>
</div>
<?php 
}
 $morder->saveOrder();
 $morder->getMemberOrderByID($morder->id);
 //email the user their invoice
 $pmproemail = new PMProEmail();
 $pmproemail->sendInvoiceEmail($user, $morder);
 $logstr .= "Created new order with ID #" . $morder->id . ". Event ID #" . $event->id . ".";
 /*
 	Checking if there is an update "after next payment" for this user.
 */
 $user_updates = $user->pmpro_stripe_updates;
 if (!empty($user_updates)) {
     foreach ($user_updates as $key => $update) {
         if ($update['when'] == 'payment') {
             //get current plan at Stripe to get payment date
             $last_order = new MemberOrder();
             $last_order->getLastMemberOrder($user_id);
             $last_order->setGateway('stripe');
             $last_order->Gateway->getCustomer();
             if (!empty($last_order->Gateway->customer)) {
                 //find the first subscription
                 if (!empty($last_order->Gateway->customer->subscriptions['data'][0])) {
                     $first_sub = $last_order->Gateway->customer->subscriptions['data'][0]->__toArray();
                     $end_timestamp = $first_sub['current_period_end'];
                 }
             }
             //if we didn't get an end date, let's set one one cycle out
             $end_timestamp = strtotime("+" . $update['cycle_number'] . " " . $update['cycle_period']);
             //build order object
             $update_order = new MemberOrder();
             $update_order->setGateway('stripe');
             $update_order->user_id = $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;
    }
    //turn into an array
    $sections = 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();
        $invoices = $wpdb->get_results("SELECT *, UNIX_TIMESTAMP(timestamp) as timestamp FROM {$wpdb->pmpro_membership_orders} WHERE user_id = '{$current_user->ID}' 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 
            //TODO: v2.0 will loop through levels here
            $level = $current_user->membership_level;
            ?>
						<tr>
							<td class="pmpro_account-membership-levelname">
								<?php 
            echo $current_user->membership_level->name;
            ?>
								<div class="pmpro_actionlinks">
									<?php 
            do_action("pmpro_member_action_links_before");
            ?>
									
									<?php 
            if (pmpro_isLevelExpiringSoon($current_user->membership_level)) {
                ?>
										<a href="<?php 
                echo pmpro_url("checkout", "?level=" . $current_user->membership_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")))) {
                ?>
										<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", "?level=" . $current_user->membership_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 ($current_user->membership_level->enddate) {
                echo date(get_option('date_format'), $current_user->membership_level->enddate);
            } else {
                echo "---";
            }
            ?>
							</td>
						</tr>
					</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 
            get_currentuserinfo();
            ?>
 
				<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(get_option("date_format"), $invoice->timestamp);
                ?>
</td>
							<td><?php 
                echo $invoice->membership_level->name;
                ?>
</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;
}
Esempio n. 9
0
				</a> |
				<a href="<?php 
    echo home_url(JAVO_DEF_LANG . JAVO_MEMBER_SLUG . '/' . wp_get_current_user()->user_login . '/' . JAVO_LOSTPW_SLUG);
    ?>
"><?php 
    _ex("Change Password", "As in 'change password'.", "pmpro");
    ?>
</a>
			</p>
		</div> <!-- end pmpro_account-profile -->
	
		<?php 
    //last invoice for current info
    //$ssorder = $wpdb->get_row("SELECT *, UNIX_TIMESTAMP(timestamp) as timestamp FROM $wpdb->pmpro_membership_orders WHERE user_id = '$current_user->ID' AND membership_id = '" . $current_user->membership_level->ID . "' AND status = 'success' ORDER BY timestamp DESC LIMIT 1");
    $ssorder = new MemberOrder();
    $ssorder->getLastMemberOrder();
    $invoices = $wpdb->get_results("SELECT *, UNIX_TIMESTAMP(timestamp) as timestamp FROM {$wpdb->pmpro_membership_orders} WHERE user_id = '{$current_user->ID}' ORDER BY timestamp DESC LIMIT 6");
    if (!empty($ssorder->id) && $ssorder->gateway != "check" && $ssorder->gateway != "paypalexpress" && $ssorder->gateway != "paypalstandard" && $ssorder->gateway != "twocheckout") {
        //default values from DB (should be last order or last update)
        $bfirstname = get_user_meta($current_user->ID, "pmpro_bfirstname", true);
        $blastname = get_user_meta($current_user->ID, "pmpro_blastname", true);
        $baddress1 = get_user_meta($current_user->ID, "pmpro_baddress1", true);
        $baddress2 = get_user_meta($current_user->ID, "pmpro_baddress2", true);
        $bcity = get_user_meta($current_user->ID, "pmpro_bcity", true);
        $bstate = get_user_meta($current_user->ID, "pmpro_bstate", true);
        $bzipcode = get_user_meta($current_user->ID, "pmpro_bzipcode", true);
        $bcountry = get_user_meta($current_user->ID, "pmpro_bcountry", true);
        $bphone = get_user_meta($current_user->ID, "pmpro_bphone", true);
        $bemail = get_user_meta($current_user->ID, "pmpro_bemail", true);
        $bconfirmemail = get_user_meta($current_user->ID, "pmpro_bconfirmemail", true);
        $CardType = get_user_meta($current_user->ID, "pmpro_CardType", true);
function pap_pmpro_add_order($morder)
{
    if (!empty($morder->total)) {
        //need to get the last order before this
        $last_order = new MemberOrder();
        $last_order->getLastMemberOrder($morder->user_id);
        if (!empty($last_order->affiliate_id)) {
            $parts = explode(",", $last_order->affiliate_subid);
            $affiliate_code = $last_order->affiliate_id;
            $campaign_id = $parts[0];
            $channel_id = $parts[1];
            $visitor_id = $parts[2];
            //api
            pap_pmpro_track_sale($morder->total, $morder->code, $affiliate_code, $campaign_id, $channel_id, $visitor_id);
            //update the affiliate id for this order
            global $pap_pmpro_affiliate_id, $pap_pmpro_affiliate_subid;
            $pap_pmpro_affiliate_id = $affiliate_code;
            $pap_pmpro_affiliate_subid = $campaign_id . "," . $channel_id . "," . $visitor_id;
        }
    }
}
function billing_content_func($atts)
{
    global $wpdb, $pmpro_msg, $pmpro_msgt, $pmpro_levels, $current_user, $levels;
    //-> If a member is logged in, show them some info here (1. past invoices. 2. billing information with button to update.)
    if ($current_user->membership_level->ID) {
        if ($pmpro_msg) {
            ?>
            <div class="pmpro_message <?php 
            echo $pmpro_msgt;
            ?>
"><?php 
            echo $pmpro_msg;
            ?>
</div>
            <?php 
        }
        ?>
	
        <div class="row billing-content">
            <div class="col-md-8 col-sm-8 col-sm-offset-3 col-md-offset-3">
                <!-- BEGIN CONTENT-->
                <div id="pmpro_account">		
                    <div id="pmpro_account-membership" class="pmpro_box-first">

                        <?php 
        //wpex_logo();
        ?>
                        <!--
                        <div class="clear clearfix"></div>
                        <br/>
                        -->
                        <?php 
        $level = $current_user->membership_level->name;
        ?>
                        <p><?php 
        _e("Membership status: <strong>" . $level . "</strong>", "pmpro");
        ?>
</p>
                        <?php 
        //die(var_dump($current_user));
        ?>
                        <ul>
                            <li><strong><?php 
        _e("Level", "pmpro");
        ?>
:</strong> <?php 
        echo $current_user->membership_level->name;
        ?>
</li>
                            <?php 
        if ($current_user->membership_level->billing_amount > 0) {
            ?>
                                <li><strong><?php 
            _e("Membership Fee", "pmpro");
            ?>
:</strong>
                                    <?php 
            $level = $current_user->membership_level;
            if ($current_user->membership_level->cycle_number > 1) {
                printf(__('%s every %d %s.', 'pmpro'), pmpro_formatPrice($level->billing_amount), $level->cycle_number, pmpro_translate_billing_period($level->cycle_period, $level->cycle_number));
            } elseif ($current_user->membership_level->cycle_number == 1) {
                printf(__('%s per %s.', 'pmpro'), pmpro_formatPrice($level->billing_amount), pmpro_translate_billing_period($level->cycle_period));
            } else {
                echo pmpro_formatPrice($current_user->membership_level->billing_amount);
            }
            ?>
                                </li>
                            <?php 
        }
        ?>
						

                            <?php 
        if ($current_user->membership_level->billing_limit) {
            ?>
                                <li><strong><?php 
            _e("Duration", "pmpro");
            ?>
:</strong> <?php 
            echo $current_user->membership_level->billing_limit . ' ' . sornot($current_user->membership_level->cycle_period, $current_user->membership_level->billing_limit);
            ?>
</li>
                            <?php 
        }
        ?>

                            <?php 
        if ($current_user->membership_level->enddate) {
            ?>
                                <li><strong><?php 
            _e("Next billing date", "pmpro");
            ?>
:</strong> <?php 
            echo date_i18n(get_option('date_format'), $current_user->membership_level->enddate);
            ?>
</li>
                            <?php 
        }
        ?>

                            <?php 
        if ($current_user->membership_level->trial_limit == 1) {
            printf(__("Your first payment will cost %s.", "pmpro"), pmpro_formatPrice($current_user->membership_level->trial_amount));
        } elseif (!empty($current_user->membership_level->trial_limit)) {
            printf(__("Your first %d payments will cost %s.", "pmpro"), $current_user->membership_level->trial_limit, pmpro_formatPrice($current_user->membership_level->trial_amount));
        }
        ?>
                        </ul>

                    </div> <!-- end pmpro_account-membership -->

                    <div id="pmpro_account-profile" class="pmpro_box hide">	
                        <?php 
        get_currentuserinfo();
        ?>
 
                        <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>
                            <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>
                        </ul>
                        <p>
                            <a href="<?php 
        echo admin_url('profile.php');
        ?>
"><?php 
        _e("Edit Profile", "pmpro");
        ?>
</a> |
                            <a href="<?php 
        echo admin_url('profile.php');
        ?>
"><?php 
        _ex("Change Password", "As in 'change password'.", "pmpro");
        ?>
</a>
                        </p>
                    </div> <!-- end pmpro_account-profile -->

                    <?php 
        //last invoice for current info
        //$ssorder = $wpdb->get_row("SELECT *, UNIX_TIMESTAMP(timestamp) as timestamp FROM $wpdb->pmpro_membership_orders WHERE user_id = '$current_user->ID' AND membership_id = '" . $current_user->membership_level->ID . "' AND status = 'success' ORDER BY timestamp DESC LIMIT 1");
        $ssorder = new MemberOrder();
        $ssorder->getLastMemberOrder();
        $invoices = $wpdb->get_results("SELECT *, UNIX_TIMESTAMP(timestamp) as timestamp FROM {$wpdb->pmpro_membership_orders} WHERE user_id = '{$current_user->ID}' ORDER BY timestamp DESC LIMIT 6");
        if (!empty($ssorder->id) && $ssorder->gateway != "check" && $ssorder->gateway != "paypalexpress" && $ssorder->gateway != "paypalstandard" && $ssorder->gateway != "twocheckout") {
            //default values from DB (should be last order or last update)
            $bfirstname = get_user_meta($current_user->ID, "pmpro_bfirstname", true);
            $blastname = get_user_meta($current_user->ID, "pmpro_blastname", true);
            $baddress1 = get_user_meta($current_user->ID, "pmpro_baddress1", true);
            $baddress2 = get_user_meta($current_user->ID, "pmpro_baddress2", true);
            $bcity = get_user_meta($current_user->ID, "pmpro_bcity", true);
            $bstate = get_user_meta($current_user->ID, "pmpro_bstate", true);
            $bzipcode = get_user_meta($current_user->ID, "pmpro_bzipcode", true);
            $bcountry = get_user_meta($current_user->ID, "pmpro_bcountry", true);
            $bphone = get_user_meta($current_user->ID, "pmpro_bphone", true);
            $bemail = get_user_meta($current_user->ID, "pmpro_bemail", true);
            $bconfirmemail = get_user_meta($current_user->ID, "pmpro_bconfirmemail", true);
            $CardType = get_user_meta($current_user->ID, "pmpro_CardType", true);
            $AccountNumber = hideCardNumber(get_user_meta($current_user->ID, "pmpro_AccountNumber", true), false);
            $ExpirationMonth = get_user_meta($current_user->ID, "pmpro_ExpirationMonth", true);
            $ExpirationYear = get_user_meta($current_user->ID, "pmpro_ExpirationYear", true);
            ?>
	

                        <div id="pmpro_account-billing" class="pmpro_box">
                            <h3><?php 
            _e("Billing Information", "pmpro");
            ?>
</h3>
                            <?php 
            if (!empty($baddress1)) {
                ?>
                                <p>
                                    <strong><?php 
                _e("Billing Address", "pmpro");
                ?>
</strong><br />
                                    <?php 
                echo $bfirstname . " " . $blastname;
                ?>
                                    <br />		
                                    <?php 
                echo $current_user->user_email;
                ?>
<br />
                                    <?php 
                echo $baddress1;
                ?>
<br />
                                    <?php 
                if ($baddress2) {
                    echo $baddress2 . "<br />";
                }
                ?>
                                    <?php 
                if ($bcity && $bstate) {
                    ?>
                                        <?php 
                    echo $bcity;
                    ?>
, <?php 
                    echo $bstate;
                    ?>
 <?php 
                    echo $bzipcode;
                    ?>
 <?php 
                    echo $bcountry;
                    ?>
                                    <?php 
                }
                ?>
                         
                                    <br />
                                    <?php 
                echo formatPhone($bphone);
                ?>
                                </p>
                            <?php 
            }
            ?>

                            <?php 
            if (!empty($AccountNumber)) {
                ?>
                                <p>
                                    <strong><?php 
                _e("Payment Method", "pmpro");
                ?>
</strong><br />
                                    <?php 
                echo $CardType;
                ?>
: <?php 
                echo last4($AccountNumber);
                ?>
 (<?php 
                echo $ExpirationMonth;
                ?>
/<?php 
                echo $ExpirationYear;
                ?>
)
                                </p>
                            <?php 
            }
            ?>

                            <?php 
            if (isset($ssorder->status) && $ssorder->status == "success" && (isset($ssorder->gateway) && in_array($ssorder->gateway, array("authorizenet", "paypal", "stripe", "braintree", "payflow", "cybersource")))) {
                ?>
                                <p><a href="<?php 
                echo pmpro_url("billing", "");
                ?>
"><?php 
                _e("Edit Billing Information", "pmpro");
                ?>
</a></p>
                                <?php 
            }
            ?>
                        </div> <!-- end pmpro_account-billing -->				
                        <?php 
        }
        ?>

                    <?php 
        if (!empty($invoices)) {
            ?>
                        <div id="pmpro_account-invoices" class="pmpro_box">
                            <h3><?php 
            _e("Past Invoices", "pmpro");
            ?>
</h3>
                            <ul>
                                <?php 
            $count = 0;
            foreach ($invoices as $invoice) {
                if ($count++ > 5) {
                    break;
                }
                ?>
                                    <li><a href="<?php 
                echo pmpro_url("invoice", "?invoice=" . $invoice->code);
                ?>
"><?php 
                echo date_i18n(get_option("date_format"), $invoice->timestamp);
                ?>
 (<?php 
                echo pmpro_formatPrice($invoice->total);
                ?>
)</a></li>
                                    <?php 
            }
            ?>
                            </ul>
                            <?php 
            //if ($count == 6) {
            ?>
                            <p><a href="<?php 
            echo pmpro_url("invoice");
            ?>
"><?php 
            _e("View All Invoices", "pmpro");
            ?>
</a></p>
                            <?php 
            //}
            ?>
                        </div> <!-- end pmpro_account-billing -->
                    <?php 
        }
        ?>
                    <!--
                    <p class="help-block">We have the following subscriptions available for our site. To join, simply click on the <strong>Change Subscription</strong> button to Change Membership Level.</p>
                    -->                  
                    <?php 
        //getLevels();
        ?>
	
                </div> <!-- end pmpro_account -->	

                <!-- END CONTENT-->
            </div>
        </div>
        <?php 
    } else {
        $user_id = $current_user->ID;
        //make sure we only run once a day
        $today = date("Y-m-d", current_time("timestamp"));
        //look for memberships that expired
        $sqlQuery = "SELECT mu.user_id, mu.membership_id, mu.startdate, mu.enddate FROM {$wpdb->pmpro_memberships_users} mu WHERE mu.status = 'expired' AND mu.enddate IS NOT NULL AND mu.enddate <> '' AND mu.enddate <> '0000-00-00 00:00:00' AND DATE(mu.enddate) <= '" . $today . "' AND mu.user_id = '" . $user_id . "' ORDER BY mu.enddate  LIMIT 1";
        $expired = $wpdb->get_results($sqlQuery);
        if (count($expired) > 0) {
            ?>
            <div class="row billing-content">
                <div class="col-md-8 col-sm-8 col-sm-offset-3 col-md-offset-3">
                    <!-- BEGIN CONTENT-->
                    <div id="pmpro_account">		
                        <div id="pmpro_account-membership" class="pmpro_box-first">
                            <?php 
            foreach ($expired as $e) {
                $level_id = $e->membership_id;
                $level = pmpro_getLevel($level_id);
                ?>
                                <div class="pmpro_message">Your "<?php 
                echo $level->name;
                ?>
" Membership has expired, please renew now <a href="<?php 
                echo pmpro_url("levels");
                ?>
"><?php 
                _e("here", "pmpro");
                ?>
</a>.</div>
                                <div id="pmpro_account-membership" class="pmpro_box-first">
                                    <?php 
                $level = $current_user->membership_level->name;
                ?>
                                    <p><?php 
                _e("Membership status: <strong>" . $level->name . "(Expired)</strong>", "pmpro");
                ?>
</p>
                                    <ul>
                                        <?php 
                if ($e->enddate) {
                    //die(var_dump($e->enddate));
                    ?>

                                            <li><strong><?php 
                    _e("Expiration billing date", "pmpro");
                    ?>
:  </strong> <?php 
                    echo " " . date_i18n(get_option('date_format'), strtotime($e->enddate));
                    ?>
</li>
                                        <?php 
                }
                ?>
                                    </ul>

                                </div> <!-- end pmpro_account-membership -->                               
                                <?php 
            }
            ?>
                        </div>
                    </div>
                </div>
            </div>
            <?php 
        }
    }
    ?>
    <?php 
}
 /**
  * 1.12 Custom confirmation page
  *
  */
 public static function pmpro_pages_shortcode_confirmation($content)
 {
     global $wpdb, $current_user, $pmpro_invoice, $pmpro_currency;
     if (empty($pmpro_invoice)) {
         $morder = new MemberOrder();
         $morder->getLastMemberOrder(get_current_user_id(), apply_filters("pmpro_confirmation_order_status", array("pending", "success")));
         if (!empty($morder) && $morder->gateway == "gourl") {
             $pmpro_invoice = $morder;
         }
     }
     if (!empty($pmpro_invoice) && $pmpro_invoice->gateway == "gourl" && isset($pmpro_invoice->total) && $pmpro_invoice->total > 0) {
         $levelName = $wpdb->get_var("SELECT name FROM {$wpdb->pmpro_membership_levels} WHERE id = '" . $pmpro_invoice->membership_id . "' LIMIT 1");
         $content = "<ul>\n\t\t\t\t\t\t\t<li><strong>" . __('Account', GOURLPMP) . ":</strong> " . $current_user->display_name . " (" . $current_user->user_email . ")</li>\n\t\t\t\t\t\t\t<li><strong>" . __('Order', GOURLPMP) . ":</strong> " . $pmpro_invoice->code . "</li>\n\t\t\t\t\t\t\t<li><strong>" . __('Membership Level', GOURLPMP) . ":</strong> " . $levelName . "</li>\n\t\t\t\t\t\t\t<li><strong>" . __('Amount', GOURLPMP) . ":</strong> " . $pmpro_invoice->total . " " . $pmpro_currency . "</li>\n\t\t\t\t\t\t  </ul>";
         $content .= self::pmpro_gourl_cryptocoin_payment($pmpro_invoice);
     }
     return $content;
 }
function pmpropbc_pmpro_account_bullets_bottom()
{
    //get invoice from DB
    if (!empty($_REQUEST['invoice'])) {
        $invoice_code = $_REQUEST['invoice'];
        if (!empty($invoice_code)) {
            $pmpro_invoice = new MemberOrder($invoice_code);
        }
    }
    //no specific invoice, check current user's last order
    if (empty($pmpro_invoice) || empty($pmpro_invoice->id)) {
        $pmpro_invoice = new MemberOrder();
        $pmpro_invoice->getLastMemberOrder(NULL, array('success', 'pending', 'cancelled', ''));
    }
    if (!empty($pmpro_invoice) && !empty($pmpro_invoice->id)) {
        if ($pmpro_invoice->status == "pending" && $pmpro_invoice->gateway == "check") {
            if (!empty($_REQUEST['invoice'])) {
                ?>
				<li>
					<?php 
                if (pmpropbc_isMemberPending($pmpro_invoice->user_id)) {
                    _e('<strong>Membership pending.</strong> We are still waiting for payment of this invoice.', 'pmpropbc');
                } else {
                    _e('<strong>Important Notice:</strong> We are still waiting for payment of this invoice.', 'pmpropbc');
                }
                ?>
				</li>
				<?php 
            } else {
                ?>
				<li><?php 
                if (pmpropbc_isMemberPending($pmpro_invoice->user_id)) {
                    printf(__('<strong>Membership pending.</strong> We are still waiting for payment for <a href="%s">your latest invoice</a>.', 'pmpropbc'), pmpro_url('invoice', '?invoice=' . $pmpro_invoice->code));
                } else {
                    printf(__('<strong>Important Notice:</strong> We are still waiting for payment for <a href="%s">your latest invoice</a>.', 'pmpropbc'), pmpro_url('invoice', '?invoice=' . $pmpro_invoice->code));
                }
                ?>
				</li>
				<?php 
            }
        }
    }
}
function pmpro_affiliates_pmpro_confirmation_message($message)
{
    if (!empty($_COOKIE['pmpro_affiliate'])) {
        $parts = split(",", $_COOKIE['pmpro_affiliate']);
        $affiliate_code = $parts[0];
        if (!empty($affiliate_code)) {
            global $current_user, $wpdb;
            $affiliate_enabled = $wpdb->get_var("SELECT enabled FROM {$wpdb->pmpro_affiliates} WHERE code = '" . $wpdb->escape($affiliate_code) . "' LIMIT 1");
            if ($affiliate_enabled) {
                $tracking_code = $wpdb->get_var("SELECT trackingcode FROM {$wpdb->pmpro_affiliates} WHERE code = '" . $wpdb->escape($affiliate_code) . "' LIMIT 1");
                if (!empty($tracking_code)) {
                    //filter
                    $order = new MemberOrder();
                    $order->getLastMemberOrder();
                    $tracking_code = str_replace("!!ORDER_ID!!", $order->code, $tracking_code);
                    $tracking_code = str_replace("!!LEVEL_NAME!!", $current_user->membership_level->name, $tracking_code);
                    //add to message
                    $message .= "\n" . stripslashes($tracking_code);
                }
            }
        }
    }
    return $message;
}
function pmpro_payflow_recurring_orders()
{
    //is PMPro even active?
    if (!function_exists('pmpro_hasMembershipLevel')) {
        return;
    }
    global $wpdb;
    $now = current_time('timestamp');
    //between what hours should the cron run?
    $cron_start = 1;
    //1 AM
    $cron_end = 6;
    //6 AM
    $current_hour = date('G', $now);
    if ($current_hour > $cron_end || $current_hour < $cron_start) {
        return;
    }
    //where did we leave off?
    if (isset($_REQUEST['start'])) {
        $start = intval($_REQUEST['start']);
        delete_option('pmpro_pfro_paused');
    } else {
        $start = get_option('payflow_recurring_orders_cron_count', 0);
    }
    //are we paused? value is timestamp. if set wait until then
    $paused = get_option('pmpro_pfro_paused', false);
    if (!empty($paused) && $paused > $now) {
        return;
    }
    //how many subscriptions to run at one time. based on your server speed and timeout limits/etc.
    $nper = 50;
    //next one
    $end = intval($start) + intval($nper);
    //get subs
    $sqlQuery = "\n\t\tSELECT SQL_CALC_FOUND_ROWS user_id FROM\n\t\t(\n\t\t\tSELECT mu.user_id,\n\t\t\t\tCASE mu.cycle_period\n\t\t\t\t\tWHEN 'Day' THEN date_add(mo.timestamp, INTERVAL mu.cycle_number DAY)\n\t\t\t\t\tWHEN 'Month' THEN date_add(mo.timestamp, INTERVAL mu.cycle_number MONTH)\n\t\t\t\t\tWHEN 'Week' THEN date_add(mo.timestamp, INTERVAL mu.cycle_number WEEK)\n\t\t\t\t\tWHEN 'Year' THEN date_add(mo.timestamp, INTERVAL mu.cycle_number YEAR)\n\t\t\t\tEND as next_payment_date\n\t\t\tFROM {$wpdb->pmpro_memberships_users} mu\n\t\t\t\tLEFT JOIN {$wpdb->pmpro_membership_orders} mo\n\t\t\t\t\tON mo.id = (\n\t\t\t\t\t\tSELECT id FROM {$wpdb->pmpro_membership_orders} WHERE gateway = 'payflowpro' AND status NOT IN('review', 'token', 'pending') AND user_id = mu.user_id ORDER BY id DESC LIMIT 1\n\t\t\t\t\t)\n\t\t\tWHERE mu.status = 'active'\n\t\t\t\tAND mo.subscription_transaction_id <> ''\n\t\t) members\n\t\tWHERE DATEDIFF('" . current_time('mysql') . "', next_payment_date) >= 0\n\t\tLIMIT {$start}, {$nper}\n\t";
    $sub_user_ids = $wpdb->get_col($sqlQuery);
    $count = $wpdb->get_var('SELECT FOUND_ROWS()');
    echo "Processing " . intval($start) . " to " . (intval($start) + intval($nper)) . " of " . $count . " subscriptions.<hr />";
    //if no more subs, pause until tomorrow
    if (empty($sub_user_ids)) {
        echo "All done. Pausing until tomorrow.<br />";
        $tomorrow = strtotime(date("Y-m-d 00:00:00", $now + 3600 * 24));
        update_option('pmpro_pfro_paused', $tomorrow);
        update_option('payflow_recurring_orders_cron_count', 0);
        return;
    }
    $failed_payment_emails = array();
    //loop through subs
    foreach ($sub_user_ids as $user_id) {
        $user = get_userdata($user_id);
        if (empty($user->ID)) {
            echo "Coundn't find user #" . $user_id . "...<br /><hr />";
            continue;
        }
        echo "Checking for recurring orders for user #" . $user->ID . " " . $user->user_login . " (" . $user->user_email . ")...<br />";
        $last_order = new MemberOrder();
        $last_order->getLastMemberOrder($user_id);
        if (!empty($last_order->id)) {
            echo "- Last order found. #" . $last_order->id . ", Code: " . $last_order->code . ", SubID: " . $last_order->subscription_transaction_id . ".<br />";
        } else {
            echo "- No last order. Skipping.";
            echo "<hr />";
            continue;
        }
        //is it even Payflow?
        if ($last_order->gateway != "payflowpro") {
            echo "- Order is for '" . $last_order->gateway . "' gateway.<br />";
            echo "<hr />";
            continue;
        }
        //check subscription
        if (!empty($last_order->subscription_transaction_id)) {
            echo "- Checking subscription #" . $last_order->subscription_transaction_id . ".<br />";
            $status = pmpropfro_getSubscriptionPayments($last_order);
            //find orders
            $payments = pmpropfro_processPaymentHistory($status);
            if (!empty($payments)) {
                foreach ($payments as $payment) {
                    if ($payment['P_TRANSTATE'] == 1 || $payment['P_TRANSTATE'] == 11) {
                        echo "- Failed payment #" . $payment['P_PNREF'] . ".";
                        //check if we have this one already
                        $old_order = new MemberOrder();
                        $old_order->getMemberOrderByPaymentTransactionID($payment['P_PNREF']);
                        if (empty($old_order->id)) {
                            $failed_payment_emails[] = $user->user_email;
                            //not there yet, add it
                            $morder = new MemberOrder();
                            $morder->user_id = $last_order->user_id;
                            $morder->membership_id = $last_order->membership_id;
                            $morder->payment_transaction_id = $payment['P_PNREF'];
                            $morder->subscription_transaction_id = $last_order->subscription_transaction_id;
                            $morder->InitialPayment = $payment['P_AMT'];
                            //not the initial payment, but the class is expecting that
                            $morder->PaymentAmount = $payment['P_AMT'];
                            $morder->status = "error";
                            //save
                            $morder->saveOrder();
                            $morder->getMemberOrderByID($morder->id);
                            echo " Saving order.";
                            //this will affect the main query, so need to roll back the "end" 1 space
                            $end--;
                            //unless there is another non-failed payment more recent, cancel their membership
                            if (!pmpropfro_paymentAfter($payments, strtotime($payment['P_TRANSTIME']))) {
                                //cancel membership
                                pmpro_changeMembershipLevel(0, $user_id);
                                echo " Membership cancelled. Member emailed.";
                                //notify them
                                $myemail = new PMProEmail();
                                $myemail->sendCancelEmail($user);
                            } else {
                                echo " More recent successful order. So not cancelling membership.";
                            }
                        } else {
                            echo " Already logged.";
                        }
                        echo "<br />";
                    } elseif ($payment['P_TRANSTATE'] == 8) {
                        //check if we have this one already
                        $old_order = new MemberOrder();
                        $old_order->getMemberOrderByPaymentTransactionID($payment['P_PNREF']);
                        if (empty($old_order->id)) {
                            //not there yet, add it
                            $morder = new MemberOrder();
                            $morder->user_id = $last_order->user_id;
                            $morder->membership_id = $last_order->membership_id;
                            $morder->payment_transaction_id = $payment['P_PNREF'];
                            $morder->subscription_transaction_id = $last_order->subscription_transaction_id;
                            $morder->InitialPayment = $payment['P_AMT'];
                            //not the initial payment, but the class is expecting that
                            $morder->PaymentAmount = $payment['P_AMT'];
                            $morder->status = "success";
                            //save
                            $morder->saveOrder();
                            $morder->getMemberOrderByID($morder->id);
                            //this will affect the main query, so need to roll back the "end" 1 space
                            $end--;
                            if (!empty($morder->id)) {
                                //update the timestamp
                                $timestamp = date("Y-m-d H:i:s", strtotime($payment['P_TRANSTIME']));
                                $wpdb->query("UPDATE {$wpdb->pmpro_membership_orders} SET timestamp = '" . $timestamp . "' WHERE id = '" . $morder->id . "' LIMIT 1");
                                echo "<strong>- Order added. #" . $morder->id . ".</strong><br />";
                                //email the user their invoice
                                $pmproemail = new PMProEmail();
                                $pmproemail->sendInvoiceEmail($user, $morder);
                                echo "- Invoice email sent to " . $user->user_email . ".";
                            } else {
                                echo "- Error adding order.";
                            }
                        } else {
                            echo "- Order already saved for #" . $payment['P_TRANSTATE'] . ".<br />";
                        }
                    } else {
                        echo "<strong>- Payment " . $payment['P_PNREF'] . " has status #" . $payment['P_TRANSTATE'] . " so not saving.</strong><br />";
                    }
                }
            } else {
                echo "- No payments found.<br />";
            }
        }
        echo "<hr />";
        echo "Going to start with #" . $end . " next time.";
        update_option('payflow_recurring_orders_cron_count', $end);
    }
    echo "<hr />";
    foreach ($failed_payment_emails as $email) {
        echo $email . "<br />";
    }
}
Esempio n. 16
0
function pmpro_next_payment($user_id = NULL, $order_status = "success")
{
    global $wpdb, $current_user;
    if (!$user_id) {
        $user_id = $current_user->ID;
    }
    if (!$user_id) {
        return false;
    }
    //get last order
    $order = new MemberOrder();
    $order->getLastMemberOrder($user_id, $order_status);
    //get current membership level
    $level = pmpro_getMembershipLevelForUser($user_id);
    if (!empty($order) && !empty($order->id) && !empty($level) && !empty($level->id) && !empty($level->cycle_number)) {
        //last payment date
        $lastdate = date("Y-m-d", $order->timestamp);
        //next payment date
        $nextdate = $wpdb->get_var("SELECT UNIX_TIMESTAMP('" . $lastdate . "' + INTERVAL " . $level->cycle_number . " " . $level->cycle_period . ")");
        return $nextdate;
    } else {
        //no order or level found, or level was not recurring
        return false;
    }
}
Esempio n. 17
0
function pmpro_membership_level_profile_fields_update()
{
    //get the user id
    global $wpdb, $current_user, $user_ID;
    get_currentuserinfo();
    if (!empty($_REQUEST['user_id'])) {
        $user_ID = $_REQUEST['user_id'];
    }
    $membership_level_capability = apply_filters("pmpro_edit_member_capability", "manage_options");
    if (!current_user_can($membership_level_capability)) {
        return false;
    }
    //level change
    if (isset($_REQUEST['membership_level'])) {
        //if the level is being set to 0 by the admin, it's a cancellation.
        $changed_or_cancelled = '';
        if ($_REQUEST['membership_level'] === 0 || $_REQUEST['membership_level'] === '0' || $_REQUEST['membership_level'] == '') {
            $changed_or_cancelled = 'admin_cancelled';
        } else {
            $changed_or_cancelled = 'admin_changed';
        }
        //if the cancel at gateway box is not checked, don't cancel
        if (empty($_REQUEST['cancel_subscription'])) {
            add_filter('pmpro_cancel_previous_subscriptions', 'pmpro_cancel_previous_subscriptions_false');
        }
        //do the change
        if (pmpro_changeMembershipLevel($_REQUEST['membership_level'], $user_ID, $changed_or_cancelled)) {
            //it changed. send email
            $level_changed = true;
        } elseif (!empty($_REQUEST['cancel_subscription'])) {
            //the level didn't change, but we were asked to cancel the subscription at the gateway, let's do that
            $order = new MemberOrder();
            $order->getLastMemberOrder($user_ID);
            if (!empty($order) && !empty($order->id)) {
                $r = $order->cancel();
            }
        }
        //remove filter after ward
        if (empty($_REQUEST['cancel_subscription'])) {
            remove_filter('pmpro_cancel_previous_subscriptions', 'pmpro_cancel_previous_subscriptions_false');
        }
    }
    //expiration change
    if (!empty($_REQUEST['expires'])) {
        //update the expiration date
        $expiration_date = intval($_REQUEST['expires_year']) . "-" . str_pad(intval($_REQUEST['expires_month']), 2, "0", STR_PAD_LEFT) . "-" . str_pad(intval($_REQUEST['expires_day']), 2, "0", STR_PAD_LEFT);
        $sqlQuery = "UPDATE {$wpdb->pmpro_memberships_users} SET enddate = '" . $expiration_date . "' WHERE status = 'active' AND membership_id = '" . intval($_REQUEST['membership_level']) . "' AND user_id = '" . $user_ID . "' LIMIT 1";
        if ($wpdb->query($sqlQuery)) {
            $expiration_changed = true;
        }
    } elseif (isset($_REQUEST['expires'])) {
        //already blank? have to check for null or '0000-00-00 00:00:00' or '' here.
        $sqlQuery = "SELECT user_id FROM {$wpdb->pmpro_memberships_users} WHERE (enddate IS NULL OR enddate = '' OR enddate = '0000-00-00 00:00:00') AND status = 'active' AND user_id = '" . $user_ID . "' LIMIT 1";
        $blank = $wpdb->get_var($sqlQuery);
        if (empty($blank)) {
            //null out the expiration
            $sqlQuery = "UPDATE {$wpdb->pmpro_memberships_users} SET enddate = NULL WHERE status = 'active' AND membership_id = '" . intval($_REQUEST['membership_level']) . "' AND user_id = '" . $user_ID . "' LIMIT 1";
            if ($wpdb->query($sqlQuery)) {
                $expiration_changed = true;
            }
        }
    }
    //emails if there was a change
    if (!empty($level_changed) || !empty($expiration_changed)) {
        //email to admin
        $pmproemail = new PMProEmail();
        if (!empty($expiration_changed)) {
            $pmproemail->expiration_changed = true;
        }
        $pmproemail->sendAdminChangeAdminEmail(get_userdata($user_ID));
        //send email
        if (!empty($_REQUEST['send_admin_change_email'])) {
            //email to member
            $pmproemail = new PMProEmail();
            if (!empty($expiration_changed)) {
                $pmproemail->expiration_changed = true;
            }
            $pmproemail->sendAdminChangeEmail(get_userdata($user_ID));
        }
    }
}
<?php

global $current_user, $pmpro_invoice;
if ($current_user->ID) {
    $current_user->membership_level = pmpro_getMembershipLevelForUser($current_user->ID);
}
/*
	Use the filter to add your gateway here if you want to show them a message on the confirmation page while their checkout is pending.
	For example, when PayPal Standard is used, we need to wait for PayPal to send a message through IPN that the payment was accepted.
	In the meantime, the order is in pending status and the confirmation page shows a message RE waiting.
*/
$gateways_with_pending_status = apply_filters('pmpro_gateways_with_pending_status', array('paypalstandard', 'twocheckout', 'gourl'));
//must be logged in
if (empty($current_user->ID) || empty($current_user->membership_level->ID) && !in_array(pmpro_getGateway(), $gateways_with_pending_status)) {
    wp_redirect(home_url());
}
//if membership is a paying one, get invoice from DB
if (!empty($current_user->membership_level) && !pmpro_isLevelFree($current_user->membership_level)) {
    $pmpro_invoice = new MemberOrder();
    $pmpro_invoice->getLastMemberOrder($current_user->ID, apply_filters("pmpro_confirmation_order_status", array("success", "pending")));
}
 /**
  * Filter pmpro_next_payment to get date via API if possible
  *
  * @since 1.8.6
  */
 static function pmpro_next_payment($timestamp, $user_id, $order_status)
 {
     //find the last order for this user
     if (!empty($user_id)) {
         //get last order
         $order = new MemberOrder();
         $order->getLastMemberOrder($user_id, $order_status);
         //check if this is a paypal express order with a subscription transaction id
         if (!empty($order->id) && !empty($order->subscription_transaction_id) && $order->gateway == "stripe") {
             //get the subscription and return the current_period end or false
             $subscription = $order->Gateway->getSubscription($order);
             if (!empty($subscription->current_period_end)) {
                 return $subscription->current_period_end;
             } else {
                 return false;
             }
         }
     }
     return $timestamp;
 }
 /**
  * Cron job for subscription updates.
  *
  * @since 1.8
  */
 static function pmpro_cron_stripe_subscription_updates()
 {
     global $wpdb;
     //get all updates for today (or before today)
     $sqlQuery = "SELECT *\n\t\t\t\t\t\t FROM {$wpdb->usermeta}\n\t\t\t\t\t\t WHERE meta_key = 'pmpro_stripe_next_on_date_update'\n\t\t\t\t\t\t\tAND meta_value IS NOT NULL\n\t\t\t\t\t\t\tAND meta_value <> ''\n\t\t\t\t\t\t\tAND meta_value < '" . date("Y-m-d", strtotime("+1 day")) . "'";
     $updates = $wpdb->get_results($sqlQuery);
     if (!empty($updates)) {
         //loop through
         foreach ($updates as $update) {
             //pull values from update
             $user_id = $update->user_id;
             $user = get_userdata($user_id);
             //if user is missing, delete the update info and continue
             if (empty($user) || empty($user->ID)) {
                 delete_user_meta($user_id, "pmpro_stripe_updates");
                 delete_user_meta($user_id, "pmpro_stripe_next_on_date_update");
                 continue;
             }
             $user_updates = $user->pmpro_stripe_updates;
             $next_on_date_update = "";
             //loop through updates looking for updates happening today or earlier
             if (!empty($user_updates)) {
                 foreach ($user_updates as $key => $update) {
                     if ($update['when'] == 'date' && $update['date_year'] . "-" . $update['date_month'] . "-" . $update['date_day'] <= date("Y-m-d")) {
                         //get level for user
                         $user_level = pmpro_getMembershipLevelForUser($user_id);
                         //get current plan at Stripe to get payment date
                         $last_order = new MemberOrder();
                         $last_order->getLastMemberOrder($user_id);
                         $last_order->setGateway('stripe');
                         $last_order->Gateway->getCustomer($last_order);
                         if (!empty($last_order->Gateway->customer)) {
                             //find the first subscription
                             if (!empty($last_order->Gateway->customer->subscriptions['data'][0])) {
                                 $first_sub = $last_order->Gateway->customer->subscriptions['data'][0]->__toArray();
                                 $end_timestamp = $first_sub['current_period_end'];
                             }
                         }
                         //if we didn't get an end date, let's set one one cycle out
                         $end_timestamp = strtotime("+" . $update['cycle_number'] . " " . $update['cycle_period']);
                         //build order object
                         $update_order = new MemberOrder();
                         $update_order->setGateway('stripe');
                         $update_order->user_id = $user_id;
                         $update_order->membership_id = $user_level->id;
                         $update_order->membership_name = $user_level->name;
                         $update_order->InitialPayment = 0;
                         $update_order->PaymentAmount = $update['billing_amount'];
                         $update_order->ProfileStartDate = date("Y-m-d", $end_timestamp);
                         $update_order->BillingPeriod = $update['cycle_period'];
                         $update_order->BillingFrequency = $update['cycle_number'];
                         //update subscription
                         $update_order->Gateway->subscribe($update_order, false);
                         //update membership
                         $sqlQuery = "UPDATE {$wpdb->pmpro_memberships_users}\n\t\t\t\t\t\t\t\t\t\t\t\tSET billing_amount = '" . esc_sql($update['billing_amount']) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\tcycle_number = '" . esc_sql($update['cycle_number']) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\tcycle_period = '" . esc_sql($update['cycle_period']) . "'\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE user_id = '" . esc_sql($user_id) . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND membership_id = '" . esc_sql($last_order->membership_id) . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND status = 'active'\n\t\t\t\t\t\t\t\t\t\t\t\tLIMIT 1";
                         $wpdb->query($sqlQuery);
                         //save order
                         $update_order->status = "success";
                         $update_order->save();
                         //remove update from list
                         unset($user_updates[$key]);
                     } elseif ($update['when'] == 'date') {
                         //this is an on date update for the future, update the next on date update
                         if (!empty($next_on_date_update)) {
                             $next_on_date_update = min($next_on_date_update, $update['date_year'] . "-" . $update['date_month'] . "-" . $update['date_day']);
                         } else {
                             $next_on_date_update = $update['date_year'] . "-" . $update['date_month'] . "-" . $update['date_day'];
                         }
                     }
                 }
             }
             //save updates in case we removed some
             update_user_meta($user_id, "pmpro_stripe_updates", $user_updates);
             //save date of next on-date update to make it easier to query for these in cron job
             update_user_meta($user_id, "pmpro_stripe_next_on_date_update", $next_on_date_update);
         }
     }
 }
Esempio n. 21
0
function pmpro_next_payment($user_id = NULL, $order_status = "success", $format = "timestamp")
{
    global $wpdb, $current_user;
    if (!$user_id) {
        $user_id = $current_user->ID;
    }
    if (!$user_id) {
        $r = false;
    } else {
        //get last order
        $order = new MemberOrder();
        $order->getLastMemberOrder($user_id, $order_status);
        //get current membership level
        $level = pmpro_getMembershipLevelForUser($user_id);
        if (!empty($order) && !empty($order->id) && !empty($level) && !empty($level->id) && !empty($level->cycle_number)) {
            //last payment date
            $lastdate = date("Y-m-d", $order->timestamp);
            //next payment date
            $nextdate = $wpdb->get_var("SELECT UNIX_TIMESTAMP('" . $lastdate . "' + INTERVAL " . $level->cycle_number . " " . $level->cycle_period . ")");
            $r = $nextdate;
        } else {
            //no order or level found, or level was not recurring
            $r = false;
        }
    }
    /**
     * Filter the next payment date.
     *
     * @since 1.8.5
     *
     * @param mixed $r false or the next payment date timestamp
     * @param int $user_id The user id to get the next payment date for
     * @param string $order_status Status or array of statuses to find the last order based on.
     */
    $r = apply_filters('pmpro_next_payment', $r, $user_id, $order_status);
    //return in desired format
    if ($r === false) {
        return false;
    } elseif ($format == "timestamp") {
        return $r;
    } elseif ($format == "date_format") {
        return date(get_option('date_format'), $r);
    } else {
        return date($format, $r);
    }
    //assume a PHP date format
}
function pmproues_wp_ajax()
{
    //make sure the user is an admin
    if (!current_user_can('manage_options')) {
        exit;
    }
    //get values
    $gateway = $_REQUEST['gateway'];
    $level = $_REQUEST['level'];
    $billing_amount = $_REQUEST['billing_amount'];
    $cycle_number = $_REQUEST['cycle_number'];
    $cycle_period = $_REQUEST['cycle_period'];
    $live = $_REQUEST['live'];
    if (empty($_REQUEST['limit'])) {
        $limit = 5;
    } else {
        $limit = intval($_REQUEST['limit']);
    }
    //continue progress?
    $hash = substr(md5($gateway . $level . $billing_amount . $cycle_number . $cycle_period . $live), 0, 16);
    $last_user = get_transient('pmproues_update_last_row_' . $hash);
    if (empty($last_user)) {
        $last_user = 0;
    }
    //find members
    global $wpdb;
    $sqlQuery = "SELECT user_id FROM {$wpdb->pmpro_memberships_users} WHERE user_id > {$last_user} AND membership_id = '" . intval($level) . "' AND status = 'active' ORDER BY user_id LIMIT {$limit}";
    $member_ids = $wpdb->get_col($sqlQuery);
    if (empty($member_ids)) {
        delete_transient('pmproues_update_last_row_' . $hash);
        echo "done";
        exit;
    } else {
        //update subs
        foreach ($member_ids as $member_id) {
            $last_user = $member_id;
            echo "\n----\nMember ID #" . $member_id . ". ";
            //get user
            $user = get_userdata($member_id);
            //no user?
            if (empty($user) || empty($user->ID)) {
                echo "Could not find user. ";
                continue;
            } else {
                echo "User found. (" . $user->user_email . ") ";
            }
            //get order
            $order = new MemberOrder();
            $order->getLastMemberOrder($user->ID);
            //no order?
            if (empty($order->id)) {
                echo "Could not find order. ";
                continue;
            } else {
                echo "Order found. (" . $order->code . ") ";
            }
            //different gateway?
            if ($order->gateway != $gateway) {
                echo "Different gateway. ";
                continue;
            } else {
                echo "Gateway matches. ";
            }
            //okay find the sub
            if (empty($order->subscription_transaction_id)) {
                echo "No subscription transaction ID. ";
                continue;
            } else {
                echo "Subscription ID found. ";
            }
            if (empty($live)) {
                echo "Would have updated the subscription here, but we're just testing. ";
                continue;
            }
            //let's do it live!
            if ($gateway == "stripe") {
                /*
                	Note: This code is copied and modified from the user_profile_fields_save method.
                */
                //get level for user
                $user_level = pmpro_getMembershipLevelForUser($user->ID);
                //get current plan at Stripe to get payment date
                $order->Gateway->getCustomer($order);
                $subscription = $order->Gateway->getSubscription($order);
                if (!empty($subscription)) {
                    $end_timestamp = $subscription->current_period_end;
                    //cancel the old subscription
                    if (!$order->Gateway->cancelSubscriptionAtGateway($subscription)) {
                        echo "Could not cancel the old subscription. Skipping. ";
                        continue;
                    }
                }
                //if we didn't get an end date, let's set one one cycle out
                if (empty($end_timestamp)) {
                    $end_timestamp = strtotime("+" . $cycle_number . " " . $cycle_period, current_time('timestamp'));
                }
                //build order object
                $update_order = new MemberOrder();
                $update_order->setGateway('stripe');
                $update_order->user_id = $user->ID;
                $update_order->Email = $user->user_email;
                $update_order->membership_id = $user_level->id;
                $update_order->membership_name = $user_level->name;
                $update_order->InitialPayment = 0;
                $update_order->PaymentAmount = $billing_amount;
                $update_order->ProfileStartDate = date("Y-m-d", $end_timestamp);
                $update_order->BillingPeriod = $cycle_period;
                $update_order->BillingFrequency = $cycle_number;
                //need filter to reset ProfileStartDate
                add_filter('pmpro_profile_start_date', create_function('$startdate, $order', 'return "' . $update_order->ProfileStartDate . 'T0:0:0";'), 10, 2);
                //update subscription
                $update_order->Gateway->subscribe($update_order, false);
                //update membership
                $sqlQuery = "UPDATE {$wpdb->pmpro_memberships_users}\r\n\t\t\t\t\t\t\t\tSET billing_amount = '" . esc_sql($billing_amount) . "',\r\n\t\t\t\t\t\t\t\t\tcycle_number = '" . esc_sql($cycle_number) . "',\r\n\t\t\t\t\t\t\t\t\tcycle_period = '" . esc_sql($cycle_period) . "',\r\n\t\t\t\t\t\t\t\t\ttrial_amount = '',\r\n\t\t\t\t\t\t\t\t\ttrial_limit = ''\r\n\t\t\t\t\t\t\t\tWHERE user_id = '" . esc_sql($user->ID) . "'\r\n\t\t\t\t\t\t\t\t\tAND membership_id = '" . esc_sql($order->membership_id) . "'\r\n\t\t\t\t\t\t\t\t\tAND status = 'active'\r\n\t\t\t\t\t\t\t\tLIMIT 1";
                $wpdb->query($sqlQuery);
                //save order so we know which plan to look for at stripe (order code = plan id)
                $update_order->status = "success";
                $update_order->saveOrder();
                echo "ORDER UPDATED!";
            }
        }
    }
    set_transient('pmproues_update_last_row_' . $hash, $last_user, 60 * 60 * 24);
    exit;
}
 function sendToFondy(&$order)
 {
     global $pmpro_currency;
     global $wpdb;
     //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);
     $fields = array('merchant_data' => 'name=' . $order->billing->name . '=phone=' . $order->billing->phone, 'product_id' => $order->membership_id, 'subscription_callback_url' => admin_url("admin-ajax.php") . "?action=fondy-ins", 'order_id' => $order->code . FondyForm::ORDER_SEPARATOR . time(), 'merchant_id' => pmpro_getOption("fondy_merchantid"), 'order_desc' => substr($order->membership_level->name . " at " . get_bloginfo("name"), 0, 127), 'amount' => round($initial_payment * 100), 'currency' => $pmpro_currency, 'server_callback_url' => admin_url("admin-ajax.php") . "?action=fondy-ins", 'response_url' => admin_url("admin-ajax.php") . "?action=fondy-ins", 'sender_email' => $order->Email, 'required_rectoken' => 'Y', 'subscription' => 'Y');
     $last_subscr_order = new MemberOrder();
     //print_r ($order);
     $last = new MemberOrder($last_subscr_order->getLastMemberOrder($order->user_id, $status = 'success', $membership_id = NULL, $gateway = NULL, $gateway_environment = NULL));
     if (isset($last->user_id) && isset($last->code)) {
         $result = $wpdb->get_row("SELECT fondy_token from `{$wpdb->pmpro_membership_orders}` WHERE user_id='" . $last->user_id . "' AND code='" . $last->code . "'");
         if (isset($result->fondy_token)) {
             $fields['rectoken'] = $result->fondy_token;
         }
     }
     $fields['signature'] = FondyForm::getSignature($fields, pmpro_getOption("fondy_securitykey"));
     //print_r ($last->user_id);die;
     unset($fields['currency']);
     $data = 'currency=' . $pmpro_currency . '&';
     foreach ($fields as $key => $val) {
         $data .= $key . "=" . $val . '&';
     }
     $url = 'https://api.fondy.eu/api/checkout/url/';
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, 'https://api.fondy.eu/api/checkout/url/');
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     $result = curl_exec($ch);
     $str = urldecode($result);
     parse_str($str, $mass);
     $fondy_url = $mass['checkout_url'];
     wp_redirect($fondy_url);
     exit;
 }
function billing_content_func($atts)
{
    global $wpdb, $pmpro_msg, $pmpro_msgt, $pmpro_levels, $current_user, $levels;
    //-> If a member is logged in, show them some info here (1. past invoices. 2. billing information with button to update.)
    if ($current_user->membership_level->ID) {
        if ($pmpro_msg) {
            ?>
            <div class="pmpro_message <?php 
            echo $pmpro_msgt;
            ?>
"><?php 
            echo $pmpro_msg;
            ?>
</div>
            <?php 
        }
        ?>
	
        <div class="row">
            <div class="col-md-8 col-sm-8 col-sm-offset-2 col-md-offset-2">
                <!-- BEGIN CONTENT-->
                <div id="pmpro_account">		
                    <div id="pmpro_account-membership" class="pmpro_box">
                        <p><?php 
        _e("Your membership is <strong>active</strong>.", "pmpro");
        ?>
</p>
                        <ul>
                            <li><strong><?php 
        _e("Level", "pmpro");
        ?>
:</strong> <?php 
        echo $current_user->membership_level->name;
        ?>
</li>
                            <?php 
        if ($current_user->membership_level->billing_amount > 0) {
            ?>
                                <li><strong><?php 
            _e("Membership Fee", "pmpro");
            ?>
:</strong>
                                    <?php 
            $level = $current_user->membership_level;
            if ($current_user->membership_level->cycle_number > 1) {
                printf(__('%s every %d %s.', 'pmpro'), pmpro_formatPrice($level->billing_amount), $level->cycle_number, pmpro_translate_billing_period($level->cycle_period, $level->cycle_number));
            } elseif ($current_user->membership_level->cycle_number == 1) {
                printf(__('%s per %s.', 'pmpro'), pmpro_formatPrice($level->billing_amount), pmpro_translate_billing_period($level->cycle_period));
            } else {
                echo pmpro_formatPrice($current_user->membership_level->billing_amount);
            }
            ?>
                                </li>
                            <?php 
        }
        ?>
						

                            <?php 
        if ($current_user->membership_level->billing_limit) {
            ?>
                                <li><strong><?php 
            _e("Duration", "pmpro");
            ?>
:</strong> <?php 
            echo $current_user->membership_level->billing_limit . ' ' . sornot($current_user->membership_level->cycle_period, $current_user->membership_level->billing_limit);
            ?>
</li>
                            <?php 
        }
        ?>

                            <?php 
        if ($current_user->membership_level->enddate) {
            ?>
                                <li><strong><?php 
            _e("Membership Expires", "pmpro");
            ?>
:</strong> <?php 
            echo date_i18n(get_option('date_format'), $current_user->membership_level->enddate);
            ?>
</li>
                            <?php 
        }
        ?>

                            <?php 
        if ($current_user->membership_level->trial_limit == 1) {
            printf(__("Your first payment will cost %s.", "pmpro"), pmpro_formatPrice($current_user->membership_level->trial_amount));
        } elseif (!empty($current_user->membership_level->trial_limit)) {
            printf(__("Your first %d payments will cost %s.", "pmpro"), $current_user->membership_level->trial_limit, pmpro_formatPrice($current_user->membership_level->trial_amount));
        }
        ?>
                        </ul>

                    </div> <!-- end pmpro_account-membership -->

                    <div id="pmpro_account-profile" class="pmpro_box hide">	
                        <?php 
        get_currentuserinfo();
        ?>
 
                        <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>
                            <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>
                        </ul>
                        <p>
                            <a href="<?php 
        echo admin_url('profile.php');
        ?>
"><?php 
        _e("Edit Profile", "pmpro");
        ?>
</a> |
                            <a href="<?php 
        echo admin_url('profile.php');
        ?>
"><?php 
        _ex("Change Password", "As in 'change password'.", "pmpro");
        ?>
</a>
                        </p>
                    </div> <!-- end pmpro_account-profile -->

                    <?php 
        //last invoice for current info
        //$ssorder = $wpdb->get_row("SELECT *, UNIX_TIMESTAMP(timestamp) as timestamp FROM $wpdb->pmpro_membership_orders WHERE user_id = '$current_user->ID' AND membership_id = '" . $current_user->membership_level->ID . "' AND status = 'success' ORDER BY timestamp DESC LIMIT 1");
        $ssorder = new MemberOrder();
        $ssorder->getLastMemberOrder();
        $invoices = $wpdb->get_results("SELECT *, UNIX_TIMESTAMP(timestamp) as timestamp FROM {$wpdb->pmpro_membership_orders} WHERE user_id = '{$current_user->ID}' ORDER BY timestamp DESC LIMIT 6");
        if (!empty($ssorder->id) && $ssorder->gateway != "check" && $ssorder->gateway != "paypalexpress" && $ssorder->gateway != "paypalstandard" && $ssorder->gateway != "twocheckout") {
            //default values from DB (should be last order or last update)
            $bfirstname = get_user_meta($current_user->ID, "pmpro_bfirstname", true);
            $blastname = get_user_meta($current_user->ID, "pmpro_blastname", true);
            $baddress1 = get_user_meta($current_user->ID, "pmpro_baddress1", true);
            $baddress2 = get_user_meta($current_user->ID, "pmpro_baddress2", true);
            $bcity = get_user_meta($current_user->ID, "pmpro_bcity", true);
            $bstate = get_user_meta($current_user->ID, "pmpro_bstate", true);
            $bzipcode = get_user_meta($current_user->ID, "pmpro_bzipcode", true);
            $bcountry = get_user_meta($current_user->ID, "pmpro_bcountry", true);
            $bphone = get_user_meta($current_user->ID, "pmpro_bphone", true);
            $bemail = get_user_meta($current_user->ID, "pmpro_bemail", true);
            $bconfirmemail = get_user_meta($current_user->ID, "pmpro_bconfirmemail", true);
            $CardType = get_user_meta($current_user->ID, "pmpro_CardType", true);
            $AccountNumber = hideCardNumber(get_user_meta($current_user->ID, "pmpro_AccountNumber", true), false);
            $ExpirationMonth = get_user_meta($current_user->ID, "pmpro_ExpirationMonth", true);
            $ExpirationYear = get_user_meta($current_user->ID, "pmpro_ExpirationYear", true);
            ?>
	

                        <div id="pmpro_account-billing" class="pmpro_box">
                            <h3><?php 
            _e("Billing Information", "pmpro");
            ?>
</h3>
                            <?php 
            if (!empty($baddress1)) {
                ?>
                                <p>
                                    <strong><?php 
                _e("Billing Address", "pmpro");
                ?>
</strong><br />
                                    <?php 
                echo $bfirstname . " " . $blastname;
                ?>
                                    <br />		
                                    <?php 
                echo $baddress1;
                ?>
<br />
                                    <?php 
                if ($baddress2) {
                    echo $baddress2 . "<br />";
                }
                ?>
                                    <?php 
                if ($bcity && $bstate) {
                    ?>
                                        <?php 
                    echo $bcity;
                    ?>
, <?php 
                    echo $bstate;
                    ?>
 <?php 
                    echo $bzipcode;
                    ?>
 <?php 
                    echo $bcountry;
                    ?>
                                    <?php 
                }
                ?>
                         
                                    <br />
                                    <?php 
                echo formatPhone($bphone);
                ?>
                                </p>
                            <?php 
            }
            ?>

                            <?php 
            if (!empty($AccountNumber)) {
                ?>
                                <p>
                                    <strong><?php 
                _e("Payment Method", "pmpro");
                ?>
</strong><br />
                                    <?php 
                echo $CardType;
                ?>
: <?php 
                echo last4($AccountNumber);
                ?>
 (<?php 
                echo $ExpirationMonth;
                ?>
/<?php 
                echo $ExpirationYear;
                ?>
)
                                </p>
                            <?php 
            }
            ?>

                            <?php 
            if (isset($ssorder->status) && $ssorder->status == "success" && (isset($ssorder->gateway) && in_array($ssorder->gateway, array("authorizenet", "paypal", "stripe", "braintree", "payflow", "cybersource")))) {
                ?>
                                <p><a href="<?php 
                echo pmpro_url("billing", "");
                ?>
"><?php 
                _e("Edit Billing Information", "pmpro");
                ?>
</a></p>
                                <?php 
            }
            ?>
                        </div> <!-- end pmpro_account-billing -->				
                        <?php 
        }
        ?>

                    <?php 
        if (!empty($invoices)) {
            ?>
                        <div id="pmpro_account-invoices" class="pmpro_box">
                            <h3><?php 
            _e("Past Invoices", "pmpro");
            ?>
</h3>
                            <ul>
                                <?php 
            $count = 0;
            foreach ($invoices as $invoice) {
                if ($count++ > 5) {
                    break;
                }
                ?>
                                    <li><a href="<?php 
                echo pmpro_url("invoice", "?invoice=" . $invoice->code);
                ?>
"><?php 
                echo date_i18n(get_option("date_format"), $invoice->timestamp);
                ?>
 (<?php 
                echo pmpro_formatPrice($invoice->total);
                ?>
)</a></li>
                                    <?php 
            }
            ?>
                            </ul>
                            <?php 
            if ($count == 6) {
                ?>
                                <p><a href="<?php 
                echo pmpro_url("invoice");
                ?>
"><?php 
                _e("View All Invoices", "pmpro");
                ?>
</a></p>
                            <?php 
            }
            ?>
                        </div> <!-- end pmpro_account-billing -->
                    <?php 
        }
        ?>
                    <p class="help-block">We have the following subscriptions available for our site. To join, simply click on the <strong>Renew</strong> or <strong>Change Subscription</strong> button and then complete the registration details.</p>
                    <?php 
        getLevels();
        ?>
                    <div id="pmpro_account-links" class="pmpro_box">
                        <h3><?php 
        _e("Manage Membership", "pmpro");
        ?>
</h3>
                        <ul>
                            <?php 
        do_action("pmpro_member_links_top");
        ?>
                            <?php 
        if (isset($ssorder->status) && $ssorder->status == "success" && (isset($ssorder->gateway) && in_array($ssorder->gateway, array("authorizenet", "paypal", "stripe", "braintree", "payflow", "cybersource")))) {
            ?>
                                <li><a href="<?php 
            echo pmpro_url("billing", "", "https");
            ?>
"><?php 
            _e("Update Billing Information", "pmpro");
            ?>
</a></li>
                            <?php 
        }
        ?>
                            <?php 
        if (count($pmpro_levels) > 1 && !defined("PMPRO_DEFAULT_LEVEL")) {
            ?>
                                <li><a href="<?php 
            echo pmpro_url("levels");
            ?>
"> <?php 
            _e("Change Membership Level", "pmpro");
            ?>
</a></li>
                            <?php 
        }
        ?>
                            <li><a href="<?php 
        echo pmpro_url("cancel");
        ?>
" class="red"><?php 
        _e("Cancel Membership", "pmpro");
        ?>
</a></li>
                            <?php 
        do_action("pmpro_member_links_bottom");
        ?>
                        </ul>
                    </div> <!-- end pmpro_account-links -->		
                </div> <!-- end pmpro_account -->	

                <!-- END CONTENT-->
            </div>
        </div>
        <?php 
    }
    ?>
    <?php 
}