Plugin Directory

Changeset 2936473


Ignore:
Timestamp:
07/10/2023 10:18:02 AM (3 years ago)
Author:
tripleatechnology
Message:

releasing v2.0.7

Location:
triplea-cryptocurrency-payment-gateway-for-woocommerce
Files:
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • triplea-cryptocurrency-payment-gateway-for-woocommerce/tags/2.0.7/includes/WooCommerce/TripleA_Payment_Gateway.php

    r2925811 r2936473  
    7272        ]);
    7373
    74         // Refresh oauth tokens
    75         $this->refreshOauthTokens();
    76 
     74
     75          //will be called only for checkout page
     76          if ( is_checkout() ) {
     77
     78
     79            $this->logger->write_log( 'refreshOauthToken() will be called now from checkout page', $this->debugLog );
     80
     81            $this->refreshOauthTokens();
     82        }
     83        add_filter('http_headers_useragent', [ $this, 'custom_user_agent' ],10,2 );
    7784        add_filter('woocommerce_available_payment_gateways', [$this, 'triplea_exclude_if_subscription_product']);
    7885    }
     
    552559        );
    553560    }
    554 
     561    /**
     562     * @return boolean  true if the token is expired or invalid or null
     563     * @return boolean  false if the token is valid.
     564     */
     565    private function isOauthTokenInvalid(){
     566
     567        $date_now       = (new DateTime())->getTimestamp();
     568        $buffer_time     = 600; // 10 min buffer time, so new token will generated after 50 min
     569        $current_token_expiry   = $this->get_option('oauth_token_expiry');
     570        $current_token   = $this->get_option('oauth_token');
     571
     572        if (isset($this->clientID) && !empty($this->clientID)
     573        && isset($this->clientSecret) && !empty($this->clientSecret)
     574        && (!isset($current_token) || empty($current_token) ||
     575            $date_now >= ( $current_token_expiry - $buffer_time ))
     576        )
     577        {
     578            //time to gernerate new token
     579            return true;
     580        }
     581        else{
     582            //current token is valid
     583            return false;
     584        }
     585
     586
     587    }
     588    /**
     589     * Store new token into database if token validity expired
     590     */
    555591    private function refreshOauthTokens($refresh_for_api_id = FALSE) {
    556592
    557         $date_now          = (new DateTime())->getTimestamp();
    558         $date_expiry_limit = $date_now - 600;   // 10 minutes before expiry token
    559 
    560         if (isset($this->clientID) && !empty($this->clientID)
    561             && isset($this->clientSecret) && !empty($this->clientSecret)
    562             && (!isset($this->oauthToken) || empty($this->oauthToken) || $this->oauthTokenExpiry <= $date_expiry_limit)
    563         ) {
    564             if ($this->oauthTokenExpiry <= $date_expiry_limit) {
     593        $date_now       = (new DateTime())->getTimestamp();
     594        $buffer_time     = 600; // 10 min buffer time, so new token will generated after 50 min
     595        $current_token_expiry   = $this->get_option('oauth_token_expiry');
     596        $current_token   = $this->get_option('oauth_token');
     597
     598        if($this->isOauthTokenInvalid())
     599        {
     600            if ($date_now >= ( $current_token_expiry - $buffer_time)) {
    565601                $this->logger->write_log( 'refreshOauthToken() OAuth token (for local currency settlement) expires in less than 10 minutes. Requesting a new oauth token.', $this->debugLog );
    566602            }
     
    568604                $this->logger->write_log( 'refreshOauthToken() OAuth token (for local currency settlement) is missing. Requesting a new oauth token.', $this->debugLog );
    569605            }
     606
    570607
    571608            $new_token_data = $this->getOauthToken($this->clientID, $this->clientSecret);
     
    590627            }
    591628        }
    592     }
     629        else{
     630            if (!isset($this->clientID) || empty($this->clientID)) {
     631                $this->logger->write_log( 'refreshOauthToken() Client ID is not set ', $this->debugLog );
     632            }
     633            if(!isset($this->clientSecret) ||  empty($this->clientSecret)){
     634                $this->logger->write_log( 'refreshOauthToken() Client Secret ID is not set ', $this->debugLog );
     635            }
     636            if($date_now < ( $current_token_expiry - $buffer_time )){
     637
     638                $this->logger->write_log( 'refreshOauthToken() OAuth token (for local currency settlement) is still valid, so not requesting for a new one.', $this->debugLog );
     639            }
     640
     641        }
     642    }
     643
    593644    /**
    594645     * Generate new OAuth token if validity expired
    595646     */
    596647    private function refreshOauthTokensForForms($refresh_for_api_id = FALSE) {
    597 
    598648        $date_now       = (new DateTime())->getTimestamp();
    599649        $buffer_time     = 600; // 10 min buffer time, so new token will generated after 50 min
     
    601651        $current_token   = $this->get_option('oauth_token');
    602652
    603         if (isset($this->clientID) && !empty($this->clientID)
    604         && isset($this->clientSecret) && !empty($this->clientSecret)
    605         && (!isset($current_token) || empty($current_token) ||
    606             $date_now >= ( $current_token_expiry - $buffer_time ))
    607         )
     653        if($this->isOauthTokenInvalid())
    608654        {
    609655            if ($date_now >= ( $current_token_expiry - $buffer_time)) {
     
    662708        ];
    663709
    664         $this->logger->write_log( 'Making an oauth token request with body: \n' . wc_print_r($body, TRUE), $this->debugLog );
     710        // $this->logger->write_log( 'Making an oauth token request with body: \n' . wc_print_r($body, TRUE), $this->debugLog );
     711        $this->logger->write_log( 'Making an oauth token request with clinet id: \n' . wc_print_r($client_id, TRUE), $this->debugLog );
    665712
    666713        $result = wp_remote_post($post_url, [
     
    682729        return json_decode($result['body']);
    683730    }
    684 
     731    public static function custom_user_agent($user_agent, $url) {
     732
     733
     734        if (strpos($url, '/oauth/token') !== false || strpos($url, 'v2/payment') !== false  ) {
     735            // Modify the user agent to your desired value
     736            $version = get_option('wc_triplea_crypto_payment_version');
     737            $user_agent = $user_agent."; wc_triplea_crypto_payment:".$version;
     738
     739        }
     740        return $user_agent;
     741    }
    685742    /**
    686743     *
  • triplea-cryptocurrency-payment-gateway-for-woocommerce/tags/2.0.7/readme.txt

    r2925811 r2936473  
    66Tags: altcoin woocommerce, bitcoin payments, bitcoin, crypto payment gateway, crypto payments
    77Requires at least: 5.5
    8 Tested up to: 6.1.1
    9 Stable tag: 2.0.6
     8Tested up to: 6.2.2
     9Stable tag: 2.0.7
    1010Requires PHP: 7.0
    1111License: GPLv2 or later
     
    109109== Changelog ==
    110110
     111= 2.0.7 =
     112Fixed: Unusual token request from elementor or javascript from frontend
     113Fixed: Prevent printing confedential information into logs
     114Fixed: Add triple-a plugin version to user-agent
     115
    111116= 2.0.6 =
    112117Fixed: Multiple oAuth token generation request issue while calling the payment form issue fixed
     
    267272== Upgrade Notice ==
    268273
     274= 2.0.7 =
     275Simply install the update. No further action is needed.
     276
    269277= 2.0.6 =
    270278Simply install the update. No further action is needed.
  • triplea-cryptocurrency-payment-gateway-for-woocommerce/tags/2.0.7/triplea-cryptocurrency-payment-gateway-for-woocommerce.php

    r2925811 r2936473  
    1717 * Plugin URI:        https://wordpress.org/plugins/triplea-cryptocurrency-payment-gateway-for-woocommerce/
    1818 * Description:       Offer cryptocurrency as a payment option on your website and get access to even more clients. Receive payments in cryptocurrency or in your local currency, directly in your bank account. Enjoy an easy setup, no cryptocurrency expertise required. Powered by TripleA.
    19  * Version:           2.0.6
     19 * Version:           2.0.7
    2020 * Author:            TripleA Team
    2121 * Author URI:        https://triple-a.io
     
    4545     * $var string
    4646     */
    47     const version = '2.0.6';
     47    const version = '2.0.7';
    4848
    4949    /*
  • triplea-cryptocurrency-payment-gateway-for-woocommerce/trunk/includes/WooCommerce/TripleA_Payment_Gateway.php

    r2925811 r2936473  
    7272        ]);
    7373
    74         // Refresh oauth tokens
    75         $this->refreshOauthTokens();
    76 
     74
     75          //will be called only for checkout page
     76          if ( is_checkout() ) {
     77
     78
     79            $this->logger->write_log( 'refreshOauthToken() will be called now from checkout page', $this->debugLog );
     80
     81            $this->refreshOauthTokens();
     82        }
     83        add_filter('http_headers_useragent', [ $this, 'custom_user_agent' ],10,2 );
    7784        add_filter('woocommerce_available_payment_gateways', [$this, 'triplea_exclude_if_subscription_product']);
    7885    }
     
    552559        );
    553560    }
    554 
     561    /**
     562     * @return boolean  true if the token is expired or invalid or null
     563     * @return boolean  false if the token is valid.
     564     */
     565    private function isOauthTokenInvalid(){
     566
     567        $date_now       = (new DateTime())->getTimestamp();
     568        $buffer_time     = 600; // 10 min buffer time, so new token will generated after 50 min
     569        $current_token_expiry   = $this->get_option('oauth_token_expiry');
     570        $current_token   = $this->get_option('oauth_token');
     571
     572        if (isset($this->clientID) && !empty($this->clientID)
     573        && isset($this->clientSecret) && !empty($this->clientSecret)
     574        && (!isset($current_token) || empty($current_token) ||
     575            $date_now >= ( $current_token_expiry - $buffer_time ))
     576        )
     577        {
     578            //time to gernerate new token
     579            return true;
     580        }
     581        else{
     582            //current token is valid
     583            return false;
     584        }
     585
     586
     587    }
     588    /**
     589     * Store new token into database if token validity expired
     590     */
    555591    private function refreshOauthTokens($refresh_for_api_id = FALSE) {
    556592
    557         $date_now          = (new DateTime())->getTimestamp();
    558         $date_expiry_limit = $date_now - 600;   // 10 minutes before expiry token
    559 
    560         if (isset($this->clientID) && !empty($this->clientID)
    561             && isset($this->clientSecret) && !empty($this->clientSecret)
    562             && (!isset($this->oauthToken) || empty($this->oauthToken) || $this->oauthTokenExpiry <= $date_expiry_limit)
    563         ) {
    564             if ($this->oauthTokenExpiry <= $date_expiry_limit) {
     593        $date_now       = (new DateTime())->getTimestamp();
     594        $buffer_time     = 600; // 10 min buffer time, so new token will generated after 50 min
     595        $current_token_expiry   = $this->get_option('oauth_token_expiry');
     596        $current_token   = $this->get_option('oauth_token');
     597
     598        if($this->isOauthTokenInvalid())
     599        {
     600            if ($date_now >= ( $current_token_expiry - $buffer_time)) {
    565601                $this->logger->write_log( 'refreshOauthToken() OAuth token (for local currency settlement) expires in less than 10 minutes. Requesting a new oauth token.', $this->debugLog );
    566602            }
     
    568604                $this->logger->write_log( 'refreshOauthToken() OAuth token (for local currency settlement) is missing. Requesting a new oauth token.', $this->debugLog );
    569605            }
     606
    570607
    571608            $new_token_data = $this->getOauthToken($this->clientID, $this->clientSecret);
     
    590627            }
    591628        }
    592     }
     629        else{
     630            if (!isset($this->clientID) || empty($this->clientID)) {
     631                $this->logger->write_log( 'refreshOauthToken() Client ID is not set ', $this->debugLog );
     632            }
     633            if(!isset($this->clientSecret) ||  empty($this->clientSecret)){
     634                $this->logger->write_log( 'refreshOauthToken() Client Secret ID is not set ', $this->debugLog );
     635            }
     636            if($date_now < ( $current_token_expiry - $buffer_time )){
     637
     638                $this->logger->write_log( 'refreshOauthToken() OAuth token (for local currency settlement) is still valid, so not requesting for a new one.', $this->debugLog );
     639            }
     640
     641        }
     642    }
     643
    593644    /**
    594645     * Generate new OAuth token if validity expired
    595646     */
    596647    private function refreshOauthTokensForForms($refresh_for_api_id = FALSE) {
    597 
    598648        $date_now       = (new DateTime())->getTimestamp();
    599649        $buffer_time     = 600; // 10 min buffer time, so new token will generated after 50 min
     
    601651        $current_token   = $this->get_option('oauth_token');
    602652
    603         if (isset($this->clientID) && !empty($this->clientID)
    604         && isset($this->clientSecret) && !empty($this->clientSecret)
    605         && (!isset($current_token) || empty($current_token) ||
    606             $date_now >= ( $current_token_expiry - $buffer_time ))
    607         )
     653        if($this->isOauthTokenInvalid())
    608654        {
    609655            if ($date_now >= ( $current_token_expiry - $buffer_time)) {
     
    662708        ];
    663709
    664         $this->logger->write_log( 'Making an oauth token request with body: \n' . wc_print_r($body, TRUE), $this->debugLog );
     710        // $this->logger->write_log( 'Making an oauth token request with body: \n' . wc_print_r($body, TRUE), $this->debugLog );
     711        $this->logger->write_log( 'Making an oauth token request with clinet id: \n' . wc_print_r($client_id, TRUE), $this->debugLog );
    665712
    666713        $result = wp_remote_post($post_url, [
     
    682729        return json_decode($result['body']);
    683730    }
    684 
     731    public static function custom_user_agent($user_agent, $url) {
     732
     733
     734        if (strpos($url, '/oauth/token') !== false || strpos($url, 'v2/payment') !== false  ) {
     735            // Modify the user agent to your desired value
     736            $version = get_option('wc_triplea_crypto_payment_version');
     737            $user_agent = $user_agent."; wc_triplea_crypto_payment:".$version;
     738
     739        }
     740        return $user_agent;
     741    }
    685742    /**
    686743     *
  • triplea-cryptocurrency-payment-gateway-for-woocommerce/trunk/readme.txt

    r2925811 r2936473  
    66Tags: altcoin woocommerce, bitcoin payments, bitcoin, crypto payment gateway, crypto payments
    77Requires at least: 5.5
    8 Tested up to: 6.1.1
    9 Stable tag: 2.0.6
     8Tested up to: 6.2.2
     9Stable tag: 2.0.7
    1010Requires PHP: 7.0
    1111License: GPLv2 or later
     
    109109== Changelog ==
    110110
     111= 2.0.7 =
     112Fixed: Unusual token request from elementor or javascript from frontend
     113Fixed: Prevent printing confedential information into logs
     114Fixed: Add triple-a plugin version to user-agent
     115
    111116= 2.0.6 =
    112117Fixed: Multiple oAuth token generation request issue while calling the payment form issue fixed
     
    267272== Upgrade Notice ==
    268273
     274= 2.0.7 =
     275Simply install the update. No further action is needed.
     276
    269277= 2.0.6 =
    270278Simply install the update. No further action is needed.
  • triplea-cryptocurrency-payment-gateway-for-woocommerce/trunk/triplea-cryptocurrency-payment-gateway-for-woocommerce.php

    r2925811 r2936473  
    1717 * Plugin URI:        https://wordpress.org/plugins/triplea-cryptocurrency-payment-gateway-for-woocommerce/
    1818 * Description:       Offer cryptocurrency as a payment option on your website and get access to even more clients. Receive payments in cryptocurrency or in your local currency, directly in your bank account. Enjoy an easy setup, no cryptocurrency expertise required. Powered by TripleA.
    19  * Version:           2.0.6
     19 * Version:           2.0.7
    2020 * Author:            TripleA Team
    2121 * Author URI:        https://triple-a.io
     
    4545     * $var string
    4646     */
    47     const version = '2.0.6';
     47    const version = '2.0.7';
    4848
    4949    /*
Note: See TracChangeset for help on using the changeset viewer.