//not our request
    pmpro_ipnExit();
}
/*
		PayPal Standard
		- we will get txn_type subscr_signup and subscr_payment (or subscr_eot or subscr_failed)
		- subscr_signup (if amount1 = 0, then we need to update membership, else ignore and wait for payment. create invoice for $0 with just subscr_id)
		- subscr_payment (check if we should update membership, add invoice for amount with subscr_id and payment_id)
		- web_accept for 1-time payment only
	PayPal Express
		- we will get txn_type express_checkout, or recurring_payment_profile_created, or recurring_payment (or recurring_payment_expired, or recurring_payment_skipped)
*/
//PayPal Standard Sign Up
if ($txn_type == "subscr_signup") {
    //if there is no amount1, this membership has a trial, and we need to update membership/etc
    $amount = pmpro_getParam("amount1", "POST");
    if ((double) $amount <= 0) {
        //trial, get the order
        $morder = new MemberOrder($item_number);
        $morder->getMembershipLevel();
        $morder->getUser();
        //no txn_id on these, so let's use the subscr_id
        if (empty($txn_id)) {
            $txn_id = $subscr_id;
        }
        //update membership
        if (pmpro_ipnChangeMembershipLevel($txn_id, $morder)) {
            ipnlog("Checkout processed (" . $morder->code . ") success!");
        } else {
            ipnlog("ERROR: Couldn't change level for order (" . $morder->code . ").");
        }
function pmpro_insChangeMembershipLevel($txn_id, &$morder)
{
    $recurring = pmpro_getParam('recurring', 'POST');
    //filter for level
    $morder->membership_level = apply_filters("pmpro_inshandler_level", $morder->membership_level, $morder->user_id);
    //fix expiration date
    if (!empty($morder->membership_level->expiration_number)) {
        $enddate = "'" . date("Y-m-d", strtotime("+ " . $morder->membership_level->expiration_number . " " . $morder->membership_level->expiration_period, current_time("timestamp"))) . "'";
    } else {
        $enddate = "NULL";
    }
    //get discount code
    $morder->getDiscountCode();
    if (!empty($morder->discount_code)) {
        //update membership level
        $morder->getMembershipLevel(true);
        $discount_code_id = $morder->discount_code->id;
    } else {
        $discount_code_id = "";
    }
    //set the start date to current_time('mysql') but allow filters
    $startdate = apply_filters("pmpro_checkout_start_date", "'" . current_time('mysql') . "'", $morder->user_id, $morder->membership_level);
    //custom level to change user to
    $custom_level = array('user_id' => $morder->user_id, 'membership_id' => $morder->membership_level->id, 'code_id' => $discount_code_id, 'initial_payment' => $morder->membership_level->initial_payment, 'billing_amount' => $morder->membership_level->billing_amount, 'cycle_number' => $morder->membership_level->cycle_number, 'cycle_period' => $morder->membership_level->cycle_period, 'billing_limit' => $morder->membership_level->billing_limit, 'trial_amount' => $morder->membership_level->trial_amount, 'trial_limit' => $morder->membership_level->trial_limit, 'startdate' => $startdate, 'enddate' => $enddate);
    global $pmpro_error;
    if (!empty($pmpro_error)) {
        echo $pmpro_error;
        inslog($pmpro_error);
    }
    if (pmpro_changeMembershipLevel($custom_level, $morder->user_id) !== false) {
        //update order status and transaction ids
        $morder->status = "success";
        $morder->payment_transaction_id = $txn_id;
        if ($recurring) {
            $morder->subscription_transaction_id = $txn_id;
        } else {
            $morder->subscription_transaction_id = '';
        }
        $morder->saveOrder();
        //add discount code use
        if (!empty($discount_code) && !empty($use_discount_code)) {
            $wpdb->query("INSERT INTO {$wpdb->pmpro_discount_codes_uses} (code_id, user_id, order_id, timestamp) VALUES('" . $discount_code_id . "', '" . $morder->user_id . "', '" . $morder->id . "', '" . current_time('mysql') . "')");
        }
        //save first and last name fields
        if (!empty($_POST['first_name'])) {
            $old_firstname = get_user_meta($morder->user_id, "first_name", true);
            if (!empty($old_firstname)) {
                update_user_meta($morder->user_id, "first_name", $_POST['first_name']);
            }
        }
        if (!empty($_POST['last_name'])) {
            $old_lastname = get_user_meta($morder->user_id, "last_name", true);
            if (!empty($old_lastname)) {
                update_user_meta($morder->user_id, "last_name", $_POST['last_name']);
            }
        }
        //hook
        do_action("pmpro_after_checkout", $morder->user_id);
        //setup some values for the emails
        if (!empty($morder)) {
            $invoice = new MemberOrder($morder->id);
        } else {
            $invoice = NULL;
        }
        inslog("CHANGEMEMBERSHIPLEVEL: ORDER: " . var_export($morder, true) . "\n---\n");
        $user = get_userdata($morder->user_id);
        if (empty($user)) {
            return false;
        }
        $user->membership_level = $morder->membership_level;
        //make sure they have the right level info
        //send email to member
        $pmproemail = new PMProEmail();
        $pmproemail->sendCheckoutEmail($user, $invoice);
        //send email to admin
        $pmproemail = new PMProEmail();
        $pmproemail->sendCheckoutAdminEmail($user, $invoice);
        return true;
    } else {
        return false;
    }
}
示例#3
0
		PayPal Standard
		- we will get txn_type subscr_signup and subscr_payment (or subscr_eot or subscr_failed)
		- subscr_signup (if amount1 = 0, then we need to update membership, else ignore and wait for payment. create invoice for $0 with just subscr_id)
		- subscr_payment (check if we should update membership, add invoice for amount with subscr_id and payment_id)
		- web_accept for 1-time payment only
		
		PayPal Express
		- we will get txn_type express_checkout, or recurring_payment_profile_created, or recurring_payment (or recurring_payment_expired, or recurring_payment_skipped)
		
	*/
	
	//PayPal Standard Sign Up
	if($txn_type == "subscr_signup")
	{		
		//if there is no amount1, this membership has a trial, and we need to update membership/etc
		$amount = pmpro_getParam("amount1", $_POST);
		if(empty($amount))
		{
			//trial, get the order
			$morder = new MemberOrder($item_number);
			$morder->getMembershipLevel();
			$morder->getUser();		
			
			//no txn_id on these, so let's use the subscr_id
			if(empty($txn_id))
				$txn_id = $subscr_id;			
						
			//update membership
			if(pmpro_ipnChangeMembershipLevel($txn_id, $morder))
			{									
				ipnlog("Checkout processed (" . $morder->code . ") success!");