コード例 #1
1
 public static function google_redirect($description, $amount, $user_id, $invoice_payment_id, $invoice_id, $currency_id)
 {
     chdir(dirname(__FILE__));
     //'includes/plugin_paymethod_google/');
     require_once 'library/googlecart.php';
     require_once 'library/googleitem.php';
     $server_type = self::is_sandbox() ? "sandbox" : '';
     $currency = module_config::get_currency($currency_id);
     self::add_payment_data($invoice_payment_id, 'log', 'Starting payment of ' . $server_type . ' in currency ' . $currency['code']);
     $cart = new GoogleCart(self::get_merchant_id(), self::get_merchant_key(), $server_type, $currency['code']);
     $total_count = 1;
     //  Check this URL for more info about the two types of digital Delivery
     //  http://code.google.com/apis/checkout/developer/Google_Checkout_Digital_Delivery.html
     //  Key/URL delivery
     self::add_payment_data($invoice_payment_id, 'log', 'Adding ' . $total_count . 'x ' . $description . ' (' . $amount . ' ' . $currency['code'] . ')');
     $item_1 = new GoogleItem($description, "", $total_count, $amount);
     // Unit price
     //$item_1->SetURLDigitalContent(module_invoice::link_receipt($invoice_payment_id),
     $item_1->SetURLDigitalContent(module_invoice::link_public_print($invoice_id), '', _l("Payment Receipt"));
     $cart->AddItem($item_1);
     $private_data = new MerchantPrivateData(array('invoice_id' => $invoice_id, 'amount' => $amount, 'currency_id' => $currency_id, 'invoice_payment_id' => $invoice_payment_id));
     $cart->SetMerchantPrivateData($private_data);
     // Specify <edit-cart-url>
     $cart->SetEditCartUrl(module_invoice::link_public($invoice_id));
     // Specify "Return to xyz" link
     $cart->SetContinueShoppingUrl(module_invoice::link_public($invoice_id));
     // Request buyer's phone number
     //$cart->SetRequestBuyerPhone(true);
     // This will do a server-2-server cart post and send an HTTP 302 redirect status
     // This is the best way to do it if implementing digital delivery
     // More info http://code.google.com/apis/checkout/developer/index.html#alternate_technique
     list($status, $error) = $cart->CheckoutServer2Server();
     // if i reach this point, something was wrong
     echo "An error had ocurred: <br />HTTP Status: " . $status . ":";
     echo "<br />Error message:<br />";
     echo $error;
     exit;
 }
コード例 #2
0
            </tr>
            <tr class="payment_type_offline">
                <td align="left" colspan="2" id="payment_type_offline_info">

                </td>
            </tr>
            </tbody>
        </table>
        <?php 
    $fieldset_data = array('heading' => array('title' => _l('Make a Payment'), 'type' => 'h3'), 'elements_before' => ob_get_clean());
    echo module_form::generate_fieldset($fieldset_data);
    unset($fieldset_data);
}
if (module_invoice::can_i('edit', 'Invoices')) {
    /*** INVOICE ADVANCED **/
    $fieldset_data = array('heading' => array('type' => 'h3', 'title' => 'Advanced'), 'class' => 'tableclass tableclass_form tableclass_full', 'elements' => array(array('title' => 'Customer Link', 'hidden' => !((int) $invoice_id > 0), 'field' => array('type' => 'html', 'value' => '<a href="' . module_invoice::link_public($invoice_id) . '" target="_blank">' . _l('Click to view external link') . '</a>', 'help' => 'You can send this link to your customer and they can preview the invoice, pay for the invoice as well as optionally download the invoice as a PDF'))));
    $fieldset_data['elements'][] = array('title' => 'Allowed Payments', 'fields' => array(array('type' => 'hidden', 'name' => 'allowed_payment_method_check', 'value' => 1), function () use(&$payment_methods, $invoice_id) {
        if (module_invoice::can_i('edit', 'Invoices')) {
            $x = 0;
            foreach ($payment_methods as &$payment_method) {
                if ($payment_method->is_enabled()) {
                    ?>

                            <input type="checkbox" name="allowed_payment_method[<?php 
                    echo $payment_method->module_name;
                    ?>
]" value="1" id="paymethodallowed<?php 
                    echo $x;
                    ?>
" <?php 
                    echo $payment_method->is_allowed_for_invoice($invoice_id) ? 'checked' : '';
コード例 #3
0
ファイル: invoice.php プロジェクト: sgh1986915/php-crm
 /**
  * @param $invoice_id
  * @param $invoice_data
  * @return array
  *
  * todo: make this method call the other 'get_replace_fields' available in website/job/etc..
  */
 public static function get_replace_fields($invoice_id, $invoice_data = false)
 {
     if (!$invoice_data) {
         $invoice_data = self::get_invoice($invoice_id);
     }
     $customer_data = array();
     if ($invoice_data['customer_id']) {
         $customer_data = module_customer::get_replace_fields($invoice_data['customer_id'], $invoice_data['user_id']);
     }
     if (!is_array($customer_data)) {
         $customer_data = array();
     }
     $data = array_merge($customer_data, $invoice_data);
     // so we get total_amount_due and stuff.
     $data = array_merge($data, array('invoice_number' => htmlspecialchars($invoice_data['name']), 'project_type' => _l(module_config::c('project_name_single', 'Website')), 'print_link' => self::link_public_print($invoice_id), 'title' => module_config::s('admin_system_name'), 'invoice_paid' => $invoice_data['total_amount_due'] <= 0 ? '<p> <font style="font-size: 1.6em;"><strong>' . _l('INVOICE PAID') . '</strong></font> </p>' : '', 'is_invoice_paid' => $invoice_data['total_amount_due'] <= 0 ? 1 : '', 'date_create' => print_date($invoice_data['date_create']), 'due_date' => print_date($invoice_data['date_due'])));
     $data['total_amount'] = dollar($invoice_data['total_amount'], true, $invoice_data['currency_id']);
     $data['total_amount_due'] = dollar($invoice_data['total_amount_due'], true, $invoice_data['currency_id']);
     $data['total_amount_paid'] = dollar($invoice_data['total_amount_paid'], true, $invoice_data['currency_id']);
     $data['date_paid'] = print_date($invoice_data['date_paid']);
     $data['date_due'] = print_date($invoice_data['date_due']);
     $data['date_sent'] = print_date($invoice_data['date_sent']);
     $data['invoice_number'] = $invoice_data['name'];
     $data['invoice_url'] = module_invoice::link_public($invoice_id);
     $data['invoice_date_range'] = '';
     if ($invoice_data['date_renew'] != '0000-00-00') {
         $data['invoice_date_range'] = _l('%s to %s', print_date($invoice_data['date_create']), print_date(strtotime("-1 day", strtotime($invoice_data['date_renew']))));
     }
     if (isset($invoice_data['credit_note_id']) && $invoice_data['credit_note_id']) {
         $credit_invoice = module_invoice::get_invoice($invoice_data['credit_note_id'], true);
         $data['credit_invoice_number'] = htmlspecialchars($credit_invoice['name']);
     }
     $data['invoice_notes'] = '';
     // grab any public notes
     if (class_exists('module_note', false) && module_note::is_plugin_enabled()) {
         $notes = module_note::get_notes(array('public' => 1, 'owner_table' => 'invoice', 'owner_id' => $invoice_id));
         if (count($notes) > 1) {
             $data['invoice_notes'] .= '<ul>';
             foreach ($notes as $note) {
                 if ($note['public']) {
                     $data['invoice_notes'] .= '<li>';
                     $data['invoice_notes'] .= htmlspecialchars($note['note']);
                     $data['invoice_notes'] .= '</li>';
                 }
             }
             $data['invoice_notes'] .= '</ul>';
         } else {
             $note = array_shift($notes);
             $data['invoice_notes'] .= htmlspecialchars($note['note']);
         }
     }
     $job_names = $website_url = $project_names = $project_names_and_url = array();
     foreach ($invoice_data['job_ids'] as $job_id) {
         $job_data = module_job::get_job($job_id);
         if ($job_data && $job_data['job_id'] == $job_id) {
             $job_names[$job_data['job_id']] = $job_data['name'];
             if (module_config::c('job_invoice_show_date_range', 1)) {
                 // check if this job is a renewable job.
                 if ($job_data['date_renew'] != '0000-00-00') {
                     $data['invoice_date_range'] = _l('%s to %s', print_date($job_data['date_start']), print_date(strtotime("-1 day", strtotime($job_data['date_renew']))));
                 }
             }
             $fields = module_job::get_replace_fields($job_id, $job_data);
             foreach ($fields as $key => $val) {
                 if (!isset($data[$key]) || !$data[$key] && $val) {
                     $data[$key] = $val;
                 }
             }
             if ($job_data['website_id']) {
                 $website_data = module_website::get_website($job_data['website_id']);
                 if ($website_data && $website_data['website_id'] == $job_data['website_id']) {
                     if (isset($website_data['url']) && $website_data['url']) {
                         $website_url[$website_data['website_id']] = module_website::urlify($website_data['url']);
                         $website_data['name_url'] = $website_data['name'] . ' (' . module_website::urlify($website_data['url']) . ')';
                     } else {
                         $website_data['name_url'] = $website_data['name'];
                     }
                     $project_names[$website_data['website_id']] = $website_data['name'];
                     $project_names_and_url[$website_data['website_id']] = $website_data['name_url'];
                     $fields = module_website::get_replace_fields($website_data['website_id'], $website_data);
                     foreach ($fields as $key => $val) {
                         if (!isset($data[$key]) || !$data[$key] && $val) {
                             $data[$key] = $val;
                         }
                     }
                 }
             }
         }
     }
     if (isset($invoice_data['website_id']) && $invoice_data['website_id']) {
         $website_data = module_website::get_website($invoice_data['website_id']);
         if ($website_data && $website_data['website_id'] == $invoice_data['website_id']) {
             if (isset($website_data['url']) && $website_data['url']) {
                 $website_url[$website_data['website_id']] = module_website::urlify($website_data['url']);
                 $website_data['name_url'] = $website_data['name'] . ' (' . module_website::urlify($website_data['url']) . ')';
             } else {
                 $website_data['name_url'] = $website_data['name'];
             }
             $project_names[$website_data['website_id']] = $website_data['name'];
             $project_names_and_url[$website_data['website_id']] = $website_data['name_url'];
             $fields = module_website::get_replace_fields($website_data['website_id'], $website_data);
             foreach ($fields as $key => $val) {
                 if (!isset($data[$key]) || !$data[$key] && $val) {
                     $data[$key] = $val;
                 }
             }
         }
     }
     $data['website_name'] = $data['project_name'] = forum_text(count($project_names) ? implode(', ', $project_names) : '');
     $data['website_name_url'] = forum_text(count($project_names_and_url) ? implode(', ', $project_names_and_url) : '');
     $data['website_url'] = forum_text(count($website_url) ? implode(', ', $website_url) : '');
     $data['job_name'] = forum_text($job_names ? implode(', ', $job_names) : '');
     if (class_exists('module_group', false)) {
         // get the job groups
         $wg = array();
         $g = array();
         foreach ($invoice_data['job_ids'] as $group_job_id) {
             $group_job_id = (int) trim($group_job_id);
             if ($group_job_id > 0) {
                 $job_data = module_job::get_job($group_job_id);
                 foreach (module_group::get_groups_search(array('owner_table' => 'job', 'owner_id' => $group_job_id)) as $group) {
                     $g[$group['group_id']] = $group['name'];
                 }
                 // get the website groups
                 if ($job_data['website_id']) {
                     foreach (module_group::get_groups_search(array('owner_table' => 'website', 'owner_id' => $job_data['website_id'])) as $group) {
                         $wg[$group['group_id']] = $group['name'];
                     }
                 }
             }
         }
         if (isset($invoice_data['website_id']) && $invoice_data['website_id']) {
             foreach (module_group::get_groups_search(array('owner_table' => 'website', 'owner_id' => $invoice_data['website_id'])) as $group) {
                 $wg[$group['group_id']] = $group['name'];
             }
         }
         $data['job_group'] = implode(', ', $g);
         $data['website_group'] = implode(', ', $wg);
     }
     // addition. find all extra keys for this invoice and add them in.
     // we also have to find any EMPTY extra fields, and add those in as well.
     if (class_exists('module_extra', false) && module_extra::is_plugin_enabled()) {
         $all_extra_fields = module_extra::get_defaults('invoice');
         foreach ($all_extra_fields as $e) {
             $data[$e['key']] = _l('N/A');
         }
         // and find the ones with values:
         $extras = module_extra::get_extras(array('owner_table' => 'invoice', 'owner_id' => $invoice_id));
         foreach ($extras as $e) {
             $data[$e['extra_key']] = $e['extra'];
         }
     }
     $new_data = hook_handle_callback('invoice_replace_fields', $invoice_id, $data);
     if (is_array($new_data)) {
         foreach ($new_data as $new_d) {
             $data = array_merge($data, $new_d);
         }
     }
     return $data;
 }
コード例 #4
0
					<li>
						<strong><?php 
                echo $payment_methods_on['name'];
                ?>
</strong><br/>
						<?php 
                echo $payment_methods_on['description'];
                ?>
					</li>
				<?php 
            }
            ?>
			</ul>
			<?php 
            $template_print = module_template::get_template_by_key('invoice_payment_methods_online_footer');
            $template_print->assign_values(array('payment_methods' => ob_get_clean(), 'link' => module_invoice::link_public($invoice_id)));
            echo $template_print->replace_content();
        }
    }
    // count( $payment_methods_online )
    $payment_methods_online_html = ob_get_clean();
    ob_start();
    if (count($payment_methods_offline)) {
        $template_print = module_template::get_template_by_key('invoice_payment_methods_offline');
        echo $template_print->content;
        ?>
        <ul>
        <?php 
        foreach ($payment_methods_offline as $payment_methods_of) {
            ?>
            <li>
コード例 #5
0
 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;
 }
コード例 #6
0
                        <h3><?php 
        _e('Advanced');
        ?>
</h3>
                        <table class="tableclass tableclass_form tableclass_full" cellpadding="0" cellspacing="0">
                            <tbody>
                            <tr>
                                <th class="width1">
                                    <?php 
        _e('Customer Link');
        ?>

                                </th>
                                <td>
                                    <a href="<?php 
        echo module_invoice::link_public($invoice_id);
        ?>
" target="_blank"><?php 
        echo _l('Click to view external link');
        ?>
</a> <?php 
        _h('You can send this link to your customer and they can preview the invoice, pay for the invoice as well as optionally download the invoice as a PDF');
        ?>

                                </td>
                            </tr>
                            <!-- <tr>
                                <th>
                                    <?php 
        _e('Cancel Date');
        ?>
コード例 #7
0
            function customer_admin_email_generate_invoice_list($invoices, $customer_id)
            {
                ob_start();
                $colspan = 9;
                $colspan2 = 0;
                $invoice_total = array();
                $invoice_total_due = array();
                foreach ($invoices as $invoice) {
                    if (!isset($invoice_total[$invoice['currency_id']])) {
                        $invoice_total[$invoice['currency_id']] = 0;
                    }
                    if ($invoice['c_total_amount'] == 0) {
                        $invoice = module_invoice::get_invoice($invoice['invoice_id']);
                    }
                    $invoice_total[$invoice['currency_id']] += $invoice['c_total_amount'];
                    if (!isset($invoice_total_due[$invoice['currency_id']])) {
                        $invoice_total_due[$invoice['currency_id']] = 0;
                    }
                    $invoice_total_due[$invoice['currency_id']] += $invoice['c_total_amount_due'];
                }
                $table_manager = module_theme::new_table_manager();
                $columns = array();
                $columns['invoice_number'] = array('title' => 'Invoice Number', 'callback' => function ($invoice) {
                    //echo module_invoice::link_open($invoice['invoice_id'],true,$invoice);
                    echo '<a href="' . module_invoice::link_public($invoice['invoice_id']) . '">' . htmlspecialchars($invoice['name']) . '</a>';
                }, 'cell_class' => 'row_action');
                $columns['invoice_status'] = array('title' => 'Status', 'callback' => function ($invoice) {
                    echo htmlspecialchars($invoice['status']);
                });
                $columns['invoice_create_date'] = array('title' => 'Create Date', 'callback' => function ($invoice) {
                    if (!$invoice['date_create'] || $invoice['date_create'] == '0000-00-00') {
                        //echo print_date($invoice['date_created']);
                    } else {
                        echo print_date($invoice['date_create']);
                    }
                });
                $columns['invoice_due_date'] = array('title' => 'Due Date', 'callback' => function ($invoice) {
                    if ((!$invoice['date_paid'] || $invoice['date_paid'] == '0000-00-00') && strtotime($invoice['date_due']) < time()) {
                        echo '<span class="error_text">';
                        echo print_date($invoice['date_due']);
                        echo '</span>';
                    } else {
                        echo print_date($invoice['date_due']);
                    }
                });
                $columns['invoice_sent_date'] = array('title' => 'Sent Date', 'callback' => function ($invoice) {
                    if ($invoice['date_sent'] && $invoice['date_sent'] != '0000-00-00') {
                        ?>

				            <?php 
                        echo print_date($invoice['date_sent']);
                        ?>

				        <?php 
                    } else {
                        ?>

				            <span class="error_text"><?php 
                        _e('Not sent');
                        ?>
</span>
				        <?php 
                    }
                });
                $columns['invoice_paid_date'] = array('title' => 'Paid Date', 'callback' => function ($invoice) {
                    if ($invoice['date_paid'] && $invoice['date_paid'] != '0000-00-00') {
                        ?>

				            <?php 
                        echo print_date($invoice['date_paid']);
                        ?>

				        <?php 
                    } else {
                        if ($invoice['date_cancel'] && $invoice['date_cancel'] != '0000-00-00') {
                            ?>

				            <span class="error_text"><?php 
                            _e('Cancelled');
                            ?>
</span>
				        <?php 
                        } else {
                            if ($invoice['overdue']) {
                                ?>

				            <span class="error_text" style="font-weight: bold; text-decoration: underline;"><?php 
                                _e('Overdue');
                                ?>
</span>
				        <?php 
                            } else {
                                ?>

				            <span class="error_text"><?php 
                                _e('Not paid');
                                ?>
</span>
				        <?php 
                            }
                        }
                    }
                });
                if (class_exists('module_website', false) && module_website::is_plugin_enabled() && module_website::can_i('view', module_config::c('project_name_plural', 'Websites'))) {
                    $colspan++;
                    $columns['invoice_website'] = array('title' => module_config::c('project_name_single', 'Website'), 'callback' => function ($invoice) {
                        if (isset($invoice['website_ids'])) {
                            foreach ($invoice['website_ids'] as $website_id) {
                                if ((int) $website_id > 0) {
                                    echo module_website::link_open($website_id, true);
                                    echo '<br/>';
                                }
                            }
                        }
                    });
                }
                $columns['invoice_job'] = array('title' => 'Job', 'callback' => function ($invoice) {
                    foreach ($invoice['job_ids'] as $job_id) {
                        if ((int) $job_id > 0) {
                            //echo module_job::link_open($job_id,true);
                            $job_data = module_job::get_job($job_id);
                            echo '<a href="' . module_job::link_public($job_id) . '">' . htmlspecialchars($job_data['name']) . '</a>';
                            if ($job_data['date_start'] && $job_data['date_start'] != '0000-00-00' && $job_data['date_renew'] && $job_data['date_renew'] != '0000-00-00') {
                                _e(' (%s to %s)', print_date($job_data['date_start']), print_date(strtotime("-1 day", strtotime($job_data['date_renew']))));
                            }
                            echo "<br/>\n";
                        }
                    }
                    hook_handle_callback('invoice_admin_list_job', $invoice['invoice_id']);
                });
                if (!isset($_REQUEST['customer_id']) && module_customer::can_i('view', 'Customers')) {
                    $colspan++;
                    $columns['invoice_customer'] = array('title' => 'Customer', 'callback' => function ($invoice) {
                        echo module_customer::link_open($invoice['customer_id'], true);
                    });
                }
                $columns['c_invoice_total'] = array('title' => 'Invoice Total', 'callback' => function ($invoice) {
                    echo dollar($invoice['total_amount'], true, $invoice['currency_id']);
                });
                $columns['c_invoice_total_due'] = array('title' => 'Amount Due', 'callback' => function ($invoice) {
                    echo dollar($invoice['total_amount_due'], true, $invoice['currency_id']);
                    ?>

				        <?php 
                    if ($invoice['total_amount_credit'] > 0) {
                        ?>

				        <span class="success_text"><?php 
                        echo _l('Credit: %s', dollar($invoice['total_amount_credit'], true, $invoice['currency_id']));
                        ?>
</span>
				            <?php 
                    }
                });
                if (class_exists('module_extra', false)) {
                    ob_start();
                    $colspan2 += module_extra::print_table_header('invoice');
                    // used in the footer calc.
                    ob_end_clean();
                    $table_manager->display_extra('invoice', function ($invoice) {
                        module_extra::print_table_data('invoice', $invoice['invoice_id']);
                    });
                }
                $table_manager->set_columns($columns);
                $table_manager->row_callback = function ($row_data) {
                    // load the full vendor data before displaying each row so we have access to more details
                    if (isset($row_data['invoice_id']) && (int) $row_data['invoice_id'] > 0) {
                        return module_invoice::get_invoice($row_data['invoice_id']);
                    }
                    return array();
                };
                $table_manager->set_rows($invoices);
                if (module_config::c('invoice_list_show_totals', 1)) {
                    $footer_rows = array();
                    foreach ($invoice_total + $invoice_total_due as $currency_id => $foo) {
                        $currency = get_single('currency', 'currency_id', $currency_id);
                        $footer_rows[] = array('invoice_number' => array('data' => '<strong>' . _l('%s Totals:', $currency && isset($currency['code']) ? $currency['code'] : '') . '</strong>', 'cell_colspan' => $colspan - 2, 'cell_class' => 'text-right'), 'c_invoice_total' => array('data' => '<strong>' . dollar(isset($invoice_total[$currency_id]) ? $invoice_total[$currency_id] : 0, true, $currency_id) . '</strong>'), 'c_invoice_total_due' => array('data' => '<strong>' . dollar(isset($invoice_total_due[$currency_id]) ? $invoice_total_due[$currency_id] : 0, true, $currency_id) . '</strong>'), 'row_bulk_action' => array('data' => ' ', 'cell_colspan' => $colspan2));
                    }
                    $table_manager->set_footer_rows($footer_rows);
                }
                $table_manager->pagination = false;
                $table_manager->print_table();
                return ob_get_clean();
            }
コード例 #8
0
ファイル: job_public.php プロジェクト: sgh1986915/php-crm
    echo $percentage >= 1 ? 'success_text' : 'error_text';
    ?>
">
                                            <?php 
    echo $percentage * 100;
    ?>
%
                                        </span>
                                    </td>
                                    <td align="center" valign="top">
                                        <?php 
    if ($task_data['invoiced'] && $task_data['invoice_id']) {
        $invoice = module_invoice::get_invoice($task_data['invoice_id']);
        ?>
 <a href="<?php 
        echo module_invoice::link_public($invoice['invoice_id']);
        ?>
"><?php 
        echo $invoice['name'];
        ?>
</a> <?php 
    } else {
        if ($percentage >= 1) {
            echo '<span class="success_text">' . _l('Pending') . '</span>';
        } else {
            echo _l('N/A');
        }
    }
    ?>
                                    </td>
                                </tr>
コード例 #9
0
ファイル: customer.php プロジェクト: sgh1986915/php-crm
 public function external_hook($hook)
 {
     switch ($hook) {
         case 'public_signup_form':
             $signup_form = module_template::get_template_by_key('customer_signup_form_wrapper');
             $signup_form->page_title = $signup_form->description;
             $signup_form->assign_values(array('signup_form' => self::get_customer_signup_form_html()));
             echo $signup_form->render('pretty_html');
             exit;
         case 'public_signup':
             // sign out if testing.
             if (module_security::is_logged_in()) {
                 set_message('Logged out due to signup');
                 module_security::logout();
             }
             $result = array('messages' => array());
             function customer_signup_complete($result)
             {
                 if (isset($_REQUEST['via_ajax'])) {
                     echo json_encode($result);
                 } else {
                     echo implode('<br/>', $result['messages']);
                 }
                 exit;
             }
             if (!module_config::c('customer_signup_allowed', 0)) {
                 $result['error'] = 1;
                 $result['messages'][] = 'Customer signup disabled';
                 customer_signup_complete($result);
             }
             //recaptcha on signup form.
             if (module_config::c('captcha_on_signup_form', 0)) {
                 if (!module_captcha::check_captcha_form()) {
                     $result['error'] = 1;
                     $result['messages'][] = 'Captcha fail, please go back and enter correct captcha code.';
                     customer_signup_complete($result);
                 }
             }
             $customer = isset($_POST['customer']) && is_array($_POST['customer']) ? $_POST['customer'] : array();
             $contact = isset($_POST['contact']) && is_array($_POST['contact']) ? $_POST['contact'] : array();
             $contact_extra = isset($contact['extra']) && is_array($contact['extra']) ? $contact['extra'] : array();
             $contact_group = isset($contact['group_ids']) && is_array($contact['group_ids']) ? $contact['group_ids'] : array();
             $customer_extra = isset($customer['extra']) ? $customer['extra'] : array();
             $customer_group = isset($customer['group_ids']) && is_array($customer['group_ids']) ? $customer['group_ids'] : array();
             $address = isset($_POST['address']) ? $_POST['address'] : array();
             $website = isset($_POST['website']) ? $_POST['website'] : array();
             $website_extra = isset($website['extra']) ? $website['extra'] : array();
             $website_group = isset($website['group_ids']) && is_array($website['group_ids']) ? $website['group_ids'] : array();
             $job = isset($_POST['job']) ? $_POST['job'] : array();
             $job_extra = isset($job['extra']) ? $job['extra'] : array();
             $subscription = isset($_POST['subscription']) ? $_POST['subscription'] : array();
             // sanatise possibly problematic fields:
             // customer:
             $allowed = array('name', 'last_name', 'customer_name', 'email', 'phone', 'mobile', 'extra', 'type');
             foreach ($customer as $key => $val) {
                 if (!in_array($key, $allowed)) {
                     unset($customer[$key]);
                 }
             }
             if (isset($customer['type']) && $customer['type'] != _CUSTOMER_TYPE_NORMAL && $customer['type'] != _CUSTOMER_TYPE_LEAD) {
                 unset($customer['type']);
             }
             // added multiple contact support in the form of arrays.
             $contact_fields = array('name', 'last_name', 'email', 'phone');
             if (module_config::c('customer_signup_password', 0)) {
                 $contact_fields[] = 'password';
             }
             foreach ($contact_fields as $multi_value) {
                 if (isset($contact[$multi_value])) {
                     if (!is_array($contact[$multi_value])) {
                         $contact[$multi_value] = array($contact[$multi_value]);
                     }
                 } else {
                     if (isset($customer[$multi_value])) {
                         $contact[$multi_value] = array($customer[$multi_value]);
                     } else {
                         $contact[$multi_value] = array();
                     }
                 }
             }
             $valid_contact_email = false;
             $name_fallback = false;
             $primary_email = false;
             foreach ($contact['email'] as $contact_key => $email) {
                 if (!$name_fallback && isset($contact['name'][$contact_key])) {
                     $name_fallback = $contact['name'][$contact_key];
                 }
                 $contact['email'][$contact_key] = filter_var(strtolower(trim($email)), FILTER_VALIDATE_EMAIL);
                 if ($contact['email'][$contact_key]) {
                     $valid_contact_email = true;
                     if (!$primary_email) {
                         $primary_email = $contact['email'][$contact_key];
                         // set the primary contact details here by adding them to the master customer array
                         foreach ($contact_fields as $primary_contact_field) {
                             $customer[$primary_contact_field] = isset($contact[$primary_contact_field][$contact_key]) ? $contact[$primary_contact_field][$contact_key] : '';
                             unset($contact[$primary_contact_field][$contact_key]);
                         }
                     }
                 }
             }
             // start error checking / required fields
             if (!isset($customer['customer_name']) || !strlen($customer['customer_name'])) {
                 $customer['customer_name'] = $name_fallback;
             }
             if (!strlen($customer['customer_name'])) {
                 $result['error'] = 1;
                 $result['messages'][] = "Failed, please go back and provide a customer name.";
             }
             if (!$valid_contact_email || !$primary_email) {
                 $result['error'] = 1;
                 $result['messages'][] = "Failed, please go back and provide an email address.";
             }
             // check all posted required fields.
             function check_required($postdata, $messages = array())
             {
                 if (is_array($postdata)) {
                     foreach ($postdata as $key => $val) {
                         if (strpos($key, '_required') && strlen($val)) {
                             $required_key = str_replace('_required', '', $key);
                             if (!isset($postdata[$required_key]) || !$postdata[$required_key]) {
                                 $messages[] = 'Required field missing: ' . htmlspecialchars($val);
                             }
                         }
                         if (is_array($val)) {
                             $messages = check_required($val, $messages);
                         }
                     }
                 }
                 return $messages;
             }
             $messages = check_required($_POST);
             if (count($messages)) {
                 $result['error'] = 1;
                 $result['messages'] = array_merge($result['messages'], $messages);
             }
             if (isset($result['error'])) {
                 customer_signup_complete($result);
             }
             // end error checking / required fields.
             // check if this customer already exists in the system, based on email address
             $customer_id = false;
             $creating_new = true;
             $_REQUEST['user_id'] = 0;
             if (isset($customer['email']) && strlen($customer['email']) && !module_config::c('customer_signup_always_new', 0)) {
                 $users = module_user::get_contacts(array('email' => $customer['email']));
                 foreach ($users as $user) {
                     if (isset($user['customer_id']) && (int) $user['customer_id'] > 0) {
                         // this user exists as a customer! yey!
                         // add them to this listing.
                         $customer_id = $user['customer_id'];
                         $creating_new = false;
                         $_REQUEST['user_id'] = $user['user_id'];
                         // dont let signups update existing passwords.
                         if (isset($customer['password'])) {
                             unset($customer['password']);
                         }
                         if (isset($customer['new_password'])) {
                             unset($customer['new_password']);
                         }
                     }
                 }
             }
             $_REQUEST['extra_customer_field'] = array();
             $_REQUEST['extra_user_field'] = array();
             module_extra::$config['allow_new_keys'] = false;
             module_extra::$config['delete_existing_empties'] = false;
             // save customer extra fields.
             if (count($customer_extra)) {
                 // format the address so "save_customer" handles the save for us
                 foreach ($customer_extra as $key => $val) {
                     $_REQUEST['extra_customer_field'][] = array('key' => $key, 'val' => $val);
                 }
             }
             // save customer and customer contact details:
             $customer_id = $this->save_customer($customer_id, $customer);
             if (!$customer_id) {
                 $result['error'] = 1;
                 $result['messages'][] = 'System error: failed to create customer.';
                 customer_signup_complete($result);
             }
             $customer_data = module_customer::get_customer($customer_id);
             // todo - merge primary and secondary contact/extra/group saving into a single loop
             if (!$customer_data['primary_user_id']) {
                 $result['error'] = 1;
                 $result['messages'][] = 'System error: Failed to create customer contact.';
                 customer_signup_complete($result);
             } else {
                 $role_id = module_config::c('customer_signup_role', 0);
                 if ($role_id > 0) {
                     module_user::add_user_to_role($customer_data['primary_user_id'], $role_id);
                 }
                 // save contact extra data (repeated below for additional contacts)
                 if (isset($contact_extra[0]) && count($contact_extra[0])) {
                     $_REQUEST['extra_user_field'] = array();
                     foreach ($contact_extra[0] as $key => $val) {
                         $_REQUEST['extra_user_field'][] = array('key' => $key, 'val' => $val);
                     }
                     module_extra::save_extras('user', 'user_id', $customer_data['primary_user_id']);
                 }
                 // save contact groups
                 if (isset($contact_group[0]) && count($contact_group[0])) {
                     foreach ($contact_group[0] as $group_id => $tf) {
                         if ($tf) {
                             module_group::add_to_group($group_id, $customer_data['primary_user_id'], 'user');
                         }
                     }
                 }
             }
             foreach ($contact['email'] as $contact_key => $email) {
                 // add any additional contacts to the customer.
                 $users = module_user::get_contacts(array('email' => $email, 'customer_id' => $customer_id));
                 if (count($users)) {
                     // this contact already exists for this customer, dont update/change it.
                     continue;
                 }
                 $new_contact = array('customer_id' => $customer_id);
                 foreach ($contact_fields as $primary_contact_field) {
                     $new_contact[$primary_contact_field] = isset($contact[$primary_contact_field][$contact_key]) ? $contact[$primary_contact_field][$contact_key] : '';
                 }
                 // dont let additional contacts have passwords.
                 if (isset($new_contact['password'])) {
                     unset($new_contact['password']);
                 }
                 if (isset($new_contact['new_password'])) {
                     unset($new_contact['new_password']);
                 }
                 global $plugins;
                 $contact_user_id = $plugins['user']->create_user($new_contact, 'signup');
                 if ($contact_user_id) {
                     $role_id = module_config::c('customer_signup_role', 0);
                     if ($role_id > 0) {
                         module_user::add_user_to_role($contact_user_id, $role_id);
                     }
                     // save contact extra data  (repeated below for primary contacts)
                     if (isset($contact_extra[$contact_key]) && count($contact_extra[$contact_key])) {
                         $_REQUEST['extra_user_field'] = array();
                         foreach ($contact_extra[$contact_key] as $key => $val) {
                             $_REQUEST['extra_user_field'][] = array('key' => $key, 'val' => $val);
                         }
                         module_extra::save_extras('user', 'user_id', $contact_user_id);
                     }
                     // save contact groups
                     if (isset($contact_group[$contact_key]) && count($contact_group[$contact_key])) {
                         foreach ($contact_group[$contact_key] as $group_id => $tf) {
                             if ($tf) {
                                 module_group::add_to_group($group_id, $contact_user_id, 'user');
                             }
                         }
                     }
                 }
             }
             if (count($customer_group)) {
                 // format the address so "save_customer" handles the save for us
                 foreach ($customer_group as $group_id => $tf) {
                     if ($tf) {
                         module_group::add_to_group($group_id, $customer_id, 'customer');
                     }
                 }
             }
             $note_keys = array('customer', 'website', 'job', 'address', 'subscription');
             $note_text = _l('Customer signed up from Signup Form:');
             $note_text .= "\n\n";
             foreach ($note_keys as $note_key) {
                 $note_text .= "\n" . ucwords(_l($note_key)) . "\n";
                 if (isset($_POST[$note_key]) && is_array($_POST[$note_key])) {
                     foreach ($_POST[$note_key] as $post_key => $post_val) {
                         $note_text .= "\n - " . _l($post_key) . ": ";
                         if (is_array($post_val)) {
                             foreach ($post_val as $p => $v) {
                                 $note_text .= "\n  - - " . _l($p) . ': ' . $v;
                             }
                         } else {
                             $note_text .= $post_val;
                         }
                     }
                 }
             }
             $note_data = array('note_id' => false, 'owner_id' => $customer_id, 'owner_table' => 'customer', 'note_time' => time(), 'note' => $note_text, 'rel_data' => module_customer::link_open($customer_id), 'reminder' => 0, 'user_id' => 0);
             update_insert('note_id', false, 'note', $note_data);
             // save customer address fields.
             if (count($address)) {
                 $address_db = module_address::get_address($customer_id, 'customer', 'physical');
                 $address_id = $address_db && isset($address_db['address_id']) ? (int) $address_db['address_id'] : false;
                 $address['owner_id'] = $customer_id;
                 $address['owner_table'] = 'customer';
                 $address['address_type'] = 'physical';
                 // we have post data to save, write it to the table!!
                 module_address::save_address($address_id, $address);
             }
             // website:
             $allowed = array('url', 'name', 'extra', 'notes');
             foreach ($website as $key => $val) {
                 if (!in_array($key, $allowed)) {
                     unset($website[$key]);
                 }
             }
             $website['url'] = isset($website['url']) ? strtolower(trim($website['url'])) : '';
             $website_id = 0;
             if (count($website) && class_exists('module_website', false) && module_website::is_plugin_enabled()) {
                 if (strlen($website['url'])) {
                     // see if website already exists, don't create or update existing one for now.
                     $existing_websites = module_website::get_websites(array('customer_id' => $customer_id, 'url' => $website['url']));
                     foreach ($existing_websites as $existing_website) {
                         $website_id = $existing_website['website_id'];
                     }
                 }
                 //   echo $website_id;echo $website['url']; print_r($website_extra);exit;
                 if (!$website_id) {
                     $website_data = module_website::get_website($website_id);
                     $website_data['url'] = isset($website['url']) ? $website['url'] : 'N/A';
                     $website_data['name'] = isset($website['url']) ? $website['url'] : 'N/A';
                     $website_data['customer_id'] = $customer_id;
                     $website_id = update_insert('website_id', false, 'website', $website_data);
                     // save website extra data.
                     if ($website_id && count($website_extra)) {
                         $_REQUEST['extra_website_field'] = array();
                         foreach ($website_extra as $key => $val) {
                             $_REQUEST['extra_website_field'][] = array('key' => $key, 'val' => $val);
                         }
                         module_extra::save_extras('website', 'website_id', $website_id);
                     }
                     if ($website_id && isset($website['notes']) && strlen($website['notes'])) {
                         // add notes to this website.
                         $note_data = array('note_id' => false, 'owner_id' => $website_id, 'owner_table' => 'website', 'note_time' => time(), 'note' => $website['notes'], 'rel_data' => module_website::link_open($website_id), 'reminder' => 0, 'user_id' => $customer_data['primary_user_id']);
                         $note_id = update_insert('note_id', false, 'note', $note_data);
                     }
                 }
                 if ($website_id) {
                     if (count($website_group)) {
                         // format the address so "save_customer" handles the save for us
                         foreach ($website_group as $group_id => $tf) {
                             if ($tf) {
                                 module_group::add_to_group($group_id, $website_id, 'website');
                             }
                         }
                     }
                 }
             }
             // generate jobs for this customer.
             $job_created = array();
             if ($job && isset($job['type']) && is_array($job['type'])) {
                 if (module_config::c('customer_signup_any_job_type', 0)) {
                     foreach ($job['type'] as $type_name) {
                         // we have a match in our system. create the job.
                         $job_data = module_job::get_job(false);
                         $job_data['type'] = $type_name;
                         if (!$job_data['name']) {
                             $job_data['name'] = $type_name;
                         }
                         $job_data['website_id'] = $website_id;
                         $job_data['customer_id'] = $customer_id;
                         $job_id = update_insert('job_id', false, 'job', $job_data);
                         // todo: add default tasks for this job type.
                         $job_created[] = $job_id;
                     }
                 } else {
                     foreach (module_job::get_types() as $type_id => $type) {
                         foreach ($job['type'] as $type_name) {
                             if ($type_name == $type) {
                                 // we have a match in our system. create the job.
                                 $job_data = module_job::get_job(false);
                                 $job_data['type'] = $type;
                                 if (!$job_data['name']) {
                                     $job_data['name'] = $type;
                                 }
                                 $job_data['website_id'] = $website_id;
                                 $job_data['customer_id'] = $customer_id;
                                 $job_id = update_insert('job_id', false, 'job', $job_data);
                                 // todo: add default tasks for this job type.
                                 $job_created[] = $job_id;
                             }
                         }
                     }
                 }
                 if (count($job_created) && count($job_extra)) {
                     // save job extra data.
                     foreach ($job_created as $job_created_id) {
                         if ($job_created_id && count($job_extra)) {
                             $_REQUEST['extra_job_field'] = array();
                             foreach ($job_extra as $key => $val) {
                                 $_REQUEST['extra_job_field'][] = array('key' => $key, 'val' => $val);
                             }
                             module_extra::save_extras('job', 'job_id', $job_created_id);
                         }
                     }
                 }
             }
             // save files against customer
             $uploaded_files = array();
             if (isset($_FILES['customerfiles']) && isset($_FILES['customerfiles']['tmp_name'])) {
                 foreach ($_FILES['customerfiles']['tmp_name'] as $file_id => $tmp_file) {
                     if (is_uploaded_file($tmp_file)) {
                         // save to file module for this customer
                         $file_name = basename($_FILES['customerfiles']['name'][$file_id]);
                         if (strlen($file_name)) {
                             $file_path = 'includes/plugin_file/upload/' . md5(time() . $file_name);
                             if (move_uploaded_file($tmp_file, $file_path)) {
                                 // success! write to db.
                                 $file_data = array('customer_id' => $customer_id, 'job_id' => current($job_created), 'website_id' => $website_id, 'status' => module_config::c('file_default_status', 'Uploaded'), 'pointers' => false, 'description' => "Uploaded from Customer Signup form", 'file_time' => time(), 'file_name' => $file_name, 'file_path' => $file_path, 'file_url' => false);
                                 $file_id = update_insert('file_id', false, 'file', $file_data);
                                 $uploaded_files[] = $file_id;
                             }
                         }
                     }
                 }
             }
             // we create subscriptions for this customer/website (if none already exist)
             $subscription['subscription_name'] = array();
             $subscription['subscription_invoice'] = array();
             if (class_exists('module_subscription', false) && module_subscription::is_plugin_enabled() && isset($subscription['for']) && isset($subscription['subscriptions'])) {
                 if ($subscription['for'] == 'website' && $website_id > 0) {
                     $owner_table = 'website';
                     $owner_id = $website_id;
                 } else {
                     $owner_table = 'customer';
                     $owner_id = $customer_id;
                 }
                 $available_subscriptions = module_subscription::get_subscriptions();
                 $members_subscriptions = module_subscription::get_subscriptions_by($owner_table, $owner_id);
                 foreach ($subscription['subscriptions'] as $subscription_id => $tf) {
                     if (isset($available_subscriptions[$subscription_id])) {
                         if (isset($members_subscriptions[$subscription_id])) {
                             // we don't allow a member to sign up to the same subscription twice (just yet)
                         } else {
                             $subscription['subscription_name'][$subscription_id] = $available_subscriptions[$subscription_id]['name'];
                             $start_date = date('Y-m-d');
                             $start_modifications = module_config::c('customer_signup_subscription_start', '');
                             if ($start_modifications == 'hidden') {
                                 $start_modifications = isset($_REQUEST['customer_signup_subscription_start']) ? $_REQUEST['customer_signup_subscription_start'] : '';
                             }
                             if (!empty($start_modifications)) {
                                 $start_date = date('Y-m-d', strtotime($start_modifications));
                             }
                             $sql = "INSERT INTO `" . _DB_PREFIX . "subscription_owner` SET ";
                             $sql .= " owner_id = '" . (int) $owner_id . "'";
                             $sql .= ", owner_table = '" . mysql_real_escape_string($owner_table) . "'";
                             $sql .= ", subscription_id = '" . (int) $subscription_id . "'";
                             $sql .= ", start_date = '{$start_date}'";
                             query($sql);
                             module_subscription::update_next_due_date($subscription_id, $owner_table, $owner_id, true);
                             // and the same option here to send a subscription straight away upon signup
                             if (module_config::c('subscription_send_invoice_straight_away', 0)) {
                                 global $plugins;
                                 $plugins['subscription']->run_cron();
                                 // check if there are any invoices for this subscription
                                 $history = module_subscription::get_subscription_history($subscription_id, $owner_table, $owner_id);
                                 if (count($history) > 0) {
                                     foreach ($history as $h) {
                                         if ($h['invoice_id']) {
                                             $invoice_data = module_invoice::get_invoice($h['invoice_id']);
                                             if ($invoice_data['date_cancel'] != '0000-00-00') {
                                                 continue;
                                             }
                                             $subscription['subscription_invoice'][] = '<a href="' . module_invoice::link_public($h['invoice_id']) . '">' . _l('Invoice #%s for %s', htmlspecialchars($invoice_data['name']), dollar($invoice_data['total_amount'], true, $invoice_data['currency_id'])) . '</a>';
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if (!count($subscription['subscription_name'])) {
                 $subscription['subscription_name'][] = _l('N/A');
             }
             if (!count($subscription['subscription_invoice'])) {
                 $subscription['subscription_invoice'][] = _l('N/A');
             }
             $subscription['subscription_name'] = implode(', ', $subscription['subscription_name']);
             $subscription['subscription_invoice'] = implode(', ', $subscription['subscription_invoice']);
             // email the admin when a customer signs up.
             $values = array_merge($customer, $customer_extra, $website, $website_extra, $address, $subscription);
             $values['customer_name'] = $customer['customer_name'];
             $values['CUSTOMER_LINK'] = module_customer::link_open($customer_id);
             $values['CUSTOMER_NAME_LINK'] = module_customer::link_open($customer_id, true);
             if ($website_id) {
                 $values['WEBSITE_LINK'] = module_website::link_open($website_id);
                 $values['WEBSITE_NAME_LINK'] = module_website::link_open($website_id, true);
             } else {
                 $values['WEBSITE_LINK'] = _l('N/A');
                 $values['WEBSITE_NAME_LINK'] = _l('N/A');
             }
             $values['JOB_LINKS'] = '';
             if (count($job_created)) {
                 $values['JOB_LINKS'] .= 'The customer created ' . count($job_created) . ' jobs in the system: <br>';
                 foreach ($job_created as $job_created_id) {
                     $values['JOB_LINKS'] .= module_job::link_open($job_created_id, true) . "<br>\n";
                 }
             } else {
                 $values['JOB_LINKS'] = _l('N/A');
             }
             if (count($uploaded_files)) {
                 $values['uploaded_files'] = 'The customer uploaded ' . count($uploaded_files) . " files:<br>\n";
                 foreach ($uploaded_files as $uploaded_file) {
                     $values['uploaded_files'] .= module_file::link_open($uploaded_file, true) . "<br>\n";
                 }
             } else {
                 $values['uploaded_files'] = 'No files were uploaded';
             }
             $values['WEBSITE_NAME'] = isset($website['url']) ? $website['url'] : 'N/A';
             if (!$creating_new) {
                 $values['system_note'] = "Note: this signup updated the existing customer record in the system.";
             } else {
                 $values['system_note'] = "Note: this signup created a new customer record in the system.";
             }
             $customer_signup_template = module_config::c('customer_signup_email_admin_template', 'customer_signup_email_admin');
             if (isset($_REQUEST['customer_signup_email_admin_template'])) {
                 $customer_signup_template = $_REQUEST['customer_signup_email_admin_template'];
             }
             if ($customer_signup_template) {
                 $template = module_template::get_template_by_key($customer_signup_template);
                 if ($template->template_id) {
                     $template->assign_values($values);
                     $html = $template->render('html');
                     $email = module_email::new_email();
                     $email->replace_values = $values;
                     $email->set_subject($template->description);
                     $email->set_to_manual(module_config::c('customer_signup_admin_email', module_config::c('admin_email_address')));
                     // do we send images inline?
                     $email->set_html($html);
                     if ($email->send()) {
                         // it worked successfully!!
                     } else {
                         /// log err?
                     }
                 }
             }
             $customer_signup_template = module_config::c('customer_signup_email_welcome_template', 'customer_signup_email_welcome');
             if (isset($_REQUEST['customer_signup_email_welcome_template'])) {
                 $customer_signup_template = $_REQUEST['customer_signup_email_welcome_template'];
             }
             if ($customer_signup_template) {
                 $template = module_template::get_template_by_key($customer_signup_template);
                 if ($template->template_id) {
                     $template->assign_values($values);
                     $html = $template->render('html');
                     $email = module_email::new_email();
                     $email->customer_id = $customer_id;
                     $email->replace_values = $values;
                     $email->set_subject($template->description);
                     $email->set_to('user', $customer_data['primary_user_id']);
                     // do we send images inline?
                     $email->set_html($html);
                     if ($email->send()) {
                         // it worked successfully!!
                     } else {
                         /// log err?
                     }
                 }
             }
             //todo: optional redirect to url
             if (isset($_REQUEST['via_ajax'])) {
                 echo json_encode(array('success' => 1, 'customer_id' => $customer_id));
                 exit;
             }
             if (module_config::c('customer_signup_redirect', '')) {
                 redirect_browser(module_config::c('customer_signup_redirect', ''));
             }
             // load up the thank you template.
             $template = module_template::get_template_by_key('customer_signup_thank_you_page');
             $template->page_title = _l("Customer Signup");
             foreach ($values as $key => $val) {
                 if (!is_array($val)) {
                     $values[$key] = htmlspecialchars($val);
                 }
             }
             $template->assign_values($values);
             echo $template->render('pretty_html');
             exit;
             break;
     }
 }
コード例 #10
0
    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>&nbsp;</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;
    }
コード例 #11
0
             echo '<p>';
             echo _l("Please pay <strong>%s</strong> to receive Priority Support. To make payment please click the button below.", dollar($invoice_data['total_amount_due'], true, $invoice_data['currency_id']));
             echo '</p>';
             echo '<p align="center">';
             echo '<a href="' . module_invoice::link_public($ticket['invoice_id']) . '" target="_blank" class="uibutton small_button">' . _l('Pay Now') . '</a>';
             echo '</p>';
         } else {
             $responsive_summary[] = '<strong>' . _l("This is a Priotity Ticket") . '</strong>';
             echo '<p>';
             _e("Thank you for purchasing Priority Support. We will answer your question shortly.");
             echo '</p>';
             echo '<p align="center">';
             if (module_invoice::can_i('view', 'Invoices')) {
                 echo '<a href="' . module_invoice::link_open($ticket['invoice_id']) . '" target="_blank">' . _l('View Invoice') . '</a>';
             } else {
                 echo '<a href="' . module_invoice::link_public($ticket['invoice_id']) . '" target="_blank">' . _l('View Invoice') . '</a>';
             }
             echo '</p>';
         }
     }
 } else {
     echo '<p>';
     echo _l("Priority Support costs <strong>%s</strong>. To make payment please click the button below.", dollar(module_config::c('ticket_priority_cost', 10), true, module_config::c('ticket_priority_currency', 1)));
     echo '</p>';
     echo '<p align="center">';
     echo '<input type="submit" name="generate_priority_invoice" value="' . _l('Pay Now') . '" class="submit_button small_button">';
     echo '</p>';
 }
 ?>
         </td>
     </tr>
コード例 #12
0
ファイル: ticket.php プロジェクト: sgh1986915/php-crm
 private function _handle_save_ticket()
 {
     $ticket_data = $_POST;
     $ticket_id = (int) $_REQUEST['ticket_id'];
     // check security can user edit this ticket
     if ($ticket_id > 0) {
         $test = self::get_ticket($ticket_id);
         if (!$test || $test['ticket_id'] != $ticket_id) {
             $ticket_id = 0;
         }
     }
     // handle some security before passing if off to the save
     if (!self::can_edit_tickets()) {
         // dont allow new "types" to be created
         /*if(isset($ticket_data['type']) && $ticket_data['type']){
               $types = self::get_types();
               $existing=false;
               foreach($types as $type){
                   if($type==$ticket_data['type']){
                       $existing=true;
                   }
               }
               if(!$existing){
                   unset($ticket_data['type']);
               }
           }*/
         if (isset($ticket_data['change_customer_id'])) {
             unset($ticket_data['change_customer_id']);
         }
         if (isset($ticket_data['change_user_id'])) {
             unset($ticket_data['change_user_id']);
         }
         if (isset($ticket_data['ticket_account_id'])) {
             unset($ticket_data['ticket_account_id']);
         }
         if (isset($ticket_data['assigned_user_id'])) {
             unset($ticket_data['assigned_user_id']);
         }
         if (isset($ticket_data['change_status_id'])) {
             unset($ticket_data['change_status_id']);
         }
         if (isset($ticket_data['change_assigned_user_id'])) {
             unset($ticket_data['change_assigned_user_id']);
         }
         if (isset($ticket_data['priority'])) {
             unset($ticket_data['priority']);
         }
         if ($ticket_id > 0 && isset($ticket_data['status_id'])) {
             unset($ticket_data['status_id']);
         }
         if ($ticket_id > 0 && isset($ticket_data['user_id'])) {
             unset($ticket_data['user_id']);
         }
     }
     $ticket_data = array_merge(self::get_ticket($ticket_id), $ticket_data);
     if (isset($_REQUEST['mark_as_unread']) && $_REQUEST['mark_as_unread']) {
         $ticket_data['unread'] = 1;
     }
     if (isset($ticket_data['change_customer_id']) && (int) $ticket_data['change_customer_id'] > 0 && $ticket_data['change_customer_id'] != $ticket_data['customer_id']) {
         // we are changing customer ids
         // todo - some extra logic in here to swap the user contact over to this new customer or something?
         $ticket_data['customer_id'] = $ticket_data['change_customer_id'];
     }
     if (isset($ticket_data['change_user_id']) && (int) $ticket_data['change_user_id'] > 0 && $ticket_data['change_user_id'] != $ticket_data['user_id']) {
         // we are changing customer ids
         // todo - some extra logic in here to swap the user contact over to this new customer or something?
         $ticket_data['user_id'] = $ticket_data['change_user_id'];
     }
     $ticket_id = $this->save_ticket($ticket_id, $ticket_data);
     // run the envato hook incase we're posting data to our sidebar bit.
     ob_start();
     handle_hook('ticket_sidebar', $ticket_id);
     ob_end_clean();
     if (isset($_REQUEST['generate_priority_invoice'])) {
         $invoice_id = $this->generate_priority_invoice($ticket_id);
         redirect_browser(module_invoice::link_public($invoice_id));
     }
     set_message("Ticket saved successfully");
     if (isset($_REQUEST['butt_notify_staff']) && $_REQUEST['butt_notify_staff']) {
         redirect_browser($this->link_open_notify($ticket_id, false, $ticket_data));
     } else {
         if (isset($_REQUEST['mark_as_unread']) && $_REQUEST['mark_as_unread']) {
             $url = $this->link_open(false);
             $url .= (strpos('?', $url) !== false ? '?' : '&') . 'do_last_search';
             redirect_browser($url);
         } else {
             if (isset($_REQUEST['newmsg_next']) && isset($_REQUEST['next_ticket_id']) && (int) $_REQUEST['next_ticket_id'] > 0) {
                 $key = array_search($ticket_id, $_SESSION['_ticket_nextprev']);
                 if ($key !== false) {
                     unset($_SESSION['_ticket_nextprev'][$key]);
                 }
                 redirect_browser($this->link_open($_REQUEST['next_ticket_id']));
             }
             redirect_browser($this->link_open($ticket_id));
         }
     }
 }
コード例 #13
0
 function handle_multisafepay_ipn()
 {
     ob_end_clean();
     ini_set('display_errors', false);
     include 'MultiSafepay.combined.php';
     $msp = new MultiSafepay();
     // transaction id (same as the transaction->id given in the transaction request)
     $transactionid = isset($_GET['transactionid']) ? $_GET['transactionid'] : false;
     if (!$transactionid) {
         send_error('No MultiSafepay transaction ID');
     }
     $multisafepay_bits = explode("|", $transactionid);
     $user_id = $multisafepay_bits[0];
     $payment_id = (int) $multisafepay_bits[1];
     $invoice_id = (int) $multisafepay_bits[2];
     //send_error('bad?');
     //send_error($payment_id.' multisafepay IPN check started',var_export($_REQUEST,true));
     if ($payment_id && $invoice_id) {
         $hash = $this->multisafepay_custom($user_id, $payment_id, $invoice_id);
         if ($hash != $transactionid) {
             send_error("Multisafepay IPN Error (incorrect hash)");
             exit;
         }
         $user_id = (int) $user_id;
         // sometimes userid is ''
         $paymetn_history = get_single('invoice_payment', 'invoice_payment_id', $payment_id);
         if (!$paymetn_history) {
             send_error("Unknown Multisafe Payment - maybe a history was deleted?");
             exit;
         }
         // (notify.php?type=initial is used as notification_url and should output a link)
         $initial = isset($_GET['type']) && $_GET['type'] == "initial";
         /*
          * Merchant Settings
          */
         //        $msp->test                         = MSP_TEST_API;
         //        $msp->merchant['account_id']       = MSP_ACCOUNT_ID;
         //        $msp->merchant['site_id']          = MSP_SITE_ID;
         //        $msp->merchant['site_code']        = MSP_SITE_CODE;
         $msp->test = self::is_sandbox();
         $msp->merchant['account_id'] = module_config::c('payment_method_multisafepay_account', '');
         $msp->merchant['site_id'] = module_config::c('payment_method_multisafepay_site_id', '');
         $msp->merchant['site_code'] = module_config::c('payment_method_multisafepay_side_code', '');
         /*
          * Transaction Details
          */
         $msp->transaction['id'] = $transactionid;
         // returns the status
         $status = $msp->getStatus();
         if ($msp->error && !$initial) {
             // only show error if we dont need to display the link
             echo "Error " . $msp->error_code . ": " . $msp->error;
             exit;
         }
         //send_error($payment_id.' MultiSafepay Status of '.$status,var_export($_REQUEST,true));
         $payment_history_data = isset($paymetn_history['data']) && strlen($paymetn_history['data']) ? unserialize($paymetn_history['data']) : array();
         if (!is_array($payment_history_data)) {
             $payment_history_data = array();
         }
         if (!isset($payment_history_data['log'])) {
             $payment_history_data['log'] = array();
         }
         $payment_history_data['log'][] = 'Payment ' . $status . ' at ' . print_date(time(), true);
         update_insert("invoice_payment_id", $payment_id, "invoice_payment", array('data' => serialize($payment_history_data)));
         switch ($status) {
             case "initialized":
                 // waiting
                 break;
             case "completed":
                 // payment complete
                 update_insert("invoice_payment_id", $payment_id, "invoice_payment", array('date_paid' => date('Y-m-d'), 'method' => 'MultiSafepay'));
                 module_invoice::save_invoice($invoice_id, array());
                 break;
             case "uncleared":
                 // waiting (credit cards or direct debit)
                 break;
             case "void":
                 // canceled
                 break;
             case "declined":
                 // declined
                 break;
             case "refunded":
                 // refunded
                 send_error("Multisafepay Error! The payment {$payment_id} has been refunded or reversed! BAD BAD! You have to follup up customer for money manually now.");
                 break;
             case "expired":
                 // expired
                 break;
             default:
         }
         if ($initial) {
             // displayed at the last page of the transaction proces (if no redirect_url is set)
             echo '<a href="' . module_invoice::link_public($invoice_id) . '">Return to Invoice</a>';
         } else {
             // link to notify.php for MultiSafepay back-end (for delayed payment notifications)
             // backend expects an "ok" if no error occurred
             echo "ok";
         }
     } else {
         send_error('No bits in transaction id');
     }
     exit;
     $multisafepay_bits = explode("|", $_REQUEST['custom']);
     $user_id = (int) $multisafepay_bits[0];
     $payment_id = (int) $multisafepay_bits[1];
     $invoice_id = (int) $multisafepay_bits[2];
     //send_error('bad?');
     if ($user_id && $payment_id && $invoice_id) {
         $hash = $this->multisafepay_custom($user_id, $payment_id, $invoice_id);
         if ($hash != $_REQUEST['custom']) {
             send_error("Multisafepay IPN Error (incorrect hash)");
             exit;
         }
         $sql = "SELECT * FROM `" . _DB_PREFIX . "user` WHERE user_id = '{$user_id}' LIMIT 1";
         $res = qa($sql);
         if ($res) {
             $user = array_shift($res);
             if ($user && $user['user_id'] == $user_id) {
                 // check for payment exists
                 $payment = module_invoice::get_invoice_payment($payment_id);
                 $invoice = module_invoice::get_invoice($invoice_id);
                 if ($payment && $invoice) {
                     $invoice_currency = module_config::get_currency($invoice['currency_id']);
                     $invoice_currency_code = $invoice_currency['code'];
                     // check correct business
                     if (!$_REQUEST['business'] && $_REQUEST['receiver_email']) {
                         $_REQUEST['business'] = $_REQUEST['receiver_email'];
                     }
                     if ($_REQUEST['business'] != module_config::c('payment_method_multisafepay_email', _ERROR_EMAIL)) {
                         send_error('Multisafepay error! Paid the wrong business name. ' . $_REQUEST['business'] . ' instead of ' . module_config::c('payment_method_multisafepay_email', _ERROR_EMAIL));
                         exit;
                     }
                     // check correct currency
                     if ($invoice_currency_code && $_REQUEST['mc_currency'] != $invoice_currency_code) {
                         send_error('Multisafepay error! Paid the wrong currency code. ' . $_REQUEST['mc_currency'] . ' instead of ' . $invoice_currency_code);
                         exit;
                     }
                     if ($_REQUEST['payment_status'] == "Canceled_Reversal" || $_REQUEST['payment_status'] == "Refunded") {
                         // funky refund!! oh noes!!
                         // TODO: store this in the database as a negative payment... should be easy.
                         // populate $_REQUEST vars then do something like $payment_history_id = update_insert("payment_history_id","new","payment_history");
                         send_error("Multisafepay Error! The payment {$payment_id} has been refunded or reversed! BAD BAD! You have to follup up customer for money manually now.");
                     } else {
                         if ($_REQUEST['payment_status'] == "Completed") {
                             // payment is completed! yeye getting closer...
                             switch ($_REQUEST['txn_type']) {
                                 case "web_accept":
                                     // running in multisafepay sandbox or not?
                                     //$sandbox = (self::is_sandbox())?"sandbox.":'';
                                     // quick check we're not getting a fake payment request.
                                     $url = 'https://www.' . (self::is_sandbox() ? 'sandbox.' : '') . 'multisafepay.com/cgi-bin/webscr';
                                     $result = self::fsockPost($url, $_POST);
                                     //send_error('multisafepay sock post: '.$url."\n\n".var_export($result,true));
                                     if (eregi("VERIFIED", $result)) {
                                         // finally have everything.
                                         // mark the payment as completed.
                                         update_insert("invoice_payment_id", $payment_id, "invoice_payment", array('date_paid' => date('Y-m-d'), 'amount' => $_REQUEST['mc_gross'], 'method' => 'Multisafepay (IPN)'));
                                         module_invoice::save_invoice($invoice_id, array());
                                         echo "Successful Payment!";
                                     } else {
                                         send_error("Multisafepay IPN Error (multisafepay rejected the payment!) " . var_export($result, true));
                                     }
                                     break;
                                 case "subscr_signup":
                                 default:
                                     // TODO: support different payment methods later? like a monthly hosting fee..
                                     send_error("Multisafepay IPN Error (we dont currently support this payment method: " . $_REQUEST['txn_type'] . ")");
                                     break;
                             }
                         } else {
                             send_error("Multisafepay info: This payment is not yet completed, this usually means it's an e-cheque, follow it up in a few days if you dont hear anything. This also means you may have to login to multisafepay and 'Accept' the payment. So check there first.");
                         }
                     }
                 } else {
                     send_error("Multisafepay IPN Error (no payment found in database!)");
                 }
             } else {
                 send_error("Multisafepay IPN Error (error with user that was found in database..)");
             }
         } else {
             send_error("Multisafepay IPN Error (no user found in database #1)");
         }
     } else {
         send_error("Multisafepay IPN Error (no user id found)");
     }
     exit;
 }
コード例 #14
0
    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;
    }