Plugin Directory

Changeset 2711177


Ignore:
Timestamp:
04/18/2022 06:06:27 PM (4 years ago)
Author:
usedrip
Message:

update datetime usage to specific methods

Location:
drip-payments/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • drip-payments/trunk/drip-payments.php

    r2708634 r2711177  
    44 * Description: Forneça a Drip como opção de pagamento para pedidos do WooCommerce.
    55 * Author: Drip
    6  * Version: 0.1.30
     6 * Version: 0.1.31
    77 */
    88
    99function drip_payments_show_plugin_version() {
    10     return '0.1.30';
     10    return '0.1.31';
    1111}
    1212
     
    158158        }
    159159
     160        private function create_date_from_cache($date) {
     161            return DateTime::createFromFormat('Y-m-d H:i:s', $date, new DateTimeZone('America/Sao_Paulo'));
     162        }
     163
     164        private function get_actual_datetime() {
     165            return new DateTime('now', new DateTimeZone('America/Sao_Paulo'));
     166        }
     167
     168        private function create_cache_expiration_date() {
     169            return date_format($this->get_actual_datetime()->add(DateInterval::createFromDateString('1 day')), 'Y-m-d 00:05:00');
     170        }
     171
    160172        public function check_is_enabled()
    161173        {
     
    166178
    167179            $server_status = (array) json_decode(get_option('drip_payments_server_status'));
    168             $now = new DateTime('now', new DateTimeZone('America/Sao_Paulo'));
    169             $expiration_time = new Datetime($server_status['expiration']->date);
    170 
     180            $now = $this->get_actual_datetime();
     181            $expiration_time = $this->create_date_from_cache($server_status['expiration']);
    171182            if(count($server_status) > 1 && $expiration_time > $now) {
    172183                if($server_status['offline']) {
     
    190201           
    191202            if (strlen($this->api_key) > 10) {
    192                 $date = $now->add(DateInterval::createFromDateString('1 day'));
    193203                $server_status = json_encode([
    194204                    'offline' => false,
    195205                    'online' => true,
    196                     'expiration' => date_format($date, 'Y-m-d 00:10:00')
     206                    'expiration' => $this->create_cache_expiration_date()
    197207                ]);
    198208                update_option('drip_payments_server_status', $server_status);
     
    204214        public function get_cashback() {
    205215            $actual_cashback = (array) json_decode(get_option('drip_payments_actual_cashback'));
    206             $now = new DateTime('now', new DateTimeZone('America/Sao_Paulo'));
    207             $expiration_time = new Datetime($actual_cashback['expiration']->date);
    208             if(count($actual_cashback) > 1 && $expiration_time > $now) {
     216            $expiration_time = $this->create_date_from_cache($actual_cashback['expiration']);
     217            if(count($actual_cashback) > 1 && $expiration_time > $this->get_actual_datetime()) {
    209218                return $actual_cashback['value'];
    210219            }
    211             $date = $now->add(DateInterval::createFromDateString('1 day'));
    212220            $actual_cashback = json_encode([
    213221                'value' => $this->checkoutRequest->getCashback(),
    214                 'expiration' => date_format($date, 'Y-m-d 00:10:00')
     222                'expiration' => $this->create_cache_expiration_date()
    215223                ]);
    216224            update_option('drip_payments_actual_cashback', $actual_cashback);
  • drip-payments/trunk/readme.txt

    r2708618 r2711177  
    55Tested up to: 5.9.2
    66Requires PHP: 7.0
    7 Stable tag: 0.1.30
     7Stable tag: 0.1.31
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.