<strong><?php echo $payment_methods_of['name']; ?> </strong><br/> <?php echo $payment_methods_of['description']; ?> </li> <?php } ?> </ul> <?php } $payment_methods_offline_html = ob_get_clean(); $template_invoice_payment_methods = module_template::get_template_by_key('invoice_payment_methods'); $template_invoice_payment_methods->assign_values(array('PAYMENT_METHODS_ONLINE' => $payment_methods_online_html, 'PAYMENT_METHODS_OFFLINE' => $payment_methods_offline_html)); $template_invoice_payment_methods->assign_values(module_invoice::get_replace_fields($invoice_id, $invoice_data)); echo $template_invoice_payment_methods->replace_content(); } else { ?> <p align="center"> <?php $template_print = module_template::get_template_by_key('invoice_payment_in_full'); echo $template_print->content; ?> </p> <?php }
public static function email_invoice_to_customer($invoice_id, $debug = false) { // this is a copy of some of the code in invoie_admin_email.php // used in the CRON job when sending out automated emails. $invoice = module_invoice::get_invoice($invoice_id); // template for sending emails. // are we sending the paid one? or the dueone. $template_name = ''; $template_prefix = isset($invoice['invoice_template_email']) && strlen($invoice['invoice_template_email']) ? $invoice['invoice_template_email'] : 'invoice_email'; if (isset($invoice['credit_note_id']) && $invoice['credit_note_id']) { $template_name = 'credit_note_email'; } else { if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') { $template_name = $template_prefix . '_paid'; } else { if ($invoice['overdue'] && $invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') { $template_name = $template_prefix . '_overdue'; } else { $template_name = $template_prefix . '_due'; } } } $template_name = hook_filter_var('invoice_email_template', $template_name, $invoice_id, $invoice); if (class_exists('module_company', false) && isset($invoice_data['company_id']) && (int) $invoice_data['company_id'] > 0) { module_company::set_current_company_id($invoice_data['company_id']); } $template = module_template::get_template_by_key($template_name); if (!$template || $template->template_key != $template_name) { // backup default templates incase someone has chosen a template that doesn't exist (eg: created invoice_email_MINE_due but not invoice_email_MINE_paid ) $template_prefix = 'invoice_email'; if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') { $template_name = $template_prefix . '_paid'; } else { if ($invoice['overdue'] && $invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') { $template_name = $template_prefix . '_overdue'; } else { $template_name = $template_prefix . '_due'; } } } $replace = module_invoice::get_replace_fields($invoice_id, $invoice); if (defined('_BLOCK_EMAILS') && _BLOCK_EMAILS) { $pdf = false; } else { $pdf = module_invoice::generate_pdf($invoice_id); } $send_email_to = array(); $to = array(); if ($invoice['customer_id']) { $customer = module_customer::get_customer($invoice['customer_id']); $replace['customer_name'] = $customer['customer_name']; if ($invoice['user_id']) { // this invoice has a manually assigned user, only send the invoice to this user. // todo: should we also send to accounts? not sure - see if peopel complain $primary = module_user::get_user($invoice['user_id']); if ($primary) { $send_email_to[] = $primary; } } else { $to = module_user::get_contacts(array('customer_id' => $invoice['customer_id'])); // hunt for 'accounts' extra field $field_to_find = strtolower(module_config::c('accounts_extra_field_name', 'Accounts')); foreach ($to as $contact) { $extras = module_extra::get_extras(array('owner_table' => 'user', 'owner_id' => $contact['user_id'])); foreach ($extras as $e) { if (strtolower($e['extra_key']) == $field_to_find) { // this is the accounts contact - woo! $send_email_to[] = $contact; } } } if (!count($send_email_to) && $customer['primary_user_id']) { $primary = module_user::get_user($customer['primary_user_id']); if ($primary) { $send_email_to[] = $primary; } } } } else { if ($invoice['member_id']) { $member = module_member::get_member($invoice['member_id']); $to = array($member); $replace['customer_name'] = $member['first_name']; } else { $to = array(); } } $template->assign_values($replace); $html = $template->render('html'); // send an email to this user. $email = module_email::new_email(); $email->replace_values = $replace; // todo: send to all customer contacts ? if ($send_email_to) { foreach ($send_email_to as $send_email_t) { if (!empty($send_email_t['user_id'])) { $email->set_to('user', $send_email_t['user_id']); } else { if (!empty($send_email_t['email'])) { $email->set_to_manual($send_email_t['email']); } } } } else { foreach ($to as $t) { if (!empty($t['user_id'])) { $email->set_to('user', $t['user_id']); } else { if (!empty($t['email'])) { $email->set_to_manual($t['email']); } } break; // only 1? todo: all? } } $email->set_bcc_manual(module_config::c('admin_email_address', ''), ''); //$email->set_from('user',); // nfi $email->set_subject($template->description); // do we send images inline? $email->set_html($html); if ($pdf) { $email->add_attachment($pdf); } $email->invoice_id = $invoice_id; $email->customer_id = $invoice['customer_id']; $email->prevent_duplicates = true; if ($email->send($debug)) { // it worked successfully!! // record a log on the invoice when it's done. self::email_sent(array('invoice_id' => $invoice_id, 'template_name' => $template_name)); return true; } else { /// log err? return false; } }
public static function start_payment($invoice_id, $payment_amount, $invoice_payment_id, $user_id = false) { if ($invoice_id && $payment_amount && $invoice_payment_id) { // we are starting a payment via coinbase! // setup a pending payment and redirect to coinbase. $invoice_data = module_invoice::get_invoice($invoice_id); if (!$user_id) { $user_id = $invoice_data['user_id']; } if (!$user_id) { $user_id = isset($invoice_data['primary_user_id']) ? $invoice_data['primary_user_id'] : 0; } if (!$user_id) { $user_id = module_security::get_loggedin_id(); } $user_data = module_user::get_user($user_id); if (!$user_data || !strpos($user_data['email'], '@')) { die('Please ensure your user account has a valid email address before paying with coinbase'); } $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id); // we add the fee details to the invoice payment record so that the new invoice total can be calculated. $fee_percent = module_config::c('payment_method_coinbase_charge_percent', 0); $fee_amount = module_config::c('payment_method_coinbase_charge_amount', 0); $fee_description = module_config::c('payment_method_coinbase_charge_description', 'Coinbase Fee'); $fee_total = 0; if ($fee_percent != 0 || $fee_amount != 0) { $fee_total = module_invoice::calculate_fee($invoice_id, $invoice_data, $payment_amount, array('percent' => $fee_percent, 'amount' => $fee_amount, 'description' => $fee_description)); if ($fee_total != 0) { // add this percent/amount to the invoice payment $payment_amount = $payment_amount + $fee_total; update_insert('invoice_payment_id', $invoice_payment_id, 'invoice_payment', array('fee_percent' => $fee_percent, 'fee_amount' => $fee_amount, 'fee_description' => $fee_description, 'fee_total' => $fee_total, 'amount' => $payment_amount)); } } // we check if this payment is a recurring payment or a standard one off payment. if (module_config::c('payment_method_coinbase_subscriptions', 0)) { // we support subscriptions! // first check if the subscription module is active, and if this invoice is part of an active subscription. $is_subscription = false; if (class_exists('module_subscription', false)) { $subscription_history = get_single('subscription_history', 'invoice_id', $invoice_id); if ($subscription_history && $subscription_history['subscription_id']) { // this invoice is for a subscription! woo! // work out when we should bill for this subscription. $subscription = module_subscription::get_subscription($subscription_history['subscription_id']); $subscription_owner = module_subscription::get_subscription_owner($subscription_history['subscription_owner_id']); if ($subscription_owner['owner_table'] && $subscription_owner['owner_id']) { // work out when the next invoice will be generated for this subscription. $members_subscriptions = module_subscription::get_subscriptions_by($subscription_owner['owner_table'], $subscription_owner['owner_id']); if (isset($members_subscriptions[$subscription_history['subscription_id']])) { $member_subscription = $members_subscriptions[$subscription_history['subscription_id']]; // everything checks out! good to go.... // for now we just do a basic "EVERY X TIME" subscription // todo: work out how long until next generate date, and set that (possibly smaller) time period as the first portion of the subscription /*echo '<pre>'; print_r($subscription_history); print_r($subscription); print_r($subscription_owner); print_r($member_subscription); exit;*/ $is_subscription = array(); if ($subscription['days'] > 0) { $is_subscription['days'] = $subscription['days']; } if ($subscription['months'] > 0) { $is_subscription['months'] = $subscription['months']; } if ($subscription['years'] > 0) { $is_subscription['years'] = $subscription['years']; } if (count($is_subscription)) { $is_subscription['name'] = $subscription['name']; $is_subscription['id'] = $subscription_history['subscription_id']; } } } } } // todo: check if this invoice has a manual renewal date, perform subscription feature as above. if ($is_subscription) { // coinbase only supports these recurring methods: // daily, weekly, every_two_weeks, monthly, quarterly, and yearly // work out which one our days are at. $days = isset($is_subscription['days']) ? $is_subscription['days'] : 0; if (isset($is_subscription['months'])) { $days += $is_subscription['months'] * 30; unset($is_subscription['months']); } if (isset($is_subscription['years'])) { $days += $is_subscription['years'] * 365; unset($is_subscription['years']); } $is_subscription['days'] = $days; if ($days == 1) { $is_subscription['coinbase_period'] = 'daily'; } else { if ($days == 7 || $days == 6 || $days == 8) { $is_subscription['coinbase_period'] = 'weekly'; } else { if ($days == 14 || $days == 13 || $days == 15) { $is_subscription['coinbase_period'] = 'every_two_weeks'; } else { if ($days == 29 || $days == 30 || $days == 31) { $is_subscription['coinbase_period'] = 'monthly'; } else { if ($days >= 87 && $days <= 95) { $is_subscription['coinbase_period'] = 'quarterly'; } else { if ($days >= 363 && $days <= 370) { $is_subscription['coinbase_period'] = 'yearly'; } else { send_error('Someone tried to pay with coinbase but coinbase does not support a recurring subscription period of ' . $days . ' days. Only: daily, weekly, every_two_weeks, monthly, quarterly, and yearly '); $is_subscription = false; // not supported. } } } } } } } if ($is_subscription && isset($is_subscription['coinbase_period'])) { $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id); if (isset($invoice_payment_data['invoice_payment_subscription_id']) && (int) $invoice_payment_data['invoice_payment_subscription_id'] > 0) { // existing subscription already! // not really sure what to do here, just redirect to coinbase as if the user is doing it for the first time. $_REQUEST['payment_subscription'] = true; // hacks! } if (isset($_REQUEST['payment_subscription']) || module_config::c('payment_method_coinbase_force_subscription', 0)) { // user is setting up a subscription! yes!! // we create an entry in our database for this particular subscription // or if one exists for this payment already then we just continue with that (ie: the user is going in again to redo it) // setup a new subscription in the database for us. if (isset($invoice_payment_data['invoice_payment_subscription_id']) && (int) $invoice_payment_data['invoice_payment_subscription_id'] > 0) { $invoice_payment_subscription_id = $invoice_payment_data['invoice_payment_subscription_id']; } else { $invoice_payment_subscription_id = update_insert('invoice_payment_subscription_id', false, 'invoice_payment_subscription', array('status' => _INVOICE_SUBSCRIPTION_PENDING, 'days' => isset($is_subscription['days']) ? $is_subscription['days'] : 0, 'months' => isset($is_subscription['months']) ? $is_subscription['months'] : 0, 'years' => isset($is_subscription['years']) ? $is_subscription['years'] : 0, 'date_start' => '0000-00-00', 'date_last_pay' => '0000-00-00', 'date_next' => '0000-00-00')); update_insert('invoice_payment_id', $invoice_payment_id, 'invoice_payment', array('invoice_payment_subscription_id' => $invoice_payment_subscription_id)); } $description = _l('Recurring payment for %s %s', $is_subscription['name'], _l(str_replace('_', ' ', $is_subscription['coinbase_period']))); $subscription_name = $is_subscription['name']; unset($is_subscription['name']); // so reset/key cals below rosk. $subscription_id = $is_subscription['id']; unset($is_subscription['id']); // so reset/key cals below rosk. $currency = module_config::get_currency($invoice_payment_data['currency_id']); $currency_code = $currency['code']; include module_theme::include_ucm('includes/plugin_paymethod_coinbase/pages/coinbase_form.php'); exit; } else { if (isset($_REQUEST['payment_single'])) { // use is choosing to continue payment as a once off amount } else { // give the user an option $template = module_template::get_template_by_key('invoice_payment_subscription'); $template->page_title = htmlspecialchars($invoice_data['name']); $template->assign_values($invoice_payment_data); $template->assign_values(module_invoice::get_replace_fields($invoice_data['invoice_id'], $invoice_data)); $template->assign_values(array('invoice_payment_id' => $invoice_payment_id, 'payment_url' => module_invoice::link_public_pay($invoice_data['invoice_id']), 'payment_method' => 'paymethod_coinbase', 'payment_amount' => $payment_amount, 'pretty_payment_amount' => dollar($payment_amount, true, $invoice_data['currency_id']), 'subscription_period' => _l('%s days (%s)', $is_subscription['days'], $is_subscription['coinbase_period']), 'fee_amount' => dollar($fee_amount, true, $invoice_data['currency_id']), 'fee_total' => dollar($fee_total, true, $invoice_data['currency_id']), 'fee_percent' => $fee_percent, 'fee_description' => $fee_description)); echo $template->render('pretty_html'); exit; } } } } $description = _l('Payment for invoice %s', $invoice_data['name']); //self::coinbase_redirect($description,$payment_amount,$user_id,$invoice_payment_id,$invoice_id,$invoice_payment_data['currency_id']); $currency = module_config::get_currency($invoice_payment_data['currency_id']); $currency_code = $currency['code']; include module_theme::include_ucm('includes/plugin_paymethod_coinbase/pages/coinbase_form.php'); /*$template = new module_template(); ob_start(); $template->content = ob_get_clean(); echo $template->render('pretty_html');*/ exit; } return false; }
$original_template_name = $template_name = 'credit_note_email'; } else { if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') { $original_template_name = $template_name = $template_prefix . '_paid'; } else { if ($invoice['overdue'] && $invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') { $original_template_name = $template_name = $template_prefix . '_overdue'; } else { $original_template_name = $template_name = $template_prefix . '_due'; } } } $template_name = isset($_REQUEST['template_name']) ? $_REQUEST['template_name'] : $template_name; $template_name = hook_filter_var('invoice_email_template', $template_name, $invoice_id, $invoice); $template = module_template::get_template_by_key($template_name); $replace = module_invoice::get_replace_fields($invoice_id, $invoice); $replace['from_name'] = module_security::get_loggedin_name(); // generate the PDF ready for sending. $pdf = module_invoice::generate_pdf($invoice_id); // find available "to" recipients. // customer contacts. $to_select = false; $to = array(); if ($invoice['customer_id']) { $customer = module_customer::get_customer($invoice['customer_id']); $replace['customer_name'] = $customer['customer_name']; if ($invoice['user_id']) { $primary = module_user::get_user($invoice['user_id']); if ($primary) { $to_select = $primary['email']; }
public static function start_payment($invoice_id, $payment_amount, $invoice_payment_id, $user_id = false) { if ($invoice_id && $payment_amount && $invoice_payment_id) { // we are starting a payment via paypal! // setup a pending payment and redirect to paypal. $invoice_data = module_invoice::get_invoice($invoice_id); if (!$user_id) { $user_id = $invoice_data['user_id']; } if (!$user_id) { $user_id = isset($invoice_data['primary_user_id']) ? $invoice_data['primary_user_id'] : 0; } $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id); // we add the fee details to the invoice payment record so that the new invoice total can be calculated. $fee_percent = module_config::c('payment_method_paypal_charge_percent', 0); $fee_amount = module_config::c('payment_method_paypal_charge_amount', 0); $fee_description = module_config::c('payment_method_paypal_charge_description', 'PayPal Fee'); $fee_total = 0; if ($fee_percent != 0 || $fee_amount != 0) { $fee_total = module_invoice::calculate_fee($invoice_id, $invoice_data, $payment_amount, array('percent' => $fee_percent, 'amount' => $fee_amount, 'description' => $fee_description)); if ($fee_total != 0) { // add this percent/amount to the invoice payment $payment_amount = $payment_amount + $fee_total; update_insert('invoice_payment_id', $invoice_payment_id, 'invoice_payment', array('fee_percent' => $fee_percent, 'fee_amount' => $fee_amount, 'fee_description' => $fee_description, 'fee_total' => $fee_total, 'amount' => $payment_amount)); } } // we check if this payment is a recurring payment or a standard one off payment. if (module_config::c('payment_method_paypal_subscriptions', 0)) { // we support subscriptions! // first check if the subscription module is active, and if this invoice is part of an active subscription. $is_subscription = false; if (class_exists('module_subscription', false)) { $subscription_history = get_single('subscription_history', 'invoice_id', $invoice_id); if ($subscription_history && $subscription_history['subscription_id']) { // this invoice is for a subscription! woo! // work out when we should bill for this subscription. $subscription = module_subscription::get_subscription($subscription_history['subscription_id']); $subscription_owner = module_subscription::get_subscription_owner($subscription_history['subscription_owner_id']); if ($subscription_owner['owner_table'] && $subscription_owner['owner_id']) { // work out when the next invoice will be generated for this subscription. $members_subscriptions = module_subscription::get_subscriptions_by($subscription_owner['owner_table'], $subscription_owner['owner_id']); if (isset($members_subscriptions[$subscription_history['subscription_id']])) { $member_subscription = $members_subscriptions[$subscription_history['subscription_id']]; // everything checks out! good to go.... // for now we just do a basic "EVERY X TIME" subscription // todo: work out how long until next generate date, and set that (possibly smaller) time period as the first portion of the subscription /*echo '<pre>'; print_r($subscription_history); print_r($subscription); print_r($subscription_owner); print_r($member_subscription); exit;*/ $is_subscription = array(); if ($subscription['days'] > 0) { $is_subscription['days'] = $subscription['days']; } if ($subscription['months'] > 0) { $is_subscription['months'] = $subscription['months']; } if ($subscription['years'] > 0) { $is_subscription['years'] = $subscription['years']; } if (count($is_subscription)) { $is_subscription['name'] = $subscription['name']; } } } } } // todo: check if this invoice has a manual renewal date, perform subscription feature as above. if ($is_subscription) { $bits = array(); if (isset($is_subscription['days']) && $is_subscription['days'] > 0) { $bits[] = _l('%s days', $is_subscription['days']); } if (isset($is_subscription['months']) && $is_subscription['months'] > 0) { $bits[] = _l('%s months', $is_subscription['months']); } if (isset($is_subscription['years']) && $is_subscription['years'] > 0) { $bits[] = _l('%s years', $is_subscription['years']); } $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id); if (isset($invoice_payment_data['invoice_payment_subscription_id']) && (int) $invoice_payment_data['invoice_payment_subscription_id'] > 0) { // existing subscription already! // not really sure what to do here, just redirect to paypal as if the user is doing it for the first time. $_REQUEST['payment_subscription'] = true; // hacks! } if (isset($_REQUEST['payment_subscription']) || module_config::c('payment_method_paypal_force_subscription', 0)) { // user is setting up a subscription! yes!! // we create an entry in our database for this particular subscription // or if one exists for this payment already then we just continue with that (ie: the user is going in again to redo it) // setup a new subscription in the database for us. if (isset($invoice_payment_data['invoice_payment_subscription_id']) && (int) $invoice_payment_data['invoice_payment_subscription_id'] > 0) { $invoice_payment_subscription_id = $invoice_payment_data['invoice_payment_subscription_id']; } else { $invoice_payment_subscription_id = update_insert('invoice_payment_subscription_id', false, 'invoice_payment_subscription', array('status' => _INVOICE_SUBSCRIPTION_PENDING, 'days' => isset($is_subscription['days']) ? $is_subscription['days'] : 0, 'months' => isset($is_subscription['months']) ? $is_subscription['months'] : 0, 'years' => isset($is_subscription['years']) ? $is_subscription['years'] : 0, 'date_start' => '0000-00-00', 'date_last_pay' => '0000-00-00', 'date_next' => '0000-00-00')); update_insert('invoice_payment_id', $invoice_payment_id, 'invoice_payment', array('invoice_payment_subscription_id' => $invoice_payment_subscription_id)); } $description = _l('Recurring payment for %s every %s', $is_subscription['name'], implode(', ', $bits)); unset($is_subscription['name']); // so reset/key cals below rosk. $currency = module_config::get_currency($invoice_payment_data['currency_id']); $url = 'https://www.' . (self::is_sandbox() ? 'sandbox.' : '') . 'paypal.com/cgi-bin/webscr?'; // if there are more than 1 recurring amounts then we convert it to days, as paypal only supports one time period. if (count($is_subscription) > 1) { $days = isset($is_subscription['days']) ? $is_subscription['days'] : 0; if (isset($is_subscription['months'])) { $days += $is_subscription['months'] * 30; unset($is_subscription['months']); } if (isset($is_subscription['years'])) { $days += $is_subscription['years'] * 365; unset($is_subscription['years']); } $is_subscription['days'] = $days; } reset($is_subscription); $time = key($is_subscription); if ($time == 'days') { $time = 'D'; } else { if ($time == 'months') { $time = 'M'; } else { if ($time == 'years') { $time = 'Y'; } } } $fields = array('cmd' => '_xclick-subscriptions', 'business' => module_config::c('payment_method_paypal_email', _ERROR_EMAIL), 'currency_code' => $currency['code'], 'item_name' => $description, 'no_shipping' => 1, 'page_style' => module_config::c('paypal_page_style', ''), 'return' => module_invoice::link_public_payment_complete($invoice_id), 'rm' => 1, 'cancel_return' => module_invoice::link_public($invoice_id), 'notify_url' => full_link(_EXTERNAL_TUNNEL . '?m=paymethod_paypal&h=ipn&method=paypal'), 'custom' => self::paypal_custom($user_id, $invoice_payment_id, $invoice_id, $invoice_payment_subscription_id), 'a3' => $payment_amount, 'p3' => current($is_subscription), 't3' => $time, 'src' => 1, 'sra' => 1, 'no_note' => 1); // is there a subscription trail period if (isset($subscription['settings']['trial_period']) && $subscription['settings']['trial_period'] > 0) { // we have to hacck the payment_amount here. // $payment_amount will be the discounted amount (eg: $5 instead of $10) // so we reverse that discounted amount for the real amount. $real_amount = $payment_amount - $fee_amount - (isset($subscription['settings']['trial_price_adjust']) ? $subscription['settings']['trial_price_adjust'] : 0); $real_fee_total = module_invoice::calculate_fee($invoice_id, $invoice_data, $real_amount, array('percent' => $fee_percent, 'amount' => $fee_amount, 'description' => $fee_description)); $real_amount += $real_fee_total; $fields['a3'] = $real_amount; $fields['a1'] = $payment_amount; // $real_amount + (isset($subscription['settings']['trial_price_adjust']) ? $subscription['settings']['trial_price_adjust'] : 0); $fields['p1'] = current($is_subscription); // * $subscription['settings']['trial_period']; $fields['t1'] = $time; } //echo '<pre>'; print_r($fields);exit; foreach ($fields as $key => $val) { $url .= $key . '=' . urlencode($val) . '&'; } //echo '<a href="'.$url.'">'.$url.'</a>';exit; redirect_browser($url); } else { if (isset($_REQUEST['payment_single'])) { // use is choosing to continue payment as a once off amount } else { // give the user an option module_template::init_template('invoice_payment_subscription', '<h2>Payment for Invoice {INVOICE_NUMBER}</h2> <p>Please choose from the available payment options below:</p> <form action="{PAYMENT_URL}" method="post"> <input type="hidden" name="invoice_payment_id" value="{INVOICE_PAYMENT_ID}"> <input type="hidden" name="payment_method" value="{PAYMENT_METHOD}"> <input type="hidden" name="payment_amount" value="{PAYMENT_AMOUNT}"> <p><input type="submit" name="payment_single" value="Pay a Once Off amount of {PRETTY_PAYMENT_AMOUNT}"></p> <p><input type="submit" name="payment_subscription" value="Setup Automatic Payments of {PRETTY_PAYMENT_AMOUNT} every {SUBSCRIPTION_PERIOD}"></p> </form> ', 'Used when a customer tries to pay an invoice that has a subscription option.', 'code'); $template = module_template::get_template_by_key('invoice_payment_subscription'); $template->page_title = htmlspecialchars($invoice_data['name']); $template->assign_values($invoice_payment_data); $template->assign_values(module_invoice::get_replace_fields($invoice_data['invoice_id'], $invoice_data)); $template->assign_values(array('invoice_payment_id' => $invoice_payment_id, 'payment_url' => module_invoice::link_public_pay($invoice_data['invoice_id']), 'payment_method' => 'paymethod_paypal', 'payment_amount' => $payment_amount, 'pretty_payment_amount' => dollar($payment_amount, true, $invoice_data['currency_id']), 'subscription_period' => implode(', ', $bits), 'fee_amount' => dollar($fee_amount, true, $invoice_data['currency_id']), 'fee_total' => dollar($fee_total, true, $invoice_data['currency_id']), 'fee_percent' => $fee_percent, 'fee_description' => $fee_description)); echo $template->render('pretty_html'); exit; } } } } $description = _l('Payment for Invoice %s', $invoice_data['name']); self::paypal_redirect($description, $payment_amount, $user_id, $invoice_payment_id, $invoice_id, $invoice_payment_data['currency_id']); return true; } return false; }
public static function banktransfer_redirect($description, $amount, $user_id, $payment_id, $invoice_id) { $invoice_data = module_invoice::get_invoice($invoice_id); $invoice_replace = module_invoice::get_replace_fields($invoice_id, $invoice_data); $bank_details = module_template::get_template_by_key('paymethod_banktransfer_details'); $bank_details->assign_values($invoice_data + array('amount' => dollar($amount, true, $invoice_data['currency_id']))); $bank_details->assign_values($invoice_replace); $bank_details_html = $bank_details->render('html'); // display a template with the bank details in it. $template = module_template::get_template_by_key('paymethod_banktransfer'); $template->assign_values(array('bank_details' => $bank_details_html, 'link' => module_invoice::link_open($invoice_id))); $template->assign_values($invoice_replace); echo $template->render('pretty_html'); exit; }
public static function start_payment($invoice_id, $payment_amount, $invoice_payment_id, $user_id = false) { if ($invoice_id && $payment_amount && $invoice_payment_id) { // we are starting a payment via stripe! // setup a pending payment and redirect to stripe. $invoice_data = module_invoice::get_invoice($invoice_id); if (!$user_id) { $user_id = $invoice_data['user_id']; } if (!$user_id) { $user_id = isset($invoice_data['primary_user_id']) ? $invoice_data['primary_user_id'] : 0; } if (!$user_id) { $user_id = module_security::get_loggedin_id(); } $user_data = module_user::get_user($user_id); if (!$user_data || !strpos($user_data['email'], '@')) { die('Please ensure your user account has a valid email address before paying with stripe'); } $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id); // we add the fee details to the invoice payment record so that the new invoice total can be calculated. $fee_percent = module_config::c('payment_method_stripe_charge_percent', 0); $fee_amount = module_config::c('payment_method_stripe_charge_amount', 0); $fee_description = module_config::c('payment_method_stripe_charge_description', 'Stripe Fee'); $fee_total = 0; if ($fee_percent != 0 || $fee_amount != 0) { $fee_total = module_invoice::calculate_fee($invoice_id, $invoice_data, $payment_amount, array('percent' => $fee_percent, 'amount' => $fee_amount, 'description' => $fee_description)); if ($fee_total != 0) { // add this percent/amount to the invoice payment $payment_amount = $payment_amount + $fee_total; update_insert('invoice_payment_id', $invoice_payment_id, 'invoice_payment', array('fee_percent' => $fee_percent, 'fee_amount' => $fee_amount, 'fee_description' => $fee_description, 'fee_total' => $fee_total, 'amount' => $payment_amount)); } } // we check if this payment is a recurring payment or a standard one off payment. if (module_config::c('payment_method_stripe_subscriptions', 0)) { // we support subscriptions! // first check if the subscription module is active, and if this invoice is part of an active subscription. $is_subscription = false; if (class_exists('module_subscription', false)) { $subscription_history = get_single('subscription_history', 'invoice_id', $invoice_id); if ($subscription_history && $subscription_history['subscription_id']) { // this invoice is for a subscription! woo! // work out when we should bill for this subscription. $subscription = module_subscription::get_subscription($subscription_history['subscription_id']); $subscription_owner = module_subscription::get_subscription_owner($subscription_history['subscription_owner_id']); if ($subscription_owner['owner_table'] && $subscription_owner['owner_id']) { // work out when the next invoice will be generated for this subscription. $members_subscriptions = module_subscription::get_subscriptions_by($subscription_owner['owner_table'], $subscription_owner['owner_id']); if (isset($members_subscriptions[$subscription_history['subscription_id']])) { $member_subscription = $members_subscriptions[$subscription_history['subscription_id']]; // everything checks out! good to go.... // for now we just do a basic "EVERY X TIME" subscription // todo: work out how long until next generate date, and set that (possibly smaller) time period as the first portion of the subscription /*echo '<pre>'; print_r($subscription_history); print_r($subscription); print_r($subscription_owner); print_r($member_subscription); exit;*/ $is_subscription = array(); if ($subscription['days'] > 0) { $is_subscription['days'] = $subscription['days']; } if ($subscription['months'] > 0) { $is_subscription['months'] = $subscription['months']; } if ($subscription['years'] > 0) { $is_subscription['years'] = $subscription['years']; } if (count($is_subscription)) { $is_subscription['name'] = $subscription['name']; $is_subscription['id'] = $subscription_history['subscription_id']; } } } } } // todo: check if this invoice has a manual renewal date, perform subscription feature as above. if ($is_subscription) { $bits = array(); if (isset($is_subscription['days']) && $is_subscription['days'] > 0) { $bits[] = _l('%s days', $is_subscription['days']); } if (isset($is_subscription['months']) && $is_subscription['months'] > 0) { $bits[] = _l('%s months', $is_subscription['months']); } if (isset($is_subscription['years']) && $is_subscription['years'] > 0) { $bits[] = _l('%s years', $is_subscription['years']); } $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id); if (isset($invoice_payment_data['invoice_payment_subscription_id']) && (int) $invoice_payment_data['invoice_payment_subscription_id'] > 0) { // existing subscription already! // not really sure what to do here, just redirect to stripe as if the user is doing it for the first time. $_REQUEST['payment_subscription'] = true; // hacks! } if (isset($_REQUEST['payment_subscription']) || module_config::c('payment_method_stripe_force_subscription', 0)) { // user is setting up a subscription! yes!! // we create an entry in our database for this particular subscription // or if one exists for this payment already then we just continue with that (ie: the user is going in again to redo it) // setup a new subscription in the database for us. if (isset($invoice_payment_data['invoice_payment_subscription_id']) && (int) $invoice_payment_data['invoice_payment_subscription_id'] > 0) { $invoice_payment_subscription_id = $invoice_payment_data['invoice_payment_subscription_id']; } else { $invoice_payment_subscription_id = update_insert('invoice_payment_subscription_id', false, 'invoice_payment_subscription', array('status' => _INVOICE_SUBSCRIPTION_PENDING, 'days' => isset($is_subscription['days']) ? $is_subscription['days'] : 0, 'months' => isset($is_subscription['months']) ? $is_subscription['months'] : 0, 'years' => isset($is_subscription['years']) ? $is_subscription['years'] : 0, 'date_start' => '0000-00-00', 'date_last_pay' => '0000-00-00', 'date_next' => '0000-00-00')); update_insert('invoice_payment_id', $invoice_payment_id, 'invoice_payment', array('invoice_payment_subscription_id' => $invoice_payment_subscription_id)); } $description = _l('Recurring payment for %s every %s', $is_subscription['name'], implode(', ', $bits)); $subscription_name = $is_subscription['name']; unset($is_subscription['name']); // so reset/key cals below rosk. $subscription_id = $is_subscription['id']; unset($is_subscription['id']); // so reset/key cals below rosk. $currency = module_config::get_currency($invoice_payment_data['currency_id']); // if there are more than 1 recurring amounts then we convert it to weeks, as stripe only supports one time period. if (count($is_subscription) > 1) { $days = isset($is_subscription['days']) ? $is_subscription['days'] : 0; if (isset($is_subscription['months'])) { $days += $is_subscription['months'] * 30; unset($is_subscription['months']); } if (isset($is_subscription['years'])) { $days += $is_subscription['years'] * 365; unset($is_subscription['years']); } $is_subscription['days'] = $days; } reset($is_subscription); $time = key($is_subscription); if ($time == 'days') { // convert days to weeks //$time = 'week'; $time = 'day'; $period = $is_subscription['days']; //$period = max(1,floor($is_subscription['days'] / 7)); } else { if ($time == 'months') { $time = 'month'; $period = $is_subscription['months']; } else { if ($time == 'years') { $time = 'year'; $period = $is_subscription['years']; } else { die('Failed to create subscription, invalid settings'); } } } $stripe_amount = $payment_amount * 100; ini_set('display_errors', true); ini_set('error_reporting', E_ALL); // create or retrieve this subscription. require_once 'includes/plugin_paymethod_stripe/stripe-php/lib/Stripe.php'; $stripe = array("secret_key" => module_config::c('payment_method_stripe_secret_key'), "publishable_key" => module_config::c('payment_method_stripe_publishable_key')); Stripe::setApiKey($stripe['secret_key']); $stripe_plan_id = 'sub_' . $subscription_id; $stripe_plan = false; if ($stripe_plan_id) { // get this plan from stripe, and check it's still valid: try { $stripe_plan = Stripe_Plan::retrieve($stripe_plan_id); } catch (Exception $e) { //print_r($e); } if ($stripe_plan && $stripe_plan->interval == $time && $stripe_plan->interval_count == $period && $stripe_plan->amount == $stripe_amount) { // still have a valid plan! yes! } else { // plan no longer exists or has changed $stripe_plan = false; } } if (!$stripe_plan) { try { $settings = array("amount" => $stripe_amount, "interval" => $time, 'interval_count' => $period, "name" => $subscription_name, "currency" => $currency['code'], "id" => $stripe_plan_id, 'metadata' => array('subscription_id' => $subscription_id)); $stripe_plan = Stripe_Plan::create($settings); } catch (Exception $e) { //print_r($e); } // print_r($stripe_plan); } if ($stripe_plan) { // right to go! // display the stripe payment form (same as stripe_form.php, just we do a subscription rather than once off payment) //self::stripe_redirect($description,$payment_amount,$user_id,$invoice_payment_id,$invoice_id,$invoice_payment_data['currency_id']); $currency = module_config::get_currency($invoice_payment_data['currency_id']); $currency_code = $currency['code']; $template = new module_template(); ob_start(); ?> <h1><?php echo htmlspecialchars($description); ?> </h1> <form action="<?php echo full_link(_EXTERNAL_TUNNEL . '?m=paymethod_stripe&h=pay_subscription&method=stripe'); ?> " method="post"> <input type="hidden" name="invoice_payment_subscription_id" value="<?php echo $invoice_payment_subscription_id; ?> "> <input type="hidden" name="invoice_payment_id" value="<?php echo $invoice_payment_id; ?> "> <input type="hidden" name="invoice_id" value="<?php echo $invoice_id; ?> "> <input type="hidden" name="stripe_plan_id" value="<?php echo $stripe_plan_id; ?> "> <input type="hidden" name="description" value="<?php echo htmlspecialchars($description); ?> "> <input type="hidden" name="user_id" value="<?php echo htmlspecialchars($user_id); ?> "> <script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button" data-key="<?php echo $stripe['publishable_key']; ?> " data-amount="<?php echo $payment_amount * 100; ?> " <?php if (isset($user_data['email']) && strlen($user_data['email'])) { ?> data-email="<?php echo htmlspecialchars($user_data['email']); ?> " <?php } ?> data-currency="<?php echo htmlspecialchars($currency_code); ?> " data-label="<?php _e('Pay %s by Credit Card', dollar($payment_amount, true, $invoice_payment_data['currency_id'])); ?> " data-description="<?php echo htmlspecialchars($description); ?> "></script> </form> <p> </p> <p> <a href="<?php echo module_invoice::link_public($invoice_id); ?> "><?php _e("Cancel"); ?> </a> </p> <?php $template->content = ob_get_clean(); echo $template->render('pretty_html'); exit; } else { die('Failed to create stripe plan. Please check settings: ' . var_export($stripe_plan, true)); } } else { if (isset($_REQUEST['payment_single'])) { // use is choosing to continue payment as a once off amount } else { // give the user an option module_template::init_template('invoice_payment_subscription', '<h2>Payment for Invoice {INVOICE_NUMBER}</h2> <p>Please choose from the available payment options below:</p> <form action="{PAYMENT_URL}" method="post"> <input type="hidden" name="invoice_payment_id" value="{INVOICE_PAYMENT_ID}"> <input type="hidden" name="payment_method" value="{PAYMENT_METHOD}"> <input type="hidden" name="payment_amount" value="{PAYMENT_AMOUNT}"> <p><input type="submit" name="payment_single" value="Pay a Once Off amount of {PRETTY_PAYMENT_AMOUNT}"></p> <p><input type="submit" name="payment_subscription" value="Setup Automatic Payments of {PRETTY_PAYMENT_AMOUNT} every {SUBSCRIPTION_PERIOD}"></p> </form> ', 'Used when a customer tries to pay an invoice that has a subscription option.', 'code'); $template = module_template::get_template_by_key('invoice_payment_subscription'); $template->page_title = htmlspecialchars($invoice_data['name']); $template->assign_values($invoice_payment_data); $template->assign_values(module_invoice::get_replace_fields($invoice_data['invoice_id'], $invoice_data)); $template->assign_values(array('invoice_payment_id' => $invoice_payment_id, 'payment_url' => module_invoice::link_public_pay($invoice_data['invoice_id']), 'payment_method' => 'paymethod_stripe', 'payment_amount' => $payment_amount, 'pretty_payment_amount' => dollar($payment_amount, true, $invoice_data['currency_id']), 'subscription_period' => implode(', ', $bits), 'fee_amount' => dollar($fee_amount, true, $invoice_data['currency_id']), 'fee_total' => dollar($fee_total, true, $invoice_data['currency_id']), 'fee_percent' => $fee_percent, 'fee_description' => $fee_description)); echo $template->render('pretty_html'); exit; } } } } $description = _l('Payment for invoice %s', $invoice_data['name']); //self::stripe_redirect($description,$payment_amount,$user_id,$invoice_payment_id,$invoice_id,$invoice_payment_data['currency_id']); $currency = module_config::get_currency($invoice_payment_data['currency_id']); $currency_code = $currency['code']; $template = new module_template(); ob_start(); include module_theme::include_ucm('includes/plugin_paymethod_stripe/pages/stripe_form.php'); $template->content = ob_get_clean(); echo $template->render('pretty_html'); exit; } return false; }
public static function start_payment($invoice_id, $payment_amount, $invoice_payment_id, $user_id = false) { if ($invoice_id && $payment_amount && $invoice_payment_id) { // we are starting a payment via authorize! // setup a pending payment and redirect to authorize. $invoice_data = module_invoice::get_invoice($invoice_id); if (!$user_id) { $user_id = $invoice_data['user_id']; } if (!$user_id) { $user_id = module_security::get_loggedin_id(); } $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id); if ($invoice_payment_data && $invoice_payment_data['invoice_id'] == $invoice_data['invoice_id']) { //self::authorize_redirect($description,$payment_amount,$user_id,$invoice_payment_id,$invoice_id,$invoice_payment_data['currency_id']); $currency = module_config::get_currency($invoice_payment_data['currency_id']); $currency_code = $currency['code']; ob_start(); include 'includes/plugin_paymethod_authorize/pages/authorize_form_default.php'; module_template::init_template('authorize_credit_card_form', ob_get_clean(), 'Form displayed for payments via Authorize.net', 'code'); $form = module_template::get_template_by_key('authorize_credit_card_form'); // $form = new module_template(); // $form->content = ob_get_clean(); ob_start(); ?> <form action="<?php echo full_link(_EXTERNAL_TUNNEL . '?m=paymethod_authorize&h=pay&method=authorize'); ?> " method="POST" id="authorize-payment-form"> <input type="hidden" name="invoice_payment_id" value="<?php echo $invoice_payment_id; ?> "> <input type="hidden" name="invoice_id" value="<?php echo $invoice_id; ?> "> <input type="hidden" name="invoice_num" value="<?php echo htmlspecialchars($invoice_data['name']); ?> "> <input type="hidden" name="description" value="<?php _e('Payment for Invoice #%', htmlspecialchars($invoice_data['name'])); ?> "> <?php echo $form->content; ?> </form> <?php $form->content = ob_get_clean(); $form->assign_values(array('INVOICE_NUMBER' => $invoice_data['name'], 'AMOUNT' => dollar($invoice_payment_data['amount'], true, $invoice_payment_data['currency_id']), 'CANCEL_URL' => module_invoice::link_public($invoice_id))); // we also want to grab all the normal invoice replace fields and add those in as well. $form->assign_values(module_invoice::get_replace_fields($invoice_id, $invoice_data)); echo $form->render('pretty_html'); } exit; } return false; }
private function _handle_send_email() { $options = @unserialize(base64_decode($_REQUEST['options'])); if (!$options) { $options = array(); } $options = $this->get_email_compose_options($options); if (isset($_REQUEST['custom_to'])) { $custom_to = is_array($_REQUEST['custom_to']) ? $_REQUEST['custom_to'] : array($_REQUEST['custom_to']); $to = array(); foreach ($custom_to as $ct) { $ct = explode('||', $ct); $ct['email'] = $ct[0]; $ct['name'] = isset($ct[1]) ? $ct[1] : ''; $ct['user_id'] = isset($ct[2]) ? (int) $ct[2] : 0; $to[] = $ct; } } else { $to = isset($options['to']) && is_array($options['to']) ? $options['to'] : array(); } $email = $this->new_email(); $email->subject = $options['subject']; foreach ($to as $t) { if (isset($t['user_id']) && $t['user_id'] > 0) { $email->set_to('user', $t['user_id'], $t['email'], $t['name'] . (isset($t['last_name']) && module_config::c('email_to_full_name', 1) ? ' ' . $t['last_name'] : '')); } else { $email->set_to_manual($t['email'], $t['name'] . (isset($t['last_name']) && module_config::c('email_to_full_name', 1) ? ' ' . $t['last_name'] : '')); } } // set from is the default from address. if (isset($options['from_email'])) { $email->set_from_manual($options['from_email'], isset($options['from_name']) ? $options['from_name'] : ''); $email->set_bounce_address($options['from_email']); } if ($options['cc'] && is_array($options['cc'])) { foreach ($options['cc'] as $cc_details) { $bits = explode('||', $cc_details); if (count($bits) >= 2 && $bits[0]) { $email->set_cc_manual($bits[0], $bits[1]); } } } if ($options['bcc']) { $bcc = explode(',', $options['bcc']); foreach ($bcc as $b) { $b = trim($b); if (strlen($b)) { $email->set_bcc_manual($b, ''); } } } if (isset($options['company_id'])) { $email->company_id = $options['company_id']; } if (isset($options['customer_id'])) { // todo: verify this is a legit customer id we can send emails to. $email->customer_id = $options['customer_id']; if ($options['customer_id'] > 0) { foreach (module_customer::get_replace_fields($options['customer_id']) as $key => $val) { //echo "Replacing $key with $val <br>"; $email->replace($key, $val); } } } if (isset($options['newsletter_id'])) { $email->newsletter_id = $options['newsletter_id']; } if (isset($options['file_id'])) { $email->file_id = $options['file_id']; } if (isset($options['send_id'])) { $email->send_id = $options['send_id']; } if (isset($options['invoice_id'])) { $email->invoice_id = $options['invoice_id']; if ($options['invoice_id'] > 0) { foreach (module_invoice::get_replace_fields($options['invoice_id']) as $key => $val) { $email->replace($key, $val); } } } if (isset($options['job_id'])) { $email->job_id = $options['job_id']; if ($options['job_id'] > 0) { foreach (module_job::get_replace_fields($options['job_id']) as $key => $val) { $email->replace($key, $val); } } } if (isset($options['website_id'])) { $email->website_id = $options['website_id']; if ($options['website_id'] > 0) { foreach (module_website::get_replace_fields($options['website_id']) as $key => $val) { $email->replace($key, $val); } } } if (isset($options['quote_id'])) { $email->quote_id = $options['quote_id']; if ($options['quote_id'] > 0) { foreach (module_quote::get_replace_fields($options['quote_id']) as $key => $val) { $email->replace($key, $val); } } } // custom data integration if (class_exists('module_data', false) && module_config::c('custom_data_in_email', 1) && $options['customer_id'] > 0 && !empty($_REQUEST['custom_data_info']) && !empty($_REQUEST['custom_data_related'])) { global $plugins; // find all possible custom data entries $data_types = $plugins['data']->get_data_types(); foreach ($data_types as $data_type) { switch ($data_type['data_type_menu']) { case _CUSTOM_DATA_MENU_LOCATION_CUSTOMER: if ($plugins['data']->can_i('view', $data_type['data_type_name'])) { $search = array('customer_id' => $options['customer_id'], 'data_type_id' => $data_type['data_type_id']); // we have to limit the data types to only those created by current user if they are not administration $datas = $plugins['data']->get_datas($search); if ($datas) { // found some! does this exist in one of our inputs? if (!empty($_REQUEST['custom_data_info'][$data_type['data_type_id']]) && !empty($_REQUEST['custom_data_related'][$data_type['data_type_id']])) { $data_record_id = $_REQUEST['custom_data_related'][$data_type['data_type_id']]; $data_info = json_decode($_REQUEST['custom_data_info'][$data_type['data_type_id']], true); if (is_array($data_info) && isset($datas[$data_record_id])) { // we have a winner! $list_fields = array(); $data_field_groups = $plugins['data']->get_data_field_groups($data_type['data_type_id']); foreach ($data_field_groups as $data_field_group) { $data_fields = $plugins['data']->get_data_fields($data_field_group['data_field_group_id']); foreach ($data_fields as $data_field) { if ($data_field['show_list']) { $list_fields[$data_field['data_field_id']] = $data_field; } } } $list_data_items = $plugins['data']->get_data_items($data_record_id); foreach ($list_fields as $list_field) { $settings = @unserialize($list_data_items[$list_field['data_field_id']]['data_field_settings']); if (!isset($settings['field_type'])) { $settings['field_type'] = isset($list_field['field_type']) ? $list_field['field_type'] : false; } $value = false; if (isset($list_data_items[$list_field['data_field_id']])) { $value = $list_data_items[$list_field['data_field_id']]['data_text']; } if ($value) { $data_info['key'] = $value; break; } } $data_info['data_record_id'] = $data_record_id[$data_type['data_type_id']]; $email->custom_data[$data_type['data_type_id']] = $data_info; $email->set_custom_data($data_type['data_type_id'], $data_record_id); } } } } } } } // final override for first_name last_name if selected from the custom to drop down foreach ($to as $t) { if (isset($t['user_id']) && $t['user_id'] > 0) { $user = module_user::get_user($t['user_id']); if ($user) { if (strpos($options['content'], '{AUTO_LOGIN_LINK}') !== false && $t['user_id'] != 1) { $email->replace('AUTO_LOGIN_LINK', module_security::generate_auto_login_link($t['user_id'])); } $email->replace('first_name', $user['name']); $email->replace('last_name', $user['last_name']); } } } if (isset($options['note_id'])) { $email->note_id = $options['note_id']; } if (isset($options['debug_message'])) { $email->debug_message = $options['debug_message']; } $email->set_html($options['content']); foreach ($options['attachments'] as $attachment) { $email->AddAttachment($attachment['path'], $attachment['name']); } // new addition, manually added attachments. if (isset($_FILES['manual_attachment']) && isset($_FILES['manual_attachment']['tmp_name'])) { foreach ($_FILES['manual_attachment']['tmp_name'] as $key => $tmp_name) { if (is_uploaded_file($tmp_name) && isset($_FILES['manual_attachment']['name'][$key]) && strlen($_FILES['manual_attachment']['name'][$key])) { $email->AddAttachment($tmp_name, $_FILES['manual_attachment']['name'][$key]); } } } if ($email->send()) { if (isset($options['success_callback_args']) && count($options['success_callback_args']) && $options['success_callback'] && is_callable($options['success_callback'])) { // new callback method using call_user_func_array $args = $options['success_callback_args']; $args['email_id'] = $email->email_id; if (preg_match('#module_\\w#', $options['success_callback'])) { call_user_func($options['success_callback'], $args); } } /*else if($options['success_callback']){ eval($options['success_callback']); }*/ set_message('Email sent successfully'); redirect_browser($options['complete_url']); } else { set_error('Sending email failed: ' . $email->error_text); redirect_browser($options['cancel_url']); } }