public function ProcessDailyInvoices($id)
 {
     $verificationGuid = 'da68e4ab-dadd-4b15-94ef-a90be9fd7095';
     if ($id === $verificationGuid) {
         log_message('debug', 'Daily Invoices: Start');
         $screenOutput = "<h3>Daily Invoicing</h3>";
         try {
             $this->load->model("usermodel");
             $userList = $this->usermodel->getUsers();
             log_message('debug', 'Daily Invoices: Found ' . count($userList) . ' users');
             $screenOutput .= 'Daily Invoices: Found ' . count($userList) . ' users<br/><br/>';
             foreach ($userList as $user) {
                 $account = RecurlyAccount::getAccount($user->id);
                 //if ($user->email_address === "*****@*****.**") {
                 //	$account->chargeAccount(12.34, 'Charging $12.34 to account from unittest');
                 //}
                 if (isset($account)) {
                     $invoice = RecurlyInvoice::createInvoice($account->account_code);
                     if (isset($invoice)) {
                         $screenOutput .= 'Invoiced account: Name = ' . $user->first_name . ' ' . $user->last_name . ', Account Code = ' . $user->id . '<br/>';
                         log_message('debug', 'Daily Invoices: Invoiced user. Name = ' . $user->first_name . ' ' . $user->last_name . ', Account Code = ' . $user->id);
                     } else {
                         $screenOutput .= 'No charges for account: Name = ' . $user->first_name . ' ' . $user->last_name . ', Account Code = ' . $user->id . '<br/>';
                     }
                 } else {
                     $screenOutput .= 'No Recurly account found for ' . $user->first_name . ' ' . $user->last_name . ', Account Code = ' . $user->id . '<br/>';
                 }
             }
         } catch (Exception $e) {
             $screenOutput .= 'Error occurred: Reason: ' + $e->getMessage() . '<br/>';
             log_message('error', 'Daily Invoices: Failed. Reason: ' + $e->getMessage());
         }
         $screenOutput .= '<br/>Invoicing complete';
         log_message('debug', 'Daily Invo ices: Finished');
         $to = EMAIL_G_ADMIN;
         $subject = "[GRIND INVOICING REPORT]";
         $body = $screenOutput;
         $headers = "From: " . EMAIL_G_ADMIN . "\r\n" . "Reply-To: " . EMAIL_G_ADMIN . "\r\n" . "X-Mailer: PHP/" . phpversion() . "\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: text/html; charset=ISO-8859-1\r\n";
         mail($to, $subject, $body, $headers);
         echo $screenOutput;
     } else {
         echo 'Invalid calling entity';
         log_message('error', 'Daily Invoices: Cron job is passing the wrong id parameter value. It should be ' . $verificationGuid);
     }
 }
Пример #2
0
 function getChargesAndCredits($userId)
 {
     $retval = array();
     $acct = RecurlyAccount::getAccount($userId);
     if ($acct) {
         $charges = $acct->listCharges();
         $credits = $acct->listCredits();
         /*
          echo "<pre>";
         print_r($charges);
         echo "</pre>";
         */
         if ($charges) {
             foreach ($charges as $id => $charge) {
                 $retval[$charge->created_at . "D"]->amount = $charge->amount_in_cents / 100;
                 $retval[$charge->created_at . "D"]->description = $charge->description;
                 $retval[$charge->created_at . "D"]->date = date("m/d/Y H:i:s", $charge->created_at);
                 $retval[$charge->created_at . "D"]->invoice = $charge->invoice_number;
             }
         }
         if ($credits) {
             foreach ($credits as $id => $credit) {
                 $retval[$credit->created_at . "C"]->amount = $credit->amount_in_cents / 100;
                 $retval[$credit->created_at . "C"]->description = $credit->description;
                 $retval[$credit->created_at . "C"]->date = date("m/d/Y H:i:s", $credit->created_at);
                 $retval[$credit->created_at . "C"]->invoice = $credit->invoice_number;
             }
         }
         ksort($retval);
         $revRetval = array_reverse($retval);
     }
     return $revRetval;
 }
Пример #3
0
 public function update($id = null)
 {
     error_log("are we even updating?", 0);
     $this->db->where('user_login', $this->email->address);
     $this->db->from('wpmember_users');
     $count = $this->db->count_all_results();
     if ($count < 1) {
         //New email is unique
         if ($this->email->is_primary) {
             //because it is the primary email address
             // we need to change it in GRIND DB, BILLING DB, AND WPDB
             $this->db->trans_begin();
             //first update wordpress
             $sql = "update wpmember_users wp JOIN user u ON wp.id = u.wp_users_id SET wp.user_login = '******', wp.user_email = '" . $this->email->address . "' WHERE u.id=" . $this->email->user_id;
             $result = $this->db->query($sql);
             if ($this->db->trans_status() === FALSE) {
                 error_log("Couldn't update wordpress", 0);
                 $this->db->trans_rollback();
                 throw new exception("Couldn't update wordpress");
             }
             //now update grind
             $this->db->set("user_id", $this->email->user_id);
             $this->db->set("is_primary", $this->email->is_primary);
             $this->db->set("email_type_luid", $this->email->email_type_luid);
             $this->db->set("address", $this->email->address);
             $this->db->where("id", $this->email->id);
             $result = $this->db->update('email');
             error_log("grind failed", 0);
             if ($this->db->trans_status() === FALSE) {
                 $this->db->trans_rollback();
                 throw new exception("Couldn't update grind");
             }
             //now update recurly
             $account = RecurlyAccount::getAccount($this->email->user_id);
             $account->email = $this->email->address;
             $account->username = $this->email->address;
             $result = $account->update();
             if (!$result) {
                 $this->db->trans_rollback();
                 error_log("recurly failed", 0);
                 throw new exception("Couldn't update recurly");
             }
             if ($this->db->trans_status() === FALSE) {
                 $this->db->trans_rollback();
                 error_log("something went wrong with email update", 0);
             } else {
                 error_log("email shoud be updated logging email update", 0);
                 $this->db->trans_commit();
             }
         } else {
             // not the primary email address so just update it in Grind
             error_log("thinks not primary address", 0);
             $this->db->set("user_id", $this->email->user_id);
             $this->db->set("is_primary", $this->email->is_primary);
             $this->db->set("email_type_luid", $this->email->email_type_luid);
             $this->db->set("address", $this->email->address);
             $this->db->where("id", $this->email->id);
             $result = $this->db->update('email');
         }
     } else {
         error_log("thinks email already taken", 0);
         throw new exception("Email Address is already taken");
     }
 }
 public function wpUpdateEmail()
 {
     session_start();
     try {
         if (isset($_POST['email'])) {
             //Check for unique email address/username in Wordpress
             $this->db->where('user_login', $_POST['email']);
             $this->db->from('wpmember_users');
             $count = $this->db->count_all_results();
             if ($count < 1) {
                 //New email is unique
                 //Change username and email in WP db
                 $data = array('user_login' => $_POST['email'], 'user_email' => $_POST['email']);
                 $this->db->where('ID', $_SESSION['wpuser']['wp_users_id']);
                 $this->db->update('wpmember_users', $data);
                 //Change primary email address in Grind db
                 $this->load->model("usermodel", "", true);
                 $this->usermodel->init($_SESSION['wpuser']['wp_users_id'], UserIdType::WORDPRESSID);
                 $this->usermodel->wpUpdateEmail($_POST);
                 //Update recurly email address
                 $account = RecurlyAccount::getAccount($_SESSION['wpuser']['id']);
                 $account->email = $_POST['email'];
                 $account->username = $_POST['email'];
                 $account->update();
                 //Return success
                 echo json_encode(array("success" => 1));
             } else {
                 //new email is not unique
                 echo json_encode(array("success" => 0, "reason" => "NOTUNIQUE"));
             }
         } else {
             echo json_encode(array("success" => 0, "reason" => "EMAILEMPTY"));
         }
     } catch (Exception $e) {
         echo json_encode(array("success" => 0, "reason" => "SYSTEMERROR"));
     }
 }
Пример #5
0
    if (mysql_num_rows($results) > 0) {
        echo '<style type="text/css"> td { text-align:center; }</style>';
        echo '<div style="margin:0 auto; width:940px; padding:0 20px 20px 20px; margin-top:100px;">';
        echo '<table style="width:100%;">' . "\n";
        echo '<tr>
				<th>Subscriber name</th>
				<th>Membership Plan</th>
				<th>Recurly Balance</th>
			 </tr>';
        //while ($row = mysql_fetch_assoc($results)) {
        while ($info = mysql_fetch_object($results)) {
            #print_r($info);
            echo '<tr>';
            echo '<td>' . $info->name . '</td>';
            echo '<td>' . $info->plan_code . '</td>';
            $account = RecurlyAccount::getAccount($info->wp_users_id);
            echo '<td>$' . number_format($account->balance_in_cents) . '</td>';
            echo '</tr>';
        }
        // end while
        echo '</table>';
        echo '</div>';
    } else {
        $contents_checkins .= "User data empty,";
        $errormsg = "User dump unsuccessful (No Results)";
        $msg .= $errormsg . "\n";
        throw new Exception($errormsg);
    }
} catch (Exception $e) {
    $msg .= 'Error occurred: Reason: ' + $e->getMessage() . '<br/>';
    error_log('Daily Reporting: Failed. Reason: ' + $e->getMessage(), 0);