public function credit($amount, $details = "")
 {
     $dollars = format_money($amount, true);
     try {
         error_log("About to credit user {$dollars} for {$details}.", 0);
         $credit = new Recurly_Adjustment();
         $credit->account_code = $this->recurlyAccount->account_code;
         $credit->currency = "USD";
         $credit->unit_amount_in_cents = -$amount;
         $credit->description = $details;
         $credit->create();
         if ($credit->uuid) {
             return true;
         } else {
             throw new Exception('transaction failed');
         }
     } catch (Exception $e) {
         issue_log($this->account->account_code, "Issue crediting user [{$dollars} for {$details}]. " . $e->getMessage(), MemberIssueType::BILLING);
     }
 }
 public function register()
 {
     // assume we have initiated the member object already if not…bail
     error_log("*****registering a user:"******", " . $this->member->wp_users_id);
     if (!$this->member->id) {
         error_log("*****member id not set");
         return false;
     }
     $data = $this->input->post();
     $this->load->model("members/emailmodel", "em", true);
     $this->em->init($this->member->id);
     $this->load->model("billing/accountmodel", "am", true);
     $this->am->init($this->member->id);
     error_log("*****Account model create");
     $this->am->create($this->member->email, $this->member->first_name, $this->member->last_name, $this->member->email);
     $this->am->billing_info->first_name = $data["billing_info"]["first_name"];
     $this->am->billing_info->last_name = $data["billing_info"]["last_name"];
     $this->am->billing_info->address1 = $data["billing_info"]["address1"];
     $this->am->billing_info->address2 = $data["billing_info"]["address2"];
     $this->am->billing_info->city = $data["billing_info"]["city"];
     $this->am->billing_info->state = $data["billing_info"]["state"];
     $this->am->billing_info->zip = $data["billing_info"]["zip"];
     $this->am->billing_info->country = $data["billing_info"]["country"];
     $this->am->billing_info->number = $data["credit_card"]["number"];
     $this->am->billing_info->month = intval($data["credit_card"]["month"]);
     $this->am->billing_info->year = intval($data["credit_card"]["year"]);
     $this->am->billing_info->verification_value = $data["credit_card"]["verification_value"];
     $data = array('membership_status_luid' => MembershipStatus::ACTIVE_MEMBER, 'terms_agree' => 1);
     $where = array("id" => $this->member->id);
     $_SESSION['member'] = $this->member;
     try {
         error_log("*****Creating Subscription");
         $result = $this->am->createSubscription($_POST["plan_code"]);
         if (is_array($result) && $result["error"]) {
             //return $result;
             throw new Exception($result["error"] . ";" . $result['message']);
         }
         $result = $this->db->update("user", $data, $where);
         if (!$result) {
             throw new Exception("error update database with new member status");
         }
         $_SESSION['membershipsuccess'] = true;
         delete_user_meta($this->member->wp_users_id, 'registerHash');
         delete_user_meta($this->member->wp_users_id, 'registerStep');
         delete_user_meta($this->member->wp_users_id, 'admin_init');
         $this->em->email_list_add($this->member->first_name . " " . $this->member->last_name);
         $user_id_role = new WP_User($this->member->wp_users_id);
         $change_role_result = $user_id_role->set_role('subscriber');
         error_log("changing role:" . $change_role_result, 0);
         wp_clear_auth_cookie();
         wp_set_auth_cookie($this->member->wp_users_id);
         $wp_user = wp_set_current_user($this->member->wp_users_id, $this->member->email);
         /* update wp user meta w/ the info that's stored in our model */
         /* added by @mattkosoy */
         // the fields we're using.
         $fields = array('first_name' => $this->member->first_name, 'last_name' => $this->member->last_name, 'email' => $this->member->email, 'company_name' => $this->member->company_name, 'company_desc' => 'Company Description', 'URL' => 'URL', 'twitter' => 'Twitter URL...', 'behance' => 'Behance URL...', 'foursquare' => 'FourSquare URL...', 'linkedin' => 'LinkedIn URL...', 'facebook' => 'Facebook URL...', 'dribbble' => 'Dribbble URL...', 'i_need' => '');
         foreach ($fields as $k => $v) {
             if (update_user_meta($this->member->wp_users_id, $k, $v)) {
                 log_message("debug", "Wordpress update user meta " . $k . " for user: "******" " . $this->member->last_name . " is successful");
             }
         }
         $notification_message = "Registering new member " . $this->member->first_name . " " . $this->member->last_name;
         issue_log($this->member->id, $notification_message, MemberIssueType::GENERAL);
         $this->load->model("emailtemplates/emailtemplatemodel", "", true);
         $notification = $this->emailtemplatemodel->init(22);
         $notification->message = $notification->message . " \n" . $notification_message;
         $result = $this->emailtemplatemodel->send(EMAIL_G_ADMIN);
         return true;
     } catch (Exception $e) {
         error_log("error creating new subscription for userid:" . $this->member->id . " message: \n" . $e, 0);
         return $result;
     }
 }
 public function register($user_id, $id_type = NULL)
 {
     error_log("Controller: Register:" . $user_id . "/" . $id_type, 0);
     $this->load->model('members/membermodel', '', true);
     $this->membermodel->init($user_id, $id_type);
     $this->membermodel->get_basicMemberData($user_id, $id_type);
     $results = $this->membermodel->register();
     if ($this->input->is_ajax_request()) {
         // output should be json encoded
         error_log("what is coming back" . $results, 0);
         if (!$results["error"] && $results) {
             error_log("we should be telling javascript good news", 0);
             $response = array("success" => 1);
             $results = json_encode($response);
             error_log($results, 0);
             echo $results;
             return;
         } else {
             error_log("but it is getting bad", 0);
             if (is_array($results)) {
                 $results = json_encode($results);
             }
             issue_log($user_id, "error when registering member");
             echo $results;
         }
     } else {
         echo $results;
     }
 }
 public function register($user_id, $id_type = NULL)
 {
     error_log("*****Begin Registration for {$user_id}/{$id_type}");
     $this->load->model('members/membermodel', '', true);
     error_log("*****Member Model loaded successfully");
     if (!isset($_POST['terms'])) {
         error_log("*****Terms and Conditions not submitted");
         $results['error'] = "Must agree to terms and conditions";
     } else {
         error_log("*****Terms and conditions passed.  Initialize Member data");
         $this->membermodel->init($user_id, $id_type);
         $this->membermodel->get_basicMemberData($user_id, $id_type);
         error_log("*****Calling register on member model");
         $results = $this->membermodel->register();
     }
     if ($this->input->is_ajax_request()) {
         // output should be json encoded
         error_log("*****what is coming back" . $results, 0);
         if (!$results["error"] && $results) {
             error_log("*****we should be telling javascript good news", 0);
             $response = array("success" => 1);
             $results = json_encode($response);
             error_log("*****" . $results, 0);
             echo $results;
             return;
         } else {
             error_log("*****but it is getting bad", 0);
             if (is_array($results)) {
                 $results = json_encode($results);
             }
             issue_log($user_id, "error when registering member");
             echo $results;
         }
     } else {
         echo $results;
     }
 }
 public function remotesignin()
 {
     $result = 0;
     // fail by default
     // add multiple locations here in the future
     $location = 1;
     $this->load->model("members/membermodel");
     $member = $this->membermodel->authMacAddr($this->input->post('mac'));
     if ($member) {
         // the macaddress was found belonging to a user
         $result = $this->membermodel->checkin($location, SignInMethod::WIFI) ? 1 : 0;
         error_log("check result" . $result, 0);
         if (!$result) {
             $result = 4;
             echo $result;
             return $result;
         } else {
             $result = 1;
             echo $result;
             return $result;
         }
     } else {
         //do we have a username and password
         $username = $this->input->post("u");
         // test if the username we have is the dummy username
         // we use a dummy username in the transparent authentication
         if ($username == "mactest") {
             // the mac wasn't recognized and we don't have a real userid
             // fail back to radius
             $result = 2;
             echo $result;
             return $result;
         }
         // now we assume we have a real username
         if (!user_pass_ok($this->input->post('u'), $this->input->post('p'))) {
             // user authentication with password failed.
             error_log("Invalid user login:"******"issue adding mac address during checkin");
             }
             $result = $member->id;
             // success
             error_log("signin checkin success!", 0);
             $result = 1;
             echo $result;
             return $result;
         } else {
             // for some reason we could not checkin the user
             error_log("signin checkin failure!", 0);
             $result = 4;
             echo $result;
             return $result;
         }
         error_log("checkin success!", 0);
         // if we made it this far we have checked in and all good. Give users access to WIFI
         $result = 1;
     }
 }