/** * Get replacement elements for country and region fields on the checkout form * * Note: extracted from the wpsc_change_tax function in ajax.php as of version 3.8.13.3 * * @since 3.8.14 * @access private * @return array checkout information */ function _wpsc_get_checkout_info() { global $wpsc_cart; // Checkout info is what we will return to the AJAX client $checkout_info = array(); // start with items that have no dependencies $checkout_info['delivery_country'] = wpsc_get_customer_meta('shippingcountry'); $checkout_info['billing_country'] = wpsc_get_customer_meta('billingcountry'); $checkout_info['country_name'] = wpsc_get_country($checkout_info['delivery_country']); $checkout_info['lock_tax'] = get_option('lock_tax'); // TODO: this is set anywhere, probably deprecated $checkout_info['needs_shipping_recalc'] = wpsc_cart_need_to_recompute_shipping_quotes(); $checkout_info['shipping_keys'] = array(); foreach ($wpsc_cart->cart_items as $key => $cart_item) { $checkout_info['shipping_keys'][$key] = wpsc_currency_display($cart_item->shipping); } if (!$checkout_info['needs_shipping_recalc']) { $wpsc_cart->update_location(); $wpsc_cart->get_shipping_method(); $wpsc_cart->get_shipping_option(); if ($wpsc_cart->selected_shipping_method != '') { $wpsc_cart->update_shipping($wpsc_cart->selected_shipping_method, $wpsc_cart->selected_shipping_option); } $tax = $wpsc_cart->calculate_total_tax(); $total = wpsc_cart_total(); $total_input = wpsc_cart_total(false); if ($wpsc_cart->coupons_amount >= $total_input && !empty($wpsc_cart->coupons_amount)) { $total = 0; } if ($wpsc_cart->total_price < 0) { $wpsc_cart->coupons_amount += $wpsc_cart->total_price; $wpsc_cart->total_price = null; $wpsc_cart->calculate_total_price(); } $cart_widget = _wpsc_ajax_get_cart(false); if (isset($cart_widget['widget_output']) && !empty($cart_widget['widget_output'])) { $checkout_info['widget_output'] = $cart_widget['widget_output']; } $checkout_info['cart_shipping'] = wpsc_cart_shipping(); $checkout_info['tax'] = $tax; $checkout_info['display_tax'] = wpsc_cart_tax(); $checkout_info['total'] = $total; $checkout_info['total_input'] = $total_input; } return apply_filters('wpsc_ajax_checkout_info', $checkout_info); }
function wpsc_display_purchlog_shipping_country() { global $purchlogitem; if (isset($purchlogitem->shippinginfo['shippingcountry'])) { return esc_html(wpsc_get_country($purchlogitem->shippinginfo['shippingcountry']['value'])); } else { return ''; } }
public function filter_confirm_transaction_page() { ob_start(); ?> <table width='400' class='paypal_express_form'> <tr> <td align='left' class='firstcol'><strong><?php _e('Order Total:', 'wpsc'); ?> </strong></td> <td align='left'><?php echo wpsc_currency_display($this->purchase_log->get('totalprice')); ?> </td> </tr> <tr> <td align='left' colspan='2'><strong><?php _e('Shipping Details:', 'wpsc'); ?> </strong></td> </tr> <tr> <td align='left' class='firstcol'> <?php echo __('Address:', 'wpsc'); ?> </td> <td align='left'> <?php echo esc_html($this->checkout_data->get('shippingaddress')); ?> </td> </tr> <tr> <td align='left' class='firstcol'> <?php echo __('City:', 'wpsc'); ?> </td> <td align='left'><?php echo esc_html($this->checkout_data->get('shippingcity')); ?> </td> </tr> <tr> <td align='left' class='firstcol'> <?php echo __('State:', 'wpsc'); ?> </td> <td align='left'> <?php echo esc_html(wpsc_get_region($this->checkout_data->get('shippingstate'))); ?> </td> </tr> <tr> <td align='left' class='firstcol'> <?php echo __('Postal code:', 'wpsc'); ?> </td> <td align='left'><?php echo esc_html($this->checkout_data->get('shippingpostcode')); ?> </td> </tr> <tr> <td align='left' class='firstcol'> <?php echo __('Country:', 'wpsc'); ?> </td> <td align='left'><?php echo esc_html(wpsc_get_country($this->checkout_data->get('shippingcountry'))); ?> </td> </tr> <tr> <td colspan='2'> <form action="<?php echo remove_query_arg(array('payment_gateway', 'payment_gateway_callback')); ?> " method='post'> <input type='hidden' name='payment_gateway' value='paypal-express-checkout' /> <input type='hidden' name='payment_gateway_callback' value='process_confirmed_payment' /> <p><input name='action' type='submit' value='<?php _e('Confirm Payment', 'wpsc'); ?> ' /></p> </form> </td> </tr> </table> <?php $output = apply_filters('wpsc_confirm_payment_message', ob_get_clean(), $this->purchase_log); return $output; }
function wpsc_packing_slip($purchase_id) { global $wpdb; $purch_sql = "SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `id`='" . $purchase_id . "'"; $purch_data = $wpdb->get_row($purch_sql, ARRAY_A); //echo "<p style='padding-left: 5px;'><strong>".TXT_WPSC_DATE."</strong>:".date("jS M Y", $purch_data['date'])."</p>"; $cartsql = "SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`=" . $purchase_id . ""; $cart_log = $wpdb->get_results($cartsql, ARRAY_A); $j = 0; if ($cart_log != null) { echo "<div class='packing_slip'>\n\r"; echo "<h2>" . TXT_WPSC_PACKING_SLIP . "</h2>\n\r"; echo "<strong>" . TXT_WPSC_ORDER . " #</strong> " . $purchase_id . "<br /><br />\n\r"; echo "<table>\n\r"; $form_sql = "SELECT * FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id` = '" . (int) $purchase_id . "'"; $input_data = $wpdb->get_results($form_sql, ARRAY_A); foreach ($input_data as $input_row) { $rekeyed_input[$input_row['form_id']] = $input_row; } if ($input_data != null) { $form_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `active` = '1'", ARRAY_A); foreach ($form_data as $form_field) { switch ($form_field['type']) { case 'country': $delivery_region_count = $wpdb->get_var("SELECT COUNT(`regions`.`id`) FROM `" . WPSC_TABLE_REGION_TAX . "` AS `regions` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN('" . $wpdb->escape($purch_data['billing_country']) . "')"); if (is_numeric($purch_data['shipping_region']) && $delivery_region_count > 0) { echo " <tr><td>" . __('State', 'wpsc') . ":</td><td>" . wpsc_get_region($purch_data['shipping_region']) . "</td></tr>\n\r"; } echo " <tr><td>" . wp_kses($form_field['name'], array()) . ":</td><td>" . wpsc_get_country($purch_data['billing_country']) . "</td></tr>\n\r"; break; case 'delivery_country': echo " <tr><td>" . wp_kses($form_field['name'], array()) . ":</td><td>" . wpsc_get_country($purch_data['shipping_country']) . "</td></tr>\n\r"; break; case 'heading': echo " <tr><td colspan='2'><strong>" . wp_kses($form_field['name'], array()) . ":</strong></td></tr>\n\r"; break; default: echo " <tr><td>" . wp_kses($form_field['name'], array()) . ":</td><td>" . htmlentities(stripslashes($rekeyed_input[$form_field['id']]['value']), ENT_QUOTES) . "</td></tr>\n\r"; break; } } } else { echo " <tr><td>" . TXT_WPSC_NAME . ":</td><td>" . $purch_data['firstname'] . " " . $purch_data['lastname'] . "</td></tr>\n\r"; echo " <tr><td>" . TXT_WPSC_ADDRESS . ":</td><td>" . $purch_data['address'] . "</td></tr>\n\r"; echo " <tr><td>" . TXT_WPSC_PHONE . ":</td><td>" . $purch_data['phone'] . "</td></tr>\n\r"; echo " <tr><td>" . TXT_WPSC_EMAIL . ":</td><td>" . $purch_data['email'] . "</td></tr>\n\r"; } if (get_option('payment_method') == 2) { $gateway_name = ''; foreach ($GLOBALS['nzshpcrt_gateways'] as $gateway) { if ($purch_data['gateway'] != 'testmode') { if ($gateway['internalname'] == $purch_data['gateway']) { $gateway_name = $gateway['name']; } } else { $gateway_name = "Manual Payment"; } } } // echo " <tr><td colspan='2'></td></tr>\n\r"; // echo " <tr><td>".TXT_WPSC_PAYMENT_METHOD.":</td><td>".$gateway_name."</td></tr>\n\r"; // //echo " <tr><td>".TXT_WPSC_PURCHASE_NUMBER.":</td><td>".$purch_data['id']."</td></tr>\n\r"; // echo " <tr><td>".TXT_WPSC_HOWCUSTOMERFINDUS.":</td><td>".$purch_data['find_us']."</td></tr>\n\r"; // $engrave_line = explode(",",$purch_data['engravetext']); // echo " <tr><td>".TXT_WPSC_ENGRAVE."</td><td></td></tr>\n\r"; // echo " <tr><td>".TXT_WPSC_ENGRAVE_LINE_ONE.":</td><td>".$engrave_line[0]."</td></tr>\n\r"; // echo " <tr><td>".TXT_WPSC_ENGRAVE_LINE_TWO.":</td><td>".$engrave_line[1]."</td></tr>\n\r"; // if($purch_data['transactid'] != '') { // echo " <tr><td>".TXT_WPSC_TXN_ID.":</td><td>".$purch_data['transactid']."</td></tr>\n\r"; // } echo "</table>\n\r"; echo "<table class='packing_slip'>"; echo "<tr>"; echo " <th>" . TXT_WPSC_QUANTITY . " </th>"; echo " <th>" . TXT_WPSC_NAME . "</th>"; echo " <th>" . TXT_WPSC_PRICE . " </th>"; echo " <th>" . TXT_WPSC_SHIPPING . " </th>"; echo '<th>Tax</th>'; echo '</tr>'; $endtotal = 0; $all_donations = true; $all_no_shipping = true; $file_link_list = array(); foreach ($cart_log as $cart_row) { $alternate = ""; $j++; if ($j % 2 != 0) { $alternate = "class='alt'"; } $productsql = "SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id`=" . $cart_row['prodid'] . ""; $product_data = $wpdb->get_results($productsql, ARRAY_A); $variation_sql = "SELECT * FROM `" . WPSC_TABLE_CART_ITEM_VARIATIONS . "` WHERE `cart_id`='" . $cart_row['id'] . "'"; $variation_data = $wpdb->get_results($variation_sql, ARRAY_A); $variation_count = count($variation_data); if ($variation_count > 1) { $variation_list = " ("; $i = 0; foreach ($variation_data as $variation) { if ($i > 0) { $variation_list .= ", "; } $value_id = $variation['value_id']; $value_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_VARIATION_VALUES . "` WHERE `id`='" . $value_id . "' LIMIT 1", ARRAY_A); $variation_list .= $value_data[0]['name']; $i++; } $variation_list .= ")"; } else { if ($variation_count == 1) { $value_id = $variation_data[0]['value_id']; $value_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_VARIATION_VALUES . "` WHERE `id`='" . $value_id . "' LIMIT 1", ARRAY_A); $variation_list = " (" . $value_data[0]['name'] . ")"; } else { $variation_list = ''; } } if ($cart_row['donation'] != 1) { $all_donations = false; } if ($cart_row['no_shipping'] != 1) { $shipping = $cart_row['pnp'] * $cart_row['quantity']; $total_shipping += $shipping; $all_no_shipping = false; } else { $shipping = 0; } $price = $cart_row['price'] * $cart_row['quantity']; $gst = $price - $price / (1 + $cart_row['gst'] / 100); if ($gst > 0) { $tax_per_item = $gst / $cart_row['quantity']; } echo "<tr {$alternate}>"; echo " <td>"; echo $cart_row['quantity']; echo " </td>"; echo " <td>"; echo $product_data[0]['name']; echo stripslashes($variation_list); echo " </td>"; echo " <td>"; echo nzshpcrt_currency_display($price, 1); echo " </td>"; echo " <td>"; echo nzshpcrt_currency_display($shipping, 1); echo " </td>"; echo '<td>'; echo nzshpcrt_currency_display($cart_row['tax_charged'], 1); echo '<td>'; echo '</tr>'; } echo "</table>"; echo "</div>\n\r"; } else { echo "<br />" . TXT_WPSC_USERSCARTWASEMPTY; } }
function transaction_results($sessionid, $echo_to_screen = true, $transaction_id = null) { global $wpdb, $wpsc_cart; //$curgateway = get_option('payment_gateway'); $curgateway = $wpdb->get_var("SELECT gateway FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE sessionid='{$sessionid}'"); $errorcode = 0; $order_status = 2; $siteurl = get_option('siteurl'); /* * {Notes} Double check that $Echo_To_Screen is a boolean value */ $echo_to_screen = !is_bool($echo_to_screen) ? true : $echo_to_screen; //exit('triggered but with errors?'.$echo_to_screen); if (is_numeric($sessionid)) { if ($echo_to_screen) { echo apply_filters('wpsc_pre_transaction_results', ''); } $purchase_log = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= " . $sessionid . " LIMIT 1", ARRAY_A); if ($purchase_log['gateway'] == "testmode" && $purchase_log['processed'] < 2) { $message = get_option('wpsc_email_receipt'); $message_html = $message; } else { $message = get_option('wpsc_email_receipt'); $message_html = $message; } $order_url = $siteurl . "/wp-admin/admin.php?page=" . WPSC_DIR_NAME . "/display-log.php&purchcaseid=" . $purchase_log['id']; if ($_GET['ipn_request'] != 'true' and get_option('paypal_ipn') == 1) { if ($purchase_log == null) { echo TXT_WPSC_ORDER_FAILED; if (get_option('purch_log_email') != null && $purchase_log['email_sent'] != 1) { wp_mail(get_option('purch_log_email'), TXT_WPSC_NEW_ORDER_PENDING_SUBJECT, TXT_WPSC_NEW_ORDER_PENDING_BODY . $order_url, "From: " . get_option('return_email') . ""); } return false; } else { if ($purchase_log['processed'] < 2) { //added by Thomas on 20/6/2007 echo TXT_WPSC_ORDER_PENDING . "<p style='margin: 1em 0px 0px 0px;' >" . nl2br(get_option('payment_instructions')) . "</p>"; /*if($purchase_log['gateway'] != 'testmode') { if((get_option('purch_log_email') != null) && ($purchase_log['email_sent'] != 1)) { mail(get_option('purch_log_email'), TXT_WPSC_NEW_ORDER_PENDING_SUBJECT, TXT_WPSC_NEW_ORDER_PENDING_BODY.$order_url, "From: ".get_option('return_email').""); } return false; }*/ } } } $cart = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid`='{$purchase_log['id']}'", ARRAY_A); if ($purchase_log['shipping_country'] != '') { $billing_country = $purchase_log['billing_country']; $shipping_country = $purchase_log['shipping_country']; } else { $country = $wpdb->get_var("SELECT `value` FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id`=" . $purchase_log['id'] . " AND `form_id` = '" . get_option('country_form_field') . "' LIMIT 1"); $billing_country = $country; $shipping_country = $country; } $email_form_field = $wpdb->get_results("SELECT `id`,`type` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type` IN ('email') AND `active` = '1' ORDER BY `order` ASC LIMIT 1", ARRAY_A); $email = $wpdb->get_var("SELECT `value` FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id`=" . $purchase_log['id'] . " AND `form_id` = '" . $email_form_field[0]['id'] . "' LIMIT 1"); $stock_adjusted = false; $previous_download_ids = array(0); $product_list = ''; if ($cart != null && $errorcode == 0) { foreach ($cart as $row) { $link = ""; $product_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id`='{$row['prodid']}' LIMIT 1", ARRAY_A); if ($purchase_log['email_sent'] != 1) { $wpdb->query("UPDATE `" . WPSC_TABLE_DOWNLOAD_STATUS . "` SET `active`='1' WHERE (`fileid` = '{$product_data['file']}' OR `cartid` = '{$row['id']}' ) AND `purchid` = '{$purchase_log['id']}'"); } do_action('wpsc_transaction_result_cart_item', array("purchase_id" => $purchase_log['id'], "cart_item" => $row, "purchase_log" => $purchase_log)); if ($purchase_log['processed'] >= 2) { //echo "SELECT * FROM `".WPSC_TABLE_DOWNLOAD_STATUS."` WHERE `active`='1' AND `purchid`='".$purchase_log['id']."' AND (`cartid` = '".$row['id']."' OR (`cartid` IS NULL AND `fileid` = '{$product_data['file']}') ) AND `id` NOT IN ('".implode("','",$previous_download_ids)."') LIMIT 1"; $download_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "` WHERE `active`='1' AND `purchid`='" . $purchase_log['id'] . "' AND (`cartid` = '" . $row['id'] . "' OR (`cartid` IS NULL AND `fileid` = '{$product_data['file']}') ) AND `id` NOT IN ('" . implode("','", $previous_download_ids) . "') LIMIT 1", ARRAY_A); //exit('IM HERE'.$errorcode.'<pre>'.print_r($download_data).'</pre>'); if ($download_data != null) { if ($download_data['uniqueid'] == null) { // if the uniqueid is not equal to null, its "valid", regardless of what it is $link = $siteurl . "?downloadid=" . $download_data['id']; } else { $link = $siteurl . "?downloadid=" . $download_data['uniqueid']; } //$order_status= 4; } else { $order_status = $purchase_log['processed']; } $previous_download_ids[] = $download_data['id']; } do_action('wpsc_confirm_checkout', $purchase_log['id']); $shipping = $row['pnp'] * $row['quantity']; $total_shipping += $shipping; if ($product_data['special'] == 1) { $price_modifier = $product_data['special_price']; } else { $price_modifier = 0; } $total += $row['price'] * $row['quantity']; $message_price = nzshpcrt_currency_display($row['price'] * $row['quantity'], $product_data['notax'], true); $shipping_price = nzshpcrt_currency_display($shipping, 1, true); $variation_values = $wpdb->get_col("SELECT `value_id` FROM `" . WPSC_TABLE_CART_ITEM_VARIATIONS . "` WHERE `cart_id`='{$row['id']}'"); //echo "<pre>".print_r($product_data,true)."</pre>"; $variation_count = count($variation_values); if ($purchase['gateway'] != 'testmode') { if ($gateway['internalname'] == $purch_data[0]['gateway']) { $gateway_name = $gateway['name']; } } else { $gateway_name = "Manual Payment"; } //echo "<pre>".print_r($variation_values,true)."</pre>"; $variation_list = ''; if ($variation_count > 0) { $value_names = $wpdb->get_col("SELECT `name` FROM `" . WPSC_TABLE_VARIATION_VALUES . "` WHERE `id` IN ('" . implode("','", $variation_values) . "')"); $variation_list = " (" . stripslashes(implode(", ", $value_names)) . ")"; } if ($link != '') { $additional_content = apply_filters('wpsc_transaction_result_content', array("purchase_id" => $purchase_log['id'], "cart_item" => $row, "purchase_log" => $purchase_log)); if (!is_string($additional_content)) { $additional_content = ''; } $product_list .= " - " . $product_data['name'] . stripslashes($variation_list) . " " . $message_price . " " . TXT_WPSC_CLICKTODOWNLOAD . ":\n\r {$link}\n\r" . $additional_content; $product_list_html .= " - " . $product_data['name'] . stripslashes($variation_list) . " " . $message_price . " <a href='{$link}'>" . TXT_WPSC_CLICKTODOWNLOAD . "</a>\n" . $additional_content; } else { $plural = ''; if ($row['quantity'] > 1) { $plural = "s"; } $product_list .= " - " . $row['quantity'] . " " . $product_data['name'] . stripslashes($variation_list) . " " . $message_price . "\n\r"; if ($shipping > 0) { $product_list .= " - " . TXT_WPSC_SHIPPING . ":" . $shipping_price . "\n\r"; } $product_list_html .= " - " . $row['quantity'] . " " . $product_data['name'] . stripslashes($variation_list) . " " . $message_price . "\n\r"; if ($shipping > 0) { $product_list_html .= " " . TXT_WPSC_SHIPPING . ":" . $shipping_price . "\n\r"; } } $report = get_option('wpsc_email_admin'); $report_product_list .= " - " . $product_data['name'] . stripslashes($variation_list) . " " . $message_price . "\n\r"; } // KTTODO - call out to ezprints here if ($purchase_log['processed'] >= 2 && $purchase_log['ezprints_order_sent_count'] < 1) { $ezprints_body = sendEzPrintsOrder($purchase_log['id']); $wpdb->query("UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `ezprints_order_sent_count` = 1 WHERE `id` = " . $purchase_log['id'] . " LIMIT 1"); } // Decrement the stock here if ($purchase_log['processed'] >= 2) { wpsc_decrement_claimed_stock($purchase_log['id']); } if ($purchase_log['discount_data'] != '') { $coupon_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE coupon_code='" . $wpdb->escape($purchase_log['discount_data']) . "' LIMIT 1", ARRAY_A); if ($coupon_data['use-once'] == 1) { $wpdb->query("UPDATE `" . WPSC_TABLE_COUPON_CODES . "` SET `active`='0', `is-used`='1' WHERE `id`='" . $coupon_data['id'] . "' LIMIT 1"); } } //$wpdb->query("UPDATE `".WPSC_TABLE_DOWNLOAD_STATUS."` SET `active`='1' WHERE `fileid`='".$product_data['file']."' AND `purchid` = '".$purchase_log['id']."' LIMIT 1"); //if (!isset($_SESSION['quote_shipping'])) //$total_shipping = nzshpcrt_determine_base_shipping($total_shipping, $shipping_country); $total_shipping += $purchase_log['base_shipping']; $total = $purchase_log['totalprice']; // echo $total; // $message.= "\n\r"; $product_list .= "Your Purchase No.: " . $purchase_log['id'] . "\n\r"; if ($purchase_log['discount_value'] > 0) { $discount_email .= TXT_WPSC_DISCOUNT . "\n\r: "; $discount_email .= $purchase_log['discount_data'] . ' : ' . nzshpcrt_currency_display($purchase_log['discount_value'], 1, true) . "\n\r"; } $total_shipping_email .= TXT_WPSC_TOTALSHIPPING . ": " . nzshpcrt_currency_display($total_shipping, 1, true) . "\n\r"; $total_price_email .= TXT_WPSC_TOTAL . ": " . nzshpcrt_currency_display($total, 1, true) . "\n\r"; $product_list_html .= "Your Purchase No.: " . $purchase_log['id'] . "\n\n\r"; if ($purchase_log['discount_value'] > 0) { $report .= $discount_email . "\n\r"; $total_shipping_html .= TXT_WPSC_DISCOUNT . ": " . nzshpcrt_currency_display($purchase_log['discount_value'], 1, true) . "\n\r"; } $total_shipping_html .= TXT_WPSC_TOTALSHIPPING . ": " . nzshpcrt_currency_display($total_shipping, 1, true) . "\n\r"; $total_price_html .= TXT_WPSC_TOTAL . ": " . nzshpcrt_currency_display($total, 1, true) . "\n\r"; if (isset($_GET['ti'])) { $message .= "\n\r" . TXT_WPSC_YOURTRANSACTIONID . ": " . $_GET['ti']; $message_html .= "\n\r" . TXT_WPSC_YOURTRANSACTIONID . ": " . $_GET['ti']; $report .= "\n\r" . TXT_WPSC_TRANSACTIONID . ": " . $_GET['ti']; } else { $report_id = "Purchase No.: " . $purchase_log['id'] . "\n\r"; } //echo "<pre>".print_r($purchase_log,true)."</pre>"; $message = str_replace('%product_list%', $product_list, $message); $message = str_replace('%total_shipping%', $total_shipping_email, $message); $message = str_replace('%total_price%', $total_price_email, $message); //$message = str_replace('%order_status%',get_option('blogname'),$message); $message = str_replace('%shop_name%', get_option('blogname'), $message); $report = str_replace('%product_list%', $report_product_list, $report); $report = str_replace('%total_shipping%', $total_shipping_email, $report); $report = str_replace('%total_price%', $total_price_email, $report); $report = str_replace('%shop_name%', get_option('blogname'), $report); $message_html = str_replace('%product_list%', $product_list_html, $message_html); $message_html = str_replace('%total_shipping%', $total_shipping_html, $message_html); $message_html = str_replace('%total_price%', $total_price_email, $message_html); $message_html = str_replace('%shop_name%', get_option('blogname'), $message_html); //$message_html = str_replace('%order_status%',get_option('blogname'),$message_html); if ($email != '' && $purchase_log['email_sent'] != 1) { add_filter('wp_mail_from', 'wpsc_replace_reply_address', 0); add_filter('wp_mail_from_name', 'wpsc_replace_reply_name', 0); if ($purchase_log['processed'] < 2) { $payment_instructions = strip_tags(get_option('payment_instructions')); $message = TXT_WPSC_ORDER_PENDING . "\n\r" . $payment_instructions . "\n\r" . $message; wp_mail($email, TXT_WPSC_ORDER_PENDING_PAYMENT_REQUIRED, $message); } else { wp_mail($email, TXT_WPSC_PURCHASERECEIPT, $message); } } remove_filter('wp_mail_from_name', 'wpsc_replace_reply_name'); remove_filter('wp_mail_from', 'wpsc_replace_reply_address'); $report_user = TXT_WPSC_CUSTOMERDETAILS . "\n\r"; $form_sql = "SELECT * FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id` = '" . $purchase_log['id'] . "'"; $form_data = $wpdb->get_results($form_sql, ARRAY_A); if ($form_data != null) { foreach ($form_data as $form_field) { $form_data = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `id` = '" . $form_field['form_id'] . "' LIMIT 1", ARRAY_A); switch ($form_data['type']) { case "country": $delivery_region_count = $wpdb->get_var("SELECT COUNT(`regions`.`id`) FROM `" . WPSC_TABLE_REGION_TAX . "` AS `regions` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN('" . $wpdb->escape($purchase_log['billing_country']) . "')"); if (is_numeric($purchase_log['shipping_region']) && $delivery_region_count > 0) { $report_user .= TXT_WPSC_STATE . ": " . wpsc_get_region($purchase_log['billing_region']) . "\n"; } $report_user .= $form_data['name'] . ": " . wpsc_get_country($form_field['value']) . "\n"; break; case "delivery_country": $delivery_region_count = $wpdb->get_var("SELECT COUNT(`regions`.`id`) FROM `" . WPSC_TABLE_REGION_TAX . "` AS `regions` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN('" . $wpdb->escape($purchase_log['shipping_country']) . "')"); if (is_numeric($purchase_log['shipping_region']) && $delivery_region_count > 0) { $report_user .= TXT_WPSC_DELIVERY_STATE . ": " . wpsc_get_region($purchase_log['shipping_region']) . "\n"; } $report_user .= $form_data['name'] . ": " . wpsc_get_country($form_field['value']) . "\n"; break; default: $report_user .= $form_data['name'] . ": " . $form_field['value'] . "\n"; break; } } } $report_user .= "\n\r"; $report = $report_user . $report_id . $report; if ($stock_adjusted == true) { $wpdb->query("UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET `stock_adjusted` = '1' WHERE `sessionid` = " . $sessionid . " LIMIT 1"); } if (get_option('purch_log_email') != null && $purchase_log['email_sent'] != 1) { wp_mail(get_option('purch_log_email'), TXT_WPSC_PURCHASEREPORT, $report); } if ($purchase_log['processed'] < 2) { echo "<br />" . nl2br(str_replace("\$", '\\$', $message_html)); return; } /// Empty the cart $wpsc_cart->submit_stock_claims($purchase_log['id']); $wpsc_cart->empty_cart(); if (true === $echo_to_screen) { echo '<div class="wrap">'; if ($sessionid != null) { echo TXT_WPSC_THETRANSACTIONWASSUCCESSFUL . "<br />"; echo "<br />" . nl2br(str_replace("\$", '\\$', $message_html)); } echo '</div>'; } } else { if (true === $echo_to_screen) { echo '<div class="wrap">'; echo TXT_WPSC_BUYPRODUCTS; echo '</div>'; } } if ($purchase_log['email_sent'] != 1 and $sessionid != '') { if (preg_match("/^[\\w\\s._,-]+\$/", $transaction_id)) { $transact_id_sql = "`transactid` = '" . $transaction_id . "',"; } $update_sql = "UPDATE `" . WPSC_TABLE_PURCHASE_LOGS . "` SET {$transact_id_sql} `email_sent` = '1', `processed` = '{$order_status}' WHERE `sessionid` = " . $sessionid . " LIMIT 1"; $wpdb->query($update_sql); } } }
/** * generates a row for use in tax settings tables * * @param string specifies mode of row to generate. Options: rates, bands * @param string the key number for the row * @param array tax rate settings (used keys: rate, name, country_code, region_code, shipping, index, row_class) * */ function wpsc_build_taxes_row($row_mode = 'rates', $row_key = 0, $tax_rate = false) { $defaults = array('rate' => null, 'name' => null, 'country_code' => null, 'region_code' => null, 'shipping' => null, 'index' => null, 'row_class' => null); $tax_rate = array_merge($defaults, (array) $tax_rate); $countries = $this->wpec_taxes->wpec_taxes_get_countries(); if (!empty($tax_rate['country_code']) && $tax_rate['country_code'] != 'all-markets') { $selected_country = array('isocode' => $tax_rate['country_code'], 'country' => wpsc_get_country($tax_rate['country_code'])); } else { $selected_country = array('isocode' => 'all-markets', 'country' => __('All Markets', 'wpsc')); } ob_start(); ?> <tr id='wpsc-taxes-<?php esc_attr_e($row_mode); ?> -row-<?php esc_attr_e($row_key); ?> ' data-row-key="<?php esc_attr_e($row_key); ?> " class='wpsc-tax-<?php esc_attr_e($row_mode); ?> -row <?php esc_attr_e($tax_rate['row_class']); ?> '> <?php if ($row_mode == 'bands') { // BAND NAME ?> <td> <input type='hidden' id='band-index-<?php esc_attr_e($row_key); ?> ' name="wpsc_options[wpec_taxes_bands][<?php esc_attr_e($row_key); ?> ][index]" value="<?php esc_attr_e($row_key); ?> " /> <input id='band-name-<?php esc_attr_e($row_key); ?> ' name="wpsc_options[wpec_taxes_bands][<?php esc_attr_e($row_key); ?> ][name]" class='taxes-band' type='text' value='<?php esc_attr_e($tax_rate['name']); ?> ' /> </td> <?php } ?> <td> <?php // MARKET COUNTRY SELECT echo $this->wpec_taxes_build_select_options($countries, 'isocode', 'country', $selected_country, array('id' => $row_mode . "-country-" . $row_key, 'name' => "wpsc_options[wpec_taxes_" . $row_mode . "][" . $row_key . "][country_code]", 'class' => 'wpsc-taxes-country-drop-down', 'data-row-key' => $row_key, 'data-row-mode' => $row_mode)); // MARKET REGION SELECT if (!empty($tax_rate['region_code'])) { $regions = $this->wpec_taxes->wpec_taxes_get_regions($tax_rate['country_code']); if (!empty($regions)) { if ($tax_rate['region_code'] == 'all-markets') { $region_name = 'All Markets'; } else { $region = new WPSC_Region($tax_rate['country_code'], $tax_rate['region_code']); $region_name = $region->get_name(); } echo $this->wpec_taxes_build_select_options($regions, 'region_code', 'name', array('region_code' => $tax_rate['region_code'], 'name' => $region_name), array('id' => $row_mode . "-region-" . $row_key, 'name' => "wpsc_options[wpec_taxes_" . $row_mode . "][" . $row_key . "][region_code]", 'class' => 'wpsc-taxes-region-drop-down')); } } // if ?> <img src="<?php echo esc_url(wpsc_get_ajax_spinner()); ?> " class="ajax-feedback" title="" alt="" /> </td> <td><?php // TAX RATE ?> <input type='text' size='3' id="<?php esc_attr_e($row_mode); ?> -rate-<?php esc_attr_e($row_key); ?> " name="wpsc_options[wpec_taxes_<?php esc_attr_e($row_mode); ?> ][<?php esc_attr_e($row_key); ?> ][rate]" class="taxes-<?php esc_attr_e($row_mode); ?> " value="<?php esc_attr_e($tax_rate['rate']); ?> " /> % </td> <?php if ($row_mode == 'rates') { // TAX SHIPPING ? ?> <td> <label> <input type='checkbox' id="shipping-<?php esc_attr_e($row_key); ?> " name="wpsc_options[wpec_taxes_<?php esc_attr_e($row_mode); ?> ][<?php esc_attr_e($row_key); ?> ][shipping]" class="taxes-<?php esc_attr_e($row_mode); ?> " <?php checked($tax_rate['shipping'] == 1); ?> /> <?php _e('Apply to Shipping', 'wpsc'); ?> </label> </td> <?php } ?> <?php // ACTIONS ?> <td> <a tabindex="-1" title="<?php _e('Delete Field', 'wpsc'); ?> " class="button-secondary wpsc-button-round wpsc-button-minus wpsc-taxes-<?php esc_attr_e($row_mode); ?> -delete" id="wpsc-taxes-<?php esc_attr_e($row_mode); ?> -delete-<?php esc_attr_e($row_key); ?> " href="#"><?php echo _x('–', 'delete item', 'wpsc'); ?> </a> <a tabindex="-1" title="<?php _e('Add Field', 'wpsc'); ?> " class="button-secondary wpsc-button-round wpsc-button-plus wpsc-taxes-<?php esc_attr_e($row_mode); ?> -add" href="#"><?php echo _x('+', 'add item', 'wpsc'); ?> </a> </td> </tr> <?php return ob_get_clean(); }
$cart = $wpdb->get_results($cartsql, ARRAY_A); //exit(nl2br(print_r($cart,true))); foreach ($cart as $item) { /* echo "<pre>".print_r($item,1)."</pre>"; */ $product = $wpdb->get_row("SELECT * FROM `" . WPSC_TABLE_PRODUCT_LIST . "` WHERE `id`=" . $item['prodid'] . " LIMIT 1", ARRAY_A); $output .= "\"" . $firstname . " " . $lastname . "\","; $output .= "\"" . $email . "\","; $output .= "\"" . $address1 . "\","; $output .= "\"" . $address2 . "\","; $output .= "\"" . $address3 . "\","; $output .= "\"" . $address4 . "\","; $output .= "\"" . $city . "\","; $output .= "\"" . $region . "\","; //Region still needs to be addressed $output .= "\"" . $postcode . "\","; $output .= "\"" . wpsc_get_country($purchase['shipping_country']) . "\","; $output .= "\"" . $purchase['id'] . "\","; $output .= "\"" . $reference . "\","; $output .= "\"" . date("d/m/Y", $purchase['date']) . "\","; $output .= "\"" . date("d/m/Y", $purchase['date']) . "\","; $total = $item["price"] * $item['quantity']; $subtotal = $total; $tax = $subtotal * get_option("country_tax"); $unitamount = $item["price"]; if ($inclusive_tax == true) { $subtotal = round($total / 1.175, 2); $tax = $total - $subtotal; $unitamount = round($subtotal / $item['quantity'], 6); } $output .= "\"" . "\","; $output .= "\"" . "\",";
/** * wpsc_change_tax function, used through ajax and in normal page loading. * No parameters, returns nothing */ function wpsc_change_tax() { global $wpdb, $wpsc_cart; $form_id = absint($_POST['form_id']); $wpsc_selected_country = $wpsc_cart->selected_country; $wpsc_selected_region = $wpsc_cart->selected_region; $wpsc_delivery_country = $wpsc_cart->delivery_country; $wpsc_delivery_region = $wpsc_cart->delivery_region; $previous_country = wpsc_get_customer_meta('billingcountry'); global $wpdb, $user_ID, $wpsc_customer_checkout_details; if (isset($_POST['billing_country'])) { $wpsc_selected_country = $_POST['billing_country']; wpsc_update_customer_meta('billingcountry', $wpsc_selected_country); } if (isset($_POST['billing_region'])) { $wpsc_selected_region = absint($_POST['billing_region']); wpsc_update_customer_meta('billingregion', $wpsc_selected_region); } $check_country_code = WPSC_Countries::country_id(wpsc_get_customer_meta('billing_region')); if (wpsc_get_customer_meta('billingcountry') != $check_country_code) { $wpsc_selected_region = null; } if (isset($_POST['shipping_country'])) { $wpsc_delivery_country = $_POST['shipping_country']; wpsc_update_customer_meta('shippingcountry', $wpsc_delivery_country); } if (isset($_POST['shipping_region'])) { $wpsc_delivery_region = absint($_POST['shipping_region']); wpsc_update_customer_meta('shippingregion', $wpsc_delivery_region); } $check_country_code = WPSC_Countries::country_id($wpsc_delivery_region); if ($wpsc_delivery_country != $check_country_code) { $wpsc_delivery_region = null; } $wpsc_cart->update_location(); $wpsc_cart->get_shipping_method(); $wpsc_cart->get_shipping_option(); if ($wpsc_cart->selected_shipping_method != '') { $wpsc_cart->update_shipping($wpsc_cart->selected_shipping_method, $wpsc_cart->selected_shipping_option); } $tax = $wpsc_cart->calculate_total_tax(); $total = wpsc_cart_total(); $total_input = wpsc_cart_total(false); if ($wpsc_cart->coupons_amount >= $total_input && !empty($wpsc_cart->coupons_amount)) { $total = 0; } if ($wpsc_cart->total_price < 0) { $wpsc_cart->coupons_amount += $wpsc_cart->total_price; $wpsc_cart->total_price = null; $wpsc_cart->calculate_total_price(); } $delivery_country = wpsc_get_customer_meta('shipping_country'); $output = _wpsc_ajax_get_cart(false); $output = $output['widget_output']; $json_response = array(); global $wpsc_checkout; if (empty($wpsc_checkout)) { $wpsc_checkout = new wpsc_checkout(); } $json_response['delivery_country'] = esc_js($delivery_country); $json_response['billing_country'] = esc_js($wpsc_selected_country); $json_response['widget_output'] = $output; $json_response['shipping_keys'] = array(); $json_response['cart_shipping'] = wpsc_cart_shipping(); $json_response['form_id'] = $form_id; $json_response['tax'] = $tax; $json_response['display_tax'] = wpsc_cart_tax(); $json_response['total'] = $total; $json_response['total_input'] = $total_input; $json_response['lock_tax'] = get_option('lock_tax'); $json_response['country_name'] = wpsc_get_country($delivery_country); if ('US' == $delivery_country || 'CA' == $delivery_country) { $output = wpsc_shipping_region_list($delivery_country, wpsc_get_customer_meta('shipping_region')); $output = str_replace(array("\n", "\r"), '', $output); $json_response['shipping_region_list'] = $output; } foreach ($wpsc_cart->cart_items as $key => $cart_item) { $json_response['shipping_keys'][$key] = wpsc_currency_display($cart_item->shipping); } $form_selected_country = null; $form_selected_region = null; $onchange_function = null; if (!empty($_POST['billing_country']) && $_POST['billing_country'] != 'undefined' && !isset($_POST['shipping_country'])) { $form_selected_country = $wpsc_selected_country; $form_selected_region = $wpsc_selected_region; $onchange_function = 'set_billing_country'; } else { if (!empty($_POST['shipping_country']) && $_POST['shipping_country'] != 'undefined' && !isset($_POST['billing_country'])) { $form_selected_country = $wpsc_delivery_country; $form_selected_region = $wpsc_delivery_region; $onchange_function = 'set_shipping_country'; } } if ($form_selected_country != null && $onchange_function != null) { $checkoutfields = 'set_shipping_country' == $onchange_function; $region_list = wpsc_country_region_list($form_id, false, $form_selected_country, $form_selected_region, $form_id, $checkoutfields); if ($region_list != null) { $json_response['region_list'] = str_replace(array("\n", "\r"), '', $region_list); } } echo json_encode($json_response); exit; }
/** * transaction_results function main function for creating the purchase reports, transaction results page, and email receipts * @access public * * @since 3.7 * @param $sessionid (string) unique session id * @param echo_to_screen (boolean) whether to output the results or return them (potentially redundant) * @param $transaction_id (int) the transaction id */ function transaction_results($sessionid, $display_to_screen = true, $transaction_id = null) { // Do we seriously need this many globals? global $wpdb, $wpsc_cart, $echo_to_screen, $purchase_log, $order_url; global $message_html, $cart, $errorcode, $wpsc_purchlog_statuses, $wpsc_gateways; $wpec_taxes_controller = new wpec_taxes_controller(); $is_transaction = false; $errorcode = 0; $purchase_log = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= %s LIMIT 1", $sessionid), ARRAY_A); $order_status = $purchase_log['processed']; $curgateway = $purchase_log['gateway']; if (!is_bool($display_to_screen)) { $display_to_screen = true; } $echo_to_screen = $display_to_screen; //new variable to check whether function is being called from wpsc_purchlog_resend_email() $resend_email = isset($_REQUEST['email_buyer_id']) ? true : false; if (is_numeric($sessionid)) { if ($echo_to_screen) { echo apply_filters('wpsc_pre_transaction_results', ''); } // New code to check whether transaction is processed, true if accepted false if pending or incomplete $is_transaction = wpsc_check_purchase_processed($purchase_log['processed']); $message_html = $message = stripslashes(get_option('wpsc_email_receipt')); if ($is_transaction) { $message = __('The Transaction was successful', 'wpsc') . "\r\n" . $message; $message_html = __('The Transaction was successful', 'wpsc') . "<br />" . $message_html; } $country = get_option('country_form_field'); $billing_country = ''; $shipping_country = ''; if (!empty($purchase_log['shipping_country'])) { $billing_country = $purchase_log['billing_country']; $shipping_country = $purchase_log['shipping_country']; } elseif (!empty($country)) { $country = $wpdb->get_var($wpdb->prepare("SELECT `value` FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id` = %d AND `form_id` = %d LIMIT 1", $purchase_log['id'], get_option('country_form_field'))); $billing_country = $country; $shipping_country = $country; } $email = wpsc_get_buyers_email($purchase_log['id']); $previous_download_ids = array(); $product_list = $product_list_html = $report_product_list = ''; $cart = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid` = %d", $purchase_log['id']), ARRAY_A); if ($cart != null && $errorcode == 0) { $total_shipping = ''; foreach ($cart as $row) { $link = array(); $wpdb->update(WPSC_TABLE_DOWNLOAD_STATUS, array('active' => '1'), array('cartid' => $row['id'], 'purchid' => $purchase_log['id'])); do_action('wpsc_transaction_result_cart_item', array("purchase_id" => $purchase_log['id'], "cart_item" => $row, "purchase_log" => $purchase_log)); if ($is_transaction) { $download_data = $wpdb->get_results($wpdb->prepare("SELECT *\n\t\t\t\t\tFROM `" . WPSC_TABLE_DOWNLOAD_STATUS . "`\n\t\t\t\t\tWHERE `active`='1'\n\t\t\t\t\tAND `purchid` = %d\n\t\t\t\t\tAND `cartid` = %d", $purchase_log['id'], $row['id']), ARRAY_A); if (count($download_data) > 0) { foreach ($download_data as $single_download) { $file_data = get_post($single_download['product_id']); // if the uniqueid is not equal to null, its "valid", regardless of what it is $argsdl = array('post_type' => 'wpsc-product-file', 'post_parent' => $single_download['product_id'], 'numberposts' => -1, 'post_status' => 'all'); $download_file_posts = (array) get_posts($argsdl); foreach ((array) $download_file_posts as $single_file_post) { if ($single_file_post->ID == $single_download['fileid']) { $current_Dl_product_file_post = $single_file_post; break; } } $file_name = $current_Dl_product_file_post->post_title; if ($single_download['uniqueid'] == null) { $link[] = array("url" => site_url("?downloadid=" . $single_download['id']), "name" => $file_name); } else { $link[] = array("url" => site_url("?downloadid=" . $single_download['uniqueid']), "name" => $file_name); } } } else { $order_status = $purchase_log['processed']; } if (isset($download_data['id'])) { $previous_download_ids[] = $download_data['id']; } } do_action('wpsc_confirm_checkout', $purchase_log['id']); $total = 0; $shipping = $row['pnp']; $total_shipping += $shipping; $total += $row['price'] * $row['quantity']; $message_price = wpsc_currency_display($total, array('display_as_html' => false)); $message_price_html = wpsc_currency_display($total); $shipping_price = wpsc_currency_display($shipping, array('display_as_html' => false)); if (isset($purchase['gateway']) && 'wpsc_merchant_testmode' != $purchase['gateway']) { if ($gateway['internalname'] == $purch_data[0]['gateway']) { $gateway_name = $gateway['name']; } } else { $gateway_name = "Manual Payment"; } $variation_list = ''; if (!empty($link)) { $additional_content = apply_filters('wpsc_transaction_result_content', array("purchase_id" => $purchase_log['id'], "cart_item" => $row, "purchase_log" => $purchase_log)); if (!is_string($additional_content)) { $additional_content = ''; } $product_list .= " - " . $row['name'] . " " . $message_price . " " . __('Click to download', 'wpsc') . ":"; $product_list_html .= " - " . $row['name'] . " " . $message_price_html . " " . __('Click to download', 'wpsc') . ":\n\r"; foreach ($link as $single_link) { $product_list .= "\n\r " . $single_link["name"] . ": " . $single_link["url"] . "\n\r"; $product_list_html .= "<a href='" . $single_link["url"] . "'>" . $single_link["name"] . "</a>\n"; } $product_list .= $additional_content; $product_list_html .= $additional_content; } else { $product_list .= " - " . $row['quantity'] . " " . $row['name'] . " " . $message_price . "\n\r"; if ($shipping > 0) { $product_list .= sprintf(__(' - Shipping: %s ', 'wpsc'), $shipping_price); } $product_list_html .= "\n\r - " . $row['quantity'] . " " . $row['name'] . " " . $message_price_html . "\n\r"; if ($shipping > 0) { $product_list_html .= sprintf(__(' Shipping: %s ', 'wpsc'), $shipping_price); } } //add tax if included if ($wpec_taxes_controller->wpec_taxes_isenabled() && $wpec_taxes_controller->wpec_taxes_isincluded()) { $taxes_text = ' - - ' . __('Tax Included', 'wpsc') . ': ' . wpsc_currency_display($row['tax_charged'], array('display_as_html' => false)) . "\n\r"; $taxes_text_html = ' - - ' . __('Tax Included', 'wpsc') . ': ' . wpsc_currency_display($row['tax_charged']); $product_list .= $taxes_text; $product_list_html .= $taxes_text_html; } // if $report = get_option('wpsc_email_admin'); $report_product_list .= " - " . $row['quantity'] . " " . $row['name'] . " " . $message_price . "\n\r"; } // closes foreach cart as row // Decrement the stock here if ($is_transaction) { wpsc_decrement_claimed_stock($purchase_log['id']); } if (!empty($purchase_log['discount_data'])) { $coupon_data = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE coupon_code = %s LIMIT 1", $purchase_log['discount_data']), ARRAY_A); if ($coupon_data['use-once'] == 1) { $wpdb->update(WPSC_TABLE_COUPON_CODES, array('active' => '0', 'is-used' => '1'), array('id' => $coupon_data['id'])); } } $total_shipping = wpsc_get_total_shipping($purchase_log['id']); $total = $purchase_log['totalprice']; $total_price_email = ''; $total_price_html = ''; $total_tax_html = ''; $total_tax = ''; $total_shipping_html = ''; $total_shipping_email = ''; if (wpsc_uses_shipping() || !empty($purchase_log['base_shipping'])) { $total_shipping_email .= sprintf(__('Total Shipping: %s ', 'wpsc'), wpsc_currency_display($total_shipping, array('display_as_html' => false))); } $total_price_email .= sprintf(__('Total: %s ', 'wpsc'), wpsc_currency_display($total, array('display_as_html' => false))); if ($purchase_log['discount_value'] > 0) { $discount_email = __('Discount', 'wpsc') . "\n\r: "; $discount_email .= $purchase_log['discount_data'] . ' : ' . wpsc_currency_display($purchase_log['discount_value'], array('display_as_html' => false)) . "\n\r"; $report .= $discount_email . "\n\r"; $total_shipping_email .= $discount_email; $total_shipping_html .= __('Discount', 'wpsc') . ": " . wpsc_currency_display($purchase_log['discount_value']) . "\n\r"; } //only show total tax if tax is not included if ($wpec_taxes_controller->wpec_taxes_isenabled() && !$wpec_taxes_controller->wpec_taxes_isincluded()) { $total_tax_html .= __('Total Tax', 'wpsc') . ': ' . wpsc_currency_display($purchase_log['wpec_taxes_total']) . "\n\r"; $total_tax .= __('Total Tax', 'wpsc') . ': ' . wpsc_currency_display($purchase_log['wpec_taxes_total'], array('display_as_html' => false)) . "\n\r"; } if (wpsc_uses_shipping() || !empty($purchase_log['base_shipping'])) { $total_shipping_html .= '<hr>' . sprintf(__('Total Shipping: %s ', 'wpsc'), wpsc_currency_display($total_shipping)); } $total_price_html .= sprintf(__('Total: %s ', 'wpsc'), wpsc_currency_display($total)); $report_id = sprintf(__("Purchase # %s\n", 'wpsc'), $purchase_log['id']); if (isset($_GET['ti'])) { $message .= "\n\r" . __('Your Transaction ID', 'wpsc') . ": " . $_GET['ti']; $message_html .= "\n\r" . __('Your Transaction ID', 'wpsc') . ": " . $_GET['ti']; $report .= "\n\r" . __('Transaction ID', 'wpsc') . ": " . $_GET['ti']; } $message = apply_filters('wpsc_transaction_result_message', $message); $message = str_replace('%purchase_id%', $report_id, $message); $message = str_replace('%product_list%', $product_list, $message); $message = str_replace('%total_tax%', $total_tax, $message); $message = str_replace('%total_shipping%', $total_shipping_email, $message); $message = str_replace('%total_price%', $total_price_email, $message); $message = str_replace('%shop_name%', get_option('blogname'), $message); $message = str_replace('%find_us%', $purchase_log['find_us'], $message); $report = apply_filters('wpsc_transaction_result_report', $report); $report = str_replace('%purchase_id%', $report_id, $report); $report = str_replace('%product_list%', $report_product_list, $report); $report = str_replace('%total_tax%', $total_tax, $report); $report = str_replace('%total_shipping%', $total_shipping_email, $report); $report = str_replace('%total_price%', $total_price_email, $report); $report = str_replace('%shop_name%', get_option('blogname'), $report); $report = str_replace('%find_us%', $purchase_log['find_us'], $report); $message_html = apply_filters('wpsc_transaction_result_message_html', $message_html); $message_html = str_replace('%purchase_id%', $report_id, $message_html); $message_html = str_replace('%product_list%', $product_list_html, $message_html); $message_html = str_replace('%total_tax%', $total_tax_html, $message_html); $message_html = str_replace('%total_shipping%', $total_shipping_html, $message_html); $message_html = str_replace('%total_price%', $total_price_html, $message_html); $message_html = str_replace('%shop_name%', get_option('blogname'), $message_html); $message_html = str_replace('%find_us%', $purchase_log['find_us'], $message_html); if (!empty($email)) { add_filter('wp_mail_from', 'wpsc_replace_reply_address', 0); add_filter('wp_mail_from_name', 'wpsc_replace_reply_name', 0); $message = apply_filters('wpsc_email_message', $message, $report_id, $product_list, $total_tax, $total_shipping_email, $total_price_email); if (!$is_transaction) { $payment_instructions = strip_tags(stripslashes(get_option('payment_instructions'))); if (!empty($payment_instructions)) { $payment_instructions .= "\n\r"; } $message = __('Thank you, your purchase is pending, you will be sent an email once the order clears.', 'wpsc') . "\n\r" . $payment_instructions . $message; $message_html = __('Thank you, your purchase is pending, you will be sent an email once the order clears.', 'wpsc') . "\n\r" . $payment_instructions . $message_html; // prevent email duplicates if (!get_transient("{$sessionid}_pending_email_sent") || $resend_email) { wp_mail($email, __('Order Pending: Payment Required', 'wpsc'), $message); set_transient("{$sessionid}_pending_email_sent", true, 60 * 60 * 12); } } elseif (!get_transient("{$sessionid}_receipt_email_sent") || $resend_email) { wp_mail($email, __('Purchase Receipt', 'wpsc'), $message); set_transient("{$sessionid}_receipt_email_sent", true, 60 * 60 * 12); } } remove_filter('wp_mail_from_name', 'wpsc_replace_reply_name'); remove_filter('wp_mail_from', 'wpsc_replace_reply_address'); $report_user = __('Customer Details', 'wpsc') . "\n\r"; $form_sql = $wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id` = %d", $purchase_log['id']); $form_data = $wpdb->get_results($form_sql, ARRAY_A); if ($form_data != null) { foreach ($form_data as $form_field) { $form_data = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `id` = %d LIMIT 1", $form_field['form_id']), ARRAY_A); switch ($form_data['type']) { case "country": $country_code = $form_field['value']; $report_user .= $form_data['name'] . ": " . wpsc_get_country($country_code) . "\n"; //check if country has a state then display if it does. $country_data = wpsc_country_has_state($country_code); if ($country_data['has_regions'] == 1) { $report_user .= __('Billing State', 'wpsc') . ": " . wpsc_get_region($purchase_log['billing_region']) . "\n"; } break; case "delivery_country": $report_user .= $form_data['name'] . ": " . wpsc_get_country($form_field['value']) . "\n"; break; default: if ($form_data['name'] == 'State' && is_numeric($form_field['value'])) { $report_user .= __('Delivery State', 'wpsc') . ": " . wpsc_get_state_by_id($form_field['value'], 'name') . "\n"; } else { $report_user .= wp_kses($form_data['name'], array()) . ": " . $form_field['value'] . "\n"; } break; } } } $report_user .= "\n\r"; $report = $report_id . $report_user . $report; //echo '======REPORT======<br />'.$report.'<br />'; //echo '======EMAIL======<br />'.$message.'<br />'; if (get_option('purch_log_email') != null && $purchase_log['email_sent'] != 1) { wp_mail(get_option('purch_log_email'), __('Purchase Report', 'wpsc'), $report); $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('email_sent' => '1'), array('sessionid' => $sessionid)); } /// Adjust stock and empty the cart $wpsc_cart->submit_stock_claims($purchase_log['id']); $wpsc_cart->empty_cart(); } } }
/** * submit to gateway */ public function submit() { global $wpdb; // check for missing or invalid values $errors = $this->validateData(); // if there were errors, fail the transaction so that user can fix things up if ($errors) { $this->set_purchase_processed_by_purchid(1); // failed //~ $this->go_to_transaction_results($this->cart_data['session_id']); return; } // get purchase logs if ($this->purchase_id > 0) { $purchase_logs = new WPSC_Purchase_Log($this->purchase_id); } elseif (!empty($this->session_id)) { $purchase_logs = new WPSC_Purchase_Log($this->session_id, 'sessionid'); $this->purchase_id = $purchase_logs->get('id'); } else { $this->set_error_message('No cart ID and no active session!'); return; } // process the payment $isLiveSite = !get_option('eway_test'); $useStored = get_option('wpsc_merchant_eway_stored'); if ($useStored) { $eway = new EwayPaymentsStoredPayment(get_option('ewayCustomerID_id'), $isLiveSite); } else { $eway = new EwayPaymentsPayment(get_option('ewayCustomerID_id'), $isLiveSite); } $eway->invoiceDescription = get_bloginfo('name'); $eway->invoiceReference = $this->purchase_id; // customer invoice reference $eway->transactionNumber = $this->purchase_id; // transaction reference $eway->cardHoldersName = $this->collected_gateway_data['card_name']; $eway->cardNumber = $this->collected_gateway_data['card_number']; $eway->cardExpiryMonth = $this->collected_gateway_data['expiry_month']; $eway->cardExpiryYear = $this->collected_gateway_data['expiry_year']; $eway->cardVerificationNumber = $this->collected_gateway_data['c_v_n']; $eway->firstName = $this->collected_gateway_data['first_name']; $eway->lastName = $this->collected_gateway_data['last_name']; $eway->emailAddress = $this->collected_gateway_data['email']; $eway->postcode = $this->collected_gateway_data['post_code']; // for Beagle (free) security if (get_option('wpsc_merchant_eway_beagle')) { $eway->customerCountryCode = $this->collected_gateway_data['country']; } // convert wp-e-commerce country code into country name $country = $this->collected_gateway_data['country'] ? wpsc_get_country($this->collected_gateway_data['country']) : ''; // aggregate street, city, state, country into a single string $parts = array ( $this->collected_gateway_data['address'], $this->collected_gateway_data['city'], $this->collected_gateway_data['state'], $country, ); $eway->address = implode(', ', array_filter($parts, 'strlen')); // use cardholder name for last name if no customer name entered if (empty($eway->firstName) && empty($eway->lastName)) { $eway->lastName = $eway->cardHoldersName; } // allow plugins/themes to modify invoice description and reference, and set option fields $eway->invoiceDescription = apply_filters('wpsc_merchant_eway_invoice_desc', $eway->invoiceDescription, $this->purchase_id); $eway->invoiceReference = apply_filters('wpsc_merchant_eway_invoice_ref', $eway->invoiceReference, $this->purchase_id); $eway->option1 = apply_filters('wpsc_merchant_eway_option1', '', $this->purchase_id); $eway->option2 = apply_filters('wpsc_merchant_eway_option2', '', $this->purchase_id); $eway->option3 = apply_filters('wpsc_merchant_eway_option3', '', $this->purchase_id); // if live, pass through amount exactly, but if using test site, round up to whole dollars or eWAY will fail $total = $purchase_logs->get('totalprice'); $eway->amount = $isLiveSite ? $total : ceil($total); try { $response = $eway->processPayment(); if ($response->status) { // transaction was successful, so record transaction number and continue if ($useStored) { $status = 2; // WPSC_Purchase_Log::ORDER_RECEIVED } else { $status = 3; // WPSC_Purchase_Log::ACCEPTED_PAYMENT } $log_details = array( 'processed' => $status, 'transactid' => $response->transactionNumber, 'authcode' => $response->authCode, ); if (!empty($response->beagleScore)) { $log_details['notes'] = 'Beagle score: ' . $response->beagleScore; } wpsc_update_purchase_log_details($this->purchase_id, $log_details); $this->go_to_transaction_results($this->cart_data['session_id']); } else { // transaction was unsuccessful, so record transaction number and the error $status = 6; // WPSC_Purchase_Log::PAYMENT_DECLINED $this->set_error_message(nl2br(esc_html($response->error))); $log_details = array( 'processed' => $status, 'notes' => $response->error, ); wpsc_update_purchase_log_details($this->purchase_id, $log_details); return; } } catch (EwayPaymentsException $e) { // an exception occured, so record the error $status = 1; // WPSC_Purchase_Log::INCOMPLETE_SALE $this->set_error_message(nl2br(esc_html($e->getMessage()))); $this->set_purchase_processed_by_purchid($status); return; } exit(); }
echo "<strong>" . __('Customer Details', 'wpsc') . ":</strong>"; echo "<table class='customer_details'>"; $form_sql = "SELECT * FROM `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` WHERE `log_id` = '" . $purchase['id'] . "'"; $input_data = $wpdb->get_results($form_sql, ARRAY_A); //exit("<pre>".print_r($input_data,true)."</pre>"); if ($input_data != null) { foreach ((array) $input_data as $form_field) { $form_sql = "SELECT * FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `active` = '1' AND `id` = '" . $form_field['form_id'] . "' LIMIT 1"; $form_data = $wpdb->get_results($form_sql, ARRAY_A); if ($form_data != null) { $form_data = $form_data[0]; if ($form_data['type'] == 'country') { if ($form_field['value'] != null) { echo " <tr><td>" . $form_data['name'] . ":</td><td>" . wpsc_get_country($form_field['value']) . "</td></tr>"; } else { echo " <tr><td>" . $form_data['name'] . ":</td><td>" . wpsc_get_country($purchase['shipping_country']) . "</td></tr>"; } } else { echo " <tr><td>" . $form_data['name'] . ":</td><td>" . $form_field['value'] . "</td></tr>"; } } } } else { echo " <tr><td>" . __('Name', 'wpsc') . ":</td><td>" . $purchase['firstname'] . " " . $purchase['lastname'] . "</td></tr>"; echo " <tr><td>" . __('Address', 'wpsc') . ":</td><td>" . $purchase['address'] . "</td></tr>"; echo " <tr><td>" . __('Phone', 'wpsc') . ":</td><td>" . $purchase['phone'] . "</td></tr>"; echo " <tr><td>" . __('Email', 'wpsc') . ":</td><td>" . $purchase['email'] . "</td></tr>"; } //if(get_option('payment_method') == 2) //{ $gateway_name = '';