public function run() { global $db; $today = date('Y-m-d'); $cron = new cron(); $data = $cron->select_crons_to_run(); $return['cron_message'] = "Cron started"; $number_of_crons_run = "0"; $cron_log = new cronlog(); $cron_log->run_date = $today; foreach ($data as $key => $value) { $cron->domain_id = $value['domain_id']; $cron_log->cron_id = $value['id']; $cron_log->domain_id = $domain_id = $value['domain_id']; $check_cron_log = $cron_log->check(); $i = "0"; if ($check_cron_log == 0) { //only proceed if cron has not been run for today $run_cron = false; $start_date = date('Y-m-d', strtotime($value['start_date'])); $end_date = $value['end_date']; // Seconds in a day = 60 * 60 * 24 = 86400 $diff = number_format((strtotime($today) - strtotime($start_date)) / 86400, 0); //only check if diff is positive if ($diff >= 0 and ($end_date == "" or $end_date >= $today)) { if ($value['recurrence_type'] == 'day') { $modulus = $diff % $value['recurrence']; if ($modulus == 0) { $run_cron = true; } else { #$return .= "cron does not runs TODAY-days"; } } if ($value['recurrence_type'] == 'week') { $period = 7 * $value['recurrence']; $modulus = $diff % $period; if ($modulus == 0) { $run_cron = true; } else { #$return .= "cron is not runs TODAY-week"; } } if ($value['recurrence_type'] == 'month') { $start_day = date('d', strtotime($value['start_date'])); $start_month = date('m', strtotime($value['start_date'])); $start_year = date('Y', strtotime($value['start_date'])); $today_day = date('d'); $today_month = date('m'); $today_year = date('Y'); $months = $today_month - $start_month + 12 * ($today_year - $start_year); $modulus = $months % $value['recurrence']; if ($modulus == 0 and $start_day == $today_day) { $run_cron = true; } else { #$return .= "cron is not runs TODAY-month"; } } if ($value['recurrence_type'] == 'year') { $start_day = date('d', strtotime($value['start_date'])); $start_month = date('m', strtotime($value['start_date'])); $start_year = date('Y', strtotime($value['start_date'])); $today_day = date('d'); $today_month = date('m'); $today_year = date('Y'); $years = $today_year - $start_year; $modulus = $years % $value['recurrence']; if ($modulus == 0 and $start_day == $today_day and $start_month == $today_month) { $run_cron = true; } else { #$return .= "cron is not runs TODAY-year"; } } //run the recurrence for this invoice if ($run_cron) { $number_of_crons_run++; $return['cron_message_' . $value['cron_id']] = "Cron ID: " . $value['cron_id'] . " - Cron for " . $value['index_name'] . " with start date of " . $value['start_date'] . ", end date of " . $value['end_date'] . " where it runs each " . $value['recurrence'] . " " . $value['recurrence_type'] . " was run today :: Info diff=" . $diff; $i++; $ni = new invoice(); $ni->id = $value['invoice_id']; $ni->domain_id = $domain_id; // $domain_id gets propagated from invoice to be copied from $new_invoice_id = $ni->recur(); //insert into cron_log date of run //$cron_log = new cronlog(); //$cron_log->run_date = $today; //$cron_log->domain_id = $domain_id; //$cron_log->cron_id = $value['cron_id']; $cron_log->insert(); ## email the people $invoiceobj = new invoice(); $invoice = $invoiceobj->select($new_invoice_id, $domain_id); $preference = getPreference($invoice['preference_id'], $domain_id); $biller = getBiller($invoice['biller_id'], $domain_id); $customer = getCustomer($invoice['customer_id'], $domain_id); #print_r($customer); #create PDF nameVj $spc2us_pref = str_replace(" ", "_", $invoice['index_name']); $pdf_file_name_invoice = $spc2us_pref . ".pdf"; // email invoice if ($value['email_biller'] == "1" or $value['email_customer'] == "1") { $export = new export(); $export->domain_id = $domain_id; $export->format = "pdf"; $export->file_location = 'file'; $export->module = 'invoice'; $export->id = $invoice['id']; $export->execute(); #$attachment = file_get_contents('./tmp/cache/' . $pdf_file_name); $email = new email(); $email->domain_id = $domain_id; $email->format = 'cron_invoice'; $email_body = new email_body(); $email_body->email_type = 'cron_invoice'; $email_body->customer_name = $customer['name']; $email_body->invoice_name = $invoice['index_name']; $email_body->biller_name = $biller['name']; $email->notes = $email_body->create(); $email->from = $biller['email']; $email->from_friendly = $biller['name']; $email->to = $this->getEmailSendAddresses($value, $customer['email'], $biller['email']); $email->invoice_name = $invoice['index_name']; $email->subject = $email->set_subject(); $email->attachment = $pdf_file_name_invoice; $return['email_message'] = $email->send(); } //Check that all details are OK before doing the eway payment $eway_check = new eway(); $eway_check->domain_id = $domain_id; $eway_check->invoice = $invoice; $eway_check->customer = $customer; $eway_check->biller = $biller; $eway_check->preference = $preference; $eway_pre_check = $eway_check->pre_check(); //do eway payment if ($eway_pre_check == 'true') { // input customerID, method (REAL_TIME, REAL_TIME_CVN, GEO_IP_ANTI_FRAUD) and liveGateway or not $eway = new eway(); $eway->domain_id = $domain_id; $eway->invoice = $invoice; $eway->biller = $biller; $eway->customer = $customer; $payment_done = $eway->payment(); $payment_id = $db->lastInsertID(); $pdf_file_name_receipt = 'payment' . $payment_id . '.pdf'; if ($payment_done == 'true') { //do email of receipt to biller and customer if ($value['email_biller'] == "1" or $value['email_customer'] == "1") { /* * If you want a new copy of the invoice being emailed to the customer * use this code */ $export_rec = new export(); $export_rec->domain_id = $domain_id; $export_rec->format = "pdf"; $export_rec->file_location = 'file'; $export_rec->module = 'invoice'; $export_rec->id = $invoice['id']; $export_rec->execute(); #$attachment = file_get_contents('./tmp/cache/' . $pdf_file_name); $email_rec = new email(); $email_rec->domain_id = $domain_id; $email_rec->format = 'cron_invoice'; $email_body_rec = new email_body(); $email_body_rec->email_type = 'cron_invoice_receipt'; $email_body_rec->customer_name = $customer['name']; $email_body_rec->invoice_name = $invoice['index_name']; $email_body_rec->biller_name = $biller['name']; $email_rec->notes = $email_body_rec->create(); $email_rec->from = $biller['email']; $email_rec->from_friendly = $biller['name']; $email_rec->to = $this->getEmailSendAddresses($value, $customer['email'], $biller['email']); $email_rec->invoice_name = $invoice['index_name']; $email_rec->attachment = $pdf_file_name_invoice; $email_rec->subject = $email_rec->set_subject('invoice_eway_receipt'); $return['email_message'] = $email_rec->send(); /* * If you want a receipt as PDF being emailed to the customer * uncomment the code below */ /* $export = new export(); $export -> format = "pdf"; $export -> file_location = 'file'; $export -> module = 'payment'; $export -> id = $payment_id; $export -> execute(); $email = new email(); $email -> format = 'cron_payment'; $email_body = new email_body(); $email_body->email_type = 'cron_payment'; $email_body->customer_name = $customer['name']; $email_body->invoice_name = 'payment'.$payment_id; $email_body->biller_name = $biller['name']; $email -> notes = $email_body->create(); $email -> from = $biller['email']; $email -> from_friendly = $biller['name']; if($value['email_customer'] == "1") { $email -> to = $customer['email']; } if($value['email_biller'] == "1" AND $value['email_customer'] == "1") { $email -> to = $customer['email'].";".$biller['email']; } if($value['email_biller'] == "1" AND $value['email_customer'] == "0") { $email -> to = $customer['email']; } $email -> subject = $pdf_file_name_receipt." from ".$biller['name']; $email -> attachment = $pdf_file_name_receipt; $return['email_message'] = $email->send(); */ } } else { //do email to biller/admin - say error $email = new email(); $email->domain_id = $domain_id; $email->format = 'cron_payment'; $email->from = $biller['email']; $email->from_friendly = $biller['name']; $email->to = $biller['email']; $email->subject = "Payment failed for " . $invoice['index_name']; $error_message = "Invoice: " . $invoice['index_name'] . "<br /> Amount: " . $invoice['total'] . " <br />"; foreach ($eway->get_message() as $key => $value) { $error_message .= "\n<br>\$ewayResponseFields[\"{$key}\"] = {$value}"; } $email->notes = $error_message; $return['email_message'] = $email->send(); } } } else { //cron not run for this cron_id $return['cron_message_' . $value['cron_id']] = "Cron ID: " . $value['cron_id'] . " NOT RUN: Cron for " . $value['index_name'] . " with start date of " . $value['start_date'] . ", end date of " . $value['end_date'] . " where it runs each " . $value['recurrence'] . " " . $value['recurrence_type'] . " did not recur today :: Info diff=" . $diff; } } else { //days diff is negative - whats going on $return['cron_message_' . $value['cron_id']] = "Cron ID: " . $value['cron_id'] . " NOT RUN: - Not cheduled for today - Cron for " . $value['index_name'] . " with start date of " . $value['start_date'] . ", end date of " . $value['end_date'] . " where it runs each " . $value['recurrence'] . " " . $value['recurrence_type'] . " did not recur today :: Info diff=" . $diff; } } else { // cron has already been run for that cron_id today $return['cron_message_' . $value['cron_id']] = "Cron ID: " . $value['cron_id'] . " - Cron has already been run for domain: " . $domain_id . " for the date: " . $today . " for invoice " . $value['invoice_id']; $return['email_message'] = ""; } } // no crons scheduled for today if ($number_of_crons_run == '0') { $return['id'] = $i; $return['cron_message'] = "No invoices recurred for this cron run for domain: " . $domain_id . " for the date: " . $today; $return['email_message'] = ""; } //insert into cron_log date of run /* $cron_log = new cronlog(); $cron_log->run_date = $today; $cron_log->domain_id = $domain_id; $cron_log->insert(); */ /* * If you want to get an email once cron has been run edit the below details * */ /* $email = new email(); $email -> format = 'cron'; #$email -> notes = $return; $email -> from = "simpleinvoices@localhost"; $email -> from_friendly = "Simple Invoices - Cron"; $email -> to = "simpleinvoices@localhost"; #$email -> bcc = $_POST['email_bcc']; $email -> subject = "Cron for Simple Invoices has been run for today:"; $email -> send (); */ return $return; }
function espresso_display_eway($payment_data) { extract($payment_data); // Setup class include_once 'Eway.php'; echo '<!-- Event Espresso eway Gateway Version ' . $eway_gateway_version . '-->'; $myeway = new eway(); // initiate an instance of the class global $org_options; //global $attendee_id; $eway_settings = get_option('event_espresso_eway_settings'); $eway_id = $eway_settings['eway_id']; $eway_username = $eway_settings['eway_username']; //$image_url = $eway_settings['button_url']; $eway_cur = $eway_settings['currency_format']; $use_sandbox = $eway_settings['use_sandbox']; $quantity = isset($quantity) && $quantity > 0 ? $quantity : espresso_count_attendees_for_registration($attendee_id); if ($use_sandbox) { // Enable test mode if needed $myeway->enableTestMode(); $myeway->addField('CustomerID', '87654321'); $myeway->addField('UserName', 'TestAccount'); } else { $myeway->addField('CustomerID', $eway_id); $myeway->addField('UserName', $eway_username); } $myeway->addField('Amount', number_format($event_cost, 2, '.', '')); $myeway->addField('Currency', $eway_cur); $myeway->addField('PageTitle', ''); $myeway->addField('PageDescription', ''); $myeway->addField('PageFooter', ''); $myeway->addField('Language', ''); $myeway->addField('CompanyName', str_replace("&", "%26", $org_options['organization'])); $myeway->addField('CustomerFirstName', $fname); $myeway->addField('CustomerLastName', $lname); $myeway->addField('CustomerAddress', $address); $myeway->addField('CustomerCity', $city); $myeway->addField('CustomerState', $state); $myeway->addField('CustomerPostCode', $zip); $myeway->addField('CustomerCountry', ''); $myeway->addField('CustomerEmail', $attendee_email); $myeway->addField('CustomerPhone', $phone); $myeway->addField('InvoiceDescription', stripslashes_deep($event_name) . ' | ' . __('Name:', 'event_espresso') . ' ' . stripslashes_deep($fname . ' ' . $lname) . ' | ' . __('Registrant Email:', 'event_espresso') . ' ' . $attendee_email . ' | ' . __('Total Registrants:', 'event_espresso') . ' ' . $quantity); $myeway->addField('CancelURL', str_replace("&", "%26", home_url() . '/?page_id=' . $org_options['cancel_return'])); if ($eway_settings['force_ssl_return']) { $home = str_replace("http://", "https://", home_url()); } else { $home = home_url(); } $myeway->addField('ReturnURL', $home . '/?page_id=' . $org_options['notify_url'] . '&id=' . $attendee_id . '®istration_id=' . $registration_id . '&event_id=' . $event_id . '&attendee_action=post_payment&form_action=payment&type=eway'); $myeway->addField('CompanyLogo', $eway_settings['image_url']); $myeway->addField('PageBanner', ''); $myeway->addField('MerchantReference', ''); $myeway->addField('MerchantInvoice', ''); $myeway->addField('MerchantOption1', ''); $myeway->addField('MerchantOption2', ''); $myeway->addField('MerchantOption3', ''); $myeway->addField('ModifiableCustomerDetails', 'false'); if ($eway_settings['bypass_payment_page'] == 'Y') { $myeway->submitPayment(); //Enable auto redirect to payment site } else { if (empty($eway_settings['button_url'])) { if (file_exists(EVENT_ESPRESSO_GATEWAY_DIR . "eway/eway_logo.png")) { $button_url = EVENT_ESPRESSO_GATEWAY_URL . "eway/eway_logo.png"; } else { $button_url = EVENT_ESPRESSO_PLUGINFULLURL . "gateways/eway/eway_logo.png"; } } else { $button_url = $eway_settings['button_url']; } $myeway->submitButton($button_url, 'eway'); //Display payment button wp_deregister_script('jquery.validate.pack'); } if ($use_sandbox) { echo '<h3 style="color:#ff0000;" title="Payments will not be processed">' . __('Debug Mode Is Turned On', 'event_espresso') . '</h3>'; $myeway->dump_fields(); // for debugging, output a table of all the fields } }
* Website: * http://www.simpleinvoices.or */ checkLogin(); #get the invoice id $invoice_id = $_GET['id']; $invoice = getInvoice($invoice_id); $invoice_number_of_taxes = numberOfTaxesForInvoice($invoice_id); $invoice_type = getInvoiceType($invoice['type_id']); $customer = getCustomer($invoice['customer_id']); $biller = getBiller($invoice['biller_id']); $preference = getPreference($invoice['preference_id']); $defaults = getSystemDefaults(); $invoiceobj = new invoice(); $invoiceItems = $invoiceobj->getInvoiceItems($invoice_id); $eway_check = new eway(); $eway_check->invoice = $invoice; $eway_pre_check = $eway_check->pre_check(); #Invoice Age - number of days - start if ($invoice['owing'] > 0) { $invoice_age_days = number_format((strtotime(date('Y-m-d')) - strtotime($invoice['calc_date'])) / (60 * 60 * 24), 0); $invoice_age = "{$invoice_age_days} {$LANG['days']}"; } else { $invoice_age = ""; } $url_for_pdf = "./index.php?module=export&view=pdf&id=" . $invoice['id']; $invoice['url_for_pdf'] = $url_for_pdf; $customFieldLabels = getCustomFieldLabels(); for ($i = 1; $i <= 4; $i++) { $customField[$i] = show_custom_field("invoice_cf{$i}", $invoice["custom_field{$i}"], "read", 'summary', '', '', 5, ':'); }
<?php $saved = false; $invoiceobj = new invoice(); $invoice_all = $invoiceobj->get_all(); if ($_POST['op'] == 'add' and !empty($_POST['invoice_id'])) { $invoice = $invoiceobj->select($_POST['invoice_id']); $eway_check = new eway(); $eway_check->invoice = $invoice; $eway_pre_check = $eway_check->pre_check(); if ($eway_pre_check == 'true') { //do eway payment $eway = new eway(); $eway->invoice = $invoice; $saved = $eway->payment(); } else { $saved = 'check_failed'; } } $smarty->assign('invoice_all', $invoice_all); $smarty->assign('saved', $saved); $smarty->assign('pageActive', 'payment'); $smarty->assign('subPageActive', 'payment_eway'); $smarty->assign('active_tab', '#money');