예제 #1
0
// this means there will be another flag called $submitted_to_paragon or something like that, which gets set when the manager sends the info on to Paragon... and then there will need to be a flag to say whether the tenant has been accepted or rejected
// this module should be shown if $submitted_guarantor_info flag is not set
// the result of submitting the info should set the flag
if ($_POST && $_POST['submit_guarantor']) {
    $current_user_id = $current_user->id;
    update_user_meta($current_user_id, 'submitted_guarantor_info', 'yes');
    update_user_meta($current_user_id, 'guarantor_first_name', $_POST['first_name']);
    update_user_meta($current_user_id, 'guarantor_last_name', $_POST['last_name']);
    update_user_meta($current_user_id, 'guarantor_email', $_POST['email']);
    update_user_meta($current_user_id, 'guarantor_phone', $_POST['phone']);
    $person = get_userdata($current_user_id);
    $manager_email_text = "Hello there! {$person->display_name} has submitted their guarantor information for {$paid_holding_deposit_address}. Please send on to Paragon at: http://sweetspot.com/property/dash";
    // TO-DO: get this into an admin screen
    $welcome_email_subject = "Guarantor information submission from {$person->display_name}";
    // TO-DO: get this into an admin screen
    sweetspot_mail('*****@*****.**', $manager_email_subject, $manager_email_text, true);
    // TO-DO: get manager email dynamically
    ?>
	<p class="grid3col left">Thanks for submitting your guarantor information. We will contact them and make reference checks over the next few days. </p>
	<?php 
} else {
    ?>

					<?php 
    if ($submitted_guarantor_info) {
        ?>
						<p class="grid3col left">You have already submitted your guarantor information. Thanks!</p>
						<?php 
        if (!$submitted_to_paragon) {
            ?>
						<p class="grid3col left">Just so you know, we haven't sent off the reference check yet.</p>
예제 #2
0
        $phone = $_POST['phone' . $i];
        if (!($firstname && $lastname && $address && $email && $phone)) {
            //$any_errors .= "i: {$i}, firstname: {$firstname}, lastname: {$lastname}, address: {$address}, email: {$email}, phone: {$phone}"; // JRL: debug
            // error! TO-DO: redirect back to this page with error set in the URL parameters
            // defering this for a while...
        } else {
            // create account if necessary
            require_once ABSPATH . WPINC . '/registration.php';
            $user_id = username_exists($email);
            if (!$user_id) {
                $random_password = wp_generate_password(12, false);
                $user_id = wp_insert_user(array('user_login' => $email, 'user_pass' => $random_password, 'user_email' => $email, 'display_name' => $firstname, 'role' => 'applicant'));
                $login_text = "\n\nYour login ID and password are:\n\nLogin ID: {$email}\nPassword: {$random_password}\n\n";
                sweetspot_mail($email, $welcome_email_subject, $welcome_email_text . $login_text);
            } else {
                sweetspot_mail($email, $welcome_email_subject, $welcome_email_text);
            }
            update_user_meta($user_id, 'first_name', $firstname);
            update_user_meta($user_id, 'last_name', $lastname);
            update_user_meta($user_id, 'postcode', $postcode);
            update_user_meta($user_id, 'address', $address);
            update_user_meta($user_id, 'phone', $phone);
            update_user_meta($user_id, 'group', $current_user->user_login);
            // set flag on $current_user
            update_user_meta($current_user_id, 'submitted_housemate_info', implode(', ', $housemate_emails));
        }
    }
    ?>
					<p class="grid3col left">
						Thanks! We've created accounts for all those people.
					</p>
예제 #3
0
function checkAllApplicants($propertyID)
{
    if (!get_post_meta($propertyID, 'notified_manager_about_AST', true)) {
        // only do this if the manager hasn't already been notified
        global $current_user;
        global $wpdb;
        $IPN_payer_email = get_post_meta($propertyID, 'ipn_payer_email', true);
        $peopleIDs = $wpdb->get_col($wpdb->prepare("SELECT {$wpdb->users}.ID FROM {$wpdb->users}"));
        foreach ($peopleIDs as $personID) {
            $person = get_userdata($personID);
            if ($person->user_email == $IPN_payer_email) {
                $lead_tenant = $person;
            }
        }
        if (!$lead_tenant) {
            // don't bother if there's no lead tenant
            return;
        }
        $group = $lead_tenant->group;
        $all_paid = true;
        foreach ($peopleIDs as $personID) {
            $person = get_userdata($personID);
            if ($person->group == $group) {
                if ($person->group == $person->user_login) {
                    // person is lead tenant
                    if (!$person->paid_security_deposit || !$person->submitted_housemate_info || !$person->submitted_guarantor_info || !$person->submitted_to_paragon) {
                        $all_paid = false;
                    }
                } else {
                    if (!$person->paid_security_deposit || !$person->submitted_guarantor_info || !$person->submitted_to_paragon) {
                        $all_paid = false;
                    }
                }
            }
        }
        if ($all_paid) {
            $address = get_post_meta($propertyID, '_address', true);
            $manager_email_subject = "All tenants approved for {$paid_holding_deposit_address}";
            // TO-DO: get into an email admin plugin
            $manager_email_text = "All the tenants have completed their approval steps for {$paid_holding_deposit_address}.\n\nPlease get their tenancy agreement together and send it out.";
            // TO-DO: get into an email admin plugin
            sweetspot_mail('*****@*****.**', $manager_email_subject, $manager_email_text, true);
            // TO-DO: get manager email dynamically
            update_post_meta($propertyID, 'notified_manager_about_AST', true);
        }
        return $all_paid;
    }
}
예제 #4
0
function handle_ipn($vars)
{
    require_once ABSPATH . WPINC . '/registration.php';
    $payment_status = $vars['payment_status'];
    // Completed/Refunded
    $item_name = $vars['item_name'];
    // Holding/Security Deposit
    $IPN_reference = $vars['txn_id'];
    // Ref/'cash'
    $IPN_address = $vars['item_number'];
    // Address
    $user_id = $vars['custom'];
    // Login id of person paying
    $user = get_userdatabylogin($user_id);
    $IPN_payer_email = $vars['payer_email'];
    $IPN_all = implode($vars, "~~");
    activity_log(array('type' => 'IPN', 'entry' => $IPN_all));
    if ($IPN_reference and $IPN_address and $payment_status and $user_id) {
        if ($item_name == "Holding Deposit") {
            $loop = new WP_Query("post_type=properties");
            // JRL: I want the properties where $address_field matches $IPN_address, but I don't think I can just search by custom field (address) - maybe a SQL query?
            $property_matches = 0;
            global $post;
            while ($loop->have_posts()) {
                $loop->the_post();
                $address_field = get_post_meta($post->ID, "_address");
                $address_field = $address_field[0];
                if ($address_field == $IPN_address) {
                    $property_matches++;
                    $the_ID = get_the_ID();
                    if ($payment_status == "Completed") {
                        update_post_meta($the_ID, '_property_status', 'under_offer');
                        add_post_meta($the_ID, 'ipn_txn_id', $IPN_reference, true) or update_post_meta($the_ID, 'ipn_txn_id', $IPN_reference);
                        add_post_meta($the_ID, 'ipn_payer_email', $user_id, true) or update_post_meta($the_ID, 'ipn_payer_email', $user_id);
                        add_post_meta($the_ID, 'ipn_all', $IPN_all, true) or update_post_meta($the_ID, 'ipn_all', $IPN_all);
                        // add payer to their own group
                        update_user_meta($user->ID, 'group', $user_id);
                        $email = $user->user_email . ",glenn@sweetspot.com";
                        // TO-DO: get the manager addresses for a property into an admin page
                        $email_body = "Hello there!\n\nThanks for paying a holding deposit. The property has been taken off the market for a while to give you and your friends chance to get confirmed as future tenants. If you have any questions, please speak to your property manager, check the FAQ at http://sweetspot.com/faq or email us at hello@sweetspot.com.\n\n";
                        // TO-DO: get this into an admin screen
                        $email_subject = "Thanks for paying a holding deposit for {$IPN_address}";
                        // TO-DO: get this into an admin screen
                        sweetspot_mail($email, $email_subject, $email_body);
                        if ($IPN_reference == "Cash") {
                            header('Location: ' . bloginfo('siteurl') . 'dash');
                            // TO-DO: replace this with meta-redirect since output already started
                        } else {
                            echo "Payment acknowledged";
                        }
                    } else {
                        if ($payment_status == "Refunded") {
                            update_post_meta($the_ID, '_property_status', 'on_the_market');
                            delete_post_meta($the_ID, 'ipn_txn_id');
                            delete_post_meta($the_ID, 'ipn_payer_email');
                            delete_post_meta($the_ID, 'ipn_all');
                            $email = $user->user_email;
                            $email_body = "Hello there!\n\nThis is to confirm we've refunded your holding deposit.";
                            // TO-DO: get this into an admin screen
                            $email_subject = "Refund for holding deposit on {$IPN_address}";
                            // TO-DO: get this into an admin screen
                            sweetspot_mail($email, $email_subject, $email_body);
                            echo "Refund processed";
                        }
                    }
                }
            }
            if ($property_matches == 0) {
                echo "did not find any property matches for " . $IPN_address;
            }
        } else {
            if ($item_name == "Security Deposit") {
                if ($payment_status == "Completed") {
                    update_user_meta($user->ID, 'paid_security_deposit', $IPN_reference);
                    $email = $user->user_email;
                    $email_body = "Hello there!\n\nThanks for paying your security deposit and 1st month's rent. We're going to be insuring your deposit with MyDeposits.co.uk. If you have any questions, please speak to your property manager, check the FAQ at http://sweetspot.com/faq or email us at hello@sweetspot.com.\n\n";
                    // TO-DO: get this into an admin screen
                    $email_subject = "Thanks for paying a security deposit and 1st month's rent for {$IPN_address}";
                    // TO-DO: get this into an admin screen
                    sweetspot_mail($email, $email_subject, $email_body);
                    // figure out if all members of a group have paid their deposits and notify manager if so
                    $lead_tenant = $user->group;
                    $peopleIDs = $wpdb->get_col($wpdb->prepare("SELECT {$wpdb->users}.ID FROM {$wpdb->users}"));
                    $all_paid = true;
                    foreach ($peopleIDs as $personID) {
                        $person = get_userdata($personID);
                        if ($person->group == $lead_tenant && !$person->paid_security_deposit) {
                            $all_paid = false;
                        }
                    }
                    if ($all_paid) {
                        $email_text = "Hi Glenn,\n\nIt looks like the applicants for {$IPN_address} have all paid their security deposits. They've been notified that their deposit will be registered with MyDeposits.";
                        sweetspot_mail('*****@*****.**', "All security deposits paid for {$IPN_address}", $email_text);
                    }
                    echo "Payment acknowledged";
                } else {
                    if ($payment_status == "Refunded") {
                        delete_post_meta($user->ID, 'paid_security_deposit');
                        $email = $user->user_email;
                        $email_body = "Hello there!\n\nThis is to confirm that we've refunded your security deposit and 1st month's rent.";
                        // TO-DO: get this into an admin screen
                        $email_subject = "Refund for security deposit and 1st month's rent on {$IPN_address}";
                        // TO-DO: get this into an admin screen
                        sweetspot_mail($email, $email_subject, $email_body);
                        echo "Refund processed";
                    }
                }
            } else {
                // unknown item name
                echo "error: do not understand item name: " . $item_name;
            }
        }
    } else {
        echo "error: send at least 'txn_id', 'item_number', 'payment_status' and 'custom' (containing person's SweetSpot account name)";
    }
}