$obj->API_Endpoint = "https://api-3t.paypal.com/nvp"; $obj->paymentType = urlencode('Sale'); $obj->returnURL = urlencode($dash_profile_link); $obj->cancelURL = urlencode($dash_profile_link); $obj->paymentAmount = get_post_meta($pack_id, 'pack_price', true); $obj->currencyID = get_option('wp_estate_submission_curency', ''); $date = $save_data[$current_user->ID]['date']; $obj->startDate = urlencode($date); $obj->billingPeriod = urlencode($billing_period); $obj->billingFreq = urlencode($billing_freq); $pack_name = get_the_title($pack_id); $obj->productdesc = urlencode($pack_name . esc_html__(' package on ', 'wpestate') . get_bloginfo('name')); $obj->user_id = $current_user->ID; $obj->pack_id = $pack_id; if ($obj->getExpressCheckout($token_recursive)) { if (wpestate_check_downgrade_situation($current_user->ID, $pack_id)) { wpestate_downgrade_to_pack($current_user->ID, $pack_id); wpestate_upgrade_user_membership($current_user->ID, $pack_id, 2, ''); } else { wpestate_upgrade_user_membership($current_user->ID, $pack_id, 2, ''); } wp_redirect($dash_profile_link); } } } ////////////////////////////////////////////////////////////////////////////////////////// // 3rd party login code ////////////////////////////////////////////////////////////////////////////////////////// if (isset($_GET['code']) && isset($_GET['state'])) { estate_facebook_login($_GET); } else {
function wpestate_upgrade_user_membership($user_id, $pack_id, $type, $paypal_tax_id) { $available_listings = get_post_meta($pack_id, 'pack_listings', true); $featured_available_listings = get_post_meta($pack_id, 'pack_featured_listings', true); $pack_unlimited_list = get_post_meta($pack_id, 'mem_list_unl', true); $current_used_listings = get_user_meta($user_id, 'package_listings', true); $curent_used_featured_listings = get_user_meta($user_id, 'package_featured_listings', true); $current_pack = get_user_meta($user_id, 'package_id', true); $user_curent_listings = wpestate_get_user_curent_listings_no_exp($user_id); $user_curent_future_listings = wpestate_get_user_curent_future_listings_no_exp($user_id); if (wpestate_check_downgrade_situation($user_id, $pack_id)) { $new_listings = $available_listings; $new_featured_listings = $featured_available_listings; } else { $new_listings = $available_listings - $user_curent_listings; $new_featured_listings = $featured_available_listings - $user_curent_future_listings; } // in case of downgrade if ($new_listings < 0) { $new_listings = 0; } if ($new_featured_listings < 0) { $new_featured_listings = 0; } if ($pack_unlimited_list == 1) { $new_listings = -1; } update_user_meta($user_id, 'package_listings', $new_listings); update_user_meta($user_id, 'package_featured_listings', $new_featured_listings); $time = time(); $date = date('Y-m-d H:i:s', $time); update_user_meta($user_id, 'package_activation', $date); update_user_meta($user_id, 'package_id', $pack_id); $headers = 'From: No Reply <noreply@' . $_SERVER['HTTP_HOST'] . '>' . "\r\n"; $message = esc_html__('Hi there,', 'wpestate') . "\r\n\r\n"; $message .= sprintf(esc_html__("Your new membership on %s is activated! You should go check it out.", 'wpestate'), get_option('blogname')) . "\r\n\r\n"; $user = get_user_by('id', $user_id); $user_email = $user->user_email; wp_mail($user_email, sprintf(esc_html__('[%s] Membership Activated', 'wpestate'), get_option('blogname')), $message, $headers); $billing_for = 'Package'; $invoice_id = wpestate_insert_invoice($billing_for, $type, $pack_id, $date, $user_id, 0, 0, $paypal_tax_id); update_post_meta($invoice_id, 'invoice_status', 'confirmed'); }