private function callback_login() { if (empty($_COOKIE[TEST_COOKIE])) { $this->message_collection->add(__("Cookies are blocked or not supported by your browser. You must <a href='http://www.google.com/cookies.html'>enable cookies</a> to log in to your account.", 'wp-e-commerce'), 'error'); } $form_args = wpsc_get_login_form_args(); $validation = wpsc_validate_form($form_args); if (is_wp_error($validation)) { wpsc_set_validation_errors($validation); return; } $user = wp_signon(array('user_login' => $_POST['username'], 'user_password' => $_POST['password'], 'rememberme' => !empty($_POST['rememberme']))); if (is_wp_error($user)) { $this->message_collection->add(__('We do not recognize the login information you entered. Please try again.', 'wp-e-commerce'), 'error'); return; } $redirect_to = wp_get_referer(); if (wpsc_get_customer_meta('checkout_after_login')) { $redirect_to = wpsc_get_checkout_url(); wpsc_delete_customer_meta('checkout_after_login'); } if (!$redirect_to || trim(str_replace(home_url(), '', $redirect_to), '/') == trim($_SERVER['REQUEST_URI'], '/')) { $redirect_to = wpsc_get_store_url(); } wp_redirect($redirect_to); exit; }
/** * Coupons constructor * * Instantiate a coupons object with optional variable $code; * * @param string code (optional) the coupon code you would like to use. * @return bool True if coupon code exists, False otherwise. */ public function __construct($code = '') { global $wpdb; if (empty($code)) { return false; } $this->code = $code; $coupon_data = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE coupon_code = %s LIMIT 1", $code), ARRAY_A); if (empty($coupon_data)) { $this->errormsg = true; wpsc_delete_customer_meta('coupon'); return false; } else { $this->coupon = new WPSC_Coupon($coupon_data['id']); // Store these values for back-compatibiilty pre 4.0? $this->value = $this->coupon->get('value'); $this->is_percentage = $this->coupon->get('is-percentage'); $this->conditions = $this->coupon->get('condition'); $this->is_used = $this->coupon->get('is-used'); $this->active = $this->coupon->get('active'); $this->use_once = $this->coupon->get('use-once'); $this->start_date = $this->coupon->get('start'); $this->end_date = $this->coupon->get('expiry'); $this->every_product = $this->coupon->get('every_product'); $this->errormsg = false; return $this->validate_coupon(); } }
/** * Coupons constructor * * Instantiate a coupons object with optional variable $code; * * @param string code (optional) the coupon code you would like to use. * @return bool True if coupon code exists, False otherwise. */ function wpsc_coupons($code = '') { global $wpdb; if (empty($code)) { return false; } $this->code = $code; $coupon_data = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_COUPON_CODES . "` WHERE coupon_code = %s LIMIT 1", $code), ARRAY_A); if (empty($coupon_data)) { $this->errormsg = true; wpsc_delete_customer_meta('coupon'); return false; } else { $coupon_data = array_merge(array('value' => '', 'is-percentage' => '', 'condition' => '', 'is-used' => '', 'active' => '', 'use-once' => '', 'start' => '', 'expiry' => '', 'every_product' => ''), $coupon_data); $this->value = (double) $coupon_data['value']; $this->is_percentage = $coupon_data['is-percentage']; $this->conditions = unserialize($coupon_data['condition']); $this->is_used = $coupon_data['is-used']; $this->active = $coupon_data['active']; $this->use_once = $coupon_data['use-once']; $this->start_date = $coupon_data['start']; $this->end_date = $coupon_data['expiry']; $this->every_product = $coupon_data['every_product']; $this->errormsg = false; return $this->validate_coupon(); } }
/** * Delete a customer meta * @param string * @return JSON encoded array with results, results include original request parameters * @since 3.8.14 */ function wpsc_delete_customer_meta_ajax() { $meta_key = isset($_POST['meta_key']) ? $_REQUEST['meta_key'] : ''; $response = array('request' => $_REQUEST); if (!empty($meta_key)) { $response['old_value'] = wpsc_get_customer_meta($meta_key); $response['type'] = __('success', 'wpsc'); $response['error'] = ''; wpsc_delete_customer_meta($meta_key); } else { $response['old_value'] = ''; $response['type'] = __('error', 'wpsc'); $response['error'] = __('no meta key', 'wpsc'); _wpsc_doing_it_wrong(__FUNCTION__, __('missing meta key', 'wpsc'), '3.8.14'); } $response = _wpsc_add_customer_meta_to_response($response); wp_send_json_success($response); }
/** * PayPal Lightbox Form redirection for the Return URL * * @return void * * @since 3.9 */ public function callback_return_url_redirect() { // Session id if (!isset($_GET['sessionid'])) { return; } else { $sessionid = $_GET['sessionid']; } // Page Styles wp_register_style('ppdg-iframe', plugins_url('dg.css', __FILE__)); // Apply any filters if (wpsc_get_customer_meta('ecs-' . $sessionid)) { add_filter('wpsc_paypal_express_checkout_transact_url', array(&$this, 'review_order_url')); add_filter('wpsc_paypal_express_checkout_return_url', array(&$this, 'review_order_callback')); wpsc_delete_customer_meta('esc-' . $sessionid); } // Return a redirection page ?> <html> <head> <title><?php _e('Processing...', 'wp-e-commerce'); ?> </title> <?php wp_print_styles('ppdg-iframe'); ?> </head> <body> <div id="left_frame"> <div id="right_frame"> <p id="message"> <?php _e('Processing Order', 'wp-e-commerce'); ?> </p> <img src="https://www.paypal.com/en_US/i/icon/icon_animated_prog_42wx42h.gif" alt="Processing..." /> <div id="right_bottom"> <div id="left_bottom"> </div> </div> </div> </div> <script type="text/javascript"> <?php $location = $this->get_original_return_url($sessionid); ?> setTimeout('if (window!=top) {top.location.replace("<?php echo $location; ?> ");}else{location.replace("<?php echo $location; ?> ");}', 1500); </script> </body> </html> <?php exit; }
/** * Merge cart from anonymous user with cart from logged in user * * @since 3.8.13 * @access private */ function _wpsc_merge_cart() { $id_from_wp_user = get_user_meta(get_current_user_id(), _wpsc_get_visitor_meta_key('visitor_id'), true); if (empty($id_from_wp_user)) { return; } do_action('_wpsc_merge_cart', $id_from_wp_user); $id_from_customer_meta = wpsc_get_customer_meta('merge_cart_vistor_id'); wpsc_delete_customer_meta('merge_cart_vistor_id'); $old_cart = wpsc_get_customer_cart($id_from_customer_meta); $items = $old_cart->get_items(); $new_cart = wpsc_get_customer_cart($id_from_wp_user); // first of all empty the old cart so that the claimed stock and related // hooks are released $old_cart->empty_cart(); // add each item to the new cart foreach ($items as $item) { $new_cart->set_item($item->product_id, array('quantity' => $item->quantity, 'variation_values' => $item->variation_values, 'custom_message' => $item->custom_message, 'provided_price' => $item->provided_price, 'time_requested' => $item->time_requested, 'custom_file' => $item->custom_file, 'is_customisable' => $item->is_customisable, 'meta' => $item->meta, 'item_meta' => $item->get_meta())); } wpsc_update_customer_cart($new_cart); // The old profile is no longer needed _wpsc_abandon_temporary_customer_profile($id_from_customer_meta); }
public function reset() { wpsc_delete_customer_meta('checkout_wizard_completed_steps'); $this->completed = array(); $this->get_disabled(); }
/** * returns shipping quotes using this shipping module. * * @param boolean $for_display (optional) (unused) * @return array collection of rates applicable. */ function getQuote($for_display = false) { global $wpdb, $wpsc_cart; $quote_shipping_method = wpsc_get_customer_meta('quote_shipping_method'); $quote_shipping_option = wpsc_get_customer_meta('quote_shipping_option'); $country = ''; if (isset($_POST['country'])) { $country = sanitize_text_field($_POST['country']); wpsc_update_customer_meta('shipping_country', $country); } else { $country = (string) wpsc_get_customer_meta('shipping_country'); } if (is_object($wpsc_cart)) { $cart_total = $wpsc_cart->calculate_subtotal(true); } if (get_option('base_country') != $country) { $results = WPSC_Countries::get_continent($country); $flatrates = get_option('flat_rates'); if ($flatrates != '') { if ($quote_shipping_method == $this->internal_name && $quote_shipping_option != __("Flat Rate", 'wp-e-commerce')) { wpsc_delete_customer_meta('quote_shipping_option'); } if (isset($flatrates[$results])) { if (stristr($flatrates[$results], '%')) { $shipping_percent = str_replace('%', '', $flatrates[$results]); $shipping_amount = $cart_total * ($shipping_percent / 100); $flatrates[$results] = (double) $shipping_amount; } return array(__("Flat Rate", 'wp-e-commerce') => (double) $flatrates[$results]); } } } else { $flatrates = get_option('flat_rates'); $shipping_quotes = array(); switch ($country) { case 'NZ': if (isset($flatrates['northisland']) && strlen($flatrates['northisland']) > 0) { $shipping_quotes[__('North Island', 'wp-e-commerce')] = esc_attr($flatrates['northisland']); } if (isset($flatrates['southisland']) && strlen($flatrates['southisland']) > 0) { $shipping_quotes[__('South Island', 'wp-e-commerce')] = esc_attr($flatrates['southisland']); } break; case 'US': if (isset($flatrates['continental']) && strlen($flatrates['continental']) > 0) { $shipping_quotes[__('Continental 48 States', 'wp-e-commerce')] = esc_attr($flatrates['continental']); } if (isset($flatrates['all']) && strlen($flatrates['all']) > 0) { $shipping_quotes[__('All 50 States', 'wp-e-commerce')] = esc_attr($flatrates['all']); } break; default: if (isset($flatrates['local']) && strlen($flatrates['local']) > 0) { $shipping_quotes[__('Local Shipping', 'wp-e-commerce')] = esc_attr($flatrates['local']); } break; } // Deal with % shipping rates foreach (array_keys($shipping_quotes) as $quote_name) { if (stristr($shipping_quotes[$quote_name], '%')) { $shipping_percent = str_replace('%', '', $shipping_quotes[$quote_name]); $shipping_amount = $cart_total * ($shipping_percent / 100); $shipping_quotes[$quote_name] = (double) $shipping_amount; } else { $shipping_quotes[$quote_name] = (double) $shipping_quotes[$quote_name]; } } if ($quote_shipping_method == $this->internal_name) { $shipping_options = array_keys($shipping_quotes); if (array_search($quote_shipping_option, $shipping_options) === false) { wpsc_delete_customer_meta('quote_shipping_option'); } } return $shipping_quotes; } }
/** * Google checkout not longer available or supported, so we are deprecating this function * * @access public * @deprecated since 3.8.14 */ function wpsc_empty_google_logs() { global $wpdb; _wpsc_deprecated_function(__FUNCTION__, '3.8.14', 'wpsc_empty_google_logs'); $sql = $wpdb->prepare("DELETE FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid` = '%s'", wpsc_get_customer_meta('checkout_session_id')); $wpdb->query($sql); wpsc_delete_customer_meta('checkout_session_id'); }
/** * prcessing functions, this is where the main logic of paypal express lives * @access public * * @since 3.8 */ function paypal_processingfunctions() { global $wpdb, $wpsc_cart; $sessionid = (string) wpsc_get_customer_meta('paypal_express_sessionid'); if (isset($_REQUEST['act']) && 'error' == $_REQUEST['act']) { $resArray = wpsc_get_customer_meta('paypal_express_reshash'); $paypal_express_message = ' <center> <table width="700" align="left"> <tr> <td colspan="2" class="header">' . __('The PayPal API has returned an error!', 'wpsc') . '</td> </tr> '; //it will print if any URL errors if (wpsc_get_customer_meta('paypal_express_curl_error_msg')) { $errorMessage = wpsc_get_customer_meta('paypal_express_curl_error_msg'); $response = wpsc_get_customer_meta('paypal_express_response'); $paypal_express_message .= ' <tr> <td>response:</td> <td>' . $response . '</td> </tr> <tr> <td>Error Message:</td> <td>' . $errorMessage . '</td> </tr>'; } else { /* If there is no URL Errors, Construct the HTML page with Response Error parameters. */ $paypal_express_message .= "\n\t\t\t\t<tr>\n\t\t\t\t\t<td>Ack:</td>\n\t\t\t\t\t<td>" . $resArray['ACK'] . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td>Correlation ID:</td>\n\t\t\t\t\t<td>" . $resArray['CORRELATIONID'] . "</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td>Version:</td>\n\t\t\t\t\t<td>" . $resArray['VERSION'] . "</td>\n\t\t\t\t</tr>"; $count = 0; while (isset($resArray["L_SHORTMESSAGE" . $count])) { $errorCode = $resArray["L_ERRORCODE" . $count]; $shortMessage = $resArray["L_SHORTMESSAGE" . $count]; $longMessage = $resArray["L_LONGMESSAGE" . $count]; $count = $count + 1; $paypal_express_message .= "\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>" . __('Error Number:', 'wpsc') . "</td>\n\t\t\t\t\t\t<td> {$errorCode} </td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>" . __('Short Message:', 'wpsc') . "</td>\n\t\t\t\t\t\t<td> {$shortMessage} </td>\n\t\t\t\t\t</tr>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>" . __('Long Message:', 'wpsc') . "</td>\n\t\t\t\t\t\t<td> {$longMessage} </td>\n\t\t\t\t\t</tr>"; } //end while } // end else $paypal_express_message .= "\n\t\t\t</center>\n\t\t\t\t</table>"; wpsc_update_customer_meta('paypal_express_message', $paypal_express_message); } else { if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'do') { /* Gather the information to make the final call to finalize the PayPal payment. The variable nvpstr holds the name value pairs */ $token = urlencode($_REQUEST['token']); $paymentAmount = urlencode(wpsc_get_customer_meta('paypal_express_converted_amount')); $paymentType = urlencode(wpsc_get_customer_meta('paypal_express_payment_type')); $currCodeType = urlencode(wpsc_get_paypal_currency_code()); $payerID = urlencode($_REQUEST['PayerID']); $serverName = urlencode($_SERVER['SERVER_NAME']); $BN = 'Instinct_e-commerce_wp-shopping-cart_NZ'; $nvpstr = '&TOKEN=' . $token . '&PAYERID=' . $payerID . '&PAYMENTREQUEST_0_PAYMENTACTION=Sale&PAYMENTREQUEST_0_CURRENCYCODE=' . $currCodeType . '&IPADDRESS=' . $serverName . "&BUTTONSOURCE=" . $BN . "&PAYMENTREQUEST_0_INVNUM=" . urlencode($sessionid); // IPN data if (get_option('paypal_ipn') == 1) { $notify_url = add_query_arg('wpsc_action', 'gateway_notification', get_option('siteurl') . "/index.php"); $notify_url = add_query_arg('gateway', 'wpsc_merchant_paypal_express', $notify_url); $notify_url = apply_filters('wpsc_paypal_express_notify_url', $notify_url); $nvpstr .= '&PAYMENTREQUEST_0_NOTIFYURL=' . urlencode($notify_url); } // Horrible code that I had to write to hot fix the issue with missing item detail in email receipts. arrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrgh!!!!! @#@$%@#%@##$#$ $purchase_log = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid` = %s", $sessionid), ARRAY_A); $cart_data = $original_cart_data = $wpdb->get_results("SELECT * FROM `" . WPSC_TABLE_CART_CONTENTS . "` WHERE `purchaseid` = {$purchase_log['id']}", ARRAY_A); $i = 0; $item_total = 0; $shipping_total = 0; foreach ($cart_data as $cart_item) { $converted_price = wpsc_paypal_express_convert($cart_item['price']); $nvpstr .= "&L_PAYMENTREQUEST_0_NAME{$i}=" . urlencode(apply_filters('the_title', $cart_item['name'])); $nvpstr .= "&L_PAYMENTREQUEST_0_AMT{$i}=" . $converted_price; $nvpstr .= "&L_PAYMENTREQUEST_0_NUMBER{$i}=" . $i; $nvpstr .= "&L_PAYMENTREQUEST_0_QTY{$i}=" . $cart_item['quantity']; $item_total += $converted_price * $cart_item['quantity']; $shipping_total += wpsc_paypal_express_convert($cart_item['pnp']); $i++; } //if we have a discount then include a negative amount with that discount if ($purchase_log['discount_value'] && 0.0 != $purchase_log['discount_value']) { $discount_value = wpsc_paypal_express_convert($purchase_log['discount_value']); // if item total < discount amount, leave at least 0.01 unit in item total, then subtract // 0.01 from shipping as well if ($discount_value >= $item_total) { $discount_value = $item_total - 0.01; $shipping_total -= 0.01; } $nvpstr .= "&L_PAYMENTREQUEST_0_NAME{$i}=" . urlencode("Discount / Coupon"); $nvpstr .= "&L_PAYMENTREQUEST_0_AMT{$i}=-" . urlencode($discount_value); $nvpstr .= "&L_PAYMENTREQUEST_0_NUMBER{$i}={$i}"; $nvpstr .= "&L_PAYMENTREQUEST_0_QTY{$i}=1"; $item_total -= $discount_value; } $item_total = wpsc_paypal_express_format($item_total); $shipping_total = wpsc_paypal_express_convert($purchase_log['base_shipping']) + $shipping_total; $nvpstr .= '&PAYMENTREQUEST_0_ITEMAMT=' . $item_total; $nvpstr .= '&PAYMENTREQUEST_0_SHIPPINGAMT=' . $shipping_total; $total = $item_total + $shipping_total; if (!wpsc_tax_isincluded()) { $tax = wpsc_paypal_express_convert($purchase_log['wpec_taxes_total']); $nvpstr .= '&PAYMENTREQUEST_0_TAXAMT=' . $tax; $total += $tax; } // adjust total amount in case we had to round up after converting currency if ($total != $paymentAmount) { $paymentAmount = $total; } $nvpstr .= "&PAYMENTREQUEST_0_AMT={$paymentAmount}"; $resArray = paypal_hash_call("DoExpressCheckoutPayment", $nvpstr); /* Display the API response back to the browser. If the response from PayPal was a success, display the response parameters' If the response was an error, display the errors received using APIError.php. */ $ack = strtoupper($resArray["ACK"]); wpsc_update_customer_meta('paypal_express_reshash', $resArray); if ($ack != "SUCCESS") { $location = get_option('transact_url') . "&act=error"; } else { $transaction_id = $resArray['PAYMENTINFO_0_TRANSACTIONID']; switch ($resArray['PAYMENTINFO_0_PAYMENTSTATUS']) { case 'Processed': // I think this is mostly equivalent to Completed // I think this is mostly equivalent to Completed case 'Completed': wpsc_update_purchase_log_status($sessionid, 3, 'sessionid'); transaction_results($sessionid, false); break; case 'Pending': // need to wait for "Completed" before processing wpsc_update_purchase_log_details($sessionid, array('processed' => 2, 'date' => time(), 'transactid' => $transaction_id), 'sessionid'); break; } $location = add_query_arg('sessionid', $sessionid, get_option('transact_url')); wpsc_delete_customer_meta('paypal_express_message'); wp_redirect($location); exit; } wpsc_delete_customer_meta('nzshpcrt_serialized_cart'); wpsc_delete_customer_meta('nzshpcart'); $wpsc_cart->empty_cart(); } else { if (isset($_REQUEST['paymentType']) || isset($_REQUEST['token'])) { $token = $_REQUEST['token']; if (!isset($token)) { $paymentAmount = wpsc_get_customer_meta('paypal_express_converted_amount'); $currencyCodeType = wpsc_get_paypal_currency_code(); $paymentType = 'Sale'; if (get_option('permalink_structure') != '') { $separator = "?"; } else { $separator = "&"; } $returnURL = urlencode(get_option('transact_url') . $separator . 'currencyCodeType=' . $currencyCodeType . '&paymentType=' . $paymentType . '&paymentAmount=' . $paymentAmount); $cancelURL = urlencode(get_option('transact_url') . $separator . 'paymentType=$paymentType'); /* Construct the parameter string that describes the PayPal payment the varialbes were set in the web form, and the resulting string is stored in $nvpstr */ $nvpstr = "&PAYMENTREQUEST_0_AMT=" . $paymentAmount . "&PAYMENTREQUEST_0_PAYMENTACTION=" . $paymentType . "&ReturnUrl=" . $returnURL . "&CANCELURL=" . $cancelURL . "&PAYMENTREQUEST_0_CURRENCYCODE=" . $currencyCodeType; /* Make the call to PayPal to set the Express Checkout token If the API call succeded, then redirect the buyer to PayPal to begin to authorize payment. If an error occured, show the resulting errors */ $resArray = paypal_hash_call("SetExpressCheckout", $nvpstr); wpsc_update_customer_meta('paypal_express_reshash', $resArray); $ack = strtoupper($resArray["ACK"]); if ($ack == "SUCCESS") { // Redirect to paypal.com here $token = urldecode($resArray["TOKEN"]); $payPalURL = $PAYPAL_URL . $token; wp_redirect($payPalURL); } else { // Redirecting to APIError.php to display errors. $location = get_option('transact_url') . "&act=error"; wp_redirect($location); } exit; } else { /* At this point, the buyer has completed in authorizing payment at PayPal. The script will now call PayPal with the details of the authorization, incuding any shipping information of the buyer. Remember, the authorization is not a completed transaction at this state - the buyer still needs an additional step to finalize the transaction */ $token = urlencode($_REQUEST['token']); /* Build a second API request to PayPal, using the token as the ID to get the details on the payment authorization */ $nvpstr = "&TOKEN=" . $token; /* Make the API call and store the results in an array. If the call was a success, show the authorization details, and provide an action to complete the payment. If failed, show the error */ $resArray = paypal_hash_call("GetExpressCheckoutDetails", $nvpstr); wpsc_update_customer_meta('paypal_express_reshash', $resArray); $ack = strtoupper($resArray["ACK"]); if ($ack == "SUCCESS") { /******************************************************** GetExpressCheckoutDetails.php This functionality is called after the buyer returns from PayPal and has authorized the payment. Displays the payer details returned by the GetExpressCheckoutDetails response and calls DoExpressCheckoutPayment.php to complete the payment authorization. Called by ReviewOrder.php. Calls DoExpressCheckoutPayment.php and APIError.php. ********************************************************/ /* Collect the necessary information to complete the authorization for the PayPal payment */ /* Display the API response back to the browser . If the response from PayPal was a success, display the response parameters */ if (isset($_REQUEST['token']) && !isset($_REQUEST['PayerID'])) { wpsc_update_customer_meta('paypal_express_message', _x('<h4>TRANSACTION CANCELED</h4>', 'paypal express cancel header', 'wpsc')); } else { wpsc_update_customer_meta('paypal_express_token', $_REQUEST['token']); wpsc_update_customer_meta('paypal_express_payer_id', $_REQUEST['PayerID']); $resArray = wpsc_get_customer_meta('paypal_express_reshash'); if (get_option('permalink_structure') != '') { $separator = "?"; } else { $separator = "&"; } if (!isset($resArray['SHIPTOSTREET2'])) { $resArray['SHIPTOSTREET2'] = ''; } $output = "\n\t\t\t\t\t <table width='400' class='paypal_express_form'>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' class='firstcol'><b>" . __('Order Total:', 'wpsc') . "</b></td>\n\t\t\t\t\t\t\t<td align='left'>" . wpsc_currency_display(wpsc_get_customer_meta('paypal_express_original_amount')) . "</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' colspan='2'><b>" . __('Shipping Address:', 'wpsc') . " </b></td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' class='firstcol'>\n\t\t\t\t\t\t\t\t" . __('Street 1:', 'wpsc') . "</td>\n\t\t\t\t\t\t\t<td align='left'>" . $resArray['SHIPTOSTREET'] . "</td>\n\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' class='firstcol'>\n\t\t\t\t\t\t\t\t" . __('Street 2:', 'wpsc') . "</td>\n\t\t\t\t\t\t\t<td align='left'>" . $resArray['SHIPTOSTREET2'] . "\n\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' class='firstcol'>\n\t\t\t\t\t\t\t\t" . __('City:', 'wpsc') . "</td>\n\n\t\t\t\t\t\t\t<td align='left'>" . $resArray['SHIPTOCITY'] . "</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' class='firstcol'>\n\t\t\t\t\t\t\t\t" . __('State:', 'wpsc') . "</td>\n\t\t\t\t\t\t\t<td align='left'>" . $resArray['SHIPTOSTATE'] . "</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' class='firstcol'>\n\t\t\t\t\t\t\t\t" . __('Postal code:', 'wpsc') . "</td>\n\n\t\t\t\t\t\t\t<td align='left'>" . $resArray['SHIPTOZIP'] . "</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td align='left' class='firstcol'>\n\t\t\t\t\t\t\t\t" . __('Country:', 'wpsc') . "</td>\n\t\t\t\t\t\t\t<td align='left'>" . $resArray['SHIPTOCOUNTRYNAME'] . "</td>\n\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td colspan='2'>"; $output .= "<form action=" . get_option('transact_url') . " method='post'>\n"; $output .= "\t<input type='hidden' name='totalAmount' value='" . wpsc_cart_total(false) . "' />\n"; $output .= "\t<input type='hidden' name='shippingStreet' value='" . $resArray['SHIPTOSTREET'] . "' />\n"; $output .= "\t<input type='hidden' name='shippingStreet2' value='" . $resArray['SHIPTOSTREET2'] . "' />\n"; $output .= "\t<input type='hidden' name='shippingCity' value='" . $resArray['SHIPTOCITY'] . "' />\n"; $output .= "\t<input type='hidden' name='shippingState' value='" . $resArray['SHIPTOSTATE'] . "' />\n"; $output .= "\t<input type='hidden' name='postalCode' value='" . $resArray['SHIPTOZIP'] . "' />\n"; $output .= "\t<input type='hidden' name='country' value='" . $resArray['SHIPTOCOUNTRYNAME'] . "' />\n"; $output .= "\t<input type='hidden' name='token' value='" . wpsc_get_customer_meta('paypal_express_token') . "' />\n"; $output .= "\t<input type='hidden' name='PayerID' value='" . wpsc_get_customer_meta('paypal_express_payer_id') . "' />\n"; $output .= "\t<input type='hidden' name='act' value='do' />\n"; $output .= "\t<p> <input name='usePayPal' type='submit' value='" . __('Confirm Payment', 'wpsc') . "' /></p>\n"; $output .= "</form>"; $output .= " </td>\n\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t</table>\n\t\t\t\t\t</center>\n\t\t\t\t\t"; wpsc_update_customer_meta('paypal_express_message', $output); } } } } } } }
function wpsc_place_shopping_cart($content = '') { if (!in_the_loop()) { return $content; } if (preg_match("/\\[shoppingcart\\]/", $content)) { // BEGIN: compatibility fix for outdated theme files still relying on sessions $_SESSION['coupon_numbers'] = wpsc_get_customer_meta('coupon'); $_SESSION['wpsc_checkout_misc_error_messages'] = wpsc_get_customer_meta('checkout_misc_error_messages'); $_SESSION['categoryAndShippingCountryConflict'] = wpsc_get_customer_meta('category_shipping_conflict'); $_SESSION['shippingSameBilling'] = wpsc_get_customer_meta('shippingSameBilling'); $_SESSION['wpsc_checkout_user_error_messages'] = wpsc_get_customer_meta('registration_error_messages'); // END: compatibility fix $GLOBALS['nzshpcrt_activateshpcrt'] = true; if (!defined('DONOTCACHEPAGE')) { define('DONOTCACHEPAGE', true); } // call this function to detect conflicts when the cart page is first loaded, otherwise // any conflict messages will only be displayed on the next page load wpsc_get_acceptable_countries(); ob_start(); do_action('wpsc_before_shopping_cart_page'); include wpsc_get_template_file_path('wpsc-shopping_cart_page.php'); do_action('wpsc_after_shopping_cart_page'); $output = ob_get_contents(); ob_end_clean(); $output = str_replace('$', '\\$', $output); wpsc_delete_customer_meta('checkout_misc_error_messages'); wpsc_delete_customer_meta('category_shipping_conflict'); wpsc_delete_customer_meta('registration_error_messages'); wpsc_delete_customer_meta('checkout_error_messages'); wpsc_delete_customer_meta('gateway_error_messages'); return preg_replace("/(<p>)*\\[shoppingcart\\](<\\/p>)*/", $output, $content); } else { return $content; } }
/** * submit checkout function, used through ajax and in normal page loading. * No parameters, returns nothing */ function wpsc_submit_checkout($collected_data = true) { global $wpdb, $wpsc_cart, $user_ID, $nzshpcrt_gateways, $wpsc_shipping_modules, $wpsc_gateways; if ($collected_data && isset($_POST['collected_data']) && is_array($_POST['collected_data'])) { _wpsc_checkout_customer_meta_update($_POST['collected_data']); } // initialize our checkout status variab;e, we start be assuming // checkout is falid, until we find a reason otherwise $is_valid = true; $num_items = 0; $use_shipping = 0; $disregard_shipping = 0; do_action('wpsc_before_submit_checkout'); $error_messages = wpsc_get_customer_meta('checkout_misc_error_messages'); if (!is_array($error_messages)) { $error_messages = array(); } $wpsc_checkout = new wpsc_checkout(); $selected_gateways = get_option('custom_gateway_options'); $submitted_gateway = isset($_POST['custom_gateway']) ? $_POST['custom_gateway'] : ''; if ($collected_data) { $form_validity = $wpsc_checkout->validate_forms(); extract($form_validity); // extracts $is_valid and $error_messages if (wpsc_has_tnc() && (!isset($_POST['agree']) || $_POST['agree'] != 'yes')) { $error_messages[] = __('Please agree to the terms and conditions, otherwise we cannot process your order.', 'wpsc'); $is_valid = false; } } else { $is_valid = true; $error_messages = array(); } $wpsc_country = new WPSC_Country(wpsc_get_customer_meta('shippingcountry')); $country_id = $wpsc_country->get_id(); $country_name = $wpsc_country->get_name(); foreach ($wpsc_cart->cart_items as $cartitem) { if (!empty($cartitem->meta[0]['no_shipping'])) { continue; } $categoriesIDs = $cartitem->category_id_list; foreach ((array) $categoriesIDs as $catid) { if (is_array($catid)) { $countries = wpsc_get_meta($catid[0], 'target_market', 'wpsc_category'); } else { $countries = wpsc_get_meta($catid, 'target_market', 'wpsc_category'); } if (!empty($countries) && !in_array($country_id, (array) $countries)) { $errormessage = sprintf(__('%s cannot be shipped to %s. To continue with your transaction please remove this product from the list below.', 'wpsc'), $cartitem->get_title(), $country_name); wpsc_update_customer_meta('category_shipping_conflict', $errormessage); $is_valid = false; } } //count number of items, and number of items using shipping $num_items++; if ($cartitem->uses_shipping != 1) { $disregard_shipping++; } else { $use_shipping++; } } // check to see if the current gateway is in the list of available gateways if (array_search($submitted_gateway, $selected_gateways) !== false) { wpsc_update_customer_meta('selected_gateway', $submitted_gateway); } else { $is_valid = false; } if ($collected_data) { // Test for required shipping information if (wpsc_core_shipping_enabled() && $num_items != $disregard_shipping) { // for shipping to work we need a method, option and a quote if (!$wpsc_cart->shipping_method_selected() || !$wpsc_cart->shipping_quote_selected()) { $error_messages[] = __('Please select one of the available shipping options, then we can process your order.', 'wpsc'); $is_valid = false; } // if we don't have a valid zip code ( the function also checks if we need it ) we have an error if (!wpsc_have_valid_shipping_zipcode()) { wpsc_update_customer_meta('category_shipping_conflict', __('Please enter a Zipcode and click calculate to proceed', 'wpsc')); $is_valid = false; } } } wpsc_update_customer_meta('checkout_misc_error_messages', $error_messages); if ($is_valid == true) { wpsc_delete_customer_meta('category_shipping_conflict'); // check that the submitted gateway is in the list of selected ones $sessionid = mt_rand(100, 999) . time(); wpsc_update_customer_meta('checkout_session_id', $sessionid); $subtotal = $wpsc_cart->calculate_subtotal(); if ($wpsc_cart->has_total_shipping_discount() == false) { $base_shipping = $wpsc_cart->calculate_base_shipping(); } else { $base_shipping = 0; } $delivery_country = $wpsc_cart->delivery_country; $delivery_region = $wpsc_cart->delivery_region; if (wpsc_uses_shipping()) { $shipping_method = $wpsc_cart->selected_shipping_method; $shipping_option = $wpsc_cart->selected_shipping_option; } else { $shipping_method = ''; $shipping_option = ''; } if (isset($_POST['how_find_us'])) { $find_us = $_POST['how_find_us']; } else { $find_us = ''; } //keep track of tax if taxes are exclusive $wpec_taxes_controller = new wpec_taxes_controller(); if (!$wpec_taxes_controller->wpec_taxes_isincluded()) { $tax = $wpsc_cart->calculate_total_tax(); $tax_percentage = $wpsc_cart->tax_percentage; } else { $tax = 0.0; $tax_percentage = 0.0; } $total = $wpsc_cart->calculate_total_price(); $args = array('totalprice' => $total, 'statusno' => '0', 'sessionid' => $sessionid, 'user_ID' => (int) $user_ID, 'date' => time(), 'gateway' => $submitted_gateway, 'billing_country' => $wpsc_cart->selected_country, 'shipping_country' => $delivery_country, 'billing_region' => $wpsc_cart->selected_region, 'shipping_region' => $delivery_region, 'base_shipping' => $base_shipping, 'shipping_method' => $shipping_method, 'shipping_option' => $shipping_option, 'plugin_version' => WPSC_VERSION, 'discount_value' => $wpsc_cart->coupons_amount, 'discount_data' => $wpsc_cart->coupons_name, 'find_us' => $find_us, 'wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage); $purchase_log = new WPSC_Purchase_Log($args); $purchase_log->save(); $purchase_log_id = $purchase_log->get('id'); if ($collected_data) { $wpsc_checkout->save_forms_to_db($purchase_log_id); } $wpsc_cart->save_to_db($purchase_log_id); $wpsc_cart->submit_stock_claims($purchase_log_id); if (!isset($our_user_id) && isset($user_ID)) { $our_user_id = $user_ID; } $wpsc_cart->log_id = $purchase_log_id; do_action('wpsc_submit_checkout', array('purchase_log_id' => $purchase_log_id, 'our_user_id' => $our_user_id)); do_action('wpsc_submit_checkout_gateway', $submitted_gateway, $purchase_log); } }
/** * coupons price, used through ajax and in normal page loading. * No parameters, returns nothing */ function wpsc_coupon_price($currCoupon = '') { global $wpsc_cart, $wpsc_coupons; if (isset($_POST['coupon_num']) && $_POST['coupon_num'] != '') { $coupon = esc_sql($_POST['coupon_num']); wpsc_update_customer_meta('coupon', $coupon); $wpsc_coupons = new wpsc_coupons($coupon); if ($wpsc_coupons->validate_coupon()) { $discountAmount = $wpsc_coupons->calculate_discount(); $wpsc_cart->apply_coupons($discountAmount, $coupon); $wpsc_coupons->errormsg = false; } else { $wpsc_coupons->errormsg = true; $wpsc_cart->coupons_amount = 0; $wpsc_cart->coupons_name = ''; wpsc_delete_customer_meta('coupon'); } } else { if ((!isset($_POST['coupon_num']) || $_POST['coupon_num'] == '') && $currCoupon == '') { $wpsc_cart->coupons_amount = 0; $wpsc_cart->coupons_name = ''; } else { if ($currCoupon != '') { $coupon = esc_sql($currCoupon); wpsc_update_customer_meta('coupon', $coupon); $wpsc_coupons = new wpsc_coupons($coupon); if ($wpsc_coupons->validate_coupon()) { $discountAmount = $wpsc_coupons->calculate_discount(); $wpsc_cart->apply_coupons($discountAmount, $coupon); $wpsc_coupons->errormsg = false; } } } } }
/** * Validate * Checks to make sure the current user can use this gateway. * @since 1.3 * @version 1.1 */ function validate($purchase_log) { $error = false; $user_id = get_current_user_id(); // Get cost $cart_total = $this->cart_data['total_price']; if ($this->prefs['rate'] != 1) { $cart_total = $this->prefs['rate'] * $cart_total; } $cart_total = $this->core->number($cart_total); $this->cost = $cart_total; // User is not logged in if (!is_user_logged_in()) { $error = $this->core->template_tags_general($this->prefs['visitor']); } elseif ($this->core->exclude_user($user_id)) { $error = __('You can not use this gateway.', 'mycred'); } else { // Rate $balance = $this->core->get_users_cred($user_id, $this->mycred_type); if ($balance < $this->cost) { $error = $this->core->template_tags_general($this->prefs['low_funds']); } } // Let others decline a store order $decline = apply_filters('mycred_decline_store_purchase', $error, $purchase_log, $this); if ($decline !== false) { wpsc_delete_customer_meta('selected_gateway'); $this->set_error_message($decline); $purchase_log->delete($this->purchase_id); unset($_SESSION['WpscGatewayErrorMessage']); $this->return_to_checkout(); exit; } // Prep for payment $this->user_id = $user_id; $this->transaction_id = 'MYCRED' . $user_id . time(); }
function wpsc_transaction_theme() { global $wpdb, $user_ID, $nzshpcrt_gateways, $sessionid, $cart_log_id, $errorcode; $errorcode = ''; $transactid = ''; $dont_show_transaction_results = false; if (isset($_GET['sessionid'])) { $sessionid = $_GET['sessionid']; } if (!isset($_GET['sessionid']) && isset($_GET['ms'])) { $sessionid = $_GET['ms']; } $selected_gateway = wpsc_get_customer_meta('selected_gateway'); if ($selected_gateway && in_array($selected_gateway, array('paypal_certified', 'wpsc_merchant_paypal_express'))) { $sessionid = wpsc_get_customer_meta('paypal_express_sessionid'); } if (isset($_REQUEST['eway']) && '1' == $_REQUEST['eway']) { $sessionid = $_GET['result']; } elseif (isset($_REQUEST['eway']) && '0' == $_REQUEST['eway']) { echo wpsc_get_customer_meta('eway_message'); } elseif (isset($_REQUEST['payflow']) && '1' == $_REQUEST['payflow']) { echo wpsc_get_customer_meta('payflow_message'); wpsc_delete_customer_meta('payflow_message'); } $dont_show_transaction_results = false; if ($selected_gateway) { // Replaces the ugly if else for gateways switch ($selected_gateway) { case 'paypal_certified': case 'wpsc_merchant_paypal_express': echo wpsc_get_customer_meta('paypal_express_message'); $reshash = wpsc_get_customer_meta('paypal_express_reshash'); if (isset($reshash['PAYMENTINFO_0_TRANSACTIONTYPE']) && in_array($reshash['PAYMENTINFO_0_TRANSACTIONTYPE'], array('expresscheckout', 'cart'))) { $dont_show_transaction_results = false; } else { $dont_show_transaction_results = true; } break; case 'dps': $sessionid = decrypt_dps_response(); break; //paystation was not updating the purchase logs for successful payment - this is ugly as need to have the databse update done in one place by all gatways on a sucsessful transaction hook not some within the gateway and some within here and some not at all??? This is getting a major overhaul but for here and now it just needs to work for the gold cart people! //paystation was not updating the purchase logs for successful payment - this is ugly as need to have the databse update done in one place by all gatways on a sucsessful transaction hook not some within the gateway and some within here and some not at all??? This is getting a major overhaul but for here and now it just needs to work for the gold cart people! case 'paystation': $ec = $_GET['ec']; $result = $_GET['em']; if ($result == 'Transaction successful' && $ec == 0) { $processed_id = '3'; } if ($result == 'Insufficient Funds' && $ec == 5) { $processed_id = '6'; } if ($processed_id) { wpsc_update_purchase_log_status($sessionid, $processed_id, 'sessionid'); } break; case 'wpsc_merchant_paymentexpress': // Payment Express sends back there own session id, which is temporarily stored in the Auth field // so just swapping that over here $query = "SELECT `sessionid` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `authcode` ='" . $sessionid . "'"; $result = $wpdb->get_var($query); if ($result != null) { // just in case they are using an older version old gold cart (pre 2.9.5) $sessionid = $result; $dont_show_transaction_results = true; } break; case 'eway_hosted': $sessionid = decrypt_eway_uk_response(); break; //default filter for other payment gateways to use //default filter for other payment gateways to use default: $sessionid = apply_filters('wpsc_previous_selected_gateway_' . $selected_gateway, $sessionid); break; } } if (!$dont_show_transaction_results) { if (!empty($sessionid)) { $cart_log_id = $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= %s LIMIT 1", $sessionid)); echo transaction_results($sessionid, true); } else { printf(__('Sorry your transaction was not accepted.<br /><a href="%1$s">Click here to go back to checkout page</a>.', 'wp-e-commerce'), wpsc_get_checkout_url()); } } }
function wpec_auth_net_user_profile_display() { $myGateway = new wpec_auth_net(); $creditcards = $myGateway->getCreditCardProfiles(); $bankaccounts = $myGateway->getBankAccountProfiles(); $shipaddress = $myGateway->getShippingProfiles(); $auth_net_message = wpsc_get_customer_meta('auth_net_message'); ?> <div id='wpec_auth_net_user_profile_manager'> <h2><?php _e('Saved Credit Card, Bank and Shipping Information', 'wpsc_gold_cart'); ?> </h2> <?php if (isGood($auth_net_message)) { ?> <div class='notice'><?php echo $auth_net_message; ?> </div> <?php wpsc_delete_customer_meta('auth_net_message'); } if ($bankaccounts) { ?> <form action="<?php echo $wpec_auth_net_user_profile_url; ?> " method="post"> <div id='bankaccounts'class='sectionBox'> <span class="sectionHeader"><?php _e("Bank Accounts You've Saved For Easy Checkout.", 'wpsc_gold_cart'); ?> </span> <div class="displayList"><?php echo $bankaccounts; ?> </div> <input type='hidden' name='type' value='bankaccounts'> <input type='submit' name='submit' class='btn' value='Delete'> </div> </form> <?php } ?> <?php if ($creditcards) { ?> <form action="<?php echo $wpec_auth_net_user_profile_url; ?> " method="post"> <div id='creditcards'class='sectionBox'> <span class="sectionHeader"><?php _e("Credit Cards You've Saved For Easy Checkout.", 'wpsc_gold_cart'); ?> </span> <div class="displayList"><?php echo $creditcards; ?> </div> <input type='hidden' name='type' value='creditcards'> <input type='submit' name='submit' class='btn' value='Delete'> </div> </form> <?php } ?> <?php if ($shipaddress) { ?> <form action="<?php echo $wpec_auth_net_user_profile_url; ?> " method="post"> <div id='shipaddress'class='sectionBox'> <span class="sectionHeader"><?php _e("Shipping Addresses You've Saved For Easy Checkout.", 'wpsc_gold_cart'); ?> </span> <div class="displayList"><?php echo $shipaddress; ?> </div> <input type='hidden' name='type' value='shippingaddress'> <input type='submit' class='btn' name='submit' value='Delete'> </div> </form> <?php } ?> </div> <?php }
public function _action_shutdown() { $this->wizard->reset(); wpsc_delete_customer_meta('current_purchase_log_id'); }
function rewind_checkout_items() { global $wpsc_checkout_error_messages; $wpsc_checkout_error_messages = array(); wpsc_delete_customer_meta('checkout_error_messages'); $this->current_checkout_item = -1; if ($this->checkout_item_count > 0) { $this->checkout_item = $this->checkout_items[0]; } }
/** * Confirm Transaction Callback * * @return bool * * @since 3.9 */ public function callback_confirm_transaction() { if (!isset($_REQUEST['sessionid']) || !isset($_REQUEST['token']) || !isset($_REQUEST['PayerID'])) { return false; } // Set the Purchase Log $this->set_purchase_log_for_callbacks(); // Display the Confirmation Page $this->do_transaction(); // Remove Shortcut option if it exists $sessionid = $_REQUEST['sessionid']; wpsc_delete_customer_meta('esc-' . $sessionid); }
/** * cleanup method, cleans up the cart just before final destruction * * @access public * * No parameters, nothing returned */ function cleanup() { wpsc_delete_customer_meta('coupon'); $claimed_query = new WPSC_Claimed_Stock(array('cart_id' => $this->unique_id)); $claimed_query->clear_claimed_stock(0); }
/** * clear shipping error messages * * @since 3.8.14.1 * * @access private * */ function _wpsc_clear_shipping_error_messages() { wpsc_delete_customer_meta('shipping_error_messages'); }
/** * submit checkout function, used through ajax and in normal page loading. * No parameters, returns nothing */ function wpsc_submit_checkout($collected_data = true) { global $wpdb, $wpsc_cart, $user_ID, $nzshpcrt_gateways, $wpsc_shipping_modules, $wpsc_gateways; $num_items = 0; $use_shipping = 0; $disregard_shipping = 0; do_action('wpsc_before_submit_checkout'); $error_messages = wpsc_get_customer_meta('checkout_misc_error_messages'); if (!is_array($error_messages)) { $error_messages = array(); } $wpsc_checkout = new wpsc_checkout(); $selected_gateways = get_option('custom_gateway_options'); $submitted_gateway = isset($_POST['custom_gateway']) ? $_POST['custom_gateway'] : ''; $options = get_option('custom_shipping_options'); if ($collected_data) { $form_validity = $wpsc_checkout->validate_forms(); extract($form_validity); // extracts $is_valid and $error_messages if (wpsc_has_tnc() && (!isset($_POST['agree']) || $_POST['agree'] != 'yes')) { $error_messages[] = __('Please agree to the terms and conditions, otherwise we cannot process your order.', 'wpsc'); $is_valid = false; } } else { $is_valid = true; $error_messages = array(); } $selectedCountry = $wpdb->get_results($wpdb->prepare("SELECT id, country FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE isocode = '%s' ", wpsc_get_customer_meta('shipping_country')), ARRAY_A); foreach ($wpsc_cart->cart_items as $cartitem) { if (!empty($cartitem->meta[0]['no_shipping'])) { continue; } $categoriesIDs = $cartitem->category_id_list; foreach ((array) $categoriesIDs as $catid) { if (is_array($catid)) { $countries = wpsc_get_meta($catid[0], 'target_market', 'wpsc_category'); } else { $countries = wpsc_get_meta($catid, 'target_market', 'wpsc_category'); } if (!empty($countries) && !in_array($selectedCountry[0]['id'], (array) $countries)) { $errormessage = sprintf(__('%s cannot be shipped to %s. To continue with your transaction please remove this product from the list below.', 'wpsc'), $cartitem->get_title(), $selectedCountry[0]['country']); wpsc_update_customer_meta('category_shipping_conflict', $errormessage); $is_valid = false; } } //count number of items, and number of items using shipping $num_items++; if ($cartitem->uses_shipping != 1) { $disregard_shipping++; } else { $use_shipping++; } } if (array_search($submitted_gateway, $selected_gateways) !== false) { wpsc_update_customer_meta('selected_gateway', $submitted_gateway); } else { $is_valid = false; } if ($collected_data) { if (get_option('do_not_use_shipping') == 0 && ($wpsc_cart->selected_shipping_method == null || $wpsc_cart->selected_shipping_option == null) && $num_items != $disregard_shipping) { $error_messages[] = __('You must select a shipping method, otherwise we cannot process your order.', 'wpsc'); $is_valid = false; } if (get_option('do_not_use_shipping') != 1 && in_array('ups', (array) $options) && !wpsc_get_customer_meta('shipping_zip') && $num_items != $disregard_shipping) { wpsc_update_customer_meta('category_shipping_conflict', __('Please enter a Zipcode and click calculate to proceed', 'wpsc')); $is_valid = false; } } wpsc_update_customer_meta('checkout_misc_error_messages', $error_messages); if ($is_valid == true) { wpsc_delete_customer_meta('category_shipping_conflict'); // check that the submitted gateway is in the list of selected ones $sessionid = mt_rand(100, 999) . time(); wpsc_update_customer_meta('checkout_session_id', $sessionid); $subtotal = $wpsc_cart->calculate_subtotal(); if ($wpsc_cart->has_total_shipping_discount() == false) { $base_shipping = $wpsc_cart->calculate_base_shipping(); } else { $base_shipping = 0; } $delivery_country = $wpsc_cart->delivery_country; $delivery_region = $wpsc_cart->delivery_region; if (wpsc_uses_shipping()) { $shipping_method = $wpsc_cart->selected_shipping_method; $shipping_option = $wpsc_cart->selected_shipping_option; } else { $shipping_method = ''; $shipping_option = ''; } if (isset($_POST['how_find_us'])) { $find_us = $_POST['how_find_us']; } else { $find_us = ''; } //keep track of tax if taxes are exclusive $wpec_taxes_controller = new wpec_taxes_controller(); if (!$wpec_taxes_controller->wpec_taxes_isincluded()) { $tax = $wpsc_cart->calculate_total_tax(); $tax_percentage = $wpsc_cart->tax_percentage; } else { $tax = 0.0; $tax_percentage = 0.0; } $total = $wpsc_cart->calculate_total_price(); $args = array('totalprice' => $total, 'statusno' => '0', 'sessionid' => $sessionid, 'user_ID' => (int) $user_ID, 'date' => time(), 'gateway' => $submitted_gateway, 'billing_country' => $wpsc_cart->selected_country, 'shipping_country' => $delivery_country, 'billing_region' => $wpsc_cart->selected_region, 'shipping_region' => $delivery_region, 'base_shipping' => $base_shipping, 'shipping_method' => $shipping_method, 'shipping_option' => $shipping_option, 'plugin_version' => WPSC_VERSION, 'discount_value' => $wpsc_cart->coupons_amount, 'discount_data' => $wpsc_cart->coupons_name, 'find_us' => $find_us, 'wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage); $purchase_log = new WPSC_Purchase_Log($args); $purchase_log->save(); $purchase_log_id = $purchase_log->get('id'); if ($collected_data) { $wpsc_checkout->save_forms_to_db($purchase_log_id); } $wpsc_cart->save_to_db($purchase_log_id); $wpsc_cart->submit_stock_claims($purchase_log_id); if (get_option('wpsc_also_bought') == 1) { wpsc_populate_also_bought_list(); } if (!isset($our_user_id) && isset($user_ID)) { $our_user_id = $user_ID; } $wpsc_cart->log_id = $purchase_log_id; do_action('wpsc_submit_checkout', array("purchase_log_id" => $purchase_log_id, "our_user_id" => $our_user_id)); if (get_option('permalink_structure') != '') { $separator = "?"; } else { $separator = "&"; } // submit to gateway $current_gateway_data =& $wpsc_gateways[$submitted_gateway]; if (isset($current_gateway_data['api_version']) && $current_gateway_data['api_version'] >= 2.0) { $merchant_instance = new $current_gateway_data['class_name']($purchase_log_id); $merchant_instance->construct_value_array(); do_action_ref_array('wpsc_pre_submit_gateway', array(&$merchant_instance)); $merchant_instance->submit(); } elseif ($current_gateway_data['internalname'] == $submitted_gateway && $current_gateway_data['internalname'] != 'google') { $gateway_used = $current_gateway_data['internalname']; $purchase_log->set('gateway', $gateway_used); $purchase_log->save(); $current_gateway_data['function']($separator, $sessionid); } elseif ($current_gateway_data['internalname'] == 'google' && $current_gateway_data['internalname'] == $submitted_gateway) { $gateway_used = $current_gateway_data['internalname']; $purchase_log->set('gateway', $gateway_used); wpsc_update_customer_meta('google_checkout', 'google'); wp_redirect(get_option('shopping_cart_url')); exit; } } }
function getQuote() { global $wpdb, $wpec_ash; if (!is_object($wpec_ash)) { $wpec_ash = new ASH(); } // Arguments array for various functions to use $args = array(); // Final rate table $rate_table = array(); // Get the ups settings from the ups account info page (Shipping tab) $wpsc_ups_settings = get_option("wpsc_ups_settings", array()); // Get the wordpress shopping cart options $wpsc_options = get_option("wpsc_options"); // API Auth settings // $args['username'] = array_key_exists('upsaccount', $wpsc_ups_settings) ? $wpsc_ups_settings['upsusername'] : ""; $args['password'] = array_key_exists('upspassword', $wpsc_ups_settings) ? $wpsc_ups_settings['upspassword'] : ""; $args['api_id'] = array_key_exists('upsid', $wpsc_ups_settings) ? $wpsc_ups_settings['upsid'] : ""; $args['account_number'] = array_key_exists('upsaccount', $wpsc_ups_settings) ? $wpsc_ups_settings['upsaccount'] : ""; $args['negotiated_rates'] = array_key_exists('ups_negotiated_rates', $wpsc_ups_settings) ? $wpsc_ups_settings['ups_negotiated_rates'] : ""; $args['residential'] = $wpsc_ups_settings['49_residential']; $args["singular_shipping"] = array_key_exists("singular_shipping", $wpsc_ups_settings) ? $wpsc_ups_settings["singular_shipping"] : "0"; $args['insured_shipment'] = array_key_exists("insured_shipment", $wpsc_ups_settings) ? $wpsc_ups_settings["insured_shipment"] : "0"; // What kind of pickup service do you use ? $args['DropoffType'] = $wpsc_ups_settings['DropoffType']; $args['packaging'] = $wpsc_ups_settings['48_container']; // Preferred Currency to display $currency_data = $wpdb->get_row($wpdb->prepare("SELECT `code`\n FROM `" . WPSC_TABLE_CURRENCY_LIST . "`\n WHERE `isocode`= %s\n LIMIT 1", get_option('currency_type')), ARRAY_A); if ($currency_data) { $args['currency'] = $currency_data['code']; } else { $args['currency'] = "USD"; } // Shipping billing / account address $origin_region_data = $wpdb->get_results($wpdb->prepare("SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "`\n WHERE `" . WPSC_TABLE_REGION_TAX . "`.`id` = %d ", get_option('base_region')), ARRAY_A); $args['shipr_state'] = is_array($origin_region_data) ? $origin_region_data[0]['code'] : ""; $args['shipr_city'] = get_option('base_city'); $args['shipr_ccode'] = get_option('base_country'); $args['shipr_pcode'] = get_option('base_zipcode'); // Physical Shipping address being shipped from $args['shipf_state'] = $args['shipr_state']; $args['shipf_city'] = $args['shipr_city']; $args['shipf_ccode'] = $args['shipr_ccode']; $args['shipf_pcode'] = $args['shipr_pcode']; // Get the total weight from the shopping cart $args['units'] = "LBS"; $args['weight'] = wpsc_cart_weight_total(); // Destination zip code $args['dest_ccode'] = wpsc_get_customer_meta('shipping_country'); if ($args['dest_ccode'] == "UK") { // So, UPS is a little off the times $args['dest_ccode'] = "GB"; } // If ths zip code is provided via a form post use it! $args['dest_pcode'] = (string) wpsc_get_customer_meta('shipping_zip'); if (isset($_POST['zipcode']) && ($_POST['zipcode'] != __("Your Zipcode", 'wpsc') && $_POST['zipcode'] != "YOURZIPCODE")) { $args['dest_pcode'] = esc_attr($_POST['zipcode']); } if (in_array($args['dest_pcode'], array(__('Your Zipcode', 'wpsc'), 'YOURZIPCODE'))) { $args['dest_pcode'] = ''; } wpsc_update_customer_meta('shipping_zip', $args['dest_pcode']); if (empty($args['dest_pcode'])) { // We cannot get a quote without a zip code so might as well return! return array(); } // If the region code is provided via a form post use it! if (isset($_POST['region']) && !empty($_POST['region'])) { $query = $wpdb->prepare("SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "`\n WHERE `" . WPSC_TABLE_REGION_TAX . "`.`id` = %d", $_POST['region']); $dest_region_data = $wpdb->get_results($query, ARRAY_A); $args['dest_state'] = is_array($dest_region_data) ? $dest_region_data[0]['code'] : ""; wpsc_update_customer_meta('ups_state', $args['dest_state']); } else { if ($dest_state = wpsc_get_customer_meta('ups_state')) { // Well, we have a zip code in the session and no new one provided $args['dest_state'] = $dest_state; } else { $args['dest_state'] = ""; } } $shipping_cache_check['state'] = $args['dest_state']; $shipping_cache_check['zipcode'] = $args['dest_pcode']; $shipping_cache_check['weight'] = $args['weight']; $session_cache_check = wpsc_get_customer_meta('ups_shipping_cache_check'); if (!is_array($session_cache_check)) { $session_cache_check = array(); } $session_cache = wpsc_get_customer_meta('ups_shipping_cache'); if (!is_array($session_cache)) { $session_cache = array(); } if (!(bool) $args["singular_shipping"]) { // This is where shipping breaks out of UPS if weight is higher than 150 LBS if ($weight > 150) { wpsc_delete_customer_meta('quote_shipping_method'); $shipping_quotes[TXT_WPSC_OVER_UPS_WEIGHT] = 0; $session_cache_check['weight'] = $args['weight']; $session_cache[$this->internal_name] = $shipping_quotes; wpsc_update_customer_meta('quote_shipping_method', $this->internal_name); wpsc_update_customer_meta('ups_shipping_cache_check', $session_cache_check); wpsc_update_customer_meta('ups_shipping_cache', $session_cache); return array($shipping_quotes); } } // We do not want to spam UPS (and slow down our process) if we already // have a shipping quote! if ($session_cache_check === $shipping_cache_check && !empty($session_cache[$this->internal_name])) { $rate_table = $session_cache[$this->internal_name]; return $rate_table; } else { global $wpsc_cart; $args["cart_total"] = $wpsc_cart->calculate_subtotal(true); // Build the XML request $request = $this->_buildRateRequest($args); // Now that we have the message to send ... Send it! $raw_quote = $this->_makeRateRequest($request); // Now we have the UPS response .. unfortunately its not ready // to be viewed by normal humans ... $quotes = $this->_parseQuote($raw_quote); // If we actually have rates back from UPS we can use em! if ($quotes != false) { $rate_table = $this->_formatTable($quotes, $args['currency']); } else { if ($wpsc_ups_settings['upsenvironment'] == '1') { echo "<strong>:: GetQuote ::DEBUG OUTPUT::</strong><br />"; echo "Arguments sent to UPS"; print_r($args); echo "<hr />"; print $request; echo "<hr />"; echo "Response from UPS"; echo $raw_quote; echo "</strong>:: GetQuote ::End DEBUG OUTPUT::"; } } } $wpec_ash->cache_results($this->internal_name, $args["dest_ccode"], $args["dest_state"], $args["dest_pcode"], $rate_table, $this->shipment); // return the final formatted array ! return $rate_table; }
function nzsc_googleResponse() { global $wpdb, $user_ID; $merchant_id = get_option('google_id'); $merchant_key = get_option('google_key'); $server_type = get_option('google_server_type'); $currency = get_option('google_cur'); $xml_response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input"); define('RESPONSE_HANDLER_ERROR_LOG_FILE', 'library/googleerror.log'); define('RESPONSE_HANDLER_LOG_FILE', 'library/googlemessage.log'); if (stristr($_SERVER['HTTP_USER_AGENT'], "Google Checkout Notification Agent")) { $Gresponse = new GoogleResponse($merchant_id, $merchant_key); $xml_response = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : file_get_contents("php://input"); if (get_magic_quotes_gpc()) { $xml_response = stripslashes($xml_response); } list($root, $data) = $Gresponse->GetParsedXML($xml_response); $message = "<pre>" . print_r($user_marketing_preference, 1) . "</pre>"; $sessionid = mt_rand(100, 999) . time(); if ($root == "new-order-notification") { wpsc_delete_customer_meta('nzshpcart'); $cart_items = $data['new-order-notification']['shopping-cart']['items']; $user_marketing_preference = $data['new-order-notification']['buyer-marketing-preferences']['email-allowed']['VALUE']; $shipping_name = $data['new-order-notification']['buyer-shipping-address']['contact-name']['VALUE']; $shipping_name = explode(" ", $shipping_name); $shipping_firstname = $shipping_name[0]; $shipping_lastname = $shipping_name[count($shipping_name) - 1]; $shipping_country = $data['new-order-notification']['buyer-shipping-address']['country-code']['VALUE']; $shipping_address1 = $data['new-order-notification']['buyer-shipping-address']['address1']['VALUE']; $shipping_address2 = $data['new-order-notification']['buyer-shipping-address']['address2']['VALUE']; $shipping_city = $data['new-order-notification']['buyer-shipping-address']['city']['VALUE']; $shipping_region = $data['new-order-notification']['buyer-shipping-address']['region']['VALUE']; $billing_name = $data['new-order-notification']['buyer-billing-address']['contact-name']['VALUE']; $billing_name = explode(" ", $shipping_name); $billing_firstname = $shipping_name[0]; $billing_lastname = $shipping_name[count($shipping_name) - 1]; $billing_region = $data['new-order-notification']['buyer-billing-address']['region']['VALUE']; $billing_country = $data['new-order-notification']['buyer-billing-address']['country-code']['VALUE']; $total_price = $data['new-order-notification']['order-total']['VALUE']; $billing_email = $data['new-order-notification']['buyer-billing-address']['email']['VALUE']; $billing_phone = $data['new-order-notification']['buyer-billing-address']['phone']['VALUE']; $billing_address = $data['new-order-notification']['buyer-billing-address']['address1']['VALUE']; $billing_address .= " " . $data['new-order-notification']['buyer-billing-address']['address2']['VALUE']; $billing_address .= " " . $data['new-order-notification']['buyer-billing-address']['city']['VALUE']; $billing_city = $data['new-order-notification']['buyer-billing-address']['city']['VALUE']; $google_order_number = $data['new-order-notification']['google-order-number']['VALUE']; $pnp = $data['new-order-notification']['order-adjustment']['shipping']['flat-rate-shipping-adjustment']['shipping-cost']['VALUE']; $affiliate_id = $data['new-order-notification']['shopping-cart']['merchant-private-data']; $affiliate_id = explode('=', $affiliate_id); if ($affiliate_id[0] == 'affiliate_id') { if ($affiliate_id[1] == '') { $affiliate_id = null; } else { $affiliate_id = $affiliate_id[1]; } } $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); $result = $Grequest->SendProcessOrder($google_order_number); $region_number = $wpdb->get_var($wpdb->prepare("SELECT id FROM " . WPSC_TABLE_REGION_TAX . "` WHERE code = %s", $billing_region)); $wpdb->insert(WPSC_TABLE_PURCHASE_LOGS, array('totalprice' => $total_price, 'sessionid' => $sessionid, 'date' => time(), 'billing_country' => $billing_country, 'shipping_country' => $shipping_country, 'base_shipping' => $pnp, 'shipping_region' => $region_number, 'user_ID' => $user_ID, 'discount_value' => wpsc_get_customer_meta('wpsc_discount'), 'gateway' => get_option('payment_gateway'), 'google_order_number' => $google_order_number, 'google_user_marketing_preference' => $user_marketing_preference, 'affiliate_id' => $affiliate_id), array('%f', '%s', '%s', '%s', '%s', '%f', '%s', '%d', '%f', '%s', '%s', '%s', '%s')); $log_id = $wpdb->get_var($wpdb->prepare("SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid` IN(%s) LIMIT 1", $sessionid)); $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('firstname' => $shipping_firstname, 'lastname' => $shipping_lastname, 'email' => $billing_email, 'phone' => $billing_phone), array('id' => $log_id), '%s', '%d'); if (array_key_exists(0, $cart_items['item'])) { $cart_items = $cart_items['item']; } //logging to submited_form_data $billing_fname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='first_name' LIMIT 1"); $sql = "INSERT INTO `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` (log_id, form_id, value) VALUES ('" . $log_id . "','" . $billing_fname_id . "','" . esc_sql($billing_firstname) . "')"; $billing_lname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='last_name' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_lname_id . "','" . esc_sql($billing_lastname) . "')"; $billing_address_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='address' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_address_id . "','" . esc_sql($billing_address) . "')"; $billing_city_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='city' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_city_id . "','" . esc_sql($billing_city) . "')"; $billing_country_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='country' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_country_id . "','" . esc_sql($billing_country) . "')"; $billing_state_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='state' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $billing_state_id . "','" . esc_sql($billing_region) . "')"; $shipping_fname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_first_name' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_fname_id . "','" . esc_sql($shipping_firstname) . "')"; $shipping_lname_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_last_name' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_lname_id . "','" . esc_sql($shipping_lastname) . "')"; $shipping_address_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_address' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_address_id . "','" . esc_sql($shipping_address1) . " " . esc_sql($shipping_address2) . "')"; $shipping_city_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_city' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_city_id . "','" . esc_sql($shipping_city) . "')"; $shipping_state_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_state' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_state_id . "','" . esc_sql($shipping_region) . "')"; $shipping_country_id = $wpdb->get_var("SELECT `id` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "` WHERE `type`='delivery_country' LIMIT 1"); $sql .= ", ('" . $log_id . "','" . $shipping_country_id . "','" . esc_sql($shipping_country) . "')"; $wpdb->query($sql); foreach ($cart_items as $cart_item) { $product_id = $cart_item['merchant-item-id']['VALUE']; $item_name = $cart_item['item-name']['VALUE']; $item_desc = $cart_item['item-description']['VALUE']; $item_unit_price = $cart_item['unit-price']['VALUE']; $item_quantity = $cart_item['quantity']['VALUE']; $product_info = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . $wpdb->posts . "` WHERE id= %d LIMIT 1", $product_id), ARRAY_A); $product_info = $product_info[0]; if ($product_info['notax'] != 1) { if (get_option('base_country') == $billing_country) { $country_data = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE `isocode` IN(%s) LIMIT 1", get_option('base_country')), ARRAY_A); if ($country_data['has_regions'] == 1) { if (get_option('base_region') == $region_number) { $region_data = $wpdb->get_row($wpdb->prepare("SELECT `" . WPSC_TABLE_REGION_TAX . "`.* FROM `" . WPSC_TABLE_REGION_TAX . "` WHERE `" . WPSC_TABLE_REGION_TAX . "`.`country_id` IN(%d) AND `" . WPSC_TABLE_REGION_TAX . "`.`id` IN(%d)", $country_data['id'], get_option('base_region')), ARRAY_A); } $gst = $region_data['tax']; } else { $gst = $country_data['tax']; } } else { $gst = 0; } } else { $gst = 0; } if ($product_info['no_shipping'] == '0') { if ($shipping_country == get_option('base_country')) { $pnp = $product_info['pnp']; } else { $pnp = $product_info['international_pnp']; } } else { $pnp = 0; } $wpdb->insert(WPSC_TABLE_CART_CONTENTS, array('prodid' => $product_id, 'purchaseid' => $log_id, 'price' => $item_unit_price, 'pnp' => $pnp, 'gst' => $gst, 'quantity' => $item_quantity, 'donation' => $product_info['donation'], 'no_shipping' => $product_info['no_shipping']), array('%d', '%d', '%s', '%f', '%f', '%d', '%s', '%s')); } } if ($root == "order-state-change-notification") { $google_order_number = $data['order-state-change-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var($wpdb->prepare("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number = %s", $google_order_number)); $google_status = unserialize($google_status); if ($google_status[0] != 'Partially Charged' && $google_status[0] != 'Partially Refunded') { $google_status[0] = $data['order-state-change-notification']['new-financial-order-state']['VALUE']; $google_status[1] = $data['order-state-change-notification']['new-fulfillment-order-state']['VALUE']; } $google_status = serialize($google_status); $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('google_status' => $google_status), array('google_order_number' => $google_order_number)); if ($data['order-state-change-notification']['new-financial-order-state']['VALUE'] == 'CHARGEABLE' && get_option('google_auto_charge') == '1') { $Grequest = new GoogleRequest($merchant_id, $merchant_key, $server_type, $currency); $result = $Grequest->SendChargeOrder($google_order_number); wpsc_delete_customer_meta('nzshpcart'); wpsc_delete_customer_meta('coupon'); wpsc_delete_customer_meta('google_session'); $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('processed' => '3'), array('google_order_number' => $google_order_number)); } } if ($root == "charge-amount-notification") { $google_order_number = $data['charge-amount-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var($wpdb->prepare("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number = %s", $google_order_number)); $google_status = unserialize($google_status); $total_charged = $data['charge-amount-notification']['total-charge-amount']['VALUE']; $google_status['partial_charge_amount'] = $total_charged; $totalprice = $wpdb->get_var($wpdb->prepare("SELECT totalprice FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number = %s", $google_order_number)); if ($totalprice > $total_charged) { $google_status[0] = 'Partially Charged'; } else { if ($totalprice = $total_charged) { $google_status[0] = 'CHARGED'; } } $google_status = serialize($google_status); $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('google_status' => $google_status), array('google_order_number' => $google_order_number)); } if ($root == "refund-amount-notification") { $google_order_number = $data['refund-amount-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var($wpdb->prepare("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number= %s", $google_order_number)); $google_status = unserialize($google_status); $total_charged = $data['refund-amount-notification']['total-refund-amount']['VALUE']; $google_status['partial_refund_amount'] = $total_charged; $totalprice = $wpdb->get_var($wpdb->prepare("SELECT totalprice FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number = %s", $google_order_number)); if ($totalprice > $total_charged) { $google_status[0] = 'Partially refunded'; } else { if ($totalprice = $total_charged) { $google_status[0] = 'REFUNDED'; } } $google_status = serialize($google_status); $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('google_status' => $google_status), array('google_order_number' => $google_order_number)); } if ($root == "risk-information-notification") { $google_order_number = $data['risk-information-notification']['google-order-number']['VALUE']; $google_status = $wpdb->get_var($wpdb->prepare("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number = %s", $google_order_number)); $google_status = unserialize($google_status); $google_status['cvn'] = $data['risk-information-notification']['risk-information']['cvn-response']['VALUE']; $google_status['avs'] = $data['risk-information-notification']['risk-information']['avs-response']['VALUE']; $google_status['protection'] = $data['risk-information-notification']['risk-information']['eligible-for-protection']['VALUE']; $google_status = serialize($google_status); $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('google_status' => $google_status), array('google_order_number' => $google_order_number)); if ($data['risk-information-notification']['risk-information']['cvn-response']['VALUE'] == 'E') { $google_risk = 'cvn'; } if (in_array($data['risk-information-notification']['risk-information']['avs-response']['VALUE'], array('N', 'U'))) { if (isset($google_risk)) { $google_risk = 'cvn+avs'; } else { $google_risk = 'avs'; } } if (isset($google_risk)) { $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('google_risk' => $google_risk), array('google_order_number' => $google_order_number)); } } if ($root == "order-state-change-notification") { $google_order_number = $data['order-state-change-notification']['google-order-number']['VALUE']; if ($data['order-state-change-notification']['new-financial-order-state']['VALUE'] == "CANCELLED_BY_GOOGLE") { $google_status = $wpdb->get_var($wpdb->prepare("SELECT google_status FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE google_order_number = %s", $google_order_number)); $google_status = unserialize($google_status); $google_status[0] = "CANCELLED_BY_GOOGLE"; $wpdb->update(WPSC_TABLE_PURCHASE_LOGS, array('google_status' => serialize($google_status)), array('google_order_number' => $google_order_number)); } } exit; } }