Ejemplo n.º 1
0
 /**
  * @param bool        $test_mode (default: false)
  * @param string|null $method
  * @return array|Mollie_API_Object_Issuer[]|Mollie_API_Object_List
  */
 public function getIssuers($test_mode = false, $method = NULL)
 {
     $locale = $this->getCurrentLocale();
     try {
         $transient_id = $this->getTransientId('api_issuers_' . ($test_mode ? 'test' : 'live') . "_{$locale}");
         if (empty(self::$api_issuers)) {
             $cached = @unserialize(get_transient($transient_id));
             if ($cached && $cached instanceof Mollie_API_Object_List) {
                 self::$api_issuers = $cached;
             } else {
                 self::$api_issuers = $this->api_helper->getApiClient($test_mode)->issuers->all();
                 set_transient($transient_id, self::$api_issuers, MINUTE_IN_SECONDS * 5);
             }
         }
         // Filter issuers by method
         if ($method !== NULL) {
             $method_issuers = array();
             foreach (self::$api_issuers as $issuer) {
                 if ($issuer->method === $method) {
                     $method_issuers[] = $issuer;
                 }
             }
             return $method_issuers;
         }
         return self::$api_issuers;
     } catch (Mollie_API_Exception $e) {
         Mollie_WC_Plugin::debug(__FUNCTION__ . ": Could not load Mollie issuers (" . ($test_mode ? 'test' : 'live') . "): " . $e->getMessage() . ' (' . get_class($e) . ')');
     }
     return array();
 }
Ejemplo n.º 2
0
 /**
  * @param bool $test_mode
  * @return Mollie_API_Client
  * @throws Mollie_WC_Exception_InvalidApiKey
  */
 public function getApiClient($test_mode = false)
 {
     global $wp_version;
     $api_key = $this->settings_helper->getApiKey($test_mode);
     if (empty($api_key)) {
         throw new Mollie_WC_Exception_InvalidApiKey(__('No API key provided.', 'mollie-payments-for-woocommerce'));
     } elseif (!preg_match('/^(live|test)_\\w+$/', $api_key)) {
         throw new Mollie_WC_Exception_InvalidApiKey(__('Invalid API key. The API key must start with \'live_\' or \'test_\' and can\'t further contain any special characters.', 'mollie-payments-for-woocommerce'));
     }
     if (empty(self::$api_client)) {
         $client = new Mollie_API_Client();
         $client->setApiKey($api_key);
         $client->setApiEndpoint(self::getApiEndpoint());
         $client->addVersionString('WordPress/' . (isset($wp_version) ? $wp_version : 'Unknown'));
         $client->addVersionString('WooCommerce/' . get_option('woocommerce_version', 'Unknown'));
         $client->addVersionString('MollieWoo/' . Mollie_WC_Plugin::PLUGIN_VERSION);
         self::$api_client = $client;
     }
     return self::$api_client;
 }
Ejemplo n.º 3
0
 /**
  * Get plugin status
  *
  * - Check compatibility
  * - Check Mollie API connectivity
  *
  * @return string
  */
 protected function getPluginStatus()
 {
     $status = Mollie_WC_Plugin::getStatusHelper();
     if (!$status->isCompatible()) {
         // Just stop here!
         return '' . '<div id="message" class="error fade">' . ' <strong>' . __('Error', 'mollie-payments-for-woocommerce') . ':</strong> ' . implode('<br/>', $status->getErrors()) . '</div>';
     }
     try {
         // Check compatibility
         $status->getMollieApiStatus();
         $api_status = '' . '<p>' . __('Mollie status:', 'mollie-payments-for-woocommerce') . ' <span style="color:green; font-weight:bold;">' . __('Connected', 'mollie-payments-for-woocommerce') . '</span>' . '</p>';
         $api_status_type = 'updated';
     } catch (Mollie_WC_Exception_CouldNotConnectToMollie $e) {
         $api_status = '' . '<p style="font-weight:bold;"><span style="color:red;">Communicating with Mollie failed:</span> ' . esc_html($e->getMessage()) . '</p>' . '<p>Please check the following conditions. You can ask your system administrator to help with this.</p>' . '<ul style="color: #2D60B0;">' . ' <li>Please check if you\'ve inserted your API key correctly.</li>' . ' <li>Make sure outside connections to <strong>' . esc_html(Mollie_WC_Helper_Api::getApiEndpoint()) . '</strong> are not blocked.</li>' . ' <li>Make sure SSL v3 is disabled on your server. Mollie does not support SSL v3.</li>' . ' <li>Make sure your server is up-to-date and the latest security patches have been installed.</li>' . '</ul><br/>' . '<p>Please contact <a href="mailto:info@mollie.com">info@mollie.com</a> if this still does not fix your problem.</p>';
         $api_status_type = 'error';
     } catch (Mollie_WC_Exception_InvalidApiKey $e) {
         $api_status = '<p style="color:red; font-weight:bold;">' . esc_html($e->getMessage()) . '</p>';
         $api_status_type = 'error';
     }
     return '' . '<div id="message" class="' . $api_status_type . ' fade">' . $api_status . '</div>';
 }