Plugin Directory

Changeset 2249399


Ignore:
Timestamp:
02/24/2020 03:48:31 PM (6 years ago)
Author:
CardGate
Message:

new pullConfig method implementation

Location:
cardgate
Files:
2 deleted
3 edited
6 copied

Legend:

Unmodified
Added
Removed
  • cardgate/tags/3.1.16/cardgate-clientlib-php/src/Client.php

    r2178570 r2249399  
    3636         * Client version.
    3737         */
    38         const CLIENT_VERSION = "1.1.12";
     38        const CLIENT_VERSION = "1.1.13";
    3939
    4040        /**
     
    383383         * @api
    384384         */
    385         static public function pullConfig( $sToken_, $bTestmode_ = FALSE ) {
     385        public function pullConfig( $sToken_ ) {
    386386            if ( ! is_string( $sToken_ ) ) {
    387387                throw new Exception( 'Client.Token.Invalid', 'invalid token for settings pull: ' . $sToken_ );
    388388            }
    389 
    390389            $sResource = "pullconfig/{$sToken_}/";
    391             $sUrl = ( $bTestmode_ ? self::URL_STAGING : self::URL_PRODUCTION ) . $sResource;
    392 
    393             $rCh = curl_init();
    394             curl_setopt( $rCh, CURLOPT_URL, $sUrl );
    395             curl_setopt( $rCh, CURLOPT_RETURNTRANSFER, 1 );
    396             curl_setopt( $rCh, CURLOPT_TIMEOUT, 60 );
    397             curl_setopt( $rCh, CURLOPT_HEADER, FALSE );
    398             curl_setopt( $rCh, CURLOPT_HTTPHEADER, [
    399                 'Content-Type: application/json',
    400                 'Accept: application/json'
    401             ] );
    402             if ( $bTestmode_ ) {
    403                 curl_setopt( $rCh, CURLOPT_SSL_VERIFYPEER, FALSE );
    404                 curl_setopt( $rCh, CURLOPT_SSL_VERIFYHOST, 0 );
    405             } else {
    406                 curl_setopt( $rCh, CURLOPT_SSL_VERIFYPEER, TRUE ); // verify SSL peer
    407                 curl_setopt( $rCh, CURLOPT_SSL_VERIFYHOST, 2 ); // check for valid common name and verify host
    408             }
    409 
    410             if ( FALSE == ( $sResults = curl_exec( $rCh ) ) ) {
    411                 $sError = curl_error( $rCh );
    412                 curl_close( $rCh );
    413                 throw new Exception( 'Client.Request.Curl.Error', $sError );
    414             } else {
    415                 curl_close( $rCh );
    416             }
    417             if ( NULL === ( $aResults = json_decode( $sResults, TRUE ) ) ) {
    418                 throw new Exception( 'Client.Request.JSON.Invalid', 'remote gave invalid JSON: ' . $sResults );
    419             }
    420             if ( isset( $aResults['error'] ) ) {
    421                 throw new Exception( 'Client.Request.Remote.' . $aResults['error']['code'], $aResults['error']['message'] );
    422             }
    423 
    424             return $aResults;
     390            return $this->doRequest($sResource);
    425391        }
    426392
  • cardgate/tags/3.1.16/cardgate.php

    r2178570 r2249399  
    77 * Text Domain: cardgate
    88 * Domain Path: /i18n/languages
    9  * Version: 3.1.15
     9 * Version: 3.1.16
    1010 * Requires at least: 4.4
    1111 * Author: CardGate
     
    4141            add_action('admin_notices', array(&$this,'my_error_notice'));
    4242    }
    43 
    44     // ////////////////////////////////////////////////
    4543   
    4644    /**
     
    428426            try {
    429427                require_once WP_PLUGIN_DIR . '/cardgate/cardgate-clientlib-php/init.php';
     428                $sVersion = ( $this->get_woocommerce_version() == '' ? 'unkown' : $this->get_woocommerce_version() );
     429                $sLanguage = substr( get_locale(), 0, 2 );
    430430                $bIsTest = ($_REQUEST['testmode'] == 1 ? true : false);
    431                 $aResult = cardgate\api\Client::pullConfig($_REQUEST['token'], $bIsTest);
    432                 $aConfigData = $aResult['pullconfig']['content'];
    433                 update_option('cgp_mode', $aConfigData['testmode']);
    434                 update_option('cgp_siteid', $aConfigData['site_id']);
    435                 update_option('cgp_hashkey', $aConfigData['site_key']);
    436                 update_option('cgp_merchant_id', $aConfigData['merchant_id']);
    437                 update_option('cgp_merchant_api_key', $aConfigData['api_key']);
    438                 die($aConfigData['merchant'] . '.' . get_option('cgp_siteid') . '.200');
     431                $iMerchantId = (int)(get_option('cgp_merchant_id')== false ? 0 : get_option('cgp_merchant_id'));
     432                $sMerchantApiKey = (get_option('cgp_merchant_api_key')== false ? 'initconfig' : get_option('cgp_merchant_api_key'));
     433                $oCardGate = new cardgate\api\Client( $iMerchantId, $sMerchantApiKey, $bIsTest );
     434                $oCardGate->setIp( $_SERVER['REMOTE_ADDR'] );
     435                $oCardGate->setLanguage( $sLanguage );
     436                $oCardGate->version()->setPlatformName( 'Woocommerce' );
     437                $oCardGate->version()->setPlatformVersion( $sVersion );
     438                $oCardGate->version()->setPluginName( 'CardGate' );
     439                $oCardGate->version()->setPluginVersion( get_option( 'cardgate_version' ) );
     440                $aResult = $oCardGate->pullConfig($_REQUEST['token']);
     441                if (isset($aResult['success']) && $aResult['success'] == 1){
     442                    $aConfigData = $aResult['pullconfig']['content'];
     443                    update_option('cgp_mode', $aConfigData['testmode']);
     444                    update_option('cgp_siteid', $aConfigData['site_id']);
     445                    update_option('cgp_hashkey', $aConfigData['site_key']);
     446                    update_option('cgp_merchant_id', $aConfigData['merchant_id']);
     447                    update_option('cgp_merchant_api_key', $aConfigData['api_key']);
     448                    die ($aConfigData['merchant'] . '.' . get_option('cgp_siteid') . '.200');
     449                } else {
     450                    die('Token retrieval failed.');
     451                }
    439452            } catch (cardgate\api\Exception $oException_) {
    440453                die(htmlspecialchars($oException_->getMessage()));
  • cardgate/tags/3.1.16/readme.txt

    r2178570 r2249399  
    55Requires at least: 4.2
    66Tested up to: 5.2
    7 Stable tag: 3.1.15
     7Stable tag: 3.1.16
    88License: GPLv3 or later
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    6868== Changelog ==
    6969
     70= 3.1.16 =
     71* New pullConfig method implementation
     72
    7073= 3.1.15 =
    7174* New payment method: OnlineÜberweisen
  • cardgate/trunk/cardgate-clientlib-php/src/Client.php

    r2178570 r2249399  
    3636         * Client version.
    3737         */
    38         const CLIENT_VERSION = "1.1.12";
     38        const CLIENT_VERSION = "1.1.13";
    3939
    4040        /**
     
    383383         * @api
    384384         */
    385         static public function pullConfig( $sToken_, $bTestmode_ = FALSE ) {
     385        public function pullConfig( $sToken_ ) {
    386386            if ( ! is_string( $sToken_ ) ) {
    387387                throw new Exception( 'Client.Token.Invalid', 'invalid token for settings pull: ' . $sToken_ );
    388388            }
    389 
    390389            $sResource = "pullconfig/{$sToken_}/";
    391             $sUrl = ( $bTestmode_ ? self::URL_STAGING : self::URL_PRODUCTION ) . $sResource;
    392 
    393             $rCh = curl_init();
    394             curl_setopt( $rCh, CURLOPT_URL, $sUrl );
    395             curl_setopt( $rCh, CURLOPT_RETURNTRANSFER, 1 );
    396             curl_setopt( $rCh, CURLOPT_TIMEOUT, 60 );
    397             curl_setopt( $rCh, CURLOPT_HEADER, FALSE );
    398             curl_setopt( $rCh, CURLOPT_HTTPHEADER, [
    399                 'Content-Type: application/json',
    400                 'Accept: application/json'
    401             ] );
    402             if ( $bTestmode_ ) {
    403                 curl_setopt( $rCh, CURLOPT_SSL_VERIFYPEER, FALSE );
    404                 curl_setopt( $rCh, CURLOPT_SSL_VERIFYHOST, 0 );
    405             } else {
    406                 curl_setopt( $rCh, CURLOPT_SSL_VERIFYPEER, TRUE ); // verify SSL peer
    407                 curl_setopt( $rCh, CURLOPT_SSL_VERIFYHOST, 2 ); // check for valid common name and verify host
    408             }
    409 
    410             if ( FALSE == ( $sResults = curl_exec( $rCh ) ) ) {
    411                 $sError = curl_error( $rCh );
    412                 curl_close( $rCh );
    413                 throw new Exception( 'Client.Request.Curl.Error', $sError );
    414             } else {
    415                 curl_close( $rCh );
    416             }
    417             if ( NULL === ( $aResults = json_decode( $sResults, TRUE ) ) ) {
    418                 throw new Exception( 'Client.Request.JSON.Invalid', 'remote gave invalid JSON: ' . $sResults );
    419             }
    420             if ( isset( $aResults['error'] ) ) {
    421                 throw new Exception( 'Client.Request.Remote.' . $aResults['error']['code'], $aResults['error']['message'] );
    422             }
    423 
    424             return $aResults;
     390            return $this->doRequest($sResource);
    425391        }
    426392
  • cardgate/trunk/cardgate.php

    r2178570 r2249399  
    77 * Text Domain: cardgate
    88 * Domain Path: /i18n/languages
    9  * Version: 3.1.15
     9 * Version: 3.1.16
    1010 * Requires at least: 4.4
    1111 * Author: CardGate
     
    4141            add_action('admin_notices', array(&$this,'my_error_notice'));
    4242    }
    43 
    44     // ////////////////////////////////////////////////
    4543   
    4644    /**
     
    428426            try {
    429427                require_once WP_PLUGIN_DIR . '/cardgate/cardgate-clientlib-php/init.php';
     428                $sVersion = ( $this->get_woocommerce_version() == '' ? 'unkown' : $this->get_woocommerce_version() );
     429                $sLanguage = substr( get_locale(), 0, 2 );
    430430                $bIsTest = ($_REQUEST['testmode'] == 1 ? true : false);
    431                 $aResult = cardgate\api\Client::pullConfig($_REQUEST['token'], $bIsTest);
    432                 $aConfigData = $aResult['pullconfig']['content'];
    433                 update_option('cgp_mode', $aConfigData['testmode']);
    434                 update_option('cgp_siteid', $aConfigData['site_id']);
    435                 update_option('cgp_hashkey', $aConfigData['site_key']);
    436                 update_option('cgp_merchant_id', $aConfigData['merchant_id']);
    437                 update_option('cgp_merchant_api_key', $aConfigData['api_key']);
    438                 die($aConfigData['merchant'] . '.' . get_option('cgp_siteid') . '.200');
     431                $iMerchantId = (int)(get_option('cgp_merchant_id')== false ? 0 : get_option('cgp_merchant_id'));
     432                $sMerchantApiKey = (get_option('cgp_merchant_api_key')== false ? 'initconfig' : get_option('cgp_merchant_api_key'));
     433                $oCardGate = new cardgate\api\Client( $iMerchantId, $sMerchantApiKey, $bIsTest );
     434                $oCardGate->setIp( $_SERVER['REMOTE_ADDR'] );
     435                $oCardGate->setLanguage( $sLanguage );
     436                $oCardGate->version()->setPlatformName( 'Woocommerce' );
     437                $oCardGate->version()->setPlatformVersion( $sVersion );
     438                $oCardGate->version()->setPluginName( 'CardGate' );
     439                $oCardGate->version()->setPluginVersion( get_option( 'cardgate_version' ) );
     440                $aResult = $oCardGate->pullConfig($_REQUEST['token']);
     441                if (isset($aResult['success']) && $aResult['success'] == 1){
     442                    $aConfigData = $aResult['pullconfig']['content'];
     443                    update_option('cgp_mode', $aConfigData['testmode']);
     444                    update_option('cgp_siteid', $aConfigData['site_id']);
     445                    update_option('cgp_hashkey', $aConfigData['site_key']);
     446                    update_option('cgp_merchant_id', $aConfigData['merchant_id']);
     447                    update_option('cgp_merchant_api_key', $aConfigData['api_key']);
     448                    die ($aConfigData['merchant'] . '.' . get_option('cgp_siteid') . '.200');
     449                } else {
     450                    die('Token retrieval failed.');
     451                }
    439452            } catch (cardgate\api\Exception $oException_) {
    440453                die(htmlspecialchars($oException_->getMessage()));
  • cardgate/trunk/readme.txt

    r2178570 r2249399  
    55Requires at least: 4.2
    66Tested up to: 5.2
    7 Stable tag: 3.1.15
     7Stable tag: 3.1.16
    88License: GPLv3 or later
    99License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    6868== Changelog ==
    6969
     70= 3.1.16 =
     71* New pullConfig method implementation
     72
    7073= 3.1.15 =
    7174* New payment method: OnlineÜberweisen
Note: See TracChangeset for help on using the changeset viewer.