function eStore_get_serial_key_for_product($retrieved_product, $cart_item_name = '', $qty = 1) { global $wpdb; $product_meta_table_name = WP_ESTORE_PRODUCTS_META_TABLE_NAME; $theid = $retrieved_product->id; $product_code_data = ""; $requested_qty = (int) $qty; eStore_payment_debug('Checking if a key needs to be issued for product id: ' . $theid . ' Requested quantity: ' . $requested_qty, true); $productmeta = $wpdb->get_row("SELECT * FROM {$product_meta_table_name} WHERE prod_id = '{$theid}' AND meta_key='available_key_codes'", OBJECT); if ($productmeta) { $available_key_codes = $productmeta->meta_value; $key_pieces = explode(WP_ESTORE_SERIAL_KEY_SEPARATOR, $available_key_codes); $my_key = ""; if ($requested_qty > 1) { for ($i = 0; $i < $requested_qty; $i++) { if ($i > 0) { $my_key .= ', '; } $my_key .= array_pop($key_pieces); } } else { $my_key = array_pop($key_pieces); } if (!empty($my_key)) { if (empty($cart_item_name)) { $cart_item_name = $retrieved_product->name; } $product_code_data .= "\n" . $cart_item_name . " - " . $my_key; eStore_payment_debug("Serial code that will be issued to this customer: " . $my_key, true); //Update the DB $new_available_key_codes = implode(WP_ESTORE_SERIAL_KEY_SEPARATOR, $key_pieces); $updatedb_meta = "UPDATE {$product_meta_table_name} SET meta_value='{$new_available_key_codes}' WHERE prod_id='{$theid}' AND meta_key='available_key_codes'"; $results = $wpdb->query($updatedb_meta); eStore_payment_debug('Updated the serial key values in the database.', true); } else { eStore_payment_debug('This product does not have any serial key available.', true); } } else { eStore_payment_debug('This product does not use the serial key feature', true); } return $product_code_data; }
function wp_eStore_handle_retrieve_cart_action($action) { eStore_payment_debug('Processing retrieve cart action...', true); $cart_id = strip_tags($_REQUEST['cart_id']); if (empty($cart_id)) { eStore_payment_debug('Error! Cart ID is empty! Cannot process this request', false); echo json_encode(array('reply_action' => $action, 'status' => 'error', 'code' => 'ESTORE_AJAX_01', 'details' => 'Cart ID is empty!')); exit; } eStore_payment_debug('Retrieving previously saved cart... Cart ID: ' . $cart_id, true); $eStore_cart = wp_eStore_get_cart_details_from_db($cart_id); if ($eStore_cart === "-1") { eStore_payment_debug('Error! Failed to retrieve cart for the given cart ID!', false); echo json_encode(array('reply_action' => $action, 'status' => 'error', 'code' => 'ESTORE_AJAX_02', 'details' => 'Failed to retrieve cart for the given cart ID!')); exit; } eStore_payment_debug('Loading cart into session...', true); wp_eStore_load_cart_class_to_session($eStore_cart); wp_eStore_write_debug_array($_SESSION['eStore_cart'], true); echo json_encode(array('reply_action' => $action, 'status' => 'success', 'ID' => $cart_id)); exit; }
function eStore_global_autoresponder_signup($firstname, $lastname, $emailaddress) { global $wp_eStore_config; $wp_eStore_config = WP_eStore_Config::getInstance(); if ($wp_eStore_config->getValue('eStore_use_new_aweber_integration') == '1') { if (get_option('eStore_enable_aweber_int') == 1) { eStore_payment_debug('Global AWeber list signup option is enabled.', true); $aweber_list = get_option('eStore_aweber_list_name'); eStore_aweber_new_signup_user($aweber_list, $firstname, $lastname, $emailaddress); } else { eStore_payment_debug('Global AWeber list signup option is disabled. No global list signup will be performed.', true); } } if (get_option('eStore_enable_global_chimp_int') == 1) { eStore_payment_debug('Mailchimp integration is being used.', true); $api = eStore_get_chimp_api_new(); $target_list_name = get_option('eStore_chimp_list_name'); $retval = eStore_mailchimp_subscribe($api, $target_list_name, $firstname, $lastname, $emailaddress); eStore_payment_debug('MailChimp global list signup operation performed. Return value is: ' . $retval, true); } if (get_option('eStore_enable_global_getResponse_int') == 1) { eStore_payment_debug('GetResponse integration is being used.', true); $campaign_name = get_option('eStore_getResponse_campaign_name'); eStore_payment_debug('GetResponse campaign to signup to:' . $campaign_name, true); $retval = eStore_getResponse_subscribe($campaign_name, $firstname, $lastname, $emailaddress); eStore_payment_debug('GetResponse global list signup operation performed. Return value is: ' . $retval, true); } if ($wp_eStore_config->getValue('eStore_use_global_generic_autoresponder_integration') == '1') { eStore_payment_debug('Generic global autoresponder integration is being used.', true); $list_email_address = $wp_eStore_config->getValue('eStore_generic_autoresponder_target_list_email'); $result = eStore_generic_autoresponder_signup($firstname, $lastname, $emailaddress, $list_email_address); eStore_payment_debug('Generic autoresponder signup result: ' . $result, true); } // API call for plugins extending the global autoresponder signup $signup_data = array('firstname' => $firstname, 'lastname' => $lastname, 'email' => $emailaddress); do_action('eStore_global_autoresponder_signup', $signup_data); }
function wp_eStore_handle_recurring_payment_charged_action($payment_data, $cart_items) { //eMember related tasks $subscr_id = $payment_data['subscr_id']; eStore_update_member_subscription_start_date_if_applicable($payment_data, $subscr_id); //Affiilate plugin related tasks $award_commission = true; if (get_option('eStore_aff_one_time_commission')) { $award_commission = false; eStore_payment_debug('One time commission option is being used, This is a recurring payment and will not generate affiliate commission.', true); } if ($award_commission) { eStore_payment_debug('Affiliate Commission may need to be tracked for this recurring payment. Invoking the commission checker function.', true); eStore_aff_award_commission($payment_data, $cart_items); } }
function eStore_track_ga_ecommerce($payment_data, $cart_items) { //Google Analytics e-commerce tracking (only do it if set in settings menu) if (get_option('eStore_enable_analytics_tracking')) { //The $payment_data arrray must have - city, state and country fields if (empty($payment_data['address_city']) || empty($payment_data['address_state']) || empty($payment_data['address_country'])) { eStore_payment_debug('Ecommerce analytics tracking failure. City, State or Country data is missing.', false); echo '<div class="">Error! City, State, Country data is missing! Cannot track Google Analytics without these data.</div>'; exit; } $transaction_id = $payment_data['txn_id']; $gross_total = $payment_data['mc_gross']; $mc_shipping = $payment_data['mc_shipping']; $mc_tax = $payment_data['mc_tax']; $city = $payment_data['address_city']; $state = $payment_data['address_state']; $country = $payment_data['address_country']; $eStore_analytics_code = array(); $eStore_analytics_code[] = "'_addTrans'," . "'" . $transaction_id . "','" . get_bloginfo('name') . "','" . $gross_total . "','" . $mc_tax . "','" . $mc_shipping . "','" . $city . "','" . $state . "','" . $country . "'"; foreach ($cart_items as $key => $item) { $eStore_analytics_code[] = "'_addItem'," . "'" . $transaction_id . "','" . $item['item_number'] . "','" . $item['item_name'] . "','','" . $item['mc_gross'] . "','" . $item['quantity'] . "'"; } $eStore_analytics_code[] = "'_trackTrans'"; $_SESSION['eStore_ga_code'] = $eStore_analytics_code; //print_r($_SESSION['eStore_ga_code'] ); add_filter('yoast-ga-push-after-pageview', 'eStore_add_trans_to_ga_tracking'); eStore_payment_debug('Ecommerce analytics tracking data has been pushed successfully.', true); } }
function eStore_paypal_validate_pdt_no_curl() { global $tx_result_error_msg; $eStore_process_pdt = true; eStore_payment_debug("eStore PayPal PDT received. Processing the request using NO CURL method...", true); if (defined('WP_AFFILIATE_PLATFORM_VERSION')) { eStore_payment_debug("PDT - Affiliate platform is installed.", true); $affiliate_auth_token = get_option('wp_aff_pdt_identity_token'); if (get_option('wp_aff_enable_3rd_party') != '' && !empty($affiliate_auth_token)) { $eStore_process_pdt = false; eStore_payment_debug("PDT - Error! you have enabled 3rd party cart integration settings in your affiliate plugin. You do not need to enable that when using the affiliate plugin with eStore.", false); } } if ($eStore_process_pdt) { $req = 'cmd=_notify-synch'; $tx_token = strip_tags($_GET['tx']); $auth_token = get_option('eStore_paypal_pdt_token'); if (empty($auth_token)) { $tx_result_error_msg .= "<br />The PDT identity token is empty. If you want to display the transaction result on the thank you page then you must specify a PDT identity token in the payment gateway settings!"; eStore_payment_debug("The PDT identity token is empty. If you want to display the transaction result on the thank you page then you must specify a PDT identity token in the payment gateway settings!", false); return; } $req .= "&tx={$tx_token}&at={$auth_token}"; $sandbox_enabled = get_option('eStore_cart_enable_sandbox'); if ($sandbox_enabled) { $host_url = 'www.sandbox.paypal.com'; $uri = 'ssl://' . $host_url; $port = '443'; $fp = fsockopen($uri, $port, $err_num, $err_str, 30); } else { $host_url = 'www.paypal.com'; $fp = fsockopen($host_url, 80, $errno, $errstr, 30); } //$fp = fsockopen ($host_url, 80, $errno, $errstr, 30); // If possible, securely post back to paypal using HTTPS // Your PHP server will need to be SSL enabled // $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); if (!$fp) { $tx_result_error_msg .= "<br />HTTP ERROR... could not establish a connection to PayPal for verification!"; eStore_payment_debug("HTTP ERROR... could not establish a connection to PayPal for verification!", false); } else { // post back to PayPal system to validate $header = ""; $header .= "POST /cgi-bin/webscr HTTP/1.1\r\n"; $header .= "Host: " . $host_url . "\r\n"; $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; $header .= "Content-Length: " . strlen($req) . "\r\n"; $header .= "Connection: close\r\n\r\n"; fputs($fp, $header . $req); // read the body data $eStore_res = ''; $headerdone = false; while (!feof($fp)) { $line = fgets($fp, 1024); if (strcmp($line, "\r\n") == 0) { // read the header $headerdone = true; } else { if ($headerdone) { // header has been read. now read the contents $eStore_res .= $line; } } } // parse the data $eStore_lines = explode("\n", $eStore_res); $eStore_keyarray = array(); if (strpos($eStore_res, "VERIFIED") !== false) { for ($i = 1; $i < count($eStore_lines); $i++) { $pdt_key_val_pieces = explode("=", $eStore_lines[$i]); if (!isset($pdt_key_val_pieces[0])) { continue; } //don't even process it if key is not set if (!isset($pdt_key_val_pieces[1])) { $pdt_key_val_pieces[1] = ''; } //set empty value list($key, $val) = $pdt_key_val_pieces; //list($key,$val) = explode("=", $eStore_lines[$i]); $eStore_keyarray[urldecode($key)] = urldecode($val); } } else { $tx_result_error_msg .= "<br />PDT verification failed! Could not verify the authenticity of the payment with PayPal!"; eStore_payment_debug("PDT verification failed! Could not verify the authenticity of the payment with PayPal!", false); $eStore_process_pdt = false; } } fclose($fp); if ($eStore_process_pdt) { eStore_process_PDT_payment_data($eStore_keyarray); } } }
function wp_eStore_get_subscription_summary_string($id, $name = '', $a3 = '') { if (empty($id)) { eStore_payment_debug('eStore product ID needs to be passed to this function', false); return; } global $wpdb; $products_table_name = WP_ESTORE_PRODUCTS_TABLE_NAME; $ret_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$id}'", OBJECT); if (empty($name)) { $item_name = $ret_product->name; } else { $item_name = $name; } if (empty($a3)) { $a3 = $ret_product->a3; } $a1 = $ret_product->a1; // trial amount (example: 5.00) $free_trial = false; $trial = false; if ($a1 != "") { $a1_value = intval($a1); if ($a1_value == 0) { $free_trial = true; } else { $trial = true; } } //a3 is recurring amount (example: 7.00) $p3 = $ret_product->p3; // recurring period (example: 30) $t3 = $ret_product->t3; // recurring period unit (example: D, M, Y) $period_unit = ""; if ($t3 == "D") { $period_unit = "day(s)"; } else { if ($t3 == "M") { $period_unit = "month(s)"; } else { if ($t3 == "Y") { $t3 = "days"; $p3 = "365"; $period_unit = "day(s)"; } } } $installment = ""; if ($ret_product->srt > 1) { $srt = $ret_product->srt; $installment = ", for " . $srt . " installment(s)"; } if (!empty($ret_product->currency_code)) { $item_currency = $ret_product->currency_code; } else { $item_currency = get_option('cart_payment_currency'); } // forming the subscription details $terms = ""; if ($free_trial) { $terms .= "Free for the first " . $p3 . " " . $period_unit . " Then "; } else { if ($trial) { $terms .= number_format($a1, 2) . " " . $item_currency . " for the first " . $p3 . " " . $period_unit . " Then "; } } $period = ''; if ($p3 == '1') { $period = ""; } else { $period = $p3 . " "; } $terms .= number_format($a3, 2) . " " . $item_currency . " for each " . $period . $period_unit . $installment; return $terms; }
function eStore_generate_download_links_for_cart_items($payment_data, $cart_items) { eStore_payment_debug('Executing eStore_generate_download_links_for_cart_items()', true); global $wpdb; $wp_eStore_config = WP_eStore_Config::getInstance(); $products_table_name = WP_ESTORE_PRODUCTS_TABLE_NAME; $product_name_array = array(); $download_link_array = array(); 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']; eStore_payment_debug('Item Number: ' . $cart_item_data_num, true); eStore_payment_debug('Item Name: ' . $cart_item_data_name, true); eStore_payment_debug('Item Quantity: ' . $cart_item_data_quantity, true); eStore_payment_debug('Item Total: ' . $cart_item_data_total, true); eStore_payment_debug('Item Currency: ' . $cart_item_data_currency, true); if ($cart_item_data_num != "SHIPPING") { // Compare the values with the values stored in the database $key = $cart_item_data_num; $retrieved_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$key}'", OBJECT); if (!$retrieved_product) { eStore_payment_debug('No Item found for the Item ID: ' . $cart_item_data_num, false); return false; } $item_name = $cart_item_data_name; $download_link = generate_download_link($retrieved_product, $item_name, $payment_data); eStore_payment_debug('Download Link : ' . $download_link, true); array_push($product_name_array, $cart_item_data_name); array_push($download_link_array, $download_link); } } for ($i = 0; $i < sizeof($product_name_array); $i++) { //Download links list for all items in the cart $constructed_download_link .= "\n"; if (is_array($download_link_array[$i])) { $package_downloads = $download_link_array[$i]; for ($j = 0; $j < sizeof($package_downloads); $j++) { $constructed_download_link .= $package_downloads[$j]; $constructed_download_link .= "\n"; } } else { $constructed_download_link .= $download_link_array[$i]; } } return $constructed_download_link; }
function wp_eStore_create_payment_data_array($eStore_customer, $eStore_cart) { $cart_custom_data = $eStore_cart->GetCustomData(); $cart_customvariables = wp_eStore_get_custom_var($cart_custom_data); $cart_eMember_id = $cart_customvariables['eMember_id']; $cart_coupon = $cart_customvariables['coupon']; $gateway = $eStore_customer->GetGatewaySelected(); $txn_id = $eStore_customer->GetTransactionID(); if (empty($txn_id)) { eStore_payment_debug("Error! Cart Transaction ID is empty: " . $txn_id, false); } $txn_type = $eStore_customer->GetTransactionType(); $txn_subject = $eStore_customer->GetTransactionSubject(); $shipping_street_address = $eStore_customer->GetShippingStreetAddress(); $shipping_city = $eStore_customer->GetShippingCity(); $shipping_state = $eStore_customer->GetShippingState(); $shipping_country = $eStore_customer->GetShippingCountry(); $shipping_address = $eStore_customer->GetShippingAddress(); $street_address = ""; $city = ""; $state = ""; $country = ""; $address = ""; if (empty($shipping_city) && empty($shipping_state) && empty($shipping_country) && empty($shipping_street_address)) { $street_address = $eStore_customer->GetStreetAddress(); $city = $eStore_customer->GetCity(); $state = $eStore_customer->GetState(); $country = $eStore_customer->GetCountry(); $address = $eStore_customer->GetAddress(); } else { $street_address = $shipping_street_address; $city = $shipping_city; $state = $shipping_state; $country = $shipping_country; $address = $shipping_address; } $payment_data = array('gateway' => $gateway, 'custom' => $cart_custom_data, 'txn_id' => $txn_id, 'txn_type' => $txn_type, 'transaction_subject' => $txn_subject, 'first_name' => $eStore_customer->GetFirstName(), 'last_name' => $eStore_customer->GetLastName(), 'payer_email' => $eStore_customer->GetEmail(), 'num_cart_items' => $eStore_cart->GetNumberOfCartItems(), 'subscr_id' => $txn_id, 'address' => $address, 'phone' => $eStore_customer->GetPhone(), 'coupon_used' => $cart_coupon, 'eMember_username' => $cart_eMember_id, 'eMember_userid' => $cart_eMember_id, 'mc_gross' => $eStore_cart->CalculateCartTotal(), 'mc_shipping' => $eStore_cart->GetCartShipping(), 'mc_tax' => $eStore_cart->CalculateCartTotalTax(), 'address_street' => $street_address, 'address_city' => $city, 'address_state' => $state, 'address_country' => $country); $is_background_post = $eStore_customer->GetISBackgroundPost(); if ($is_background_post === "yes") { $payment_data['background_post'] = 'yes'; } return $payment_data; }
function eStore_manual_gateway_form_processing_code() { if (isset($_POST['submit_shipping'])) { if (eStore_get_total_cart_item_qty() < 1) { //Cart does not have any item echo '<div class="eStore_error_message">Error! Your shopping cart is empty. Please add items to your cart before checking out.</div>'; return; } $input_verified = false; global $wpdb; $wp_eStore_config = WP_eStore_Config::getInstance(); $err_msg = eStore_check_address_details(); if (!empty($err_msg)) { $msg = '<div id="error">'; $msg .= ESTORE_REQUIRED_FIELDS_MISSING; $msg .= $err_msg; $msg .= '</div>'; echo $msg; } else { //Fire the begin processing hook $clientip = $_SERVER['REMOTE_ADDR']; $clientemail = $_POST['email']; do_action('eStore_begin_manual_co_processing', $clientemail, $clientip); $last_records_id = $wp_eStore_config->getValue('eStore_custom_receipt_counter'); //get_option('eStore_custom_receipt_counter'); if (empty($last_records_id)) { $last_records_id = 0; } $receipt_counter = $last_records_id + 1; $wp_eStore_config->setValue('eStore_custom_receipt_counter', $receipt_counter); $wp_eStore_config->saveConfig(); $address = $_POST['address'] . ", " . $_POST['city'] . ", " . $_POST['state'] . " " . $_POST['postcode'] . " " . $_POST['country']; $payment_data = extract_manaul_co_general_payment_data($_POST['firstname'], $_POST['lastname'], $_POST['email'], $address, $_POST['phone']); $cart_items = extract_manual_item_data(); $cust_direction = get_option('eStore_manual_co_cust_direction'); $curr_symbol = get_option('cart_currency_symbol'); if (!empty($cust_direction)) { $cust_direction_mod = eStore_apply_post_payment_dynamic_tags($cust_direction, $payment_data, $cart_items); $body .= "\n-------------------------------\n"; $body .= $cust_direction_mod; $body .= "\n-------------------------------\n"; } $count = 1; $constructed_download_link .= "<br />"; $product_key_data = ""; $show_tax_inc_price = $wp_eStore_config->getValue('eStore_show_tax_inclusive_price'); foreach ($_SESSION['eStore_cart'] as $item) { $products_table_name = $wpdb->prefix . "wp_eStore_tbl"; $key = $item['item_number']; $retrieved_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$key}'", OBJECT); $rounded_price = round($item['price'], 2); $body .= "\n" . WP_ESTORE_DETAILS_OF_ORDERED_PRODUCT . ": " . $count; $body .= "\n-------------------------"; $body .= "\n" . ESTORE_PRODUCT_ID . ": " . $item['item_number']; $body .= "\n" . ESTORE_PRODUCT_NAME . ": " . $item['name']; if ($show_tax_inc_price == '1') { $rounded_price = eStore_get_tax_include_price_by_prod_id($item['item_number'], $rounded_price); } $formatted_price = print_digi_cart_payment_currency($rounded_price, $curr_symbol); $body .= "\n" . ESTORE_PRICE . ": " . $formatted_price; $body .= "\n" . ESTORE_QUANTITY . ": " . $item['quantity'] . "\n"; if (get_option('eStore_manual_co_give_download_links') != '') { $download_link = generate_download_link_for_product($item['item_number'], $item['name'], $payment_data); $constructed_download_link .= $download_link . "<br />"; $body .= $download_link . "\n"; $product_key = eStore_post_sale_retrieve_serial_key_and_update($retrieved_product, $item['name'], $item['quantity']); $product_key_data .= $product_key; $body .= $product_key; $product_specific_instructions = eStore_get_product_specific_instructions($retrieved_product); $product_specific_instructions = eStore_apply_post_payment_dynamic_tags($product_specific_instructions, $payment_data, $cart_items); $body .= $product_specific_instructions; } $count++; //Check and signup WishList or WP eMember user if needed //if(get_option('eStore_manual_co_auto_update_db')=='1') if ($wp_eStore_config->getValue('eStore_manual_co_auto_create_membership') == '1') { $member_ref = $retrieved_product->ref_text; eStore_payment_debug('Checking if membership inegration is being used. Reference Text Value: ' . $member_ref, true); if (!empty($member_ref)) { if (get_option('eStore_enable_wishlist_int')) { eStore_payment_debug('WishList integration is being used... doing member account creation/upgrade task... see the "subscription_handle_debug.log" file for details', true); wl_handle_subsc_signup($payment_data, $member_ref, $payment_data['txn_id']); } else { if (function_exists('wp_eMember_install')) { $eMember_id = $payment_data['eMember_userid']; eStore_payment_debug('eMember integration is being used... doing member account creation/upgrade task... see the "subscription_handle_debug.log" file for details', true); eMember_handle_subsc_signup($payment_data, $member_ref, $payment_data['txn_id'], $eMember_id); } } } } //=== End of membership handling code === } $body .= "\n-------------------------------\n"; if ($show_tax_inc_price != '1') { $body .= ESTORE_SUB_TOTAL . ": " . print_digi_cart_payment_currency($_SESSION['eStore_cart_sub_total'], $curr_symbol); } if (!empty($_SESSION['eStore_cart_postage_cost'])) { $body .= "\n" . ESTORE_SHIPPING . ": " . print_digi_cart_payment_currency($_SESSION['eStore_cart_postage_cost'], $curr_symbol); } if (!empty($_SESSION['eStore_cart_total_tax'])) { $body .= "\n" . WP_ESTORE_TAX . ": " . print_digi_cart_payment_currency($_SESSION['eStore_cart_total_tax'], $curr_symbol); } $total = $_SESSION['eStore_cart_sub_total'] + $_SESSION['eStore_cart_postage_cost'] + $_SESSION['eStore_cart_total_tax']; $body .= "\n" . ESTORE_TOTAL . ": " . print_digi_cart_payment_currency($total, $curr_symbol); $conversion_rate = get_option('eStore_secondary_currency_conversion_rate'); if (!empty($conversion_rate)) { $secondary_curr_symbol = get_option('eStore_secondary_currency_symbol'); $body .= "\n" . ESTORE_TOTAL . ' (' . get_option('eStore_secondary_currency_code') . '): ' . print_digi_cart_payment_currency($total * $conversion_rate, $secondary_curr_symbol); } if (isset($_SESSION['eStore_store_pickup_checked']) && $_SESSION['eStore_store_pickup_checked'] == '1') { $body .= "\nStore Pickup: Yes"; } $total_items = $count - 1; $body .= "\n" . WP_ESTORE_TOTAL_ITEMS_ORDERED . ": " . $total_items; $body .= "\n" . ESTORE_TRANSACTION_ID . ": " . $payment_data['txn_id']; $body .= "\n\n" . WP_ESTORE_CUSTOMER_DETAILS; $body .= "\n-------------------------"; $body .= "\n" . WP_ESTORE_NAME . ": " . $_POST['firstname'] . " " . $_POST['lastname']; $body .= "\n" . ESTORE_EMAIL . ": " . $_POST['email']; $body .= "\n" . ESTORE_PHONE . ": " . $_POST['phone']; $body .= "\n" . ESTORE_ADDRESS . ": " . $_POST['address']; $body .= "\n" . ESTORE_CITY . ": " . $_POST['city']; $body .= "\n" . ESTORE_STATE . ": " . $_POST['state']; $body .= "\n" . ESTORE_POSTCODE . ": " . $_POST['postcode']; $body .= "\n" . ESTORE_COUNTRY . ": " . $_POST['country']; $body .= "\n" . WP_ESTORE_ADDITIONAL_COMMENT . ": " . $_POST['additional_comment']; $notify_email = get_option('eStore_manual_notify_email'); $buyer_email = $_POST['email']; if (empty($notify_email)) { $notify_email = get_bloginfo('admin_email'); } // Get referrer if (!empty($_SESSION['ap_id'])) { $referrer = $_SESSION['ap_id']; } else { if (isset($_COOKIE['ap_id'])) { $referrer = $_COOKIE['ap_id']; } } //Call the filter for email notification body eStore_payment_debug('Applying filter - eStore_notification_email_body_filter', true); $body = apply_filters('eStore_notification_email_body_filter', $body, $payment_data, $cart_items); $seller_email_body = $body . "\n\n" . WP_ESTORE_REFERRER . ": " . $referrer; $from_email_address = get_option('eStore_download_email_address'); $headers = 'From: ' . $from_email_address . "\r\n"; // Notify Seller $n_subject = $wp_eStore_config->getValue('seller_email_subject_manual_co'); if (empty($n_subject)) { $n_subject = get_option('eStore_seller_email_subj'); } wp_mail($notify_email, $n_subject, $seller_email_body, $headers); // Notify Buyer $buyer_email_subj = $wp_eStore_config->getValue('buyer_email_subject_manual_co'); if (empty($buyer_email_subj)) { $buyer_email_subj = get_option('eStore_buyer_email_subj'); } wp_mail($buyer_email, $buyer_email_subj, $body, $headers); if (!empty($product_key_data)) { //Lets add any serial key info to the data $payment_data['product_key_data'] = $product_key_data; } //Fire the manual checkout hook do_action('eStore_manual_checkout_form_data', $payment_data, $cart_items); //Add to the customer database if the option is enabled if (get_option('eStore_manual_co_auto_update_db') == '1') { record_sales_data($payment_data, $cart_items); } //Perform autoresponder signup if (get_option('eStore_manual_co_do_autoresponder_signup') == '1') { eStore_item_specific_autoresponder_signup($cart_items, $_POST['firstname'], $_POST['lastname'], $_POST['email']); eStore_global_autoresponder_signup($_POST['firstname'], $_POST['lastname'], $_POST['email']); } //Award Affiliate Commission eStore_award_commission_manual_co($payment_data, $cart_items); // Revenue sharing eStore_award_author_commission_manual_co($payment_data, $cart_items); //Create affiliate account if needed eStore_handle_auto_affiliate_account_creation($payment_data); //Post IPN data to external site if needed eStore_POST_IPN_data_to_url($payment_data, '', $cart_items); //Save transaction result for thank you page display if (get_option('eStore_manual_co_give_download_links') != '') { $constructed_download_link = wp_eStore_replace_url_in_string_with_link($constructed_download_link); eStore_save_trans_result_for_thank_you_page_display($payment_data, $constructed_download_link, $cart_items); } $return_url = get_option('eStore_manual_return_url'); if (empty($return_url)) { $return_url = get_bloginfo('wpurl'); } //Google analytics tracking if (get_option('eStore_enable_analytics_tracking') && get_option('eStore_manual_co_give_download_links') != '') { eStore_track_ga_ecommerce($payment_data, $cart_items); $return_url = eStore_append_http_get_data_to_url($return_url, "eStore_manual_co_track_ga", "1"); } //Reset cart and redirect to Thank you page reset_eStore_cart(); eStore_redirect_to_url($return_url); } } }
function extract_2co_general_payment_data_secondary($raw_data, $gateway, $cart_items) { eStore_payment_debug("2CO IPN Processing - Creating payment data using thank you page post data.", true); $custom_data = $cart_items[0]['custom']; $customvariables = get_custom_var($custom_data); $eMember_id = $customvariables['eMember_id']; $coupon = $customvariables['coupon']; $total_shipping = $cart_items[0]['total_shipping']; $total_tax = $cart_items[0]['total_tax']; $sub_total = $cart_items[0]['subtotal']; $gross_total = $sub_total + $total_shipping + $total_tax; $address = $raw_data['street_address'] . " " . $raw_data['street_address2'] . ", " . $raw_data['street_address'] . ", " . $raw_data['state'] . " " . $raw_data['zip'] . ", " . $raw_data['country']; //item_type_# = bill or refund $payment_data = array('gateway' => $gateway, 'custom' => $custom_data, 'txn_id' => $raw_data['invoice_id'], 'txn_type' => "ORDER_CREATED", 'transaction_subject' => $raw_data['message_description'], 'first_name' => $raw_data['first_name'], 'last_name' => $raw_data['last_name'], 'payer_email' => $raw_data['email'], 'num_cart_items' => count($cart_items), 'subscr_id' => $raw_data['invoice_id'], 'address' => $address, 'phone' => $raw_data['phone'], 'coupon_used' => $coupon, 'eMember_username' => $eMember_id, 'eMember_userid' => $eMember_id, 'mc_gross' => $gross_total, 'mc_shipping' => $total_shipping, 'mc_tax' => $total_tax, 'address_street' => $raw_data['street_address'], 'address_city' => $raw_data['city'], 'address_state' => $raw_data['state'], 'address_country' => $raw_data['country']); return $payment_data; }
function validate_and_dispatch_product() { // Check Product Name , Price , Currency , Receivers email , global $error_msg; global $wpdb; $wp_eStore_config = WP_eStore_Config::getInstance(); $clientdate = date("Y-m-d"); $clienttime = date("H:i:s"); $product_specific_instructions = ""; $currency_symbol = get_option('cart_currency_symbol'); //Post/Forward IPN data to external URL if needed eStore_POST_IPN_data_to_url($this->ipn_data); // Read the IPN and validate if (get_option('eStore_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 false; } else { $this->debug_log('Seller Paypal Email Address is Valid: ' . $this->ipn_data['receiver_email'], true); } } $payment_status = $this->ipn_data['payment_status']; if (!empty($payment_status)) { if ($payment_status == "Denied") { $error_msg .= 'Payment status for this transaction is DENIED. You denied the transaction... most likely a cancellation of an eCheque.'; $this->debug_log("You denied the transaction. Most likely a cancellation of an eCheque. Nothing to do here.", false); return false; } if ($payment_status == "Canceled_Reversal") { $this->debug_log("This is a dispute closed notification in your favour. The plugin will not do anyting.", false); return true; } if ($payment_status != "Completed" && $payment_status != "Processed" && $payment_status != "Refunded" && $payment_status != "Reversed") { $error_msg .= 'Funds have not been cleared yet. Product(s) will be delivered when the funds clear!'; $this->debug_log($error_msg, false); $to_address = $this->ipn_data['payer_email']; $subject = ESTORE_PENDING_PAYMENT_EMAIL_SUBJECT; $body = ESTORE_PENDING_PAYMENT_EMAIL_BODY; $from_address = get_option('eStore_download_email_address'); eStore_send_notification_email($to_address, $subject, $body, $from_address); return false; } } $transaction_type = $this->ipn_data['txn_type']; if ($transaction_type == "new_case") { $this->debug_log('This is a dispute case', true); return true; } $transaction_id = $this->ipn_data['txn_id']; $transaction_subject = $this->ipn_data['transaction_subject']; $custom = $this->ipn_data['custom']; $delimiter = "&"; $customvariables = array(); $namevaluecombos = explode($delimiter, $custom); foreach ($namevaluecombos as $keyval_unparsed) { $equalsignposition = strpos($keyval_unparsed, '='); if ($equalsignposition === false) { $customvariables[$keyval_unparsed] = ''; continue; } $key = substr($keyval_unparsed, 0, $equalsignposition); $value = substr($keyval_unparsed, $equalsignposition + 1); $customvariables[$key] = $value; } $eMember_id = $customvariables['eMember_id']; $pictureID = $customvariables['ngg_pid']; //Check for refund payment $gross_total = $this->ipn_data['mc_gross']; if ($gross_total < 0) { // This is a refund or reversal so handle the refund eStore_handle_refund($this->ipn_data); $this->debug_log('This is a refund/reversal. Refund amount: ' . $gross_total, true); return true; } //Check for duplicate notification due to server setup issue if (eStore_is_txn_already_processed($this->ipn_data)) { $error_msg .= 'The transaction ID and the email address already exists in the database. So this seems to be a duplicate transaction notification. This usually happens with bad server setup.'; $this->debug_log('The transaction ID and the email address already exists in the database. So this seems to be a duplicate transaction notification. This usually happens with bad server setup.', false); return true; //No need to be alarmed } //=== End of duplicate notification check === //Fire the begin processing hook do_action('eStore_begin_payment_processing', $this->ipn_data['payer_email'], $customvariables['ip']); $time = time(); global $wpdb; $products_table_name = $wpdb->prefix . "wp_eStore_tbl"; $customer_table_name = $wpdb->prefix . "wp_eStore_customer_tbl"; $sales_table_name = $wpdb->prefix . "wp_eStore_sales_tbl"; 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]; //$item_name = mb_convert_encoding($item_name, "UTF-8"); $quantity = $this->ipn_data['quantity' . $i]; $mc_gross = $this->ipn_data['mc_gross_' . $i]; $mc_shipping = $this->ipn_data['mc_shipping' . $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_shipping' => $mc_shipping, 'mc_currency' => $mc_currency); array_push($cart_items, $current_item); $i++; } } else { if ($transaction_type == "subscr_signup") { $this->debug_log('Subscription signup IPN received... (handled by the subscription IPN handler). Check the "subscription_handle_debug.log" file more details.', true); if (eStore_chk_and_record_cust_data_for_free_trial_signup($this->ipn_data)) { //Check and record customer data for free trial return true; } $subsc_prod_id = $this->ipn_data['item_number']; $ret_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$subsc_prod_id}'", OBJECT); if (!$ret_product) { $error_msg .= 'Request received for subscription product ID: ' . $subsc_prod_id . '. Could not find this Product ID in the product database (please check the manage products menu and verify that you have specified the correct product ID).'; $this->debug_log($error_msg, false); return false; } $subsc_ref = $ret_product->ref_text; if (!empty($subsc_ref)) { //Do membership signup task $this->debug_log('Reference Text field value: ' . $subsc_ref, true); if (get_option('eStore_enable_wishlist_int')) { $this->debug_log('WishList integration is being used... creating member account... see the "subscription_handle_debug.log" file for details', true); wl_handle_subsc_signup($this->ipn_data, $subsc_ref, $this->ipn_data['subscr_id']); } else { if (function_exists('wp_eMember_install')) { $this->debug_log('eMember integration is being used... creating member account... see the "subscription_handle_debug.log" file for details', true); eMember_handle_subsc_signup($this->ipn_data, $subsc_ref, $this->ipn_data['subscr_id'], $eMember_id); } } } return true; } else { if ($transaction_type == "subscr_cancel" || $transaction_type == "subscr_eot" || $transaction_type == "subscr_failed") { if (get_option('eStore_enable_wishlist_int')) { wl_handle_subsc_cancel($this->ipn_data); } else { // Code to handle the IPN for subscription cancellation if (function_exists('wp_eMember_install')) { eMember_handle_subsc_cancel($this->ipn_data); } } $this->debug_log('Subscription cancellation IPN received... nothing to do here(handled by the subscription IPN handler)', true); return true; } else { $cart_items = array(); $this->debug_log('Transaction Type (Buy Now/Subscribe): ' . $transaction_type, true); $item_number = $this->ipn_data['item_number']; $item_name = $this->ipn_data['item_name']; //$item_name = mb_convert_encoding($item_name, "UTF-8"); $quantity = $this->ipn_data['quantity']; if (empty($quantity)) { $quantity = 1; } $mc_tax = $this->ipn_data['tax']; if (!empty($mc_tax)) { //For "web_accept" txn, the total tax is included in the "mc_gross" amt. $mc_gross = $this->ipn_data['mc_gross'] - $mc_tax; $this->debug_log('Deducting tax amount (' . $mc_tax . ') from mc_gross amt', true); } else { $mc_gross = $this->ipn_data['mc_gross']; } $mc_shipping = $this->ipn_data['mc_shipping']; $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_shipping' => $mc_shipping, 'mc_currency' => $mc_currency); array_push($cart_items, $current_item); } } } // URL of directory where script is stored ( include trailing slash ) $script_location = get_option('eStore_download_script'); $random_key = get_option('eStore_random_code'); $payment_currency = get_option('cart_payment_currency'); $product_id_array = array(); $product_name_array = array(); $product_price_array = array(); $product_qty_array = array(); $download_link_array = array(); $download_link_for_digital_item = array(); $product_key_data = ""; $counter = 0; foreach ($cart_items as $current_cart_item) { $cart_item_data_num = $current_cart_item['item_number']; $key = $cart_item_data_num; $retrieved_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$key}'", OBJECT); if (!$retrieved_product) { $error_msg .= 'Request received for product ID: ' . $cart_item_data_num . '. Could not find this Product ID in the product database (please check the manage products menu and verify that you have specified the correct product ID).'; $this->debug_log($error_msg, false); return false; } $cart_item_data_name = trim($current_cart_item['item_name']); //$retrieved_product->name; $cart_item_data_quantity = $current_cart_item['quantity']; $cart_item_data_total = $current_cart_item['mc_gross']; $cart_item_shipping = $current_cart_item['mc_shipping']; $cart_item_data_currency = $current_cart_item['mc_currency']; if (empty($cart_item_data_quantity)) { $cart_item_data_quantity = 1; } $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 Price: ' . $cart_item_data_total, true); $this->debug_log('Item Shipping: ' . $cart_item_shipping, true); $this->debug_log('Item Currency: ' . $cart_item_data_currency, true); // Compare the values with the values stored in the database $coupon_code = $customvariables['coupon']; if (!empty($coupon_code)) { $this->debug_log('Coupon Code Used : ' . $coupon_code, true); $coupon_table_name = $wpdb->prefix . "wp_eStore_coupon_tbl"; $ret_coupon = $wpdb->get_row("SELECT * FROM {$coupon_table_name} WHERE coupon_code = '{$coupon_code}'", OBJECT); if ($ret_coupon) { $discount_amount = $ret_coupon->discount_value; $discount_type = $ret_coupon->discount_type; if ($discount_type == 0) { //apply % discount $discount = $retrieved_product->price * $discount_amount / 100; $true_product_price = $retrieved_product->price - $discount; } else { // apply value discount $true_product_price = $retrieved_product->price - $discount_amount; } } else { eStore_payment_debug('Could not find the coupon in the database: ' . $coupon_code, false); } if ($transaction_type == "subscr_payment") { $true_product_price = 0; //Used coupon on subscription product eStore_payment_debug('Coupon discount was used on a subscription product', true); } } else { if (is_numeric($retrieved_product->a3)) { $true_product_price = 0; //subscription product } else { if (is_numeric($retrieved_product->price)) { $true_product_price = $retrieved_product->price * $cart_item_data_quantity; } else { $true_product_price = 0; //most likely a subscription } } } $check_price = true; $msg = ""; $msg = apply_filters('eStore_before_checking_price_filter', $msg, $current_cart_item); if (!empty($msg) && $msg == "currency-check-override") { $check_price = false; $this->debug_log('Price and currency check override enabled by filter eStore_before_checking_price_filter', true); } if ($check_price) { $true_product_price = round($true_product_price, 2); if ($cart_item_data_total < $true_product_price) { $error_msg .= 'Wrong Product Price Detected! Actual Product Price : ' . $true_product_price . ' Amount Paid: ' . $cart_item_data_total; $this->debug_log($error_msg, false); return false; } if (!empty($retrieved_product->currency_code)) { $payment_currency = $retrieved_product->currency_code; } if ($payment_currency != $cart_item_data_currency) { $error_msg .= 'Invalid Product Currency Detected! The payment was made in currency: ' . $cart_item_data_currency; $this->debug_log($error_msg, false); $this->debug_log('You specified to receive payment in: ' . $payment_currency . ' for this product. Check eStore settings or this product\'s Buy Now/Subscription section and correct the currency code to fix this issue.', false); return false; } } //*** Handle Membership Payment *** $member_ref = $retrieved_product->ref_text; $this->debug_log('Value of the reference text field for this product: ' . $member_ref, true); if (!empty($member_ref)) { if ($transaction_type == "web_accept") { if (get_option('eStore_enable_wishlist_int')) { $this->debug_log('WishList integration is being used... creating member account... see the "subscription_handle_debug.log" file for details', true); wl_handle_subsc_signup($this->ipn_data, $member_ref, $this->ipn_data['txn_id']); } else { if (function_exists('wp_eMember_install')) { $this->debug_log('eMember integration is being used... creating member account... see the "subscription_handle_debug.log" file for details', true); eMember_handle_subsc_signup($this->ipn_data, $member_ref, $this->ipn_data['txn_id'], $eMember_id); } } } else { if ($transaction_type == "cart") { if (get_option('eStore_enable_wishlist_int')) { $this->debug_log('WishList integration is being used... creating member account... see the "subscription_handle_debug.log" file for details', true); wl_handle_subsc_signup($this->ipn_data, $member_ref, $this->ipn_data['txn_id']); } else { if (function_exists('wp_eMember_install')) { $this->debug_log('eMember integration is being used... creating member account... see the "subscription_handle_debug.log" file for details', true); eMember_handle_subsc_signup($this->ipn_data, $member_ref, $this->ipn_data['txn_id'], $eMember_id); } } } else { if ($transaction_type == "subscr_payment") { $subscr_id = $this->ipn_data['subscr_id']; eStore_update_member_subscription_start_date_if_applicable($this->ipn_data, $subscr_id); } } } } //== End of Membership payment handling == $product_id = $retrieved_product->id; //Check if nextgen gallery integration is being used $pid_check_value = eStore_is_ngg_pid_present($cart_item_data_name); if ($pid_check_value != -1) { $pictureID = $pid_check_value; } //Generate link from Nextgen gallery if PID is present. if (!empty($pictureID)) { $download_link = eStore_get_ngg_image_url($pictureID, $cart_item_data_name); $pictureID = ""; } else { $this->debug_log('Generating encrypted download link for this product.', true); $download_link = generate_download_link($retrieved_product, $cart_item_data_name, $this->ipn_data); } $this->debug_log('Download Link: [hidden]', true); //$download_link $product_specific_instructions .= eStore_get_product_specific_instructions($retrieved_product); //Product license key generation if using the license manager if (function_exists('wp_lic_manager_install')) { $product_license_data .= eStore_check_and_generate_license_key($retrieved_product, $this->ipn_data); $this->debug_log('License Data: [hidden]', true); //$product_license_data } //Issue serial key if this feature is being used $product_key_data .= eStore_post_sale_retrieve_serial_key_and_update($retrieved_product, $cart_item_data_name, $cart_item_data_quantity); array_push($product_name_array, $cart_item_data_name); array_push($product_id_array, $product_id); array_push($product_price_array, $cart_item_data_total); array_push($product_qty_array, $cart_item_data_quantity); array_push($download_link_array, $download_link); if (eStore_check_if_string_contains_url($download_link)) { array_push($download_link_for_digital_item, $download_link); } $counter++; $download_link = ''; } if (!empty($product_key_data)) { $this->ipn_data['product_key_data'] = $product_key_data; } // How long the download link remain valid (hours) $download_url_life = get_option('eStore_download_url_life'); // Email settings data $notify_email = get_option('eStore_notify_email_address'); // Email which will receive notification of sale (sellers email) $download_email = get_option('eStore_download_email_address'); // Email from which the mail wil be sent from $email_subject = get_option('eStore_buyer_email_subj'); $email_body = get_option('eStore_buyer_email_body'); $notify_subject = get_option('eStore_seller_email_subj'); $notify_body = get_option('eStore_seller_email_body'); // Send the product for ($i = 0; $i < sizeof($product_name_array); $i++) { $constructed_products_name .= $product_name_array[$i]; $constructed_products_name .= ", "; $constructed_products_price .= $product_price_array[$i]; $constructed_products_price .= ", "; $constructed_products_id .= $product_id_array[$i]; $constructed_products_id .= ", "; $constructed_products_details .= "\n" . $product_name_array[$i] . " x " . $product_qty_array[$i] . " - " . $currency_symbol . $product_price_array[$i] . " (" . $payment_currency . ")"; $tax_inc_price = eStore_get_tax_include_price_by_prod_id($product_id_array[$i], $product_price_array[$i]); $constructed_products_details_tax_inc .= "\n" . $product_name_array[$i] . " x " . $product_qty_array[$i] . " - " . $currency_symbol . $tax_inc_price . " (" . $payment_currency . ")"; //Download links list for all items in the cart $constructed_download_link .= "\n"; if (is_array($download_link_array[$i])) { $package_downloads = $download_link_array[$i]; for ($j = 0; $j < sizeof($package_downloads); $j++) { $constructed_download_link .= $package_downloads[$j]; $constructed_download_link .= "\n"; } } else { $constructed_download_link .= $download_link_array[$i]; } //Download links for only digital items in the cart $constructed_download_link_for_digital_item .= "\n"; if (is_array($download_link_for_digital_item[$i])) { $package_downloads2 = $download_link_for_digital_item[$i]; for ($j = 0; $j < sizeof($package_downloads2); $j++) { $constructed_download_link_for_digital_item .= $package_downloads2[$j]; $constructed_download_link_for_digital_item .= "\n"; } } else { $constructed_download_link_for_digital_item .= $download_link_for_digital_item[$i]; } } $purchase_date = date("Y-m-d"); $total_purchase_amt = $this->ipn_data['mc_gross']; $txn_id = $this->ipn_data['txn_id']; $total_tax = $this->ipn_data['tax']; $total_shipping = round($this->ipn_data['mc_handling'] + $this->ipn_data['mc_shipping'], 2); $total_minus_total_tax = round($total_purchase_amt - $total_tax, 2); $this->ipn_data['mc_tax'] = $total_tax; $this->ipn_data['mc_shipping'] = $total_shipping; //Counter for incremental receipt number $last_records_id = $wp_eStore_config->getValue('eStore_custom_receipt_counter'); //get_option('eStore_custom_receipt_counter'); if (empty($last_records_id)) { $last_records_id = 0; } $receipt_counter = $last_records_id + 1; $this->debug_log('Incremental counter value for PayPal checkout: ' . $receipt_counter, true); $wp_eStore_config->setValue('eStore_custom_receipt_counter', $receipt_counter); $wp_eStore_config->saveConfig(); $buyer_shipping_info = "\n" . $this->ipn_data['address_name']; $buyer_shipping_info .= "\n" . $this->ipn_data['address_street']; $buyer_shipping_info .= "\n" . $this->ipn_data['address_city']; $buyer_shipping_info .= "\n" . $this->ipn_data['address_state'] . " " . $this->ipn_data['address_zip']; $buyer_shipping_info .= "\n" . $this->ipn_data['address_country']; $buyer_shipping_info .= "\n" . $this->ipn_data['contact_phone']; $this->ipn_data['address'] = $buyer_shipping_info; $buyer_phone = $this->ipn_data['contact_phone']; $shipping_option = $customvariables['ship_option']; if (empty($shipping_option)) { $shipping_option = "Default"; } $product_specific_instructions = eStore_apply_post_payment_dynamic_tags($product_specific_instructions, $this->ipn_data, $cart_items); $tags = array("{first_name}", "{last_name}", "{payer_email}", "{product_name}", "{product_link}", "{product_price}", "{product_id}", "{download_life}", "{product_specific_instructions}", "{product_details}", "{product_details_tax_inclusive}", "{shipping_info}", "{license_data}", "{purchase_date}", "{purchase_amt}", "{transaction_id}", "{shipping_option_selected}", "{product_link_digital_items_only}", "{total_tax}", "{total_shipping}", "{total_minus_total_tax}", "{customer_phone}", "{counter}", "{coupon_code}", "{serial_key}"); $vals = array($this->ipn_data['first_name'], $this->ipn_data['last_name'], $this->ipn_data['payer_email'], $constructed_products_name, $constructed_download_link, $constructed_products_price, $constructed_products_id, $download_url_life, $product_specific_instructions, $constructed_products_details, $constructed_products_details_tax_inc, $buyer_shipping_info, $product_license_data, $purchase_date, $total_purchase_amt, $txn_id, $shipping_option, $constructed_download_link_for_digital_item, $total_tax, $total_shipping, $total_minus_total_tax, $buyer_phone, $receipt_counter, $coupon_code, $product_key_data); $subject = str_replace($tags, $vals, $email_subject); $body = stripslashes(str_replace($tags, $vals, $email_body)); $headers = 'From: ' . $download_email . "\r\n"; $attachment = ''; //Call the filter for email notification body $this->debug_log('Applying filter - eStore_notification_email_body_filter', true); $body = apply_filters('eStore_notification_email_body_filter', $body, $this->ipn_data, $cart_items); // Determine if it's a recurring payment $recurring_payment = is_paypal_recurring_payment($this->ipn_data); if (!$recurring_payment) { if (get_option('eStore_send_buyer_email')) { if (get_option('eStore_use_wp_mail')) { wp_eStore_send_wp_mail($this->ipn_data['payer_email'], $subject, $body, $headers); //wp_mail($this->ipn_data['payer_email'], $subject, $body, $headers); $this->debug_log('Product Email successfully sent to ' . $this->ipn_data['payer_email'] . '.', true); } else { if (@eStore_send_mail($this->ipn_data['payer_email'], $body, $subject, $download_email, $attachment)) { $this->debug_log('Product Email successfully sent (using PHP mail) to ' . $this->ipn_data['payer_email'] . '.', true); } else { $this->debug_log('Error sending product Email (using PHP mail) to ' . $this->ipn_data['payer_email'] . '.', false); } } } } // Notify seller $n_subject = str_replace($tags, $vals, $notify_subject); $n_body = str_replace($tags, $vals, $notify_body); if ($wp_eStore_config->getValue('eStore_add_payment_parameters_to_admin_email') == '1') { $n_body .= "\n\n------- User Email ----------\n" . $body . "\n\n------- Paypal Parameters (Only admin will receive this) -----\n" . $this->post_string; } $n_body = stripslashes($n_body); if (!$recurring_payment) { $notify_emails_array = explode(",", $notify_email); foreach ($notify_emails_array as $notify_email_address) { if (!empty($notify_email_address)) { $recipient_email_address = trim($notify_email_address); if (get_option('eStore_use_wp_mail')) { wp_eStore_send_wp_mail($recipient_email_address, $n_subject, $n_body, $headers); //wp_mail($recipient_email_address, $n_subject, $n_body, $headers); $this->debug_log('Notify Email successfully sent to ' . $recipient_email_address . '.', true); } else { if (@eStore_send_mail($recipient_email_address, $n_body, $n_subject, $download_email)) { $this->debug_log('Notify Email successfully sent (using PHP mail) to ' . $recipient_email_address . '.', true); } else { $this->debug_log('Error sending notify Email (using PHP mail) to ' . $recipient_email_address . '.', false); } } } } } // Do Post operations if (!$recurring_payment) { $this->debug_log('Updating Products, Customers, Coupons, Sales Database Tables with Sales Data.', true); $firstname = $this->ipn_data['first_name']; $lastname = $this->ipn_data['last_name']; $emailaddress = $this->ipn_data['payer_email']; $address = esc_sql(stripslashes($buyer_shipping_info)); $phone = $this->ipn_data['contact_phone']; $subscr_id = $this->ipn_data['subscr_id']; $customer_ip = $customvariables['ip']; if (empty($customer_ip)) { $customer_ip = "No information"; } $product_key_data = $this->ipn_data['product_key_data']; if (empty($product_key_data)) { $product_key_data = ""; } $notes = ""; $status = "Paid"; if (function_exists('wp_eMember_install') && empty($eMember_id)) { //eMember purchase history additional check $this->debug_log('No eMember ID was passed so the user was not logged in. Quering member database to see if a user account exists for: ' . $emailaddress, true); $members_table_name = $wpdb->prefix . "wp_eMember_members_tbl"; $query_emem_db = $wpdb->get_row("SELECT member_id FROM {$members_table_name} WHERE email = '{$emailaddress}'", OBJECT); if ($query_emem_db) { $eMember_id = $query_emem_db->member_id; $this->debug_log('Found a user account with the purchaser email address. adding this purchase to account ID: ' . $eMember_id, true); } } $counter = 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']; $key = $cart_item_data_num; $retrieved_product = $wpdb->get_row("SELECT * FROM {$products_table_name} WHERE id = '{$key}'", OBJECT); $current_product_id = $cart_item_data_num; $cart_item_qty = $current_cart_item['quantity']; $sale_price = $current_cart_item['mc_gross']; if (empty($cart_item_qty)) { $cart_item_qty = 1; } $this->debug_log('Product ID: ' . $cart_item_data_num . '. Current available copies value: ' . $retrieved_product->available_copies . ' Sales count value: ' . $retrieved_product->sales_count, true); $new_available_copies = ""; if (is_numeric($retrieved_product->available_copies)) { $new_available_copies = $retrieved_product->available_copies - $cart_item_qty; } $new_sales_count = $retrieved_product->sales_count + $cart_item_qty; $this->debug_log('New available copies value: ' . $new_available_copies . ' New sales count value: ' . $new_sales_count, true); $updatedb = "UPDATE {$products_table_name} SET available_copies = '{$new_available_copies}', sales_count = '{$new_sales_count}' WHERE id='{$current_product_id}'"; $results = $wpdb->query($updatedb); // Update the Customer table $product_name = esc_sql(stripslashes($cart_item_data_name)); $eMember_username = $eMember_id; $updatedb = "INSERT INTO {$customer_table_name} (first_name, last_name, email_address, purchased_product_id,txn_id,date,sale_amount,coupon_code_used,member_username,product_name,address,phone,subscr_id,purchase_qty,ipaddress,status,serial_number,notes) VALUES ('{$firstname}', '{$lastname}','{$emailaddress}','{$current_product_id}','{$transaction_id}','{$clientdate}','{$sale_price}','{$coupon_code}','{$eMember_username}','{$product_name}','{$address}','{$phone}','{$subscr_id}','{$cart_item_qty}','{$customer_ip}','{$status}','{$product_key_data}','{$notes}')"; $results = $wpdb->query($updatedb); $updatedb2 = "INSERT INTO {$sales_table_name} (cust_email, date, time, item_id, sale_price) VALUES ('{$emailaddress}','{$clientdate}','{$clienttime}','{$current_product_id}','{$sale_price}')"; $results = $wpdb->query($updatedb2); } if (!empty($coupon_code)) { $coupon_table_name = $wpdb->prefix . "wp_eStore_coupon_tbl"; $ret_coupon = $wpdb->get_row("SELECT * FROM {$coupon_table_name} WHERE coupon_code = '{$coupon_code}'", OBJECT); if ($ret_coupon) { $redemption_count = $ret_coupon->redemption_count + 1; $updatedb = "UPDATE {$coupon_table_name} SET redemption_count = '{$redemption_count}' WHERE coupon_code='{$coupon_code}'"; $results = $wpdb->query($updatedb); } } $this->debug_log('Products, Customers, Coupons, Sales Database Tables Updated.', true); //Autoresponder signups eStore_item_specific_autoresponder_signup($cart_items, $firstname, $lastname, $emailaddress); eStore_global_autoresponder_signup($firstname, $lastname, $emailaddress); $this->ipn_data['eMember_userid'] = $eMember_id; //need to add the member ID to the IPN data do_action('eStore_product_database_updated_after_payment', $this->ipn_data, $cart_items); //eStore's action after post payment product database is update } $this->debug_log('Updating Affiliate Database Table with Sales Data if Using the WP Affiliate Platform Plugin.', true); if (eStore_affiliate_capability_exists()) { //$this->debug_log('WP Affiliate Platform is installed, checking referral details...',true); $award_commission = true; if (get_option('eStore_aff_one_time_commission')) { if ($recurring_payment) { $award_commission = false; $this->debug_log('One time commission option is being used, This is a recurring payment and will not generate affiliate commission.', true); } } if ($award_commission) { $this->debug_log('Affiliate Commission may need to be tracked. See the "eStore_post_payment_debug.log" file for more details on commission calculation', true); eStore_aff_award_commission($this->ipn_data, $cart_items); } //Handle auto affiliate account creation if this feature is used eStore_handle_auto_affiliate_account_creation($this->ipn_data); } else { $this->debug_log('Not Using the WP Affiliate Platform Plugin.', true); } //Fire Recurring payment action hook if ($recurring_payment) { $this->debug_log('Firing the PayPal recurring payment action hook.', true); do_action('eStore_paypal_recurring_payment_received', $this->ipn_data, $cart_items); } //Revenue sharing $share_revenue = get_option('eStore_aff_enable_revenue_sharing'); if (!empty($share_revenue)) { eStore_award_author_commission($this->ipn_data, $cart_items); } //POST IPN Data to memberwing script if specified in the settings $memberwing_external_post_url = get_option('eStore_memberwing_ipn_post_url'); if (!empty($memberwing_external_post_url)) { $this->debug_log('Posting IPN data to Memberwing plugin :' . $memberwing_external_post_url, true); eStore_POST_IPN_data_to_url($this->ipn_data, $memberwing_external_post_url); } return true; }