| Conditions | 19 |
| Paths | 4352 |
| Total Lines | 168 |
| Code Lines | 95 |
| Lines | 0 |
| Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 11 | function gateway_chronopay($separator, $sessionid) |
||
|
|
|||
| 12 | { |
||
| 13 | global $wpdb; |
||
| 14 | $purchase_log_sql = $wpdb->prepare( "SELECT * FROM `".WPSC_TABLE_PURCHASE_LOGS."` WHERE `sessionid`= %s LIMIT 1", $sessionid ); |
||
| 15 | $purchase_log = $wpdb->get_results($purchase_log_sql,ARRAY_A) ; |
||
| 16 | |||
| 17 | $cart_sql = "SELECT * FROM `".WPSC_TABLE_CART_CONTENTS."` WHERE `purchaseid`='".$purchase_log[0]['id']."'"; |
||
| 18 | $cart = $wpdb->get_results($cart_sql,ARRAY_A) ; |
||
| 19 | |||
| 20 | // ChronoPay post variables |
||
| 21 | $chronopay_url = get_option('chronopay_url'); |
||
| 22 | |||
| 23 | $data['product_id'] = get_option('chronopay_product_id'); |
||
| 24 | $data['product_name'] = get_option('chronopay_product_name'); |
||
| 25 | $data['product_price_currency'] = get_option('chronopay_curcode'); |
||
| 26 | $data['language'] = get_option('chronopay_language'); |
||
| 27 | $data['cb_url'] = add_query_arg( 'chronopay_callback', 'true', home_url( '/' ) ); |
||
| 28 | $data['cb_type'] = 'P'; |
||
| 29 | $data['decline_url'] = home_url( '/?chronopay_callback=true' ); |
||
| 30 | $data['cs1'] = $sessionid; |
||
| 31 | $data['cs2'] = 'chronopay'; |
||
| 32 | $salt = get_option('chronopay_salt'); |
||
| 33 | $data['cs3'] = md5($salt . md5($sessionid . $salt)); // placed in here for security so that the return call can be validated as 'real' |
||
| 34 | |||
| 35 | // User details |
||
| 36 | if($_POST['collected_data'][get_option('chronopay_form_first_name')] != '') |
||
| 37 | { |
||
| 38 | $data['f_name'] = $_POST['collected_data'][get_option('chronopay_form_first_name')]; |
||
| 39 | } |
||
| 40 | if($_POST['collected_data'][get_option('chronopay_form_last_name')] != "") |
||
| 41 | { |
||
| 42 | $data['s_name'] = $_POST['collected_data'][get_option('chronopay_form_last_name')]; |
||
| 43 | } |
||
| 44 | if($_POST['collected_data'][get_option('chronopay_form_address')] != '') |
||
| 45 | { |
||
| 46 | $data['street'] = str_replace("\n",', ', $_POST['collected_data'][get_option('chronopay_form_address')]); |
||
| 47 | } |
||
| 48 | if($_POST['collected_data'][get_option('chronopay_form_city')] != '') |
||
| 49 | { |
||
| 50 | $data['city'] = $_POST['collected_data'][get_option('chronopay_form_city')]; |
||
| 51 | } |
||
| 52 | |||
| 53 | $data['country'] = (string) wpsc_get_customer_meta( 'billingcountry' ); |
||
| 54 | |||
| 55 | // Change suggested by [email protected], if email to be sent is not there, dont send an email address |
||
| 56 | $email_data = $wpdb->get_results("SELECT `id`,`type` FROM `".WPSC_TABLE_CHECKOUT_FORMS."` WHERE `type` IN ('email') AND `active` = '1'",ARRAY_A); |
||
| 57 | foreach((array)$email_data as $email) |
||
| 58 | { |
||
| 59 | $data['email'] = $_POST['collected_data'][$email['id']]; |
||
| 60 | } |
||
| 61 | if(($_POST['collected_data'][get_option('email_form_field')] != null) && ($data['email'] == null)) |
||
| 62 | { |
||
| 63 | $data['email'] = $_POST['collected_data'][get_option('email_form_field')]; |
||
| 64 | } |
||
| 65 | |||
| 66 | // Get Currency details abd price |
||
| 67 | $currency_code = WPSC_Countries::get_currency_code( get_option( 'currency_type' ) ); |
||
| 68 | $local_currency_code = $currency_code[0]['code']; |
||
| 69 | $chronopay_currency_code = get_option('chronopay_curcode'); |
||
| 70 | |||
| 71 | // ChronoPay only processes in the set currency. This is USD or EUR dependent on what the Chornopay account is set up with. |
||
| 72 | // This must match the ChronoPay settings set up in wordpress. Convert to the chronopay currency and calculate total. |
||
| 73 | $curr=new CURRENCYCONVERTER(); |
||
| 74 | $decimal_places = 2; |
||
| 75 | $total_price = 0; |
||
| 76 | |||
| 77 | $i = 1; |
||
| 78 | |||
| 79 | $all_donations = true; |
||
| 80 | $all_no_shipping = true; |
||
| 81 | |||
| 82 | foreach($cart as $item) |
||
| 83 | { |
||
| 84 | $product_data = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `" . $wpdb->posts . "` WHERE `id`= %d LIMIT 1", $item['prodid'] ), ARRAY_A ); |
||
| 85 | $product_data = $product_data[0]; |
||
| 86 | $variation_count = count($product_variations); |
||
| 87 | |||
| 88 | //Does this even still work in 3.8? We're not using this table. |
||
| 89 | $variation_sql = $wpdb->prepare( "SELECT * FROM `".WPSC_TABLE_CART_ITEM_VARIATIONS."` WHERE `cart_id` = %d", $item['id'] ); |
||
| 90 | $variation_data = $wpdb->get_results( $variation_sql, ARRAY_A ); |
||
| 91 | $variation_count = count($variation_data); |
||
| 92 | |||
| 93 | if($variation_count >= 1) |
||
| 94 | { |
||
| 95 | $variation_list = " ("; |
||
| 96 | $j = 0; |
||
| 97 | |||
| 98 | foreach($variation_data as $variation) |
||
| 99 | { |
||
| 100 | if($j > 0) |
||
| 101 | { |
||
| 102 | $variation_list .= ", "; |
||
| 103 | } |
||
| 104 | $value_id = $variation['venue_id']; |
||
| 105 | $value_data = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `".WPSC_TABLE_VARIATION_VALUES."` WHERE `id`= %d LIMIT 1", $value_id ), ARRAY_A); |
||
| 106 | $variation_list .= $value_data[0]['name']; |
||
| 107 | $j++; |
||
| 108 | } |
||
| 109 | $variation_list .= ")"; |
||
| 110 | } |
||
| 111 | else |
||
| 112 | { |
||
| 113 | $variation_list = ''; |
||
| 114 | } |
||
| 115 | |||
| 116 | $local_currency_productprice = $item['price']; |
||
| 117 | |||
| 118 | $local_currency_shipping = $item['pnp']; |
||
| 119 | |||
| 120 | |||
| 121 | $chronopay_currency_productprice = $local_currency_productprice; |
||
| 122 | $chronopay_currency_shipping = $local_currency_shipping; |
||
| 123 | |||
| 124 | $data['item_name_'.$i] = $product_data['name'].$variation_list; |
||
| 125 | $data['amount_'.$i] = number_format(sprintf("%01.2f", $chronopay_currency_productprice),$decimal_places,'.',''); |
||
| 126 | $data['quantity_'.$i] = $item['quantity']; |
||
| 127 | $data['item_number_'.$i] = $product_data['id']; |
||
| 128 | |||
| 129 | if($item['donation'] !=1) |
||
| 130 | { |
||
| 131 | $all_donations = false; |
||
| 132 | $data['shipping_'.$i] = number_format($chronopay_currency_shipping,$decimal_places,'.',''); |
||
| 133 | $data['shipping2_'.$i] = number_format($chronopay_currency_shipping,$decimal_places,'.',''); |
||
| 134 | } |
||
| 135 | else |
||
| 136 | { |
||
| 137 | $data['shipping_'.$i] = number_format(0,$decimal_places,'.',''); |
||
| 138 | $data['shipping2_'.$i] = number_format(0,$decimal_places,'.',''); |
||
| 139 | } |
||
| 140 | |||
| 141 | if($product_data['no_shipping'] != 1) { |
||
| 142 | $all_no_shipping = false; |
||
| 143 | } |
||
| 144 | |||
| 145 | |||
| 146 | $total_price = $total_price + ($data['amount_'.$i] * $data['quantity_'.$i]); |
||
| 147 | |||
| 148 | if( $all_no_shipping != false ) |
||
| 149 | $total_price = $total_price + $data['shipping_'.$i] + $data['shipping2_'.$i]; |
||
| 150 | |||
| 151 | $i++; |
||
| 152 | } |
||
| 153 | $base_shipping = $purchase_log[0]['base_shipping']; |
||
| 154 | if(($base_shipping > 0) && ($all_donations == false) && ($all_no_shipping == false)) |
||
| 155 | { |
||
| 156 | $data['handling_cart'] = number_format($base_shipping,$decimal_places,'.',''); |
||
| 157 | $total_price += number_format($base_shipping,$decimal_places,'.',''); |
||
| 158 | } |
||
| 159 | |||
| 160 | $data['product_price'] = $total_price; |
||
| 161 | |||
| 162 | // Create Form to post to ChronoPay |
||
| 163 | $output = " |
||
| 164 | <form id=\"chronopay_form\" name=\"chronopay_form\" method=\"post\" action=\"$chronopay_url\">\n"; |
||
| 165 | |||
| 166 | foreach($data as $n=>$v) { |
||
| 167 | $output .= " <input type=\"hidden\" name=\"$n\" value=\"$v\" />\n"; |
||
| 168 | } |
||
| 169 | |||
| 170 | $output .= " <input type=\"submit\" value=\"Continue to ChronoPay\" /> |
||
| 171 | </form> |
||
| 172 | "; |
||
| 173 | |||
| 174 | // Output the form. |
||
| 175 | echo $output; |
||
| 176 | echo "<script language=\"javascript\" type=\"text/javascript\">document.getElementById('chronopay_form').submit();</script>"; |
||
| 177 | exit(); |
||
| 178 | } |
||
| 179 | |||
| 453 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.