public static function export($encrypt = true) { if (!self::$connection) { self::connect(); } $tableActions = array(); $insertString = ''; $tables = mysql_query('SHOW TABLES'); while ($table = mysql_fetch_row($tables)) { //Stuktur exportieren $creationString = mysql_fetch_row(mysql_query('SHOW CREATE TABLE ' . $table[0])); $insertString = "DROP TABLE IF EXISTS `" . $table[0] . "`;\n" . $creationString[1] . ";\n"; $fields = mysql_query('DESCRIBE `' . $table[0] . "`"); $insertHead = "\nINSERT INTO `" . $table[0] . "` (" . self::getInsertionHeadFormat($fields) . ") VALUES \n"; $data = mysql_query('SELECT * FROM `' . $table[0] . "`"); $dataArray = self::getInsertionDataArray($data); $rowsPerInsert = 100; $dataCount = count($dataArray); for ($i = 0; $i < $dataCount; $i += $rowsPerInsert) { $currentData = array_slice($dataArray, $i, $rowsPerInsert); $insertString .= $insertHead; $insertString .= implode(",\n ", $currentData) . ";"; } array_push($tableActions, $insertString); } mysql_close(); $res = implode("\n\n\n", $tableActions); if ($encrypt) { $res = ENCRYPTIONSIGNAL . base64_encode(Security::rijndael($res, Configure::read('Security.key'), 'encrypt')); } return $res; }
public function afterFind($results = array(), $primary = false) { foreach ($this->encryptedFields as $fieldName) { foreach ($results as $key => $value) { if (!empty($results[$key][$this->alias][$fieldName])) { $results[$key][$this->alias][$fieldName] = Security::rijndael($results[$key][$this->alias][$fieldName], Configure::read('Security.key'), 'decrypt'); } } } return $results; }
public function main() { $this->out(date("Y-m-d H:i:s") . ' - Start'); $this->Billing->recursive = 0; /* Nightly Payments Update Logic ------------------------ //Logic to //Create new billing cycle Get all Units Loop through each unit If Unit Has Resident if Current_Due_Date <= today AND Current_Due_Date < Lease_End Create New Billing Cycle Calculate Rent Due = Rent Total + One Time Fee + Recurring Fee - Free Rent + CC fees - Rent Credit ACH => Rent Total + recurring fee - free rent + fee $3.95 (fee only if tenant paying fees) CC/Debit - Rent Total + recurring fee - free rent + fee 2.75% (fee only if tenant percent) Update last due date if has one time fee, create record */ //Find All Units $units = $this->Billing->Unit->find('all', array('conditions' => array('Unit.active' => 1))); //Loop through each Unit foreach ($units as $unit) { //if unit has residents if ($this->User->find('count', array('conditions' => array('User.unit_id' => $unit['Unit']['id']))) > 0) { //if Current Due Date <= Today and Current Due Date < End of Lease, then Create New Record $current_due_date = strtotime($unit['Unit']['current_due_date']); if ($current_due_date <= time() && $current_due_date < strtotime($unit['Unit']['lease_end'])) { $data = array(); $billing_end = $this->Billing->Unit->set_billing_end_date($unit['Unit']['billing_frequency'], $unit['Unit']['current_due_date'], $unit['Unit']['monthly_day']); $rent_period = $this->Billing->Unit->set_billing_end_date($unit['Unit']['billing_frequency'], $billing_end, $unit['Unit']['monthly_day']); $total_fees = $this->Billing->Unit->getRentTotal($unit['Unit']['id'], date("Y-m-d H:i:s", strtotime($unit['Unit']['current_due_date'])), $billing_end); $data["Billing"] = array('unit_id' => $unit['Unit']['id'], 'property_id' => $unit['Unit']['property_id'], 'rent_due' => $total_fees['Rent']['Total'], 'balance' => $total_fees['Rent']['Total'], 'status' => 'unpaid', 'billing_start' => date("Y-m-d H:i:s", strtotime($unit['Unit']['current_due_date'])), 'billing_end' => $billing_end, 'rent_period' => $rent_period); $data['BillingFee'] = $total_fees['BillingFee']; $this->Billing->create(); if ($this->Billing->saveAll($data)) { $this->out('Billing #' . $this->Billing->id . ' created for Unit' . $unit['Unit']['number']); //Check for Unit Credit if (floatval($unit['Unit']['rent_credit']) > 0) { //Determine amount of credit to use $credit_amount = 0; //if credit is greater than rent due, subtract rent due from credit if (floatval($unit['Unit']['rent_credit']) > $total_fees['Rent']['Total']) { $credit_amount = floatval($unit['Unit']['rent_credit']) - floatval($total_fees['Rent']['Total']); } else { $credit_amount = floatval($unit['Unit']['rent_credit']); } $payment["Payment"] = array('billing_id' => $this->Billing->id, 'unit_id' => $unit['Unit']['id'], 'user_id' => 1, 'type' => 'Credit', 'amount' => $credit_amount, 'status' => 'Complete', 'notes' => 'Unit Credit'); //save payment $this->Billing->Payment->create(); if ($this->Billing->Payment->saveAll($payment)) { //update credit $this->Unit->id = $unit['Unit']['id']; $this->Unit->saveField('credit', $unit['Unit']['rent_credit'] - $credit_amount); } } } //Update current due date $this->Billing->Unit->id = $unit['Unit']['id']; $this->Billing->Unit->saveField('current_due_date', $billing_end); if (strtotime($billing_end) < time()) { $this->out(date("Y-m-d H:i:s") . ' - Billing End Date is before Today for Unit ' . $unit['Unit']['id']); } } else { //Do nothing } //if has one time fee, create record foreach ($unit['UnitFee'] as $unit_fee) { if ($unit_fee['one_time'] && $unit_fee['one_time_status'] == 'P') { //P -> Pending //Create Billing $data = array(); $data["Billing"] = array('unit_id' => $unit['Unit']['id'], 'property_id' => $unit['Unit']['property_id'], 'rent_due' => $unit_fee['amount'], 'balance' => $unit_fee['amount'], 'status' => 'unpaid', 'billing_start' => date("Y-m-d H:i:s"), 'billing_end' => date("Y-m-d H:i:s", strtotime($unit_fee['one_time_date'])), 'type' => 'One Time Fee'); $data['BillingFee'][0]['name'] = 'One Time Fee - ' . $unit_fee['name']; $data['BillingFee'][0]['amount'] = floatval($unit_fee['amount']); $this->Billing->create(); if ($this->Billing->saveAll($data)) { $this->out('Billing Cycle #' . $this->Billing->id . ' created for One Time Fee for Unit' . $unit['Unit']['number']); $this->Billing->Unit->UnitFee->id = $unit_fee['id']; $this->Billing->Unit->UnitFee->saveField('one_time_status', 'C'); //__sendOneTimeFeeMail } } // if Unit Fee is One Time Fee } //foreach Unit Fee } //if unit has resident } //foreach unit $this->out(date("Y-m-d H:i:s") . ' - All Unit Loop Complete'); /* Get all open Billing Cycles not paid (unpaid,due,late) if unpaid check if paid mark as paid if no paid if due date = current date set status = due check Reminder Email [email_for_rent] else check Invoice Email [invoice_day] check Reminder Email [before_due_reminder][before_due_days] if due check if paid mark as paid if no pay mark as late if late assign late fee */ $this->Billing->Behaviors->load('Containable'); $billing_cycles = $this->Billing->find('all', array('conditions' => array('status !=' => 'paid'), 'contain' => array('Unit' => array('Property')))); foreach ($billing_cycles as $billing_cycle) { $this->Billing->id = $billing_cycle['Billing']['id']; $total_payments = 0; $total_payments = $this->Billing->Payment->find('all', array('fields' => 'sum(Payment.amount) as total_payment', 'conditions' => array('Payment.billing_id' => $billing_cycle['Billing']['id']))); $total_paid = $total_payments[0][0]['total_payment']; if ($total_paid > $billing_cycle['Billing']['rent_due']) { //Over Paid //Mark as Paid $this->Billing->saveField('status', 'paid'); //Add Credit [Add Code] } else { if ($total_paid == $billing_cycle['Billing']['rent_due']) { //Paid In full //Mark as Paid $this->Billing->saveField('status', 'paid'); } else { if (0 >= $billing_cycle['Billing']['rent_due']) { //If Rent is 0, Mark as Paid $this->Billing->saveField('status', 'paid'); } else { //Not Paid //if due date = current date if (date('Ymd', strtotime($billing_cycle['Billing']['billing_end'])) == date('Ymd')) { // set status = due $this->Billing->saveField('status', 'due'); //if tenant checked Rent Reminder Email [User][email_for_rent], send email $tenants = $this->User->find('all', array('conditions' => array('User.unit_id' => $billing_cycle['Billing']['unit_id']), 'contain' => array('AutoPayment' => array('order' => 'AutoPayment.created DESC', 'limit' => 1), 'PaymentMethod', 'Property'))); foreach ($tenants as $tenant) { //Check to see if tenant has auto pay on if (isset($tenant['AutoPayment']) && count($tenant['AutoPayment']) > 0 && $billing_cycle['Billing']['type'] == 'Rent') { //If active and in time frame if ($tenant['AutoPayment'][0]['active'] && (strtotime($tenant['AutoPayment'][0]['auto_start']) <= time() && time() <= strtotime($tenant['AutoPayment'][0]['auto_end']))) { //$tenant['AutoPayment'][0]['vault_id'] //$tenant['AutoPayment'][0]['amount'] //Charge Fee based on ACH or CC //Determine Transaction Fees $pay_amount = $tenant['AutoPayment'][0]['amount']; $total_amount = 0; //Is selected payment CC or ACH //ACH => Rent Total + recurring fee - free rent + fee $3.95 (fee only if tenant paying fees) //CC/Debit - Rent Total + recurring fee - free rent + fee 2.75% (fee only if tenant percent) //if ACH //if tenant pays //add $3.95 //else CC //if tenant pays //add2.75% $i = 0; foreach ($tenant['PaymentMethod'] as $paymentMethod) { if ($paymentMethod['vault_id'] == $tenant['AutoPayment'][0]['vault_id']) { $paymentType = $tenant['PaymentMethod'][$i]['type']; break; } $i++; } if ($paymentType == 'CC') { //Payment is Credit Card if ($tenant['Property']['prop_pays_cc_fee']) { $pay_fee = floatval($pay_amount) * floatval(CC_FEE); $total_amount = floatval($pay_amount) - floatval($pay_fee); $result = $this->Payment->processPayment($total_amount, $tenant['AutoPayment'][0]['vault_id'], $tenant['Property']['pp_user'], Security::rijndael($tenant['Property']['pp_pass'], Configure::read('Security.salt2'), 'decrypt')); parse_str($result); if (isset($response) && $response == 1) { $auto_payment = array(); $auto_payment['Payment']['ppresponse'] = $response; $auto_payment['Payment']['ppresponsetext'] = $responsetext; $auto_payment['Payment']['ppauthcode'] = $authcode; $auto_payment['Payment']['pptransactionid'] = $transactionid; $auto_payment['Payment']['ppresponse_code'] = $response_code; $auto_payment['Payment']['status'] = 'Complete'; $auto_payment['Payment']['type'] = 'Auto CC'; $auto_payment['Payment']['notes'] = 'Auto Payment'; $auto_payment['Payment']['user_id'] = $tenant['User']['id']; $auto_payment['Payment']['billing_id'] = $billing_cycle['Billing']['id']; $auto_payment['Payment']['unit_id'] = $billing_cycle['Billing']['unit_id']; $auto_payment['Payment']['amount'] = $tenant['AutoPayment'][0]['amount']; $auto_payment['Payment']['is_fee'] = 0; $auto_payment['Payment']['amt_processed'] = floatval($total_amount); $auto_payment['Payment']['total_bill'] = floatval($pay_amount); //Add to Payments Table $this->Payment->create(); if ($this->Payment->save($auto_payment)) { $this->Billing->updatebillingstatus($billing_cycle['Billing']['id']); $this->out($billing_cycle['Billing']['id'] . ' - Applied Auto Payment of ' . $tenant['AutoPayment'][0]['amount']); //Send Email Payment was processed $email_data['name'] = $tenant['User']['first_name']; $email_data['amount'] = $total_amount; $email_data['trans_id'] = $transactionid; $email_data['unit_name'] = $billing_cycle['Unit']['number']; $email_data['prop_name'] = $billing_cycle['Unit']['Property']['name']; if ($this->__sendAutoPaymentSuccess($tenant['User']['email'], $email_data)) { $this->out('Payment Received Email sent to ' . $tenant['User']['email']); } } } else { //$failed=$data; $failed = array(); $failed['FailedPayment']['billing_id'] = $billing_cycle['Billing']['id']; $failed['FailedPayment']['unit_id'] = $billing_cycle['Billing']['unit_id']; $failed['FailedPayment']['user_id'] = $tenant['User']['id']; $failed['FailedPayment']['amount'] = $tenant['AutoPayment'][0]['amount']; $failed['FailedPayment']['type'] = 'Auto CC'; $failed['FailedPayment']['ppresponse'] = $response; $failed['FailedPayment']['ppresponsetext'] = $responsetext; $failed['FailedPayment']['ppauthcode'] = $authcode; $failed['FailedPayment']['pptransactionid'] = $transactionid; $failed['FailedPayment']['ppresponse_code'] = $response_code; if ($this->FailedPayment->save($failed)) { $this->out($billing_cycle['Billing']['id'] . ' - Auto Payment FAILED'); } } $result = $this->Payment->processPayment($pay_fee, $tenant['AutoPayment'][0]['vault_id'], RENTSQUARE_MERCH_USER, RENTSQUARE_MERCH_PASS); parse_str($result); if (isset($response) && $response == 1) { $auto_payment = array(); $auto_payment['Payment']['ppresponse'] = $response; $auto_payment['Payment']['ppresponsetext'] = $responsetext; $auto_payment['Payment']['ppauthcode'] = $authcode; $auto_payment['Payment']['pptransactionid'] = $transactionid; $auto_payment['Payment']['ppresponse_code'] = $response_code; $auto_payment['Payment']['status'] = 'Complete'; $auto_payment['Payment']['type'] = 'Auto CC'; $auto_payment['Payment']['notes'] = 'Auto Payment'; $auto_payment['Payment']['user_id'] = $tenant['User']['id']; $auto_payment['Payment']['billing_id'] = $billing_cycle['Billing']['id']; $auto_payment['Payment']['unit_id'] = $billing_cycle['Billing']['unit_id']; $auto_payment['Payment']['amount'] = 0; $auto_payment['Payment']['is_fee'] = 1; $auto_payment['Payment']['amt_processed'] = floatval($pay_fee); $auto_payment['Payment']['total_bill'] = floatval($pay_amount); //Add to Payments Table $this->Payment->create(); if ($this->Payment->save($auto_payment)) { $this->Billing->updatebillingstatus($billing_cycle['Billing']['id']); $this->out($billing_cycle['Billing']['id'] . ' - Applied Auto Payment of ' . $tenant['AutoPayment'][0]['amount']); //Send Email Payment was processed $email_data['name'] = $tenant['User']['first_name']; $email_data['amount'] = $total_amount; $email_data['trans_id'] = $transactionid; $email_data['unit_name'] = $billing_cycle['Unit']['number']; $email_data['prop_name'] = $billing_cycle['Unit']['Property']['name']; if ($this->__sendAutoPaymentSuccess($tenant['User']['email'], $email_data)) { $this->out('Payment Received Email sent to ' . $tenant['User']['email']); } } } else { //$failed=$data; $failed = array(); $failed['FailedPayment']['billing_id'] = $billing_cycle['Billing']['id']; $failed['FailedPayment']['unit_id'] = $billing_cycle['Billing']['unit_id']; $failed['FailedPayment']['user_id'] = $tenant['User']['id']; $failed['FailedPayment']['amount'] = $tenant['AutoPayment'][0]['amount']; $failed['FailedPayment']['type'] = 'Auto CC'; $failed['FailedPayment']['ppresponse'] = $response; $failed['FailedPayment']['ppresponsetext'] = $responsetext; $failed['FailedPayment']['ppauthcode'] = $authcode; $failed['FailedPayment']['pptransactionid'] = $transactionid; $failed['FailedPayment']['ppresponse_code'] = $response_code; if ($this->FailedPayment->save($failed)) { $this->out($billing_cycle['Billing']['id'] . ' - Auto Payment FAILED'); } } } else { $pay_fee = floatval($pay_amount) * floatval(CC_FEE); $total_amount = floatval($pay_amount); $result = $this->Payment->processPayment($total_amount, $tenant['AutoPayment'][0]['vault_id'], $tenant['Property']['pp_user'], Security::rijndael($tenant['Property']['pp_pass'], Configure::read('Security.salt2'), 'decrypt')); parse_str($result); if (isset($response) && $response == 1) { $auto_payment = array(); $auto_payment['Payment']['ppresponse'] = $response; $auto_payment['Payment']['ppresponsetext'] = $responsetext; $auto_payment['Payment']['ppauthcode'] = $authcode; $auto_payment['Payment']['pptransactionid'] = $transactionid; $auto_payment['Payment']['ppresponse_code'] = $response_code; $auto_payment['Payment']['type'] = 'Auto CC'; $auto_payment['Payment']['status'] = 'Complete'; $auto_payment['Payment']['notes'] = 'Auto Payment'; $auto_payment['Payment']['user_id'] = $tenant['User']['id']; $auto_payment['Payment']['billing_id'] = $billing_cycle['Billing']['id']; $auto_payment['Payment']['unit_id'] = $billing_cycle['Billing']['unit_id']; $auto_payment['Payment']['amount'] = $tenant['AutoPayment'][0]['amount']; $auto_payment['Payment']['is_fee'] = 0; $auto_payment['Payment']['amt_processed'] = floatval($total_amount); $auto_payment['Payment']['total_bill'] = floatval($pay_amount) + floatval($pay_fee); //Add to Payments Table $this->Payment->create(); if ($this->Payment->save($auto_payment)) { $this->Billing->updatebillingstatus($billing_cycle['Billing']['id']); $this->out($billing_cycle['Billing']['id'] . ' - Applied Auto Payment of ' . $tenant['AutoPayment'][0]['amount']); //Send Email Payment was processed $email_data['name'] = $tenant['User']['first_name']; $email_data['amount'] = $total_amount; $email_data['trans_id'] = $transactionid; $email_data['unit_name'] = $billing_cycle['Unit']['number']; $email_data['prop_name'] = $billing_cycle['Unit']['Property']['name']; if ($this->__sendAutoPaymentSuccess($tenant['User']['email'], $email_data)) { $this->out('Payment Received Email sent to ' . $tenant['User']['email']); } } } else { //$failed=$data; $failed = array(); $failed['FailedPayment']['billing_id'] = $billing_cycle['Billing']['id']; $failed['FailedPayment']['unit_id'] = $billing_cycle['Billing']['unit_id']; $failed['FailedPayment']['user_id'] = $tenant['User']['id']; $failed['FailedPayment']['amount'] = $tenant['AutoPayment'][0]['amount']; $failed['FailedPayment']['type'] = 'Auto CC'; $failed['FailedPayment']['ppresponse'] = $response; $failed['FailedPayment']['ppresponsetext'] = $responsetext; $failed['FailedPayment']['ppauthcode'] = $authcode; $failed['FailedPayment']['pptransactionid'] = $transactionid; $failed['FailedPayment']['ppresponse_code'] = $response_code; if ($this->FailedPayment->save($failed)) { $this->out($billing_cycle['Billing']['id'] . ' - Auto Payment FAILED'); } } $result = $this->Payment->processPayment($pay_fee, $tenant['AutoPayment'][0]['vault_id'], RENTSQUARE_MERCH_USER, RENTSQUARE_MERCH_PASS); parse_str($result); if (isset($response) && $response == 1) { $auto_payment = array(); $auto_payment['Payment']['ppresponse'] = $response; $auto_payment['Payment']['ppresponsetext'] = $responsetext; $auto_payment['Payment']['ppauthcode'] = $authcode; $auto_payment['Payment']['pptransactionid'] = $transactionid; $auto_payment['Payment']['ppresponse_code'] = $response_code; $auto_payment['Payment']['type'] = 'Auto CC'; $auto_payment['Payment']['status'] = 'Complete'; $auto_payment['Payment']['notes'] = 'Auto Payment'; $auto_payment['Payment']['user_id'] = $tenant['User']['id']; $auto_payment['Payment']['billing_id'] = $billing_cycle['Billing']['id']; $auto_payment['Payment']['unit_id'] = $billing_cycle['Billing']['unit_id']; $auto_payment['Payment']['amount'] = 0; $auto_payment['Payment']['is_fee'] = 1; $auto_payment['Payment']['amt_processed'] = floatval($pay_fee); $auto_payment['Payment']['total_bill'] = floatval($pay_amount) + floatval($pay_fee); //Add to Payments Table $this->Payment->create(); if ($this->Payment->save($auto_payment)) { $this->Billing->updatebillingstatus($billing_cycle['Billing']['id']); $this->out($billing_cycle['Billing']['id'] . ' - Applied Auto Payment of ' . $tenant['AutoPayment'][0]['amount']); //Send Email Payment was processed $email_data['name'] = $tenant['User']['first_name']; $email_data['amount'] = $total_amount; $email_data['trans_id'] = $transactionid; $email_data['unit_name'] = $billing_cycle['Unit']['number']; $email_data['prop_name'] = $billing_cycle['Unit']['Property']['name']; if ($this->__sendAutoPaymentSuccess($tenant['User']['email'], $email_data)) { $this->out('Payment Received Email sent to ' . $tenant['User']['email']); } } } else { //$failed=$data; $failed = array(); $failed['FailedPayment']['billing_id'] = $billing_cycle['Billing']['id']; $failed['FailedPayment']['unit_id'] = $billing_cycle['Billing']['unit_id']; $failed['FailedPayment']['user_id'] = $tenant['User']['id']; $failed['FailedPayment']['amount'] = $tenant['AutoPayment'][0]['amount']; $failed['FailedPayment']['type'] = 'Auto CC'; $failed['FailedPayment']['ppresponse'] = $response; $failed['FailedPayment']['ppresponsetext'] = $responsetext; $failed['FailedPayment']['ppauthcode'] = $authcode; $failed['FailedPayment']['pptransactionid'] = $transactionid; $failed['FailedPayment']['ppresponse_code'] = $response_code; if ($this->FailedPayment->save($failed)) { $this->out($billing_cycle['Billing']['id'] . ' - Auto Payment FAILED'); } } } } else { //Payment is ACH if ($tenant['Property']['prop_pays_ach_fee']) { $pay_fee = floatval(ACH_FEE); $total_amount = floatval($pay_amount) - $pay_fee; $result = $this->Payment->processPayment($total_amount, $tenant['AutoPayment'][0]['vault_id'], $tenant['Property']['pp_user'], Security::rijndael($tenant['Property']['pp_pass'], Configure::read('Security.salt2'), 'decrypt')); parse_str($result); if (isset($response) && $response == 1) { $auto_payment = array(); $auto_payment['Payment']['ppresponse'] = $response; $auto_payment['Payment']['ppresponsetext'] = $responsetext; $auto_payment['Payment']['ppauthcode'] = $authcode; $auto_payment['Payment']['pptransactionid'] = $transactionid; $auto_payment['Payment']['ppresponse_code'] = $response_code; $auto_payment['Payment']['type'] = 'Auto ACH'; $auto_payment['Payment']['status'] = 'Complete'; $auto_payment['Payment']['notes'] = 'Auto Payment'; $auto_payment['Payment']['user_id'] = $tenant['User']['id']; $auto_payment['Payment']['billing_id'] = $billing_cycle['Billing']['id']; $auto_payment['Payment']['unit_id'] = $billing_cycle['Billing']['unit_id']; $auto_payment['Payment']['amount'] = $tenant['AutoPayment'][0]['amount']; $auto_payment['Payment']['is_fee'] = 0; $auto_payment['Payment']['amt_processed'] = floatval($total_amount); $auto_payment['Payment']['total_bill'] = floatval($pay_amount); //Add to Payments Table $this->Payment->create(); if ($this->Payment->save($auto_payment)) { $this->Billing->updatebillingstatus($billing_cycle['Billing']['id']); $this->out($billing_cycle['Billing']['id'] . ' - Applied Auto Payment of ' . $tenant['AutoPayment'][0]['amount']); //Send Email Payment was processed $email_data['name'] = $tenant['User']['first_name']; $email_data['amount'] = $total_amount; $email_data['trans_id'] = $transactionid; $email_data['unit_name'] = $billing_cycle['Unit']['number']; $email_data['prop_name'] = $billing_cycle['Unit']['Property']['name']; if ($this->__sendAutoPaymentSuccess($tenant['User']['email'], $email_data)) { $this->out('Payment Received Email sent to ' . $tenant['User']['email']); } } } else { //$failed=$data; $failed = array(); $failed['FailedPayment']['billing_id'] = $billing_cycle['Billing']['id']; $failed['FailedPayment']['unit_id'] = $billing_cycle['Billing']['unit_id']; $failed['FailedPayment']['user_id'] = $tenant['User']['id']; $failed['FailedPayment']['amount'] = $tenant['AutoPayment'][0]['amount']; $failed['FailedPayment']['type'] = 'Auto ACH'; $failed['FailedPayment']['ppresponse'] = $response; $failed['FailedPayment']['ppresponsetext'] = $responsetext; $failed['FailedPayment']['ppauthcode'] = $authcode; $failed['FailedPayment']['pptransactionid'] = $transactionid; $failed['FailedPayment']['ppresponse_code'] = $response_code; if ($this->FailedPayment->save($failed)) { $this->out($billing_cycle['Billing']['id'] . ' - Auto Payment FAILED'); } } $result = $this->Payment->processPayment($pay_fee, $tenant['AutoPayment'][0]['vault_id'], RENTSQUARE_MERCH_USER, RENTSQUARE_MERCH_PASS); parse_str($result); if (isset($response) && $response == 1) { $auto_payment = array(); $auto_payment['Payment']['ppresponse'] = $response; $auto_payment['Payment']['ppresponsetext'] = $responsetext; $auto_payment['Payment']['ppauthcode'] = $authcode; $auto_payment['Payment']['pptransactionid'] = $transactionid; $auto_payment['Payment']['ppresponse_code'] = $response_code; $auto_payment['Payment']['type'] = 'Auto ACH'; $auto_payment['Payment']['status'] = 'Complete'; $auto_payment['Payment']['notes'] = 'Auto Payment'; $auto_payment['Payment']['user_id'] = $tenant['User']['id']; $auto_payment['Payment']['billing_id'] = $billing_cycle['Billing']['id']; $auto_payment['Payment']['unit_id'] = $billing_cycle['Billing']['unit_id']; $auto_payment['Payment']['amount'] = 0; $auto_payment['Payment']['is_fee'] = 1; $auto_payment['Payment']['amt_processed'] = floatval($pay_fee); $auto_payment['Payment']['total_bill'] = floatval($pay_amount); //Add to Payments Table $this->Payment->create(); if ($this->Payment->save($auto_payment)) { $this->Billing->updatebillingstatus($billing_cycle['Billing']['id']); $this->out($billing_cycle['Billing']['id'] . ' - Applied Auto Payment of ' . $tenant['AutoPayment'][0]['amount']); //Send Email Payment was processed $email_data['name'] = $tenant['User']['first_name']; $email_data['amount'] = $total_amount; $email_data['trans_id'] = $transactionid; $email_data['unit_name'] = $billing_cycle['Unit']['number']; $email_data['prop_name'] = $billing_cycle['Unit']['Property']['name']; if ($this->__sendAutoPaymentSuccess($tenant['User']['email'], $email_data)) { $this->out('Payment Received Email sent to ' . $tenant['User']['email']); } } } else { //$failed=$data; $failed = array(); $failed['FailedPayment']['billing_id'] = $billing_cycle['Billing']['id']; $failed['FailedPayment']['unit_id'] = $billing_cycle['Billing']['unit_id']; $failed['FailedPayment']['user_id'] = $tenant['User']['id']; $failed['FailedPayment']['amount'] = $tenant['AutoPayment'][0]['amount']; $failed['FailedPayment']['type'] = 'Auto ACH'; $failed['FailedPayment']['ppresponse'] = $response; $failed['FailedPayment']['ppresponsetext'] = $responsetext; $failed['FailedPayment']['ppauthcode'] = $authcode; $failed['FailedPayment']['pptransactionid'] = $transactionid; $failed['FailedPayment']['ppresponse_code'] = $response_code; if ($this->FailedPayment->save($failed)) { $this->out($billing_cycle['Billing']['id'] . ' - Auto Payment FAILED'); } } } else { $pay_fee = floatval(ACH_FEE); $total_amount = floatval($pay_amount); $result = $this->Payment->processPayment($total_amount, $tenant['AutoPayment'][0]['vault_id'], $tenant['Property']['pp_user'], Security::rijndael($tenant['Property']['pp_pass'], Configure::read('Security.salt2'), 'decrypt')); parse_str($result); if (isset($response) && $response == 1) { $auto_payment = array(); $auto_payment['Payment']['ppresponse'] = $response; $auto_payment['Payment']['ppresponsetext'] = $responsetext; $auto_payment['Payment']['ppauthcode'] = $authcode; $auto_payment['Payment']['pptransactionid'] = $transactionid; $auto_payment['Payment']['ppresponse_code'] = $response_code; $auto_payment['Payment']['type'] = 'Auto ACH'; $auto_payment['Payment']['status'] = 'Complete'; $auto_payment['Payment']['notes'] = 'Auto Payment'; $auto_payment['Payment']['user_id'] = $tenant['User']['id']; $auto_payment['Payment']['billing_id'] = $billing_cycle['Billing']['id']; $auto_payment['Payment']['unit_id'] = $billing_cycle['Billing']['unit_id']; $auto_payment['Payment']['amount'] = $tenant['AutoPayment'][0]['amount']; $auto_payment['Payment']['is_fee'] = 0; $auto_payment['Payment']['amt_processed'] = floatval($total_amount); $auto_payment['Payment']['total_bill'] = floatval($pay_amount) + floatval($pay_fee); //Add to Payments Table $this->Payment->create(); if ($this->Payment->save($auto_payment)) { $this->Billing->updatebillingstatus($billing_cycle['Billing']['id']); $this->out($billing_cycle['Billing']['id'] . ' - Applied Auto Payment of ' . $tenant['AutoPayment'][0]['amount']); //Send Email Payment was processed $email_data['name'] = $tenant['User']['first_name']; $email_data['amount'] = $total_amount; $email_data['trans_id'] = $transactionid; $email_data['unit_name'] = $billing_cycle['Unit']['number']; $email_data['prop_name'] = $billing_cycle['Unit']['Property']['name']; if ($this->__sendAutoPaymentSuccess($tenant['User']['email'], $email_data)) { $this->out('Payment Received Email sent to ' . $tenant['User']['email']); } } } else { //$failed=$data; $failed = array(); $failed['FailedPayment']['billing_id'] = $billing_cycle['Billing']['id']; $failed['FailedPayment']['unit_id'] = $billing_cycle['Billing']['unit_id']; $failed['FailedPayment']['user_id'] = $tenant['User']['id']; $failed['FailedPayment']['amount'] = $tenant['AutoPayment'][0]['amount']; $failed['FailedPayment']['type'] = 'Auto ACH'; $failed['FailedPayment']['ppresponse'] = $response; $failed['FailedPayment']['ppresponsetext'] = $responsetext; $failed['FailedPayment']['ppauthcode'] = $authcode; $failed['FailedPayment']['pptransactionid'] = $transactionid; $failed['FailedPayment']['ppresponse_code'] = $response_code; if ($this->FailedPayment->save($failed)) { $this->out($billing_cycle['Billing']['id'] . ' - Auto Payment FAILED'); } } $result = $this->Payment->processPayment($pay_fee, $tenant['AutoPayment'][0]['vault_id'], RENTSQUARE_MERCH_USER, RENTSQUARE_MERCH_PASS); parse_str($result); if (isset($response) && $response == 1) { $auto_payment = array(); $auto_payment['Payment']['ppresponse'] = $response; $auto_payment['Payment']['ppresponsetext'] = $responsetext; $auto_payment['Payment']['ppauthcode'] = $authcode; $auto_payment['Payment']['pptransactionid'] = $transactionid; $auto_payment['Payment']['ppresponse_code'] = $response_code; $auto_payment['Payment']['type'] = 'Auto ACH'; $auto_payment['Payment']['status'] = 'Complete'; $auto_payment['Payment']['notes'] = 'Auto Payment'; $auto_payment['Payment']['user_id'] = $tenant['User']['id']; $auto_payment['Payment']['billing_id'] = $billing_cycle['Billing']['id']; $auto_payment['Payment']['unit_id'] = $billing_cycle['Billing']['unit_id']; $auto_payment['Payment']['amount'] = 0; $auto_payment['Payment']['is_fee'] = 1; $auto_payment['Payment']['amt_processed'] = floatval($pay_fee); $auto_payment['Payment']['total_bill'] = floatval($pay_amount) + floatval($pay_fee); //Add to Payments Table $this->Payment->create(); if ($this->Payment->save($auto_payment)) { $this->Billing->updatebillingstatus($billing_cycle['Billing']['id']); $this->out($billing_cycle['Billing']['id'] . ' - Applied Auto Payment of ' . $tenant['AutoPayment'][0]['amount']); //Send Email Payment was processed $email_data['name'] = $tenant['User']['first_name']; $email_data['amount'] = $total_amount; $email_data['trans_id'] = $transactionid; $email_data['unit_name'] = $billing_cycle['Unit']['number']; $email_data['prop_name'] = $billing_cycle['Unit']['Property']['name']; if ($this->__sendAutoPaymentSuccess($tenant['User']['email'], $email_data)) { $this->out('Payment Received Email sent to ' . $tenant['User']['email']); } } } else { //$failed=$data; $failed = array(); $failed['FailedPayment']['billing_id'] = $billing_cycle['Billing']['id']; $failed['FailedPayment']['unit_id'] = $billing_cycle['Billing']['unit_id']; $failed['FailedPayment']['user_id'] = $tenant['User']['id']; $failed['FailedPayment']['amount'] = $tenant['AutoPayment'][0]['amount']; $failed['FailedPayment']['type'] = 'Auto ACH'; $failed['FailedPayment']['ppresponse'] = $response; $failed['FailedPayment']['ppresponsetext'] = $responsetext; $failed['FailedPayment']['ppauthcode'] = $authcode; $failed['FailedPayment']['pptransactionid'] = $transactionid; $failed['FailedPayment']['ppresponse_code'] = $response_code; if ($this->FailedPayment->save($failed)) { $this->out($billing_cycle['Billing']['id'] . ' - Auto Payment FAILED'); } } } } } } else { //Else check to see if tenant wants an email reminder if ($tenant['User']['email_for_rent'] == "1") { //set data to pass $data = array('unit_num' => $billing_cycle['Unit']['number'], 'rent_due' => $billing_cycle['Billing']['rent_due'], 'first_name' => $tenant['User']['first_name'], 'billing_start' => $billing_cycle['Billing']['billing_start'], 'billing_end' => $billing_cycle['Billing']['billing_end'], 'property_name' => $tenant['Property']['name'], 'rent_period' => $billing_cycle['Billing']['rent_period']); if ($this->__sendRentDueReminderMail($tenant['User']['email'], $data)) { $this->out($billing_cycle['Billing']['id'] . ' - Sent Rent Due Reminder To ' . $tenant['User']['email']); } else { $this->out($billing_cycle['Billing']['id'] . ' - Error sending Rent Due Reminder To ' . $tenant['User']['email']); } } } } // check if late } elseif (strtotime($billing_cycle['Billing']['billing_end']) < time()) { // set status = late $this->Billing->saveField('status', 'late'); //Charge Auto Late Fee if Checked if ($billing_cycle['Unit']['Property']['auto_late_fee']) { //$property['day_rent_late'] => Days after rent due $late_fee_day = $billing_cycle['Unit']['Property']['day_rent_late']; // if today - $late_fee_day is equal to billing end, charge late fee if (date('Ymd', strtotime('-' . $late_fee_day . ' days')) == date('Ymd', strtotime($billing_cycle['Billing']['billing_end']))) { //$property['auto_late_fee_amt'] => Late Fee Amt //Charge late fee if (!$billing_cycle['Billing']['auto_late_fee']) { if ($this->Billing->addLateFee($billing_cycle['Billing']['id'], $billing_cycle['Unit']['Property']['auto_late_fee_amt'], true)) { $this->out($billing_cycle['Billing']['id'] . ' - Auto Late Fee of $' . $billing_cycle['Unit']['Property']['auto_late_fee_amt'] . ' charged'); } else { $this->out($billing_cycle['Billing']['id'] . ' - Auto Late Fee for Billing Id ' . $billing_cycle['Billing']['id'] . ' failed.'); } } else { $this->out($billing_cycle['Billing']['id'] . ' - Auto Late Fee for Billing Id ' . $billing_cycle['Billing']['id'] . ' already charged.'); } } } //$property['auto_late_fee'] => Checkbox //if tenant checked Rent Reminder Email [User][email_for_rent], send email $tenants = $this->User->find('all', array('conditions' => array('User.unit_id' => $billing_cycle['Billing']['unit_id']))); foreach ($tenants as $tenant) { if ($tenant['User']['email_for_rent'] == "1") { //set data to pass $data = array('unit_num' => $billing_cycle['Unit']['number'], 'rent_due' => $billing_cycle['Billing']['rent_due'], 'first_name' => $tenant['User']['first_name'], 'billing_start' => $billing_cycle['Billing']['billing_start'], 'billing_end' => $billing_cycle['Billing']['billing_end'], 'property_name' => $tenant['Property']['name'], 'rent_period' => $billing_cycle['Billing']['rent_period']); //Only Send Late Reminder on Date Late and 2 Days after Late if (date('Y-m-d', strtotime($billing_cycle['Billing']['billing_end'])) == date('Y-m-d', time()) || date('Y-m-d', strtotime($billing_cycle['Billing']['billing_end'])) == date('Y-m-d', strtotime('+2 days'))) { if ($this->__sendRentLateReminderMail($tenant['User']['email'], $data)) { $this->out($billing_cycle['Billing']['id'] . ' - Sent Late Reminder To ' . $tenant['User']['email']); } else { $this->out($billing_cycle['Billing']['id'] . ' - Error sending Late Reminder To ' . $tenant['User']['email']); } } } } //End foreach tenant to send late reminder } else { // else not late and not due // check Invoice Email [invoice_day] //Get Property to check invoice_day - Invoice blank days before rent due $invoice_day = $billing_cycle['Unit']['Property']['invoice_day']; // if today + invoice days is equal to due date if (date('Ymd', strtotime('+' . $invoice_day . ' days')) == date('Ymd', strtotime($billing_cycle['Billing']['billing_end']))) { //Get Tenants and Send Invoice Email $tenants = $this->User->find('all', array('conditions' => array('User.unit_id' => $billing_cycle['Billing']['unit_id']))); foreach ($tenants as $tenant) { if ($tenant['User']['email_for_rent'] == "1") { //set data to pass $data = array('unit_num' => $billing_cycle['Unit']['number'], 'rent_due' => $billing_cycle['Billing']['rent_due'], 'first_name' => $tenant['User']['first_name'], 'billing_start' => $billing_cycle['Billing']['billing_start'], 'billing_end' => $billing_cycle['Billing']['billing_end'], 'property_name' => $billing_cycle['Unit']['Property']['name'], 'rent_period' => $billing_cycle['Billing']['rent_period']); if ($this->__sendInvoiceMail($tenant['User']['email'], $data)) { $this->out($billing_cycle['Billing']['id'] . ' - Sent Invoice To ' . $tenant['User']['email']); } else { $this->out($billing_cycle['Billing']['id'] . ' - Error sending invoice To ' . $tenant['User']['email']); } } } } //End check if Invoice Day //check Reminder Email [before_due_reminder][before_due_days] if ($billing_cycle['Unit']['Property']['before_due_reminder']) { $reminder_day = $billing_cycle['Unit']['Property']['before_due_days']; // if today + reminder days is equal to due date if (date('Ymd', strtotime('+' . $reminder_day . ' days')) == date('Ymd', strtotime($billing_cycle['Billing']['billing_end']))) { //Get Tenants and Send Reminder Email $tenants = $this->User->find('all', array('conditions' => array('User.unit_id' => $billing_cycle['Billing']['unit_id']))); foreach ($tenants as $tenant) { if ($tenant['User']['email_for_rent'] == "1") { //set data to pass $data = array('unit_num' => $billing_cycle['Unit']['number'], 'rent_due' => $billing_cycle['Billing']['rent_due'], 'first_name' => $tenant['User']['first_name'], 'billing_start' => $billing_cycle['Billing']['billing_start'], 'billing_end' => $billing_cycle['Billing']['billing_end'], 'property_name' => $billing_cycle['Unit']['Property']['name'], 'rent_period' => $billing_cycle['Billing']['rent_period']); if ($this->__sendCourtesyReminderMail($tenant['User']['email'], $data)) { $this->out($billing_cycle['Billing']['id'] . ' - Sent Courtesy Reminder To ' . $tenant['User']['email']); } else { $this->out($billing_cycle['Billing']['id'] . ' - Error sending courtesy reminder To ' . $tenant['User']['email']); } } } } //End check if Before Due Reminder Day } //if($property['before_due_reminder']) } } } } } //$billing_cycles as $billing_cycle $this->out(date("Y-m-d H:i:s") . ' - End'); }
/** * testRijndaelInvalidKey method * * @expectedException PHPUnit_Framework_Error * @return void */ public function testRijndaelInvalidKey() { $txt = 'The quick brown fox jumped over the lazy dog.'; $key = 'too small'; Security::rijndael($txt, $key, 'encrypt'); }
/** * Decodes and decrypts a single value. * * @param string $value The value to decode & decrypt. * @return string Decoded value. */ protected function _decode($value) { $prefix = 'Q2FrZQ==.'; $pos = strpos($value, $prefix); if ($pos === false) { return $this->_explode($value); } $value = base64_decode(substr($value, strlen($prefix))); if ($this->_type === 'rijndael') { $plain = Security::rijndael($value, $this->key, 'decrypt'); } if ($this->_type === 'cipher') { $plain = Security::cipher($value, $this->key); } if ($this->_type === 'aes') { $plain = Security::decrypt($value, $this->key); } return $this->_explode($plain); }
function activateproperty() { $this->adminCheck(); $this->loadModel('Property'); $property = $this->Property->find('list', array('conditions' => array('Property.active' => 0))); $this->set(compact('property')); if (!empty($this->request->data)) { $data = $this->request->data; $this->Property->id = $data['Property']['id']; $data['Property']['pp_pass'] = Security::rijndael($data['Property']['pp_pass'], Configure::read('Security.salt2'), 'encrypt'); $data['Property']['active'] = 1; //active property only after success payment. if ($this->Property->save($data)) { //Wave One Time Fee? if ($data['Property']['no_one_time_fee']) { $this->Session->setFlash('Property Activated Successfully. Waved signup fee.', 'flash_good'); $this->redirect(array('action' => 'index')); } //Charge One Time Setup Fee $this->loadModel('Payment'); //Get Property Data $property_data = $this->Property->findById($this->Property->id); //Determine Cost base on number of units. If actual unit_count in system is greater //than num_units provided by user, charge actual number if ($property_data['Property']['num_units'] > $property_data['Property']['unit_count']) { $amount = intval($this->get_monthly_fee($property_data['Property']['num_units'])) * 2; } else { $amount = intval($this->get_monthly_fee($property_data['Property']['unit_count'])) * 2; } //Process One Time Fee Payment to RentSquare $result = $this->Payment->processPayment($amount, $property_data['Property']['vault_id'], RENTSQUARE_MERCH_USER, RENTSQUARE_MERCH_PASS); parse_str($result); if (isset($response) && $response == 1) { $this->Property->id = $property_data['Property']['id']; $this->Property->saveField('active', 1); // 2014-09-15 - Wolff - Set fee_due_day $this->Property->saveField('fee_due_day', date('j')); $this->__sendPropertyActivation($property_data); $signup_fee = array(); $signup_fee['Payment']['ppresponse'] = $response; $signup_fee['Payment']['ppresponsetext'] = $responsetext; $signup_fee['Payment']['ppauthcode'] = $authcode; $signup_fee['Payment']['pptransactionid'] = $transactionid; $signup_fee['Payment']['ppresponse_code'] = $response_code; $signup_fee['Payment']['status'] = 'Complete'; $signup_fee['Payment']['notes'] = 'Signup Fee'; $signup_fee['Payment']['user_id'] = $property_data['Property']['manager_id']; $signup_fee['Payment']['billing_id'] = 0; $signup_fee['Payment']['unit_id'] = 0; $signup_fee['Payment']['amount'] = $amount; $signup_fee['Payment']['is_fee'] = 0; $signup_fee['Payment']['amt_processed'] = floatval($amount); $signup_fee['Payment']['total_bill'] = floatval($amount); //Add to Payments Table $this->Payment->create(); $this->Payment->save($signup_fee); $this->Session->setFlash('Property Activated Successfully and One Time Fee Processed', 'flash_good'); $this->redirect(array('action' => 'index')); } else { $this->loadModel('FailedPayment'); $failed = $property_data; $failed['FailedPayment']['billing_id'] = '0'; $failed['FailedPayment']['unit_id'] = '0'; $failed['FailedPayment']['user_id'] = $property_data['Property']['manager_id']; $failed['FailedPayment']['amount'] = $amount; $failed['FailedPayment']['ppresponse'] = $response; $failed['FailedPayment']['ppresponsetext'] = $responsetext; $failed['FailedPayment']['ppauthcode'] = $authcode; $failed['FailedPayment']['pptransactionid'] = $transactionid; $failed['FailedPayment']['ppresponse_code'] = $response_code; $failed['FailedPayment']['notes'] = "Failed on One Time Fee Charge. Property id " . $property_data['Property']['id']; if ($this->FailedPayment->save($failed)) { $this->Session->setFlash(__('Payment has failed with error ' . $responsetext), 'flash_bad'); } else { $this->Session->setFlash(__('Payment has failed with error ' . $responsetext), 'flash_bad'); } } } else { $this->Session->setFlash('Error activating property.', 'flash_bad'); } } }
/** * Decrypts the shop ID the transaction in question is related to. * * @param string $eShopId encrypted shop ID as supplied by SOFORT.com notify * request */ public static function DecryptShopId($eShopId) { // URL param from CakePHP comes in decoded already // but to handle + signs correctly we need to encode and decode again $urlEncoded = urlencode($eShopId); $base64 = rawurldecode($urlEncoded); $encrypted = self::Base64Decode($base64); return Security::rijndael($encrypted, Configure::read('Security.salt'), 'decrypt'); }
/** * Calls Sofortueberweisung::sendRequest and redirects the buyer to * the payment url. * @throws SofortLibException when Sofortueberweisung returns an error * @throws InvalidArgumentException when no shop_id has been set. */ public function PaymentRedirect() { if (empty($this->shop_id)) { throw new InvalidArgumentException("No shop_id set."); } $eShopId = rawurlencode(self::Base64Encode(Security::rijndael($this->shop_id, Configure::read('Security.salt'), 'encrypt'))); $notificationUrl = Router::url('/SofortComPayment/Notify/' . $eShopId, true); foreach ($this->states as $state) { $this->Sofortueberweisung->setNotificationUrl($notificationUrl . '/' . $state, $state); } App::uses('SofortComShopTransaction', 'SofortCom.Model'); $SofortComShopTransaction = new SofortComShopTransaction(); $this->Sofortueberweisung->sendRequest(); if ($this->Sofortueberweisung->isError()) { $error = $this->Sofortueberweisung->getError(); $exception = new SofortLibRequestException($error); $exception->errors = $this->Sofortueberweisung->getErrors(); throw $exception; } $transaction = $this->Sofortueberweisung->getTransactionId(); $payment_url = $this->Sofortueberweisung->getPaymentUrl(); $SofortComShopTransaction->Add($transaction, $this->shop_id); if (!empty($this->newTransactionCallback) && is_callable($this->newTransactionCallback)) { $args = array($transaction, $payment_url); call_user_func_array($this->newTransactionCallback, array_merge($args, $this->newTransactionCallbackArgs)); } header('Location: ' . $payment_url); exit; }
/** * パスワードの複合化 * @param type $user_password * @return string */ public function passwordDecrypt($user_password) { $password = base64_decode($user_password); return Security::rijndael($password, self::CIPHER_KEY, 'decrypt'); }
/** * delete method * * @param string $id * @return void */ public function delete($id = null) { if (isset($this->request->data['PaymentMethod']['id'])) { $id = $this->request->data['PaymentMethod']['id']; } if (!$this->request->is('post')) { throw new MethodNotAllowedException(); } $this->PaymentMethod->id = $id; if (!$this->PaymentMethod->exists()) { throw new NotFoundException(__('Invalid payment method')); } if ($this->PaymentMethod->delete()) { $this->loadModel('Property'); $prop = $this->Property->findById($this->Auth->user('property_id')); //Get Phoenix Payment Password $pp_password = Security::rijndael($prop['Property']['pp_pass'], Configure::read('Security.salt2'), 'decrypt'); $paymentmethod['user_id'] = $id; $paymentmethod['pp_user'] = $prop['Property']['pp_user']; $paymentmethod['pp_password'] = $pp_password; $this->PaymentMethod->delete_from_vault($paymentmethod); $this->Session->setFlash(__('Payment method deleted'), 'flash_good'); $this->redirect(array('controller' => 'Users', 'action' => 'myaccount', 'payment_methods')); } $this->Session->setFlash(__('Payment method was not deleted'), 'flash_bad'); $this->redirect(array('controller' => 'Users', 'action' => 'myaccount', 'payment_methods')); }
protected function _decrypt($idul, $encrypted) { return substr(Security::rijndael($encrypted, Configure::read('Security.key'), 'decrypt'), strlen($idul . Configure::read('Security.salt'))); }
public function cross_domain_login() { $tokeno = $this->request->query['token']; $token = base64_decode($tokeno); $token = Security::rijndael($token, Configure::read('Security.salt'), 'decrypt'); $token = explode(' ', $token); if (count($token) != 3 or $token[2] != CROSSDOMAIN_salt) { throw new BadRequestException(); } $uid = $token[1]; if ($this->Auth->loggedIn()) { // logout if different user if ($this->Auth->user('id') != $uid) { $this->Auth->logout(); } } $userCl = new User(); $user = $userCl->read($uid); if (empty($user)) { throw new Exception("Was expecting user data"); } // login this user $this->Auth->login($user); // no view $this->layout = 'ajax'; $this->render(false); }
function payrent() { if ($this->request->is('post') || $this->request->is('put')) { $data = $this->request->data; $pay_amount = $data['Payment']['amount']; //Determine Transaction Fees $this->loadModel('User'); $this->User->contain('Property', 'PaymentMethod', 'Unit'); $user = $this->User->find('first', array('conditions' => array('User.id' => $this->Auth->user('id')))); //Is selected payment CC or ACH $i = 0; $paymentType = ""; foreach ($user['PaymentMethod'] as $paymentMethod) { if ($paymentMethod['vault_id'] == $data['Payment']['vault_id']) { $paymentType = $user['PaymentMethod'][$i]['type']; break; } $i++; } if ($paymentType == 'CC') { //Payment is Credit Card if ($user['Property']['prop_pays_cc_fee']) { $amount = floatval($pay_amount); $amt_fee = $amount * floatval(CC_FEE); $amt_processed = floatval($amount) - $amt_fee; $total_bill = floatval($pay_amount); } else { $amount = floatval($pay_amount); $amt_fee = $amount * floatval(CC_FEE); $amt_processed = floatval($amount); $total_bill = floatval($amt_processed) + floatval($amt_fee); } } else { //Payment is ACH if ($user['Property']['prop_pays_ach_fee']) { $amount = floatval($pay_amount); $amt_fee = floatval(ACH_FEE); $amt_processed = floatval($amount) - $amt_fee; $total_bill = floatval($amount); } else { $amount = floatval($pay_amount); $amt_fee = floatval(ACH_FEE); $amt_processed = floatval($amount); $total_bill = floatval($amount) + floatval(ACH_FEE); } } $pp_password = Security::rijndael($user['Property']['pp_pass'], Configure::read('Security.salt2'), 'decrypt'); //Submit Payment $result = $this->Payment->processPayment($amt_processed, $data['Payment']['vault_id'], $user['Property']['pp_user'], $pp_password); parse_str($result); if (isset($response) && $response == 1) { $this->loadModel('Billing'); $amt_process_transid = $transactionid; $data['Payment']['ppresponse'] = $response; $data['Payment']['ppresponsetext'] = $responsetext; $data['Payment']['ppauthcode'] = $authcode; $data['Payment']['pptransactionid'] = $transactionid; $data['Payment']['ppresponse_code'] = $response_code; $data['Payment']['status'] = 'Complete'; $data['Payment']['user_id'] = $this->Auth->user('id'); $data['Payment']['type'] = $paymentType; $data['Payment']['is_fee'] = 0; $data['Payment']['amt_processed'] = floatval($amt_processed); $data['Payment']['total_bill'] = floatval($total_bill); //If Payment id = 0 (AKA pay toward current balance) if ($data['Payment']['billing_id'] == 0) { $this->loadModel('Billing'); $billing_ids = $this->Billing->find('all', array('conditions' => array('status !=' => 'paid', 'unit_id' => $data['Payment']['unit_id']), 'fields' => array('id', 'rent_due', 'unit_id'), 'order' => array('Billing.id'))); $total_payment = floatval($data['Payment']['amount']); $failed = 0; //For each open billing id associated to unit foreach ($billing_ids as $billing_id) { //get how much is due including payments have been made $total_due = floatval($billing_id['Billing']['rent_due']); if (isset($billing_id['Payment'])) { foreach ($billing_id['Payment'] as $payment) { $total_due = $total_due - floatval($payment['amount']); } // $billing_id['Payment'] as $payment } if (floatval($total_payment) > 0) { $data['Payment']['billing_id'] = $billing_id['Billing']['id']; if ($total_due < $total_payment) { $data['Payment']['amount'] = floatval($total_due); } else { $data['Payment']['amount'] = floatval($total_payment); } $this->Payment->create(); if ($this->Payment->save($data)) { $this->loadModel('Billing'); $this->Billing->updatebillingstatus($billing_id['Billing']['id']); $total_payment = $total_payment - $total_due; } else { $failed = $billing_id['Billing']['id']; } } } //$billing_ids as $billing_id // if $total_payment > 0 add credit to account if ($total_payment > 0 && !$failed) { $this->loadModel('Unit'); $this->Unit->creditUnit($billing_id['Billing']['unit_id'], $total_payment); } if ($failed) { $this->Session->setFlash(__('The payment for #' . $failed . ' could not be saved. Please, try again.'), 'flash_bad'); $this->redirect(array('action' => 'index', 'failed', number_format($amount, 2))); } else { $this->Session->setFlash(__('The payment has been saved!'), 'flash_good'); } } else { if ($this->Payment->save($data)) { $this->Session->setFlash(__('The payment has been saved!'), 'flash_good'); $this->Billing->updatebillingstatus($data['Payment']['billing_id']); } else { $this->Session->setFlash(__('The payment could not be saved. Please, try again.'), 'flash_bad'); $this->redirect(array('action' => 'index', 'failed', number_format($amount, 2))); } } $this->loadModel('PaymentMethod'); $rs_vault = $this->PaymentMethod->find('first', array('conditions' => array('vault_id' => $data['Payment']['vault_id']))); //Process Transaction Fee $result = $this->Payment->processPayment($amt_fee, $rs_vault['PaymentMethod']['rs_vault_id'], RENTSQUARE_MERCH_USER, RENTSQUARE_MERCH_PASS); parse_str($result); if (isset($response) && $response == 1) { $data['Payment']['ppresponse'] = $response; $data['Payment']['ppresponsetext'] = $responsetext; $data['Payment']['ppauthcode'] = $authcode; $data['Payment']['pptransactionid'] = $transactionid; $data['Payment']['ppresponse_code'] = $response_code; $data['Payment']['status'] = 'Complete'; $data['Payment']['notes'] = 'Transaction Fee'; $data['Payment']['amount'] = 0; $data['Payment']['is_fee'] = 1; $data['Payment']['amt_processed'] = floatval($amt_fee); $data['Payment']['total_bill'] = floatval($total_bill); //Add to Payments Table $this->Payment->Create(); if ($this->Payment->save($data)) { //Send Payment Email $email_data['name'] = $user['User']['first_name']; $email_data['unit_name'] = $user['Unit']['number']; $email_data['prop_name'] = $user['Property']['name']; $email_data['trans_id'] = $amt_process_transid; $email_data['amount'] = $total_bill; $this->__sendPaymentSuccess($user['User']['email'], $email_data); $this->redirect(array('action' => 'index', 'success', number_format($amount, 2))); } } else { $this->loadModel('FailedPayment'); $failed = $data; $failed['FailedPayment']['billing_id'] = $data['Payment']['billing_id']; $failed['FailedPayment']['unit_id'] = $data['Payment']['unit_id']; $failed['FailedPayment']['user_id'] = $this->Auth->user('id'); $failed['FailedPayment']['amount'] = $amt_fee; $failed['FailedPayment']['ppresponse'] = $response; $failed['FailedPayment']['ppresponsetext'] = $responsetext; $failed['FailedPayment']['ppauthcode'] = $authcode; $failed['FailedPayment']['pptransactionid'] = $transactionid; $failed['FailedPayment']['ppresponse_code'] = $response_code; $failed['FailedPayment']['type'] = $paymentType; if ($this->FailedPayment->save($failed)) { $this->Session->setFlash(__('The rent payment has been processed however the transaction fee payment has failed with error ' . $responsetext . '. Please contact RentSquare Support'), 'flash_bad'); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('The rent payment has been processed however the transaction fee payment has failed with error ' . $responsetext . '. Please contact RentSquare Support'), 'flash_bad'); $this->redirect(array('action' => 'index')); } } } else { $this->loadModel('FailedPayment'); $failed = $data; $failed['FailedPayment']['billing_id'] = $data['Payment']['billing_id']; $failed['FailedPayment']['unit_id'] = $data['Payment']['unit_id']; $failed['FailedPayment']['user_id'] = $this->Auth->user('id'); $failed['FailedPayment']['amount'] = $amt_processed; $failed['FailedPayment']['ppresponse'] = $response; $failed['FailedPayment']['ppresponsetext'] = $responsetext; $failed['FailedPayment']['ppauthcode'] = $authcode; $failed['FailedPayment']['pptransactionid'] = $transactionid; $failed['FailedPayment']['ppresponse_code'] = $response_code; $failed['FailedPayment']['type'] = $paymentType; if ($this->FailedPayment->save($failed)) { $this->Session->setFlash(__('The payment has failed with error ' . $responsetext . '. Please contact RentSquare Support'), 'flash_bad'); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash(__('The payment has failed with error ' . $responsetext . '. Please contact RentSquare Support.'), 'flash_bad'); } } } }
/** * Encrypts $value using public $type method in Security class * * @param string $value Value to encrypt * * @return string Encoded values */ protected function _encrypt($value) { if (is_array($value)) { $value = $this->_implode($value); } if (!$this->_encrypted) { return $value; } $prefix = "Q2FrZQ==."; if ($this->_type === 'rijndael') { $cipher = Security::rijndael($value, $this->key, 'encrypt'); } if ($this->_type === 'cipher') { $cipher = Security::cipher($value, $this->key); } if ($this->_type === 'aes') { $cipher = Security::encrypt($value, $this->key); } return $prefix . base64_encode($cipher); }