Пример #1
0
function simple_cart_total()
{
    $grand_total = 0;
    foreach ((array) $_SESSION['simpleCart'] as $item) {
        $total += $item['price'] * $item['quantity'];
        $item_total_shipping += $item['shipping'] * $item['quantity'];
    }
    $grand_total = $total + $item_total_shipping;
    return wpspsc_number_format_price($grand_total);
}
function print_wp_shopping_cart($args = array())
{
    $output = "";
    if (!cart_not_empty()) {
        $empty_cart_text = '';
        if (!empty($empty_cart_text)) {
            $output .= '<div class="wp_cart_empty_cart_section">';
            if (preg_match("/http/", $empty_cart_text)) {
                $output .= '<img src="' . $empty_cart_text . '" alt="' . $empty_cart_text . '" class="wp_cart_empty_cart_image" />';
            } else {
                $output .= $empty_cart_text;
            }
            $output .= '</div>';
        }
        $cart_products_page_url = get_option('cart_products_page_url');
        if (!empty($cart_products_page_url)) {
            $output .= '';
        }
        return $output;
    }
    $email = get_bloginfo('admin_email');
    $use_affiliate_platform = get_option('wp_use_aff_platform');
    $defaultCurrency = get_option('cart_payment_currency');
    $defaultSymbol = get_option('cart_currency_symbol');
    $defaultEmail = get_option('cart_paypal_email');
    if (!empty($defaultCurrency)) {
        $paypal_currency = $defaultCurrency;
    } else {
        $paypal_currency = __("USD", "wordpress-simple-paypal-shopping-cart");
    }
    if (!empty($defaultSymbol)) {
        $paypal_symbol = $defaultSymbol;
    } else {
        $paypal_symbol = __("\$", "wordpress-simple-paypal-shopping-cart");
    }
    if (!empty($defaultEmail)) {
        $email = $defaultEmail;
    }
    $decimal = '.';
    $urls = '';
    $return = get_option('cart_return_from_paypal_url');
    if (empty($return)) {
        $return = WP_CART_SITE_URL . '/';
    }
    $return_url = add_query_arg('reset_wp_cart', '1', $return);
    $urls .= '<input type="hidden" name="return" value="' . $return_url . '" />';
    $notify = WP_CART_SITE_URL . '/?simple_cart_ipn=1';
    $urls .= '<input type="hidden" name="notify_url" value="' . $notify . '" />';
    $title = get_option('wp_cart_title');
    //if (empty($title)) $title = __("Your Shopping Cart", "wordpress-simple-paypal-shopping-cart");
    global $plugin_dir_name;
    $output .= '<div class="shopping_cart">';
    if (!get_option('wp_shopping_cart_image_hide')) {
        $output .= "<img src='" . WP_CART_URL . "/images/shopping_cart_icon.png' class='wspsc_cart_header_image' value='" . __("Cart", "wordpress-simple-paypal-shopping-cart") . "' alt='" . __("Cart", "wordpress-simple-paypal-shopping-cart") . "' />";
    }
    if (!empty($title)) {
        $output .= '<h2>';
        $output .= $title;
        $output .= '</h2>';
    }
    $output .= '<span id="pinfo" style="display: none; font-weight: bold; color: red;">' . __("Hit enter to submit new Quantity.", "wordpress-simple-paypal-shopping-cart") . '</span>';
    $output .= '<table style="width: 100%;">';
    $count = 1;
    $total_items = 0;
    $total = 0;
    $form = '';
    if ($_SESSION['simpleCart'] && is_array($_SESSION['simpleCart'])) {
        $output .= '
        <tr class="wspsc_cart_item_row">
        <th class="wspsc_cart_item_name_th">' . __("Item Name", "wordpress-simple-paypal-shopping-cart") . '</th><th class="wspsc_cart_qty_th">' . __("Quantity", "wordpress-simple-paypal-shopping-cart") . '</th><th class="wspsc_cart_price_th">' . __("Price", "wordpress-simple-paypal-shopping-cart") . '</th><th></th>
        </tr>';
        $item_total_shipping = 0;
        $postage_cost = 0;
        foreach ($_SESSION['simpleCart'] as $item) {
            $total += $item['price'] * $item['quantity'];
            $item_total_shipping += $item['shipping'] * $item['quantity'];
            $total_items += $item['quantity'];
        }
        if (!empty($item_total_shipping)) {
            $baseShipping = get_option('cart_base_shipping_cost');
            $postage_cost = $item_total_shipping + $baseShipping;
        }
        $cart_free_shipping_threshold = get_option('cart_free_shipping_threshold');
        if (!empty($cart_free_shipping_threshold) && $total > $cart_free_shipping_threshold) {
            $postage_cost = 0;
        }
        foreach ($_SESSION['simpleCart'] as $item) {
            $output .= '<tr class="wspsc_cart_item_thumb"><td style="overflow: hidden;">';
            $output .= '<div class="wp_cart_item_info">';
            if (isset($args['show_thumbnail'])) {
                $output .= '<span class="wp_cart_item_thumbnail"><img src="' . $item['thumbnail'] . '" class="wp_cart_thumb_image" alt="' . $item['name'] . '" ></span>';
            }
            $item_info = apply_filters('wspsc_cart_item_name', '<a href="' . $item['cartLink'] . '">' . $item['name'] . '</a>', $item);
            $output .= '<span class="wp_cart_item_name">' . $item_info . '</span>';
            $output .= '<span class="wp_cart_clear_float"></span>';
            $output .= '</div>';
            $output .= '</td>';
            $output .= "<td style='text-align: center'><form method=\"post\"  action=\"\" name='pcquantity' style='display: inline'>\n                <input type=\"hidden\" name=\"wspsc_product\" value=\"" . htmlspecialchars($item['name']) . "\" />\n\t        <input type='hidden' name='cquantity' value='1' /><input type='text' name='quantity' value='" . $item['quantity'] . "' size='1' onchange='document.pcquantity.submit();' onkeypress='document.getElementById(\"pinfo\").style.display = \"\";' /></form></td>\n\t        <td style='text-align: center'>" . print_payment_currency($item['price'] * $item['quantity'], $paypal_symbol, $decimal) . "</td>\n\t        <td><form method=\"post\" action=\"\" class=\"wp_cart_remove_item_form\">\n\t        <input type=\"hidden\" name=\"wspsc_product\" value=\"" . $item['name'] . "\" />\n\t        <input type='hidden' name='delcart' value='1' />\n\t        <input type='image' src='" . WP_CART_URL . "/images/Shoppingcart_delete.png' value='" . __("Remove", "wordpress-simple-paypal-shopping-cart") . "' title='" . __("Remove", "wordpress-simple-paypal-shopping-cart") . "' /></form></td></tr>\n\t        ";
            $form .= "\n\t            <input type=\"hidden\" name=\"item_name_{$count}\" value=\"" . $item['name'] . "\" />\n\t            <input type=\"hidden\" name=\"amount_{$count}\" value='" . wpspsc_number_format_price($item['price']) . "' />\n\t            <input type=\"hidden\" name=\"quantity_{$count}\" value=\"" . $item['quantity'] . "\" />\n\t            <input type='hidden' name='item_number_{$count}' value='" . $item['item_number'] . "' />\n\t        ";
            $count++;
        }
        if (!get_option('wp_shopping_cart_use_profile_shipping')) {
            $postage_cost = wpspsc_number_format_price($postage_cost);
            $form .= "<input type=\"hidden\" name=\"shipping_1\" value='" . $postage_cost . "' />";
            //You can also use "handling_cart" variable to use shipping and handling here
        }
        if (get_option('wp_shopping_cart_collect_address')) {
            //force address collection
            $form .= "<input type=\"hidden\" name=\"no_shipping\" value=\"2\" />";
        }
    }
    $count--;
    if ($count) {
        if ($postage_cost != 0) {
            $output .= "\n                <tr class='wspsc_cart_subtotal'><td colspan='2' style='font-weight: bold; text-align: right;'>" . __("Subtotal", "wordpress-simple-paypal-shopping-cart") . ": </td><td style='text-align: center'>" . print_payment_currency($total, $paypal_symbol, $decimal) . "</td><td></td></tr>\n                <tr class='wspsc_cart_shipping'><td colspan='2' style='font-weight: bold; text-align: right;'>" . __("Shipping", "wordpress-simple-paypal-shopping-cart") . ": </td><td style='text-align: center'>" . print_payment_currency($postage_cost, $paypal_symbol, $decimal) . "</td><td></td></tr>";
        }
        $output .= "<tr class='wspsc_cart_total'><td colspan='2' style='font-weight: bold; text-align: right;'>" . __("Total", "wordpress-simple-paypal-shopping-cart") . ": </td><td style='text-align: center'>" . print_payment_currency($total + $postage_cost, $paypal_symbol, $decimal) . "</td><td></td></tr>";
        if (isset($_SESSION['wpspsc_cart_action_msg']) && !empty($_SESSION['wpspsc_cart_action_msg'])) {
            $output .= '<tr class="wspsc_cart_action_msg"><td colspan="4"><span class="wpspsc_cart_action_msg">' . $_SESSION['wpspsc_cart_action_msg'] . '</span></td></tr>';
        }
        if (get_option('wpspsc_enable_coupon') == '1') {
            $output .= '<tr class="wspsc_cart_coupon_row"><td colspan="4">
                <div class="wpspsc_coupon_section">
                <span class="wpspsc_coupon_label">' . __("Enter Coupon Code", "wordpress-simple-paypal-shopping-cart") . '</span>
                <form  method="post" action="" >
                <input type="text" name="wpspsc_coupon_code" value="" size="10" />
                <span class="wpspsc_coupon_apply_button"><input type="submit" name="wpspsc_apply_coupon" class="wpspsc_apply_coupon" value="' . __("Apply", "wordpress-simple-paypal-shopping-cart") . '" /></span>
                </form>
                </div>
                </td></tr>';
        }
        $paypal_checkout_url = WP_CART_LIVE_PAYPAL_URL;
        if (get_option('wp_shopping_cart_enable_sandbox')) {
            $paypal_checkout_url = WP_CART_SANDBOX_PAYPAL_URL;
        }
        $form_target_code = '';
        if (get_option('wspsc_open_pp_checkout_in_new_tab')) {
            $form_target_code = 'target="_blank"';
        }
        $output .= "<tr class='wpspsc_checkout_form'><td colspan='4'>";
        $output .= '<form action="' . $paypal_checkout_url . '" method="post" ' . $form_target_code . '>';
        $output .= $form;
        if ($count) {
            $output .= '<input type="image" src="' . WP_CART_URL . '/images/' . __("paypal_checkout_EN.png", "wordpress-simple-paypal-shopping-cart") . '" name="submit" class="wp_cart_checkout_button" alt="' . __("Make payments with PayPal - it\\'s fast, free and secure!", "wordpress-simple-paypal-shopping-cart") . '" />';
        }
        $output .= $urls . '
            <input type="hidden" name="business" value="' . $email . '" />
            <input type="hidden" name="currency_code" value="' . $paypal_currency . '" />
            <input type="hidden" name="cmd" value="_cart" />
            <input type="hidden" name="upload" value="1" />
            <input type="hidden" name="rm" value="2" />
            <input type="hidden" name="charset" value="utf-8" />
            <input type="hidden" name="bn" value="TipsandTricks_SP" />';
        $wp_cart_note_to_seller_text = get_option('wp_cart_note_to_seller_text');
        if (!empty($wp_cart_note_to_seller_text)) {
            $output .= '<input type="hidden" name="no_note" value="0" /><input type="hidden" name="cn" value="' . $wp_cart_note_to_seller_text . '" />';
        }
        $page_style_name = get_option('wp_cart_paypal_co_page_style');
        if (!empty($page_style_name)) {
            $output .= '<input type="hidden" name="page_style" value="' . $page_style_name . '" />';
        }
        $output .= wp_cart_add_custom_field();
        $output .= '</form>';
        $output .= '</td></tr>';
    }
    $output .= "</table></div>";
    return $output;
}
Пример #3
0
 function validate_and_dispatch_product()
 {
     // Check Product Name , Price , Currency , Receivers email ,
     global $products, $currency, $paypal_email;
     $txn_id = $this->ipn_data['txn_id'];
     $transaction_type = $this->ipn_data['txn_type'];
     $payment_status = $this->ipn_data['payment_status'];
     $transaction_subject = $this->ipn_data['transaction_subject'];
     $custom_value_str = $this->ipn_data['custom'];
     //$this->debug_log('custom values from paypal: '.$custom_value_str,true);
     $first_name = $this->ipn_data['first_name'];
     $last_name = $this->ipn_data['last_name'];
     $buyer_email = $this->ipn_data['payer_email'];
     $street_address = $this->ipn_data['address_street'];
     $city = $this->ipn_data['address_city'];
     $state = $this->ipn_data['address_state'];
     $zip = $this->ipn_data['address_zip'];
     $country = $this->ipn_data['address_country'];
     $phone = $this->ipn_data['contact_phone'];
     $address = $street_address . ", " . $city . ", " . $state . ", " . $zip . ", " . $country;
     $custom_values = wp_cart_get_custom_var_array($custom_value_str);
     $this->debug_log('Payment Status: ' . $payment_status, true);
     if ($payment_status == "Completed" || $payment_status == "Processed") {
         //We will process this notification
     } else {
         $this->debug_log('This is not a payment complete notification. This IPN will not be processed.', true);
         return true;
     }
     if ($transaction_type == "cart") {
         $this->debug_log('Transaction Type: Shopping Cart', true);
         // Cart Items
         $num_cart_items = $this->ipn_data['num_cart_items'];
         $this->debug_log('Number of Cart Items: ' . $num_cart_items, true);
         $i = 1;
         $cart_items = array();
         while ($i < $num_cart_items + 1) {
             $item_number = $this->ipn_data['item_number' . $i];
             $item_name = $this->ipn_data['item_name' . $i];
             $quantity = $this->ipn_data['quantity' . $i];
             $mc_gross = $this->ipn_data['mc_gross_' . $i];
             $mc_currency = $this->ipn_data['mc_currency'];
             $current_item = array('item_number' => $item_number, 'item_name' => $item_name, 'quantity' => $quantity, 'mc_gross' => $mc_gross, 'mc_currency' => $mc_currency);
             array_push($cart_items, $current_item);
             $i++;
         }
     } else {
         $cart_items = array();
         $this->debug_log('Transaction Type: Buy Now', true);
         $item_number = $this->ipn_data['item_number'];
         $item_name = $this->ipn_data['item_name'];
         $quantity = $this->ipn_data['quantity'];
         $mc_gross = $this->ipn_data['mc_gross'];
         $mc_currency = $this->ipn_data['mc_currency'];
         $current_item = array('item_number' => $item_number, 'item_name' => $item_name, 'quantity' => $quantity, 'mc_gross' => $mc_gross, 'mc_currency' => $mc_currency);
         array_push($cart_items, $current_item);
     }
     $payment_currency = get_option('cart_payment_currency');
     $individual_paid_item_total = 0;
     foreach ($cart_items as $current_cart_item) {
         $cart_item_data_num = $current_cart_item['item_number'];
         $cart_item_data_name = $current_cart_item['item_name'];
         $cart_item_data_quantity = $current_cart_item['quantity'];
         $cart_item_data_total = $current_cart_item['mc_gross'];
         $cart_item_data_currency = $current_cart_item['mc_currency'];
         $individual_paid_item_total += $cart_item_data_total;
         $this->debug_log('Item Number: ' . $cart_item_data_num, true);
         $this->debug_log('Item Name: ' . $cart_item_data_name, true);
         $this->debug_log('Item Quantity: ' . $cart_item_data_quantity, true);
         $this->debug_log('Item Total: ' . $cart_item_data_total, true);
         $this->debug_log('Item Currency: ' . $cart_item_data_currency, true);
         // Compare the currency values to make sure it is correct.
         if ($payment_currency != $cart_item_data_currency) {
             $this->debug_log('Invalid Product Currency : ' . $payment_currency, false);
             return false;
         }
     }
     $post_id = $custom_values['wp_cart_id'];
     $orig_cart_items = get_post_meta($post_id, 'wpsc_cart_items', true);
     $ip_address = $custom_values['ip'];
     $applied_coupon_code = $custom_values['coupon_code'];
     $currency_symbol = get_option('cart_currency_symbol');
     $this->debug_log('Custom values', true);
     $this->debug_log_array($custom_values, true);
     $this->debug_log('Order post id: ' . $post_id, true);
     //*** Do security checks ***
     if (empty($post_id)) {
         $this->debug_log('Order ID ' . $post_id . ' does not exist in the IPN notification. This request will not be processed.', false);
         return;
     }
     if (!get_post_status($post_id)) {
         $this->debug_log('Order ID ' . $post_id . ' does not exist in the database. This is not a Simple PayPal Shopping Cart order', false);
         return;
     }
     if (get_option('wp_shopping_cart_strict_email_check') != '') {
         $seller_paypal_email = get_option('cart_paypal_email');
         if ($seller_paypal_email != $this->ipn_data['receiver_email']) {
             $error_msg .= 'Invalid Seller Paypal Email Address : ' . $this->ipn_data['receiver_email'];
             $this->debug_log($error_msg, false);
             return;
         } else {
             $this->debug_log('Seller Paypal Email Address is Valid: ' . $this->ipn_data['receiver_email'], true);
         }
     }
     $transaction_id = get_post_meta($post_id, 'wpsc_txn_id', true);
     if (!empty($transaction_id)) {
         if ($transaction_id == $txn_id) {
             $this->debug_log('This transaction has been already processed once. Transaction ID: ' . $transaction_id, false);
             return;
         }
     }
     //Validate prices
     $orig_individual_item_total = 0;
     foreach ($orig_cart_items as $item) {
         $orig_individual_item_total += $item['price'] * $item['quantity'];
     }
     $orig_individual_item_total = round($orig_individual_item_total, 2);
     $individual_paid_item_total = round($individual_paid_item_total, 2);
     $this->debug_log('Checking price. Original price: ' . $orig_individual_item_total . '. Paid price: ' . $individual_paid_item_total, true);
     if ($individual_paid_item_total < $orig_individual_item_total) {
         //Paid price is less so block this transaction.
         $this->debug_log('Error! Post payment price validation failed. The price amount may have been altered. This transaction will not be processed.', false);
         $this->debug_log('Original total price: ' . $orig_individual_item_total . '. Paid total price: ' . $individual_paid_item_total, false);
         return;
     }
     //*** End of security check ***
     $updated_wpsc_order = array('ID' => $post_id, 'post_status' => 'publish', 'post_type' => 'wpsc_cart_orders');
     wp_update_post($updated_wpsc_order);
     update_post_meta($post_id, 'wpsc_first_name', $first_name);
     update_post_meta($post_id, 'wpsc_last_name', $last_name);
     update_post_meta($post_id, 'wpsc_email_address', $buyer_email);
     update_post_meta($post_id, 'wpsc_txn_id', $txn_id);
     $mc_gross = $this->ipn_data['mc_gross'];
     update_post_meta($post_id, 'wpsc_total_amount', $mc_gross);
     update_post_meta($post_id, 'wpsc_ipaddress', $ip_address);
     update_post_meta($post_id, 'wpsc_address', $address);
     update_post_meta($post_id, 'wpspsc_phone', $phone);
     $status = "Paid";
     update_post_meta($post_id, 'wpsc_order_status', $status);
     update_post_meta($post_id, 'wpsc_applied_coupon', $applied_coupon_code);
     $product_details = "";
     $item_counter = 1;
     $shipping = "";
     if ($orig_cart_items) {
         foreach ($orig_cart_items as $item) {
             if ($item_counter != 1) {
                 $product_details .= "\n";
             }
             $item_total = $item['price'] * $item['quantity'];
             $product_details .= $item['name'] . " x " . $item['quantity'] . " - " . $currency_symbol . wpspsc_number_format_price($item_total) . "\n";
             if ($item['file_url']) {
                 $file_url = base64_decode($item['file_url']);
                 $product_details .= "Download Link: " . $file_url . "\n";
             }
             if (!empty($item['shipping'])) {
                 $shipping += $item['shipping'] * $item['quantity'];
             }
             $item_counter++;
         }
     }
     if (empty($shipping)) {
         $shipping = "0.00";
     } else {
         $baseShipping = get_option('cart_base_shipping_cost');
         $shipping = $shipping + $baseShipping;
         $shipping = wpspsc_number_format_price($shipping);
     }
     update_post_meta($post_id, 'wpsc_shipping_amount', $shipping);
     $args = array();
     $args['product_details'] = $product_details;
     $args['order_id'] = $post_id;
     $args['coupon_code'] = $applied_coupon_code;
     $args['address'] = $address;
     update_post_meta($post_id, 'wpspsc_items_ordered', $product_details);
     $from_email = get_option('wpspc_buyer_from_email');
     $subject = get_option('wpspc_buyer_email_subj');
     $body = get_option('wpspc_buyer_email_body');
     $args['email_body'] = $body;
     $body = wpspc_apply_dynamic_tags_on_email_body($this->ipn_data, $args);
     $this->debug_log('Applying filter - wspsc_buyer_notification_email_body', true);
     $body = apply_filters('wspsc_buyer_notification_email_body', $body, $this->ipn_data, $cart_items);
     $headers = 'From: ' . $from_email . "\r\n";
     if (!empty($buyer_email)) {
         $args['payer_email'] = $buyer_email;
         if (get_option('wpspc_send_buyer_email')) {
             wp_mail($buyer_email, $subject, $body, $headers);
             $this->debug_log('Product Email successfully sent to ' . $buyer_email, true);
             update_post_meta($post_id, 'wpsc_buyer_email_sent', 'Email sent to: ' . $buyer_email);
         }
     }
     $notify_email = get_option('wpspc_notify_email_address');
     $seller_email_subject = get_option('wpspc_seller_email_subj');
     $seller_email_body = get_option('wpspc_seller_email_body');
     $args['email_body'] = $seller_email_body;
     $seller_email_body = wpspc_apply_dynamic_tags_on_email_body($this->ipn_data, $args);
     $this->debug_log('Applying filter - wspsc_seller_notification_email_body', true);
     $seller_email_body = apply_filters('wspsc_seller_notification_email_body', $seller_email_body, $this->ipn_data, $cart_items);
     if (!empty($notify_email)) {
         if (get_option('wpspc_send_seller_email')) {
             wp_mail($notify_email, $seller_email_subject, $seller_email_body, $headers);
             $this->debug_log('Notify Email successfully sent to ' . $notify_email, true);
         }
     }
     /**** Affiliate plugin integratin ****/
     $this->debug_log('Updating Affiliate Database Table with Sales Data if Using the WP Affiliate Platform Plugin.', true);
     if (function_exists('wp_aff_platform_install')) {
         $this->debug_log('WP Affiliate Platform is installed, registering sale...', true);
         $referrer = $custom_values['ap_id'];
         $sale_amount = $this->ipn_data['mc_gross'];
         if (!empty($referrer)) {
             do_action('wp_affiliate_process_cart_commission', array("referrer" => $referrer, "sale_amt" => $sale_amount, "txn_id" => $txn_id, "buyer_email" => $buyer_email));
             $message = 'The sale has been registered in the WP Affiliates Platform Database for referrer: ' . $referrer . ' for sale amount: ' . $sale_amount;
             $this->debug_log($message, true);
         } else {
             $this->debug_log('No Referrer Found. This is not an affiliate sale', true);
         }
     } else {
         $this->debug_log('Not Using the WP Affiliate Platform Plugin.', true);
     }
     do_action('wpspc_paypal_ipn_processed', $this->ipn_data);
     return true;
 }