Changeset 2684604
- Timestamp:
- 02/24/2022 09:00:21 PM (4 years ago)
- Location:
- drip-payments/trunk
- Files:
-
- 3 edited
-
drip-payments.php (modified) (3 diffs)
-
readme.txt (modified) (1 diff)
-
src/DripPaymentsCheckoutRequest.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
drip-payments/trunk/drip-payments.php
r2682627 r2684604 4 4 * Description: Forneça a Drip como opção de pagamento para pedidos do WooCommerce. 5 5 * Author: Drip 6 * Version: 0.0.1 86 * Version: 0.0.19 7 7 */ 8 8 … … 62 62 $this->enabled = $this->check_is_enabled(); 63 63 64 //$this->cnpj = $this->get_cnpj(); 65 64 66 add_action('woocommerce_update_options_payment_gateways_drip', array($this, 'process_admin_options')); 65 67 add_action('woocommerce_api_resolve_checkout', array($this, 'resolve_checkout')); … … 68 70 public function check_is_enabled() 69 71 { 72 if(!$this->get_option('enabled')) { 73 return 'no'; 74 } 75 76 $server_status = (array) json_decode(get_option('drip_payments_server_status')); 77 $now = new DateTime(); 78 $expiration_time = new Datetime($server_status['expiration']->date); 79 80 if(count($server_status) > 1 && $server_status['offline'] && $expiration_time > $now) { 81 return 'no'; 82 } 70 83 if ($this->checkoutRequest->isDisabled()) { 84 $server_status = json_encode([ 85 'offline' => true, 86 'expiration' => $now->add(new DateInterval('PT5M')) 87 ]); 88 update_option('drip_payments_server_status', $server_status); 71 89 return "no"; 72 90 } 73 if ($this->get_option('enabled') && strlen($this->api_key) > 10) { 91 92 if (strlen($this->api_key) > 10) { 74 93 return "yes"; 75 94 } 76 95 return "no"; 96 } 97 98 public function get_cnpj() 99 { 100 if ($this->enabled) { 101 $cnpj = get_option('drip_payments_merchant_cnpj_from_api_key', null); 102 103 if ($cnpj != null) { 104 return $cnpj; 105 } 106 107 $new_cnpj = $this->checkoutRequest->getCnpj($this->api_key); 108 if (is_string($new_cnpj) && strlen($new_cnpj) > 7) { 109 update_option('drip_payments_merchant_cnpj_from_api_key', $new_cnpj); 110 } 111 return $cnpj; 112 } 77 113 } 78 114 -
drip-payments/trunk/readme.txt
r2682612 r2684604 3 3 Tags: payments, drip, drip payments, woocommerce, bnpl 4 4 Requires at least: 4.7 5 Tested up to: 5. 85 Tested up to: 5.9.1 6 6 Requires PHP: 7.0 7 Stable tag: 0.0.1 87 Stable tag: 0.0.19 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html -
drip-payments/trunk/src/DripPaymentsCheckoutRequest.php
r2682612 r2684604 11 11 const IS_DISABLED_PATH = self::CHECKOUTS_PATH . '/disabled'; 12 12 const SIMULATOR_PATH = 'v1/instalments_simulator'; 13 const MERCHANT_CNPJ = 'v1/merchant_cnpj'; 13 14 14 15 … … 19 20 'base_uri' => $testMode 20 21 ? self::BASE_URI_SANDBOX 21 : self::BASE_URI_PRODUCTION 22 : self::BASE_URI_PRODUCTION, 23 'connect_timeout' => 5, 24 'read_timeout' => 5, 25 'timeout' => 5 22 26 ]; 23 27 } … … 35 39 try { 36 40 $response = $this->client->get(self::IS_DISABLED_PATH); 37 41 38 42 return ($response->getStatusCode() === 200) && json_decode($response->getBody())->isDisabled; 39 43 } catch (RuntimeException $e) { 40 return false;44 return true; 41 45 } 42 46 } … … 83 87 } 84 88 } 89 90 public function getCnpj() 91 { 92 try { 93 $response = $this->client->get(self::MERCHANT_CNPJ, ['headers' => ['X-API-Key' => $this->merchantKey]]); 94 if ($response->getStatusCode() !== 200) 95 return '2'; 96 97 $resp_body = (array) json_decode($response->getBody()); 98 return $resp_body['cnpj']; 99 } catch (RuntimeException $e) { 100 return null; 101 } 102 } 85 103 }
Note: See TracChangeset
for help on using the changeset viewer.