Plugin Directory

Changeset 2907185


Ignore:
Timestamp:
05/02/2023 10:30:25 PM (3 years ago)
Author:
gratifypay
Message:

feat: new health checks that will disable gratify payment option if the servers are unhealthy

Location:
gratifypay/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • gratifypay/trunk/class/wc-gratify-pay-admin.php

    r2870328 r2907185  
    4848                wp_enqueue_script('gratify-pay_admin_js', plugins_url( 'assets/js/gratifypay-admin.js', dirname(__FILE__)), array('jquery'));
    4949                wp_enqueue_style('gratify-pay_admin_css', plugins_url( 'assets/css/gratifypay-admin.css', dirname(__FILE__)) , array(), Gratify_BNPL::$version);
    50                 wp_enqueue_style('gp', "https://assets.gratifypay.com/plugin/v-latest/styles.css", array(), $plugin_version );
     50                wp_enqueue_style('gp', "https://assets.gratifypay.com/plugin/v-latest/styles.css", array(), Gratify_BNPL::$version );
    5151            }
    5252        }
  • gratifypay/trunk/class/wc-gratify-pay-gateway.php

    r2870328 r2907185  
    13701370         */
    13711371        private function api_is_ok() {
    1372             return true;
     1372            // HTTP get call to /health/fast
     1373            // If response is 200, return true
     1374
     1375            $response = $this->getGratifyClient()->checkApiHealth();
     1376            self::log( 'API Health Check: ' . $response);
     1377            // if status code is 200, return true
     1378            if($response == 200) {
     1379                return true;
     1380            }
     1381            return false;
    13731382        }
    13741383
  • gratifypay/trunk/gratify-BNPL.php

    r2870328 r2907185  
    1212 * Plugin URI:        https://docs.gratifypay.com/docs/woocommerce
    1313 * Description:       GratifyPay's Woocommerce plugin for Gratify BNPL payment gateway
    14  * Version:           1.3.2
     14 * Version:           1.3.3
    1515 * Requires PHP:      7.3
    1616 * Author:            Gratify Pay
  • gratifypay/trunk/vendor/gratifypay/plugin-php-sdk/composer.json

    r2813807 r2907185  
    33  "description": "Gratify Pay PHP SDK",
    44  "license": "AFL-3.0",
    5   "version": "1.2.0 ",
     5  "version": "1.3.0 ",
    66  "type": "library",
    77  "require": {
  • gratifypay/trunk/vendor/gratifypay/plugin-php-sdk/src/Client.php

    r2774436 r2907185  
    4040
    4141    /**
     42     * Check the connection
     43     *
     44     * @return bool success connection or not
     45     */
     46    public function checkConnection(): bool {
     47        try {
     48            $result = $this->getMerchant();
     49        }
     50        catch (\Exception $e) {
     51            return false;
     52        }
     53
     54        if (!empty($result)) {
     55            return true;
     56        }
     57
     58        return false;
     59    }
     60
     61    /**
     62     * Check the API health page
     63     *
     64     * @param bool $fast
     65     * @param string $merchantId
     66     * @return int HTTP status of 200 OK or 500 SERVER ERROR
     67     */
     68    public function checkApiHealth(bool $fast = true, string $merchantId = null): int
     69    {
     70        $return = 200;
     71        try {
     72            if(empty($merchantId)) {
     73                $merchantId = $this->merchantPublicId;
     74            }
     75            $params = ['merchant_id' => $merchantId];
     76            $result = $this->request('GET', '/health' . ($fast ? '/fast' : '') . $this->formatParams($params));
     77        }
     78        catch (\Exception $e) {
     79            $return = 500;
     80        }
     81
     82        if (empty($result)) {
     83            $return = 500;
     84        }
     85
     86        return $return;
     87    }
     88
     89    /**
    4290     * @return Merchant
    4391     * @throws \Exception
     
    146194    }
    147195
     196    /**
     197     * Return $params as a Url formated parameter string
     198     *
     199     * @param array $params
     200     * @return string
     201     */
     202    private function formatParams(array $params = [])
     203    {
     204        return !empty($params) ? '?' . http_build_query($params) : '';
     205    }
    148206
    149207}
Note: See TracChangeset for help on using the changeset viewer.