</a> | <?php } else { ?> <a href="<?php echo module_finance::link_open('new', false) . '&invoice_payment_id=' . $invoice_payment_data['invoice_payment_id']; ?> "><?php _e('More'); ?> </a> | <?php } } ?> <a href="<?php echo module_invoice::link_receipt($invoice_payment_data['invoice_payment_id']); ?> " target="_blank"><?php _e('Receipt'); ?> </a> </td> </tr> <?php } ?> </tbody> </table> </div>
$replace['title'] = '<h3>' . _l('Payment History:') . '</h3>'; } else { $replace['title'] = '<strong>' . _l('Payment History:') . '</strong><br/>'; } if (preg_match('#<tr[^>]+data-item-row="true">.*</tr>#imsU', $t->content, $matches)) { $item_row_html = $matches[0]; $t->content = str_replace($item_row_html, '{ITEM_ROW_CONTENT}', $t->content); } else { set_error('Please ensure a TR with data-item-row="true" is in the invoice_payment_history template'); $item_row_html = ''; } $all_item_row_html = ''; $item_count = 0; // changed from 1 foreach ($payment_historyies as $invoice_payment_id => $invoice_payment_data) { $row_replace = array('ITEM_ODD_OR_EVEN' => $item_count++ % 2 ? 'odd' : 'even', 'ITEM_PAYMENT_DATE' => !trim($invoice_payment_data['date_paid']) || $invoice_payment_data['date_paid'] == '0000-00-00' ? _l('Pending on %s', print_date($invoice_payment_data['date_created'])) : print_date($invoice_payment_data['date_paid']), 'ITEM_PAYMENT_METHOD' => htmlspecialchars($invoice_payment_data['method']), 'ITEM_PAYMENT_DETAILS' => '', 'ITEM_PAYMENT_AMOUNT' => dollar($invoice_payment_data['amount'], true, $invoice_payment_data['currency_id']), 'ITEM_PAYMENT_RECEIPT_URL' => module_invoice::link_receipt($invoice_payment_data['invoice_payment_id'])); if (isset($invoice_payment_data['data']) && $invoice_payment_data['data']) { $details = unserialize($invoice_payment_data['data']); if (isset($details['custom_notes'])) { $row_replace['ITEM_PAYMENT_DETAILS'] = htmlspecialchars($details['custom_notes']); } } $this_item_row_html = $item_row_html; $this_item_row_html = str_replace(' data-item-row="true"', '', $this_item_row_html); foreach ($row_replace as $key => $val) { $this_item_row_html = str_replace('{' . strtoupper($key) . '}', $val, $this_item_row_html); } $all_item_row_html .= $this_item_row_html; } $replace['ITEM_ROW_CONTENT'] = $all_item_row_html; $t->assign_values($replace);
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']); if (isset($_POST['stripeToken']) && isset($invoice_payment_data) && $invoice_payment_data['amount'] > 0) { $token = $_POST['stripeToken']; // Create the charge on Stripe's servers - this will charge the user's card try { $charge = Stripe_Charge::create(array("amount" => $invoice_payment_data['amount'] * 100, "currency" => $currency_code, "card" => $token, "description" => $description)); if ($charge && $charge->paid && $charge->captured) { // successfully paid! update_insert("invoice_payment_id", $invoice_payment_id, "invoice_payment", array('date_paid' => date('Y-m-d'), 'amount' => $charge->amount > 0 ? $charge->amount / 100 : 0, 'method' => 'Stripe')); module_paymethod_stripe::add_payment_data($invoice_payment_id, 'log', "Successfully paid: " . var_export($charge, true)); module_invoice::save_invoice($invoice_id, array()); // success! // redirect to receipt page. redirect_browser(module_invoice::link_receipt($invoice_payment_id)); } else { $error = "Something went wrong during strip payment. Please confirm invoice payment went through: " . htmlspecialchars($description); send_error($error); echo $error; } } catch (Stripe_CardError $e) { // The card has been declined $body = $e->getJsonBody(); $err = $body['error']; $error = "Sorry: Payment failed. <br><br>\n\n" . htmlspecialchars($description) . ". <br><br>\n\n"; $error .= $err['message']; echo $error; $error .= "\n\n\n" . var_export($err, true); send_error($error); } catch (Exception $e) {
public function external_hook($hook) { switch ($hook) { case 'public': $job_id = isset($_REQUEST['i']) ? (int) $_REQUEST['i'] : false; $hash = isset($_REQUEST['hash']) ? trim($_REQUEST['hash']) : false; if ($job_id && $hash) { $correct_hash = $this->link_public($job_id, true); if ($correct_hash == $hash) { // all good to print a receipt for this payment. $job_data = $this->get_job($job_id); if ($job_data) { $job_data = self::get_replace_fields($job_id, $job_data); $customer_data = $job_data['customer_id'] ? module_customer::get_replace_fields($job_data['customer_id']) : array(); $website_data = $job_data['website_id'] ? module_website::get_replace_fields($job_data['website_id']) : array(); module_template::init_template('external_job', '{HEADER}<h2>Job Overview</h2> Job Name: <strong>{JOB_NAME}</strong> <br/> {PROJECT_TYPE} Name: <strong>{PROJECT_NAME}</strong> <br/> <br/> <h3>Task List: {TASK_PERCENT_COMPLETED}</h3> <br/> {TASK_LIST} <br/><br/> {JOB_INVOICES} ', 'Used when displaying the external view of a job.', 'code'); // correct! // load up the receipt template. $template = module_template::get_template_by_key('external_job'); // generate the html for the task output ob_start(); include module_theme::include_ucm('includes/plugin_job/pages/job_public.php'); $public_html = ob_get_clean(); $job_data['task_list'] = $public_html; // do we link the job name? $job_data['header'] = ''; if (module_security::is_logged_in() && $this->can_i('edit', 'Jobs')) { $job_data['header'] = '<div style="text-align: center; padding: 0 0 10px 0; font-style: italic;">' . _l('You can send this page to your customer as a quote or progress update (this message will be hidden).') . '</div>'; } // is this a job or a quote? if ($job_data['date_quote'] != '0000-00-00' && ($job_data['date_start'] == '0000-00-00' && $job_data['date_completed'] == '0000-00-00')) { $job_data['job_or_quote'] = _l('Quote'); } else { $job_data['job_or_quote'] = _l('Job'); } //$job_data['job_name'] = $job_data['name']; $job_data['job_name'] = self::link_open($job_id, true); // format some dates: $job_data['date_quote'] = $job_data['date_quote'] == '0000-00-00' ? _l('N/A') : print_date($job_data['date_quote']); $job_data['date_start'] = $job_data['date_start'] == '0000-00-00' ? _l('N/A') : print_date($job_data['date_start']); $job_data['date_due'] = $job_data['date_due'] == '0000-00-00' ? _l('N/A') : print_date($job_data['date_due']); $job_data['date_completed'] = $job_data['date_completed'] == '0000-00-00' ? _l('N/A') : print_date($job_data['date_completed']); $job_data['TASK_PERCENT_COMPLETED'] = $job_data['total_percent_complete'] > 0 ? _l('(%s%% completed)', $job_data['total_percent_complete'] * 100) : ''; $job_data['job_invoices'] = ''; $invoices = module_invoice::get_invoices(array('job_id' => $job_id)); $job_data['project_type'] = _l(module_config::c('project_name_single', 'Website')); //$website_data = $job_data['website_id'] ? module_website::get_website($job_data['website_id']) : array(); $job_data['project_name'] = isset($website_data['name']) && strlen($website_data['name']) ? $website_data['name'] : _l('N/A'); if (count($invoices)) { $job_data['job_invoices'] .= '<h3>' . _l('Job Invoices:') . '</h3>'; $job_data['job_invoices'] .= '<ul>'; foreach ($invoices as $invoice) { $job_data['job_invoices'] .= '<li>'; $invoice = module_invoice::get_invoice($invoice['invoice_id']); $job_data['job_invoices'] .= module_invoice::link_open($invoice['invoice_id'], true); $job_data['job_invoices'] .= "<br/>"; $job_data['job_invoices'] .= _l('Total: ') . dollar($invoice['total_amount'], true, $invoice['currency_id']); $job_data['job_invoices'] .= "<br/>"; $job_data['job_invoices'] .= '<span class="'; if ($invoice['total_amount_due'] > 0) { $job_data['job_invoices'] .= 'error_text'; } else { $job_data['job_invoices'] .= 'success_text'; } $job_data['job_invoices'] .= '">'; if ($invoice['total_amount_due'] > 0) { $job_data['job_invoices'] .= dollar($invoice['total_amount_due'], true, $invoice['currency_id']); $job_data['job_invoices'] .= ' ' . _l('due'); } else { $job_data['job_invoices'] .= _l('All paid'); } $job_data['job_invoices'] .= '</span>'; $job_data['job_invoices'] .= "<br>"; // view receipts: $payments = module_invoice::get_invoice_payments($invoice['invoice_id']); if (count($payments)) { $job_data['job_invoices'] .= "<ul>"; foreach ($payments as $invoice_payment_id => $invoice_payment_data) { $job_data['job_invoices'] .= "<li>"; $job_data['job_invoices'] .= '<a href="' . module_invoice::link_receipt($invoice_payment_data['invoice_payment_id']) . '" target="_blank">' . _l('View Receipt for payment of %s', dollar($invoice_payment_data['amount'], true, $invoice_payment_data['currency_id'])) . '</a>'; $job_data['job_invoices'] .= "</li>"; } $job_data['job_invoices'] .= "</ul>"; } $job_data['job_invoices'] .= '</li>'; } $job_data['job_invoices'] .= '</ul>'; } $template->assign_values($customer_data); $template->assign_values($website_data); $template->assign_values($job_data); $template->page_title = $job_data['name']; echo $template->render('pretty_html'); } } } break; } }
public function external_hook($hook) { switch ($hook) { case 'pay': // result is retured via ajax and displayed on the page. $invoice_id = isset($_REQUEST['invoice_id']) ? $_REQUEST['invoice_id'] : false; $invoice_payment_id = isset($_REQUEST['invoice_payment_id']) ? $_REQUEST['invoice_payment_id'] : false; if ($invoice_id && $invoice_payment_id) { $invoice_payment_data = module_invoice::get_invoice_payment($invoice_payment_id); $invoice_data = module_invoice::get_invoice($invoice_id); if ($invoice_payment_data && $invoice_data && $invoice_id == $invoice_data['invoice_id'] && $invoice_payment_data['invoice_id'] == $invoice_data['invoice_id']) { $currency = module_config::get_currency($invoice_payment_data['currency_id']); $currency_code = $currency['code']; $description = _l('Payment for invoice %s', $invoice_data['name']); require_once 'includes/plugin_paymethod_authorize/anet_php_1.1.8/AuthorizeNet.php'; $transaction = new AuthorizeNetAIM(module_config::c('payment_method_authorize_api_login_id', ''), module_config::c('payment_method_authorize_transaction_key', '')); $transaction->setSandbox(module_config::c('payment_method_authorize_sandbox', 0)); $transaction->VERIFY_PEER = module_config::c('payment_method_authorize_ssl_verify', 1); $transaction->amount = $invoice_payment_data['amount']; // USD ONLY foreach (array("address", "allow_partial_auth", "amount", "auth_code", "authentication_indicator", "bank_aba_code", "bank_acct_name", "bank_acct_num", "bank_acct_type", "bank_check_number", "bank_name", "card_code", "card_num", "cardholder_authentication_value", "city", "company", "country", "cust_id", "customer_ip", "delim_char", "delim_data", "description", "duplicate_window", "duty", "echeck_type", "email", "email_customer", "encap_char", "exp_date", "fax", "first_name", "footer_email_receipt", "freight", "header_email_receipt", "invoice_num", "last_name", "line_item", "login", "method", "phone", "po_num", "recurring_billing", "relay_response", "ship_to_address", "ship_to_city", "ship_to_company", "ship_to_country", "ship_to_first_name", "ship_to_last_name", "ship_to_state", "ship_to_zip", "split_tender_id", "state", "tax", "tax_exempt", "test_request", "tran_key", "trans_id", "type", "version", "zip") as $possible_value) { if (isset($_POST[$possible_value])) { $transaction->setField($possible_value, $_POST[$possible_value]); } } $transaction->setField('card_num', isset($_POST['number']) ? $_POST['number'] : ''); $transaction->setField('exp_date', $_POST['month'] . '/' . $_POST['year']); $transaction->setField('card_code', $_POST['cvv']); //$transaction->card_num = isset($_POST['number']) ? $_POST['number'] : ''; //$transaction->exp_date = $_POST['month'].'/'.$_POST['year']; //$transaction->card_code = $_POST['cvv']; $response = $transaction->authorizeAndCapture(); if ($response->approved) { // echo "<h1>Success! The test credit card has been charged!</h1>"; // echo "Transaction ID: " . $response->transaction_id; update_insert("invoice_payment_id", $invoice_payment_id, "invoice_payment", array('date_paid' => date('Y-m-d'))); module_paymethod_stripe::add_payment_data($invoice_payment_id, 'log', "Successfully paid: " . var_export($response, true)); module_invoice::save_invoice($invoice_id, array()); // success! // redirect to receipt page. redirect_browser(module_invoice::link_receipt($invoice_payment_id)); } else { echo isset($response->error_message) ? $response->error_message : (isset($response->response_reason_text) ? $response->response_reason_text : var_export($response, true)); } exit; } } echo 'Error paying via Authorize'; exit; } }