Changeset 2689760
- Timestamp:
- 03/07/2022 04:00:46 AM (4 years ago)
- Location:
- appture-pay
- Files:
-
- 11 added
- 6 edited
-
tags/1.5.0 (added)
-
tags/1.5.0/MeprAppturePayGateway.php (added)
-
tags/1.5.0/appturelab-appture-pay.php (added)
-
tags/1.5.0/class-wc-gateway-appture-pay.php (added)
-
tags/1.5.0/class-wc-shipping-appture-pay.php (added)
-
tags/1.5.0/img (added)
-
tags/1.5.0/img/logo_wordpress_20.png (added)
-
tags/1.5.0/includes (added)
-
tags/1.5.0/includes/AppturePayAPI.php (added)
-
tags/1.5.0/includes/ApptureWebRequest.php (added)
-
tags/1.5.0/readme.txt (added)
-
trunk/appturelab-appture-pay.php (modified) (5 diffs)
-
trunk/class-wc-gateway-appture-pay.php (modified) (5 diffs)
-
trunk/class-wc-shipping-appture-pay.php (modified) (7 diffs)
-
trunk/includes/AppturePayAPI.php (modified) (19 diffs)
-
trunk/includes/ApptureWebRequest.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
appture-pay/trunk/appturelab-appture-pay.php
r2605388 r2689760 4 4 * Plugin URI: https://www.appturepay.com/plugins 5 5 * Description: Unify payment and shipping providers with Appture Pay - for merchants in South Africa. Works with WooCommerce and MemberPress. 6 * Version: 1. 4.46 * Version: 1.5.0 7 7 * Requires at least: 5.2 8 8 * Requires PHP: 7.2 … … 15 15 * 16 16 * WC requires at least: 3.7 17 * WC tested up to: 3.7.117 * WC tested up to: 6.2.1 18 18 * 19 19 * Mepr requires at least: 1.9.3 … … 248 248 add_filter( 'woocommerce_payment_gateways', 'appturelab_appturepay_add_gateway' ); 249 249 250 251 // Save settings in admin if you have any defined 252 //add_action('woocommerce_update_options_shipping', 'process_admin_options'); 253 254 // Save delivery id and service meta data on the order as it is created 255 add_action('woocommerce_checkout_create_order', 'appturelab_appturepay_before_checkout_create_order', 20, 2); 256 257 // purge transients so we can be sure a new delivery is generated for the next order, after completion of an order 258 add_action('woocommerce_new_order', 'appturelab_appturepay_woocommerce_new_order', 10, 1); 259 250 260 } 251 261 … … 273 283 $mepr_gateway_paths[] = untrailingslashit(plugin_dir_path( __FILE__ )); 274 284 return $mepr_gateway_paths; 285 } 286 287 function appturelab_appturepay_woocommerce_new_order( $order ) { 288 // purge transients 289 global $wpdb; 290 291 //error_log("Purge shipping rates"); 292 293 $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_wc_ship%'" ); 294 295 // Delete all the wc_ship transient scum, you aren’t wanted around here, move along. 296 // Same as being in shipping debug mode 297 $transients = $wpdb->get_col(" 298 SELECT option_name FROM $wpdb->options 299 WHERE option_name LIKE '_transient_wc_ship%'" 300 ); 301 302 if (count($transients)) { 303 foreach ($transients as $tr) { 304 $hash = substr($tr, 11); 305 //error_log("Deleted? ".intval(delete_transient($hash))); 306 } 307 } 308 309 $transient_value = get_transient("shipping-transient-version"); 310 WC_Cache_Helper::delete_version_transients($transient_value); 311 312 if(WC()->session) { 313 WC()->session->set("shipping_for_package", ""); 314 WC()->session->set("shipping_for_package_0", ""); 315 WC()->session->set('appturepay_shipping_delivery_id',0); 316 } 317 } 318 319 function appturelab_appturepay_validate_add_cart_item( $passed, $product_id, $quantity, $variation_id = '', $variations= '' ) { 320 321 // call purge when this is a new cart 322 if ( sizeof( WC()->cart->get_cart() ) == 0 ) { 323 appturelab_appturepay_woocommerce_new_order( null ); 324 } 325 326 return true; 327 328 } 329 add_filter( 'woocommerce_add_to_cart_validation', 'appturelab_appturepay_validate_add_cart_item', 10, 5 ); 330 331 function appturelab_appturepay_before_checkout_create_order($order, $package) { 332 333 $shipping = new WC_Shipping_Appture_Pay(); 334 $shipping->before_checkout_create_order($order, $package); 335 275 336 } 276 337 … … 530 591 return in_array( 'memberpress/memberpress.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ); 531 592 } 593 594 // 3rd party dsv courier's slow server is causing timeout issues so we added these 595 add_filter('http_request_args', 'appturelab_appturepay_http_request_args', 100, 1); 596 function appturelab_appturepay_http_request_args($r) //called on line 237 597 { 598 $r['timeout'] = 15; 599 return $r; 600 } 601 add_action('http_api_curl', 'appturelab_appturepay_http_api_curl', 100, 1); 602 function appturelab_appturepay_http_api_curl($handle) //called on line 1315 603 { 604 curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, 15 ); 605 curl_setopt( $handle, CURLOPT_TIMEOUT, 15 ); 606 } -
appture-pay/trunk/class-wc-gateway-appture-pay.php
r2605388 r2689760 10 10 $this->has_fields = false; 11 11 $this->method_title = "Appture Pay"; 12 $this->method_description = "Appture Pay works by sending the user to Appture Pay's Gateway to enter their payment information.";12 $this->method_description = "Appture Pay works by sending the user to Appture Pay's secure Gateway to enter their payment information."; 13 13 $this->available_countries = array( 'ZA' ); 14 14 … … 67 67 'type' => 'text', 68 68 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ), 69 'default' => __( ' Credit or debitcard', 'woocommerce' ),69 'default' => __( 'Visa or Mastercard', 'woocommerce' ), 70 70 'desc_tip' => true, 71 71 ), … … 74 74 'type' => 'textarea', 75 75 'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce' ), 76 'default' => __("Pay via Appture Pay using your Visa, Mastercard or other creditcard", 'woocommerce')76 'default' => __("Pay via Appture Pay using a Visa or Mastercard bank card", 'woocommerce') 77 77 ) 78 78 ); … … 240 240 ); 241 241 242 if($data["itn"] ) {242 if($data["itn"] !== null) { 243 243 244 244 $this->log( 'Appture Pay: Check ITN' ); … … 783 783 */ 784 784 public function log($message) { 785 //error_log($message); 785 786 if ($this->enable_logging) { 786 787 if (empty($this->logger)) { -
appture-pay/trunk/class-wc-shipping-appture-pay.php
r2605388 r2689760 30 30 $this->init_form_fields(); // This is part of the settings API. Override the method to add your own settings 31 31 $this->init_settings(); // This is part of the settings API. Loads settings you previously init. 32 33 // Save settings in admin if you have any defined34 add_action('woocommerce_update_options_shipping_' . $this->id, array($this, 'process_admin_options'));35 36 // Save delivery id and service meta data on the order as it is created37 add_action('woocommerce_checkout_create_order', array($this, 'before_checkout_create_order'), 20, 2);38 39 // purge transients so we can be sure a new delivery is generated for the next order, after completion of an order40 add_action('woocommerce_new_order', array($this, 'woocommerce_new_order'), 10, 1);41 }42 43 function woocommerce_new_order () {44 $this->purge_transients();45 }46 47 function purge_transients() {48 global $wpdb;49 50 $this->log("Purge shipping rates");51 52 $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_wc_ship%'" );53 54 // Delete all the wc_ship transient scum, you aren’t wanted around here, move along.55 // Same as being in shipping debug mode56 /*$transients = $wpdb->get_col("57 SELECT option_name FROM $wpdb->options58 WHERE option_name LIKE '_transient_wc_ship%'"59 );60 61 if (count($transients)) {62 foreach ($transients as $tr) {63 $hash = substr($tr, 11);64 $this->log("Deleted? ".intval(delete_transient($hash)));65 }66 }*/67 68 $transient_value = get_transient("shipping-transient-version");69 WC_Cache_Helper::delete_version_transients($transient_value);70 71 if(WC()->session) {72 WC()->session->set("shipping_for_package", "");73 WC()->session->set("shipping_for_package_0", "");74 WC()->session->set('appturepay_shipping_delivery_id',0);75 }76 32 } 77 33 … … 151 107 "products" => array(), 152 108 "value" => $package["contents_cost"], 153 "insurance" => 0 // addinsurance by default109 "insurance" => 0 // no insurance by default 154 110 ); 155 111 foreach ( $package['contents'] as $item_id => $values ) { 156 112 $_product = $values['data']; 157 113 $quote_payload["products"][] = array( 114 "value" => $package["contents_cost"]/count($package['contents']), 158 115 "weight" => max(1,intval($_product->get_weight())), // expecting kg 159 116 "width" => intval($_product->get_width()) * 10, // expecting mm … … 184 141 "delivery_contact_number_1" => "N/A", 185 142 "delivery_contact_number_2" => "", 186 "delivery_street" => empty($package['destination']["address_1"]) ? "Quoting - no street address provided" : implode(", ", array_filter( array( $package['destination']["address_1"], $package['destination']["address_2"] ) )),143 "delivery_street" => empty($package['destination']["address_1"]) ? "Quoting" : implode(", ", array_filter( array( $package['destination']["address_1"], $package['destination']["address_2"] ) )), 187 144 "delivery_suburb" => $package['destination']["city"], 188 145 "delivery_city" => $package['destination']["city"], … … 194 151 195 152 // courier check the address 196 $response = $api->delivery CheckPostalCode($deliveryAddress["delivery_postal_code"], array("city" => $deliveryAddress["delivery_city"]));153 $response = $api->deliveryGetCheckPostalCode($deliveryAddress["delivery_postal_code"], array("city" => $deliveryAddress["delivery_city"])); 197 154 $this->log("Delivery Check Postal Code: ".json_encode($response)); 198 155 199 if($response && isset($response["success"]) && $response["success"]) { 200 201 // great, its been checked 202 $deliveryAddress["delivery_courier_checked"] = 1; 156 if($response && isset($response["success"])) { 157 158 if($response["success"]) { 159 160 // great, its been checked 161 $deliveryAddress["delivery_courier_checked"] = 1; 162 163 } else if($response["message"] == "Address validated to possible places by courier") { 164 165 // run through possible items and make sure we get atleast one item to match town and postal code provided 166 foreach($response["data"] as $item) { 167 if($item["Town"] == $deliveryAddress["delivery_city"] && $item["PostalCode"] == $deliveryAddress["delivery_postal_code"]) { 168 169 // great, its been checked 170 $deliveryAddress["delivery_courier_checked"] = 1; 171 break; 172 } 173 } 174 175 } else { 176 177 return; 178 179 } 203 180 204 181 } else { … … 261 238 ) 262 239 ); 240 241 $this->log("Set session rate: ".json_encode($rate)); 263 242 264 243 // Register the rate … … 295 274 } 296 275 } 276 277 $this->log("Should remove delivery ID:".($service !== null). " && ". ($delivery_id !== null)); 297 278 298 279 if ($service !== null && $delivery_id !== null) { … … 347 328 */ 348 329 public function log($message) { 349 error_log($message);330 //error_log($message); 350 331 if ($this->enable_logging) { 351 332 if (empty($this->logger)) { -
appture-pay/trunk/includes/AppturePayAPI.php
r2605388 r2689760 29 29 $this->authClient(); 30 30 } 31 31 32 return AppturePayAPI::$session; 32 33 } … … 59 60 60 61 $response = $this->doWebRequest("POST", "auth/access_token", $payload, $headers); 61 $ curlInfo = $this->getCurlInfo();62 63 if($ curlInfo && $curlInfo["http_code"] === 200) {62 $requestInfo = $this->getRequestInfo(); 63 64 if($requestInfo && $requestInfo["http_code"] === 200) { 64 65 $response["time"] = microtime(true); 65 66 $response["client_id"] = $this->clientId; … … 99 100 100 101 $response = $this->doWebRequest("POST", "auth/access_token", $payload, $headers); 101 $ curlInfo = $this->getCurlInfo();102 $requestInfo = $this->getRequestInfo(); 102 103 103 if($ curlInfo && $curlInfo["http_code"] === 200) {104 if($requestInfo && $requestInfo["http_code"] === 200) { 104 105 $response["time"] = microtime(true); 105 106 $response["client_id"] = $this->clientId; … … 133 134 134 135 $response = $this->doWebRequest("POST", "auth/revoke_token", $payload, $headers); 135 $ curlInfo = $this->getCurlInfo();136 $requestInfo = $this->getRequestInfo(); 136 137 137 if($ curlInfo && $curlInfo["http_code"] === 200) {138 if($requestInfo && $requestInfo["http_code"] === 200) { 138 139 AppturePayAPI::$session = null; 139 140 $_SESSION["session"] = null; … … 182 183 183 184 $response = $this->doWebRequest("GET", "transaction?". http_build_query($parameters), null, $headers); 184 $ curlInfo = $this->getCurlInfo();185 $response[" curl"] = $curlInfo;185 $requestInfo = $this->getRequestInfo(); 186 $response["request"] = $requestInfo; 186 187 187 188 return $response; … … 209 210 210 211 $response = $this->doWebRequest("POST", "transaction", $data, $headers); 211 $ curlInfo = $this->getCurlInfo();212 $response[" curl"] = $curlInfo;212 $requestInfo = $this->getRequestInfo(); 213 $response["request"] = $requestInfo; 213 214 214 215 return $response; … … 235 236 236 237 $response = $this->doWebRequest("GET", "transaction/{$id}", null, $headers); 237 $ curlInfo = $this->getCurlInfo();238 $response[" curl"] = $curlInfo;238 $requestInfo = $this->getRequestInfo(); 239 $response["request"] = $requestInfo; 239 240 240 241 return $response; … … 261 262 262 263 $response = $this->doWebRequest("DELETE", "transaction/{$id}", null, $headers); 263 $ curlInfo = $this->getCurlInfo();264 $response[" curl"] = $curlInfo;264 $requestInfo = $this->getRequestInfo(); 265 $response["request"] = $requestInfo; 265 266 266 267 return $response; … … 288 289 289 290 $response = $this->doWebRequest("PUT", "transaction/{$id}/capture", $data, $headers); 290 $ curlInfo = $this->getCurlInfo();291 $response[" curl"] = $curlInfo;291 $requestInfo = $this->getRequestInfo(); 292 $response["request"] = $requestInfo; 292 293 293 294 return $response; … … 315 316 316 317 $response = $this->doWebRequest("PUT", "transaction/{$id}/reverse", $data, $headers); 317 $ curlInfo = $this->getCurlInfo();318 $response[" curl"] = $curlInfo;318 $requestInfo = $this->getRequestInfo(); 319 $response["request"] = $requestInfo; 319 320 320 321 return $response; … … 342 343 343 344 $response = $this->doWebRequest("GET", "recurring_transaction/{$id}", null, $headers); 344 $ curlInfo = $this->getCurlInfo();345 $response[" curl"] = $curlInfo;345 $requestInfo = $this->getRequestInfo(); 346 $response["request"] = $requestInfo; 346 347 347 348 return $response; … … 369 370 370 371 $response = $this->doWebRequest("PUT", "recurring_transaction/{$id}", $data, $headers); 371 $ curlInfo = $this->getCurlInfo();372 $response[" curl"] = $curlInfo;372 $requestInfo = $this->getRequestInfo(); 373 $response["request"] = $requestInfo; 373 374 374 375 return $response; … … 396 397 397 398 $response = $this->doWebRequest("GET", "delivery?". http_build_query($parameters), null, $headers); 398 $ curlInfo = $this->getCurlInfo();399 $response[" curl"] = $curlInfo;399 $requestInfo = $this->getRequestInfo(); 400 $response["request"] = $requestInfo; 400 401 401 402 return $response; … … 447 448 448 449 $response = $this->doWebRequest("POST", "delivery", $data, $headers); 449 $ curlInfo = $this->getCurlInfo();450 $response[" curl"] = $curlInfo;450 $requestInfo = $this->getRequestInfo(); 451 $response["request"] = $requestInfo; 451 452 452 453 return $response; … … 474 475 475 476 $response = $this->doWebRequest("PUT", "delivery/{$id}", $data, $headers); 476 $ curlInfo = $this->getCurlInfo();477 $response[" curl"] = $curlInfo;477 $requestInfo = $this->getRequestInfo(); 478 $response["request"] = $requestInfo; 478 479 479 480 return $response; … … 500 501 501 502 $response = $this->doWebRequest("DELETE", "delivery/{$id}", null, $headers); 502 $ curlInfo = $this->getCurlInfo();503 $response[" curl"] = $curlInfo;503 $requestInfo = $this->getRequestInfo(); 504 $response["request"] = $requestInfo; 504 505 505 506 return $response; … … 610 611 611 612 $response = $this->doWebRequest("POST", "delivery/{$id}/quote", $data, $headers); // note that we are POSTing for this PUT 612 $ curlInfo = $this->getCurlInfo();613 $response[" curl"] = $curlInfo;613 $requestInfo = $this->getRequestInfo(); 614 $response["request"] = $requestInfo; 614 615 615 616 return $response; … … 637 638 638 639 $response = $this->doWebRequest("PUT", "delivery/{$id}/quote", $data, $headers); // note that we are POSTing for this PUT 639 $ curlInfo = $this->getCurlInfo();640 $response[" curl"] = $curlInfo;640 $requestInfo = $this->getRequestInfo(); 641 $response["request"] = $requestInfo; 641 642 642 643 return $response; … … 664 665 665 666 $response = $this->doWebRequest("PUT", "delivery/{$id}/dispatch", $data, $headers); // note that we are POSTing for this PUT 666 $ curlInfo = $this->getCurlInfo();667 $response[" curl"] = $curlInfo;667 $requestInfo = $this->getRequestInfo(); 668 $response["request"] = $requestInfo; 668 669 669 670 return $response; -
appture-pay/trunk/includes/ApptureWebRequest.php
r2605388 r2689760 16 16 private static $calls = array(); 17 17 18 protected function get CurlInfo() {18 protected function getRequestInfo() { 19 19 if($this->lastCurlInfo) { 20 20 return $this->lastCurlInfo; … … 74 74 75 75 //extute the request and store the respond 76 $this->lastResponse = wp_remote_request($wp_url, $wp_args); 77 $this->lastCurlInfo = (json_decode($this->lastResponse['body'], true)); 76 $this->lastResponse = wp_remote_request($wp_url, $wp_args); 77 78 if(!is_wp_error( $this->lastResponse )) { 79 80 $this->lastCurlInfo = json_decode($this->lastResponse['body'], true); 78 81 79 //Add http_code to accomodate AppturePayAPI_functions80 $this->lastCurlInfo['http_code'] = $this->lastResponse['response']['code'];82 //Add http_code to accomodate AppturePayAPI_functions 83 $this->lastCurlInfo['http_code'] = $this->lastResponse['response']['code']; 81 84 82 // Return headers seperatly from the Response Body83 $headers = $this->lastResponse['headers'];84 $body = $this->lastResponse['body'];85 // Return headers seperatly from the Response Body 86 $headers = $this->lastResponse['headers']; 87 $body = $this->lastResponse['body']; 85 88 89 ApptureWebRequest::$totalTime += (microtime(true)-$time); 90 ApptureWebRequest::$calls[] = array("url" => $this->apiUrl.$url, "method" => $method, "time" => microtime(true)-$time); 86 91 87 ApptureWebRequest::$totalTime += (microtime(true)-$time); 88 ApptureWebRequest::$calls[] = array("url" => $this->apiUrl.$url, "method" => $method, "time" => microtime(true)-$time); 89 90 if (is_wp_error($this->lastResponse)) { 91 return array("error" => "Request Failed - Check URL");//, "curl" => $this->lastCurlInfo); 92 } 93 94 $dec = json_decode($body, true); 95 if (!$dec) { 96 return array("error" => "Invalid JSON returned", "response" => $this->lastResponse); 92 if (is_wp_error($this->lastResponse)) { 93 return array("error" => "Request Failed - Check URL");//, "curl" => $this->lastCurlInfo); 94 } 95 96 $dec = json_decode($body, true); 97 if (!$dec) { 98 return array("error" => "Invalid JSON returned", "response" => $this->lastResponse); 99 } 100 101 } else { 102 return array("error" => $this->lastResponse->get_error_message(), "request" => array("wp_url"=>$wp_url, "wp_args"=>$wp_args)); 97 103 } 98 104 -
appture-pay/trunk/readme.txt
r2605388 r2689760 1 1 === Appture Pay === 2 2 Tags: woocommerce, memberpress, payment provider, shipping provider 3 Stable tag: 1. 4.43 Stable tag: 1.5.0 4 4 Requires at least: 5.2 5 Tested up to: 5. 85 Tested up to: 5.9 6 6 License: GPLv2 or later 7 7 License URI: http://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset
for help on using the changeset viewer.