public function save() { // check if there is a non-masked credit card number in the input // if the second cararcter is a * then it's already masked $newcc = FALSE; // set to false so we don't replace it unnecessarily // get some inputs that we need to process this input $billing_id = $this->input->post('billing_id'); $billing_type = $this->input->post('billing_type'); $from_date = $this->input->post('from_date'); $creditcard_number = $this->input->post('creditcard_number'); // check if the credit card entered already masked and not blank // eg: a replacement was not entered if ($creditcard_number[1] != '*' and $creditcard_number != '') { // destroy the output array before we use it again unset($encrypted); // load the encryption helper for use when calling gpg things $this->load->helper('encryption'); // run the gpg command $encrypted = encrypt_command($this->config->item('gpg_command'), $creditcard_number); // if there is a gpg error, stop here if (substr($encrypted, 0, 5) == "error") { die("Credit Card Encryption Error: {$encrypted}"); } // change the ouput array into ascii ciphertext block $encrypted_creditcard_number = $encrypted; // wipe out the middle of the creditcard_number before it gets inserted $length = strlen($creditcard_number); $firstdigit = substr($creditcard_number, 0, 1); $lastfour = substr($creditcard_number, -4); $creditcard_number = "{$firstdigit}" . "***********" . "{$lastfour}"; $newcc = TRUE; } // fill in the billing data array with new info $billing_data = array('name' => $this->input->post('name'), 'company' => $this->input->post('company'), 'street' => $this->input->post('street'), 'city' => $this->input->post('city'), 'state' => $this->input->post('state'), 'zip' => $this->input->post('zip'), 'country' => $this->input->post('country'), 'phone' => $this->input->post('phone'), 'fax' => $this->input->post('fax'), 'billing_type' => $this->input->post('billing_type'), 'creditcard_expire' => $this->input->post('creditcard_expire'), 'next_billing_date' => $this->input->post('next_billing_date'), 'from_date' => $this->input->post('from_date'), 'payment_due_date' => $this->input->post('payment_due_date'), 'notes' => $this->input->post('notes'), 'pastdue_exempt' => $this->input->post('pastdue_exempt'), 'po_number' => $this->input->post('po_number'), 'automatic_receipt' => $this->input->post('automatic_receipt'), 'contact_email' => $this->input->post('contact_email')); // check if rerun_date should be NULL or not $rerun_date = $this->input->post('rerun_date'); if ($rerun_date == "0000-00-00") { // rerun date is null $billing_data['rerun_date'] = NULL; } else { // rerun date has something in it $billing_data['rerun_date'] = $rerun_date; } if ($newcc == TRUE) { // insert with a new credit card and encrypted ciphertext $billing_data['encrypted_creditcard_number'] = $encrypted_creditcard_number; $billing_data['creditcard_number'] = $creditcard_number; $billing_data['creditcard_expire'] = $this->input->post('creditcard_expire'); } elseif ($creditcard_number == '') { $billing_data['encrypted_creditcard_number'] = NULL; $billing_data['creditcard_number'] = NULL; $billing_data['creditcard_expire'] = NULL; } // save the data to the customer record $data = $this->billing_model->save_record($billing_id, $billing_data); // set the to_date automatically $this->billing_model->automatic_to_date($from_date, $billing_type, $billing_id); // add a log entry that this billing record was edited $this->log_model->activity($this->user, $this->account_number, 'edit', 'billing', $billing_id, 'success', $_SERVER['REMOTE_ADDR']); redirect('/billing'); }
public function encryptcards() { // load models $this->load->model('billing_model'); $this->load->model('support_model'); $this->load->model('settings_model'); // load the encryption helper for use when calling gpg things $this->load->helper('encryption'); $result = $this->billing_model->list_creditcards(); // walk through each individual result foreach ($result as $myresult) { echo "counter: {$i}\n"; $id = $myresult['id']; $creditcard_number = $myresult['creditcard_number']; // check if there is a non-masked credit card number in the input // if the second cararcter is a * then it's already masked // check if the credit card entered already masked // eg: a replacement was not entered if ($creditcard_number[1] != '*') { // destroy the output array before we use it again unset($encrypted); $encrypted = encrypt_command($this->config->item('gpg_command'), $creditcard_number); // if there is a gpg error, stop here if (substr($encrypted, 0, 5) == "error") { die("Credit Card Encryption Error: {$encrypted}"); } $encrypted_creditcard_number = $encrypted; // wipe out the middle of the creditcard_number before it gets inserted $firstdigit = substr($creditcard_number, 0, 1); $lastfour = substr($creditcard_number, -4); $creditcard_number = "{$firstdigit}" . "***********" . "{$lastfour}"; //echo "$gpgcommandline<pre>$encrypted_creditcard_number</pre>\n"; $this->billing_model->input_encrypted_card($creditcard_number, $encrypted_creditcard_number, $id); print "{$id} creditcard updated {$encrypted_creditcard_number}\n"; } else { print "{$id} skipped\n"; } // end if creditcard_number } // end while myresult }
function billing_post() { // check if there is a non-masked credit card number in the input // if the second cararcter is a * then it's already masked $newcc = FALSE; // set to false so we don't replace it unnecessarily $creditcard_number = $this->post('creditcard_number'); // check if the credit card entered already masked and not blank // eg: a replacement was not entered if ($creditcard_number[1] != '*' and $creditcard_number != '') { // destroy the output array before we use it again unset($encrypted); // load the encryption helper for use when calling gpg things $this->load->helper('encryption'); // run the gpg command $encrypted = encrypt_command($this->config->item('gpg_command'), $creditcard_number); // if there is a gpg error, stop here if (substr($encrypted, 0, 5) == "error") { die("Credit Card Encryption Error: {$encrypted}"); } // change the ouput array into ascii ciphertext block $encrypted_creditcard_number = $encrypted; // wipe out the middle of the creditcard_number before it gets inserted $length = strlen($creditcard_number); $firstdigit = substr($creditcard_number, 0, 1); $lastfour = substr($creditcard_number, -4); $creditcard_number = "{$firstdigit}" . "***********" . "{$lastfour}"; $newcc = TRUE; } // fill in the billing data array with new address $billing_data = array('name' => $this->input->post('name'), 'company' => $this->input->post('company'), 'street' => $this->input->post('street'), 'city' => $this->input->post('city'), 'state' => $this->input->post('state'), 'zip' => $this->input->post('zip'), 'country' => $this->input->post('country'), 'phone' => $this->input->post('phone'), 'fax' => $this->input->post('fax'), 'contact_email' => $this->input->post('contact_email'), 'creditcard_expire' => $this->input->post('creditcard_expire')); // if they are providing a new credit card, put that in the array too if ($newcc == TRUE) { // insert with a new credit card and encrypted ciphertext $billing_data['encrypted_creditcard_number'] = $encrypted_creditcard_number; $billing_data['creditcard_number'] = $creditcard_number; } // update address and card on each billing ID they have $this->load->model('billing_model'); $record_list = $this->billing_model->record_list($this->authuser); foreach ($record_list as $record) { $record_billing_id = $record['b_id']; // save the data to the customer record $data = $this->billing_model->save_record($record_billing_id, $billing_data); // add a log entry that this billing record was edited $this->log_model->activity("portal", $this->authuser, 'edit', 'billing', $record_billing_id, 'success', $_SERVER['REMOTE_ADDR']); } $this->response(array('success' => 'Input Saved'), 200); }