/** * Sends order mail * @param $order_number * @param $order_type * @param $customer_id */ public static function SendOrderEmail($order_number, $order_type = 'accepted', $customer_id = '') { global $objSettings; $currencyFormat = get_currency_format(); $order_details = ''; // send email to customer $sql = 'SELECT o.*, CASE WHEN o.payment_type = 0 THEN "' . _ONLINE_ORDER . '" WHEN o.payment_type = 1 THEN "' . _PAYPAL . '" WHEN o.payment_type = 2 THEN "2CO" WHEN o.payment_type = 3 THEN "Authorize.Net" ELSE "' . _UNKNOWN . '" END as m_payment_type, CASE WHEN o.payment_method = 0 THEN "' . _PAYMENT_COMPANY_ACCOUNT . '" WHEN o.payment_method = 1 THEN "' . _CREDIT_CARD . '" WHEN o.payment_method = 2 THEN "E-Check" ELSE "' . _UNKNOWN . '" END as m_payment_method, CASE WHEN o.status = 0 THEN "<span style=color:#960000>' . _PREPARING . '</span>" WHEN o.status = 1 THEN "<span style=color:#FF9966>' . _PENDING . '</span>" WHEN o.status = 2 THEN "<span style=color:#336699>' . _PAID . '</span>" WHEN o.status = 3 THEN "<span style=color:#009600>' . _COMPLETED . '</span>" WHEN o.status = 4 THEN "<span style=color:#969600>' . _REFUNDED . '</span>" ELSE "' . _UNKNOWN . '" END as m_status, c.first_name, c.last_name, c.user_name as customer_name, c.preferred_language, c.email, c.b_address, c.b_address_2, c.b_city, c.b_state, count.name as b_country, c.b_zipcode, c.phone, c.fax, cur.symbol, cur.symbol_placement FROM ' . TABLE_ORDERS . ' o LEFT OUTER JOIN ' . TABLE_CURRENCIES . ' cur ON o.currency = cur.code LEFT OUTER JOIN ' . TABLE_CUSTOMERS . ' c ON o.customer_id = c.id LEFT OUTER JOIN ' . TABLE_COUNTRIES . ' count ON c.b_country = count.abbrv WHERE o.customer_id = ' . (int) $customer_id . ' AND o.order_number = "' . $order_number . '"'; $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY); if ($result[1] > 0) { $plan_info = AdvertisePlans::GetPlanInfo($result[0]['advertise_plan_id']); if (ModulesSettings::Get('payments', 'mode') == 'TEST MODE') { $order_details .= '<div style="text-align:center;padding:10px;color:#a60000;border:1px dashed #a60000;width:100px">TEST MODE!</div><br />'; } // Personal Info $order_details .= '<b>' . _PERSONAL_INFORMATION . ':</b><br />'; $order_details .= _FIRST_NAME . ' : ' . $result[0]['first_name'] . '<br />'; $order_details .= _LAST_NAME . ' : ' . $result[0]['last_name'] . '<br />'; $order_details .= _EMAIL_ADDRESS . ' : ' . $result[0]['email'] . '<br />'; $order_details .= '<br />'; // Billing Info $order_details .= '<b>' . _BILLING_INFORMATION . ':</b><br />'; $order_details .= _ADDRESS . ': ' . $result[0]['b_address'] . '<br />'; $order_details .= _ADDRESS_2 . ': ' . $result[0]['b_address_2'] . '<br />'; $order_details .= _CITY . ': ' . $result[0]['b_city'] . '<br />'; $order_details .= _STATE_PROVINCE . ': ' . $result[0]['b_state'] . '<br />'; $order_details .= _COUNTRY . ': ' . $result[0]['b_country'] . '<br />'; $order_details .= _ZIP_CODE . ': ' . $result[0]['b_zipcode'] . '<br />'; if (!empty($result[0]['phone'])) { $order_details .= _PHONE . ' : ' . $result[0]['phone'] . '<br />'; } if (!empty($result[0]['fax'])) { $order_details .= _FAX . ' : ' . $result[0]['fax'] . '<br />'; } $order_details .= '<br />'; // Order Details $order_details .= '<b>' . _ORDER_DETAILS . ':</b><br />'; $order_details .= _ORDER_DESCRIPTION . ': ' . $result[0]['order_description'] . '<br />'; $order_details .= _ADVERTISE_PLAN . ': ' . (isset($plan_info[0]['plan_name']) ? $plan_info[0]['plan_name'] : '') . '<br />'; $order_details .= _LISTINGS_COUNT . ': ' . $result[0]['listings_amount'] . '<br />'; $order_details .= _CURRENCY . ': ' . $result[0]['currency'] . '<br />'; $order_details .= _CREATED_DATE . ': ' . format_datetime($result[0]['created_date']) . '<br />'; $order_details .= _PAYMENT_DATE . ': ' . format_datetime($result[0]['payment_date']) . '<br />'; $order_details .= _PAYMENT_TYPE . ': ' . $result[0]['m_payment_type'] . '<br />'; $order_details .= _PAYMENT_METHOD . ': ' . $result[0]['m_payment_method'] . '<br />'; //$order_details .= (($result[0]['campaign_name'] != '') ? _DISCOUNT_CAMPAIGN.': '.$result[0]['campaign_name'].' ('.$result[0]['discount_percent'].'%)' : '').'<br />'; $order_details .= _ORDER_PRICE . ': ' . Currencies::PriceFormat($result[0]['order_price'], $result[0]['symbol'], $result[0]['symbol_placement'], $currencyFormat) . '<br />'; $order_details .= _VAT . ': ' . Currencies::PriceFormat($result[0]['vat_fee'], $result[0]['symbol'], $result[0]['symbol_placement'], $currencyFormat) . ' (' . $result[0]['vat_percent'] . '%)' . '<br />'; $order_details .= _TOTAL_PRICE . ': ' . Currencies::PriceFormat($result[0]['total_price'], $result[0]['symbol'], $result[0]['symbol_placement'], $currencyFormat) . '<br />'; //$order_details .= _ADDITIONAL_INFO.': '.nl2br($result[0]['additional_info']).'<br /><br />'; $send_order_copy_to_admin = ModulesSettings::Get('payments', 'send_order_copy_to_admin'); //////////////////////////////////////////////////////////// $sender = $objSettings->GetParameter('admin_email'); $recipient = $result[0]['email']; if ($order_type == 'completed') { // exit if email was already sent if ($result[0]['email_sent'] == '1') { return true; } $email_template = 'order_paid'; $admin_copy_subject = 'Client order has been paid (admin copy)'; } else { $email_template = 'order_accepted_online'; $admin_copy_subject = 'Client has placed online order (admin copy)'; } //////////////////////////////////////////////////////////// send_email($recipient, $sender, $email_template, array('{FIRST NAME}' => $result[0]['first_name'], '{LAST NAME}' => $result[0]['last_name'], '{ORDER NUMBER}' => $order_number, '{ORDER DETAILS}' => $order_details), $result[0]['preferred_language'], $send_order_copy_to_admin == 'yes' ? $sender : '', $send_order_copy_to_admin == 'yes' ? $admin_copy_subject : ''); //////////////////////////////////////////////////////////// if ($order_type == 'completed') { $sql = 'UPDATE ' . TABLE_ORDERS . ' SET email_sent = 1 WHERE order_number = \'' . $order_number . '\''; database_void_query($sql); } //////////////////////////////////////////////////////////// return true; } else { ///echo $sql; ///echo mysql_error(); } return false; }
/** * Draw prepayment info * @param $draw */ public static function DrawPrepayment($plan_id = '', $payment_type = '', $currency = '', $draw = true) { global $objSettings, $objLogin; $plan_id = empty($plan_id) ? MicroGrid::GetParameter('plan_id', false) : $plan_id; $payment_type = empty($payment_type) ? MicroGrid::GetParameter('payment_type', false) : $payment_type; $currency = empty($currency) ? MicroGrid::GetParameter('currency', false) : $currency; $output = ''; // retrieve module parameters $paypal_email = ModulesSettings::Get('payments', 'paypal_email'); $collect_credit_card = ModulesSettings::Get('payments', 'online_collect_credit_card'); $two_checkout_vendor = ModulesSettings::Get('payments', 'two_checkout_vendor'); $authorize_login_id = ModulesSettings::Get('payments', 'authorize_login_id'); $authorize_transaction_key = ModulesSettings::Get('payments', 'authorize_transaction_key'); $mode = ModulesSettings::Get('payments', 'mode'); $vat_value = ModulesSettings::Get('payments', 'vat_value'); // retrieve credit card info $cc_type = isset($_REQUEST['cc_type']) ? prepare_input($_REQUEST['cc_type']) : ''; $cc_holder_name = isset($_POST['cc_holder_name']) ? prepare_input($_POST['cc_holder_name']) : ''; $cc_number = isset($_POST['cc_number']) ? prepare_input($_POST['cc_number']) : ""; $cc_expires_month = isset($_POST['cc_expires_month']) ? prepare_input($_POST['cc_expires_month']) : "1"; $cc_expires_year = isset($_POST['cc_expires_year']) ? prepare_input($_POST['cc_expires_year']) : date("Y"); $cc_cvv_code = isset($_POST['cc_cvv_code']) ? prepare_input($_POST['cc_cvv_code']) : ""; // prepare datetime format $field_date_format = get_datetime_format(); $currency_format = get_currency_format(); $arr_durations = self::PrepareDurationsArray(); // prepare clients info $sql = 'SELECT * FROM ' . TABLE_CUSTOMERS . ' WHERE id = ' . (int) $objLogin->GetLoggedID(); $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY); $client_info = array(); $client_info['first_name'] = isset($result[0]['first_name']) ? $result[0]['first_name'] : ''; $client_info['last_name'] = isset($result[0]['last_name']) ? $result[0]['last_name'] : ''; $client_info['address1'] = isset($result[0]['b_address']) ? $result[0]['b_address'] : ''; $client_info['address2'] = isset($result[0]['b_address2']) ? $result[0]['b_address2'] : ''; $client_info['city'] = isset($result[0]['b_city']) ? $result[0]['b_city'] : ''; $client_info['state'] = isset($result[0]['b_state']) ? $result[0]['b_state'] : ''; $client_info['zip'] = isset($result[0]['b_zipcode']) ? $result[0]['b_zipcode'] : ''; $client_info['country'] = isset($result[0]['b_country']) ? $result[0]['b_country'] : ''; $client_info['email'] = isset($result[0]['email']) ? $result[0]['email'] : ''; $client_info['company'] = isset($result[0]['company']) ? $result[0]['company'] : ''; $client_info['phone'] = isset($result[0]['phone']) ? $result[0]['phone'] : ''; $client_info['fax'] = isset($result[0]['fax']) ? $result[0]['fax'] : ''; if ($cc_holder_name == '') { if ($objLogin->IsLoggedIn()) { $cc_holder_name = $objLogin->GetLoggedFirstName() . ' ' . $objLogin->GetLoggedLastName(); } else { $cc_holder_name = $client_info['first_name'] . ' ' . $client_info['last_name']; } } // get order number $sql = 'SELECT id, order_number FROM ' . TABLE_ORDERS . ' WHERE customer_id = ' . (int) $objLogin->GetLoggedID() . ' AND status = 0 ORDER BY id DESC'; $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY); if ($result[1] > 0) { $order_number = $result[0]['order_number']; } else { $order_number = strtoupper(get_random_string(10)); } $additional_info = ''; $cart_total_wo_vat = 0; $vat_cost = 0; $cart_total = 0; $sql = 'SELECT ap.id, ap.listings_count, ap.price, ap.duration, ap.is_default, apd.name, apd.description FROM ' . TABLE_ADVERTISE_PLANS . ' ap LEFT OUTER JOIN ' . TABLE_ADVERTISE_PLANS_DESCRIPTION . ' apd ON ap.id = apd.advertise_plan_id AND apd.language_id = \'' . Application::Get('lang') . '\' WHERE ap.id = ' . (int) $plan_id; $result = database_query($sql, DATA_AND_ROWS, FIRST_ROW_ONLY); $fisrt_part = '<table border="0" width="97%" align="center"> <tr><td colspan="3"><h4>' . _ORDER_DESCRIPTION . '</h4></td></tr> <tr><td width="20%">' . _ORDER_DATE . ' </td><td width="2%"> : </td><td> ' . format_datetime(date('Y-m-d H:i:s'), $field_date_format) . '</td></tr>'; if ($result[1] > 0) { if ($result[0]['price'] == 0) { $payment_type = 'online'; $collect_credit_card = 'no'; } $cart_total_wo_vat = $result[0]['price'] * Application::Get('currency_rate'); $vat_cost = $cart_total_wo_vat * ($vat_value / 100); $cart_total = $cart_total_wo_vat + $vat_cost; $duration = isset($arr_durations[$result[0]['duration']]) ? $arr_durations[$result[0]['duration']] : ''; $fisrt_part .= '<tr><td>' . _ADVERTISE_PLAN . ' </td><td width="2%"> : </td><td> ' . $result[0]['name'] . '</td></tr>'; $fisrt_part .= '<tr><td>' . _DURATION . ' </td><td width="2%"> : </td><td> ' . $duration . '</td></tr>'; $fisrt_part .= '<tr><td>' . _LISTINGS . ' </td><td width="2%"> : </td><td> ' . $result[0]['listings_count'] . '</td></tr>'; $fisrt_part .= '<tr><td>' . _PRICE . ' </td><td width="2%"> : </td><td> ' . Currencies::PriceFormat($cart_total_wo_vat) . '</td></tr>'; $fisrt_part .= '<tr><td>' . _DESCRIPTION . ' </td><td width="2%"> : </td><td> ' . $result[0]['description'] . '</td></tr>'; } $pp_params = array('api_login' => '', 'transaction_key' => '', 'order_number' => $order_number, 'address1' => $client_info['address1'], 'address2' => $client_info['address2'], 'city' => $client_info['city'], 'zip' => $client_info['zip'], 'country' => $client_info['country'], 'state' => $client_info['state'], 'first_name' => $client_info['first_name'], 'last_name' => $client_info['last_name'], 'email' => $client_info['email'], 'company' => $client_info['company'], 'phone' => $client_info['phone'], 'fax' => $client_info['fax'], 'notify' => '', 'return' => 'index.php?page=payment_return', 'cancel_return' => 'index.php?page=payment_cancel', 'paypal_form_type' => '', 'paypal_form_fields' => '', 'paypal_form_fields_count' => '', 'collect_credit_card' => $collect_credit_card, 'cc_type' => '', 'cc_holder_name' => '', 'cc_number' => '', 'cc_cvv_code' => '', 'cc_expires_month' => '', 'cc_expires_year' => '', 'currency_code' => Application::Get('currency_code'), 'additional_info' => $additional_info, 'discount_value' => '', 'extras_param' => '', 'extras_sub_total' => '', 'vat_cost' => $vat_cost, 'cart_total' => number_format((double) $cart_total, (int) Application::Get('currency_decimals'), '.', ','), 'is_prepayment' => false, 'pre_payment_type' => '', 'pre_payment_value' => 0); $fisrt_part .= ' <tr><td colspan="3" nowrap="nowrap" height="10px"></td></tr> <tr><td colspan="3"><h4>' . _TOTAL . '</h4></td></tr> <tr><td>' . _SUBTOTAL . ' </td><td> : </td><td> ' . Currencies::PriceFormat($cart_total_wo_vat, '', '', $currency_format) . '</td></tr>'; $fisrt_part .= '<tr><td>' . _VAT . ' (' . $vat_value . '%) </td><td> : </td><td> ' . Currencies::PriceFormat($vat_cost, '', '', $currency_format) . '</td></tr>'; $fisrt_part .= '<tr><td>' . _PAYMENT_SUM . ' </td><td> : </td><td> <b>' . Currencies::PriceFormat($cart_total, '', '', $currency_format) . '</b></td></tr>'; $fisrt_part .= '<tr><td colspan="3" nowrap="nowrap" height="0px"></td></tr>'; $fisrt_part .= '<tr><td colspan="3">'; //if($additional_info != ''){ // $fisrt_part .= '<tr><td colspan="3" nowrap height="10px"></td></tr>'; // $fisrt_part .= '<tr><td colspan="3"><h4>'._ADDITIONAL_INFO.'</h4>'.$additional_info.'</td></tr>'; //} $second_part = ' </td></tr> </table><br />'; if ($payment_type == 'online') { $output .= $fisrt_part; $pp_params['credit_card_required'] = $collect_credit_card; $pp_params['cc_type'] = $cc_type; $pp_params['cc_holder_name'] = $cc_holder_name; $pp_params['cc_number'] = $cc_number; $pp_params['cc_cvv_code'] = $cc_cvv_code; $pp_params['cc_expires_month'] = $cc_expires_month; $pp_params['cc_expires_year'] = $cc_expires_year; $output .= PaymentIPN::DrawPaymentForm('online', $pp_params, $mode == 'TEST MODE' ? 'test' : 'real', false); $output .= $second_part; } else { if ($payment_type == 'paypal') { $output .= $fisrt_part; $pp_params['api_login'] = $paypal_email; $pp_params['notify'] = 'index.php?page=payment_notify_paypal'; $pp_params['paypal_form_type'] = 'single'; $pp_params['paypal_form_fields'] = ''; $pp_params['paypal_form_fields_count'] = ''; $output .= PaymentIPN::DrawPaymentForm('paypal', $pp_params, $mode == 'TEST MODE' ? 'test' : 'real', false); $output .= $second_part; } else { if ($payment_type == '2co') { $output .= $fisrt_part; $pp_params['api_login'] = $two_checkout_vendor; $pp_params['notify'] = 'index.php?page=payment_notify_2co'; $output .= PaymentIPN::DrawPaymentForm('2co', $pp_params, $mode == 'TEST MODE' ? 'test' : 'real', false); $output .= $second_part; } else { if ($payment_type == 'authorize') { $output .= $fisrt_part; $pp_params['api_login'] = $authorize_login_id; $pp_params['transaction_key'] = $authorize_transaction_key; $pp_params['notify'] = 'index.php?page=payment_notify_autorize_net'; // authorize.net accepts only USD, so we need to convert the sum into USD $pp_params['cart_total'] = number_format($pp_params['cart_total'] * Application::Get('currency_rate'), '2', '.', ','); $output .= PaymentIPN::DrawPaymentForm('authorize.net', $pp_params, $mode == 'TEST MODE' ? 'test' : 'real', false); $output .= $second_part; } } } } if ($draw) { echo $output; } else { $output; } }