Plugin Directory

Changeset 2689760


Ignore:
Timestamp:
03/07/2022 04:00:46 AM (4 years ago)
Author:
appture
Message:

update to version 1.5.0

Location:
appture-pay
Files:
11 added
6 edited

Legend:

Unmodified
Added
Removed
  • appture-pay/trunk/appturelab-appture-pay.php

    r2605388 r2689760  
    44 * Plugin URI:        https://www.appturepay.com/plugins
    55 * Description:       Unify payment and shipping providers with Appture Pay - for merchants in South Africa. Works with WooCommerce and MemberPress.
    6  * Version:           1.4.4
     6 * Version:           1.5.0
    77 * Requires at least: 5.2
    88 * Requires PHP:      7.2
     
    1515 *
    1616 * WC requires at least: 3.7
    17  * WC tested up to: 3.7.1
     17 * WC tested up to: 6.2.1
    1818 *
    1919 * Mepr requires at least: 1.9.3
     
    248248        add_filter( 'woocommerce_payment_gateways', 'appturelab_appturepay_add_gateway' );
    249249       
     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       
    250260    }
    251261   
     
    273283    $mepr_gateway_paths[] = untrailingslashit(plugin_dir_path( __FILE__ ));
    274284    return $mepr_gateway_paths;
     285}
     286
     287function 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
     319function 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}
     329add_filter( 'woocommerce_add_to_cart_validation', 'appturelab_appturepay_validate_add_cart_item', 10, 5 );
     330
     331function 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   
    275336}
    276337
     
    530591    return in_array( 'memberpress/memberpress.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) );
    531592}
     593
     594// 3rd party dsv courier's slow server is causing timeout issues so we added these
     595add_filter('http_request_args', 'appturelab_appturepay_http_request_args', 100, 1);
     596function appturelab_appturepay_http_request_args($r) //called on line 237
     597{
     598    $r['timeout'] = 15;
     599    return $r;
     600}
     601add_action('http_api_curl', 'appturelab_appturepay_http_api_curl', 100, 1);
     602function 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  
    1010        $this->has_fields = false;
    1111        $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.";
    1313        $this->available_countries  = array( 'ZA' );
    1414       
     
    6767                'type' => 'text',
    6868                'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ),
    69                 'default' => __( 'Credit or debit card', 'woocommerce' ),
     69                'default' => __( 'Visa or Mastercard', 'woocommerce' ),
    7070                'desc_tip'      => true,
    7171            ),
     
    7474                'type' => 'textarea',
    7575                'description' => __( 'This controls the description which the user sees during checkout.', 'woocommerce' ),
    76                 'default' => __("Pay via Appture Pay using your Visa, Mastercard or other credit card", 'woocommerce')
     76                'default' => __("Pay via Appture Pay using a Visa or Mastercard bank card", 'woocommerce')
    7777            )
    7878        );
     
    240240        );
    241241       
    242         if($data["itn"]) {
     242        if($data["itn"] !== null) {
    243243           
    244244            $this->log( 'Appture Pay: Check ITN' );
     
    783783     */
    784784    public function log($message) {
     785        //error_log($message);
    785786        if ($this->enable_logging) {
    786787            if (empty($this->logger)) {
  • appture-pay/trunk/class-wc-shipping-appture-pay.php

    r2605388 r2689760  
    3030        $this->init_form_fields(); // This is part of the settings API. Override the method to add your own settings
    3131        $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 defined
    34         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 created
    37         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 order
    40         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 mode
    56         /*$transients = $wpdb->get_col("
    57             SELECT option_name FROM $wpdb->options
    58             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         }
    7632    }
    7733   
     
    151107            "products" => array(),
    152108            "value" => $package["contents_cost"],
    153             "insurance" => 0 // add insurance by default
     109            "insurance" => 0 // no insurance by default
    154110        );
    155111        foreach ( $package['contents'] as $item_id => $values ) {
    156112            $_product  = $values['data'];
    157113            $quote_payload["products"][] = array(
     114                "value" => $package["contents_cost"]/count($package['contents']),
    158115                "weight" => max(1,intval($_product->get_weight())), // expecting kg
    159116                "width" => intval($_product->get_width()) * 10, // expecting mm
     
    184141            "delivery_contact_number_1" => "N/A",
    185142            "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"] ) )),
    187144            "delivery_suburb" => $package['destination']["city"],
    188145            "delivery_city" => $package['destination']["city"],
     
    194151       
    195152        // courier check the address
    196         $response = $api->deliveryCheckPostalCode($deliveryAddress["delivery_postal_code"], array("city" => $deliveryAddress["delivery_city"]));
     153        $response = $api->deliveryGetCheckPostalCode($deliveryAddress["delivery_postal_code"], array("city" => $deliveryAddress["delivery_city"]));
    197154        $this->log("Delivery Check Postal Code: ".json_encode($response));
    198155       
    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            }
    203180           
    204181        } else {
     
    261238                    )
    262239                );
     240                   
     241                $this->log("Set session rate: ".json_encode($rate));
    263242
    264243                // Register the rate
     
    295274            }
    296275        }
     276       
     277        $this->log("Should remove delivery ID:".($service !== null). " && ". ($delivery_id !== null));
    297278
    298279        if ($service !== null && $delivery_id !== null) {
     
    347328     */
    348329    public function log($message) {
    349         error_log($message);
     330        //error_log($message);
    350331        if ($this->enable_logging) {
    351332            if (empty($this->logger)) {
  • appture-pay/trunk/includes/AppturePayAPI.php

    r2605388 r2689760  
    2929            $this->authClient();
    3030        }
     31       
    3132        return AppturePayAPI::$session;
    3233    }
     
    5960           
    6061            $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) {
    6465                $response["time"] = microtime(true);
    6566                $response["client_id"] = $this->clientId;
     
    99100       
    100101        $response = $this->doWebRequest("POST", "auth/access_token", $payload, $headers);
    101         $curlInfo = $this->getCurlInfo();
     102        $requestInfo = $this->getRequestInfo();
    102103
    103         if($curlInfo && $curlInfo["http_code"] === 200) {
     104        if($requestInfo && $requestInfo["http_code"] === 200) {
    104105            $response["time"] = microtime(true);
    105106            $response["client_id"] = $this->clientId;
     
    133134
    134135            $response = $this->doWebRequest("POST", "auth/revoke_token", $payload, $headers);
    135             $curlInfo = $this->getCurlInfo();
     136            $requestInfo = $this->getRequestInfo();
    136137
    137             if($curlInfo && $curlInfo["http_code"] === 200) {
     138            if($requestInfo && $requestInfo["http_code"] === 200) {
    138139                AppturePayAPI::$session = null;
    139140                $_SESSION["session"] = null;
     
    182183           
    183184            $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;
    186187           
    187188            return $response;
     
    209210           
    210211            $response = $this->doWebRequest("POST", "transaction", $data, $headers);
    211             $curlInfo = $this->getCurlInfo();
    212             $response["curl"] = $curlInfo;
     212            $requestInfo = $this->getRequestInfo();
     213            $response["request"] = $requestInfo;
    213214           
    214215            return $response;
     
    235236           
    236237            $response = $this->doWebRequest("GET", "transaction/{$id}", null, $headers);
    237             $curlInfo = $this->getCurlInfo();
    238             $response["curl"] = $curlInfo;
     238            $requestInfo = $this->getRequestInfo();
     239            $response["request"] = $requestInfo;
    239240           
    240241            return $response;
     
    261262           
    262263            $response = $this->doWebRequest("DELETE", "transaction/{$id}", null, $headers);
    263             $curlInfo = $this->getCurlInfo();
    264             $response["curl"] = $curlInfo;
     264            $requestInfo = $this->getRequestInfo();
     265            $response["request"] = $requestInfo;
    265266           
    266267            return $response;
     
    288289           
    289290            $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;
    292293           
    293294            return $response;
     
    315316           
    316317            $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;
    319320           
    320321            return $response;
     
    342343           
    343344            $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;
    346347           
    347348            return $response;
     
    369370           
    370371            $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;
    373374           
    374375            return $response;
     
    396397           
    397398            $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;
    400401           
    401402            return $response;
     
    447448           
    448449            $response = $this->doWebRequest("POST", "delivery", $data, $headers);
    449             $curlInfo = $this->getCurlInfo();
    450             $response["curl"] = $curlInfo;
     450            $requestInfo = $this->getRequestInfo();
     451            $response["request"] = $requestInfo;
    451452           
    452453            return $response;
     
    474475           
    475476            $response = $this->doWebRequest("PUT", "delivery/{$id}", $data, $headers);
    476             $curlInfo = $this->getCurlInfo();
    477             $response["curl"] = $curlInfo;
     477            $requestInfo = $this->getRequestInfo();
     478            $response["request"] = $requestInfo;
    478479           
    479480            return $response;
     
    500501           
    501502            $response = $this->doWebRequest("DELETE", "delivery/{$id}", null, $headers);
    502             $curlInfo = $this->getCurlInfo();
    503             $response["curl"] = $curlInfo;
     503            $requestInfo = $this->getRequestInfo();
     504            $response["request"] = $requestInfo;
    504505           
    505506            return $response;
     
    610611           
    611612            $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;
    614615           
    615616            return $response;
     
    637638           
    638639            $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;
    641642           
    642643            return $response;
     
    664665           
    665666            $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;
    668669           
    669670            return $response;
  • appture-pay/trunk/includes/ApptureWebRequest.php

    r2605388 r2689760  
    1616    private static $calls = array();
    1717   
    18     protected function getCurlInfo() {
     18    protected function getRequestInfo() {
    1919        if($this->lastCurlInfo) {
    2020            return $this->lastCurlInfo;
     
    7474
    7575        //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);
    7881
    79         //Add http_code to accomodate AppturePayAPI_functions
    80         $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'];
    8184
    82         // Return headers seperatly from the Response Body
    83         $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'];
    8588
     89            ApptureWebRequest::$totalTime += (microtime(true)-$time);
     90            ApptureWebRequest::$calls[] = array("url" => $this->apiUrl.$url, "method" => $method, "time" => microtime(true)-$time);
    8691
    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));
    97103        }
    98104
  • appture-pay/trunk/readme.txt

    r2605388 r2689760  
    11=== Appture Pay ===
    22Tags: woocommerce, memberpress, payment provider, shipping provider
    3 Stable tag: 1.4.4
     3Stable tag: 1.5.0
    44Requires at least: 5.2
    5 Tested up to: 5.8
     5Tested up to: 5.9
    66License: GPLv2 or later
    77License URI: http://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.