/** * Display fields below payment method in checkout */ public function payment_fields() { // Display description above issuers parent::payment_fields(); $test_mode = Mollie_WC_Plugin::getSettingsHelper()->isTestModeEnabled(); $ideal_issuers = Mollie_WC_Plugin::getDataHelper()->getIssuers($test_mode, $this->getMollieMethodId()); $selected_issuer = $this->getSelectedIssuer(); $html = '<select name="' . Mollie_WC_Plugin::PLUGIN_ID . '_issuer_' . $this->id . '">'; $html .= '<option value=""></option>'; foreach ($ideal_issuers as $issuer) { $html .= '<option value="' . esc_attr($issuer->id) . '"' . ($selected_issuer == $issuer->id ? ' selected=""' : '') . '>' . esc_html($issuer->name) . '</option>'; } $html .= '</select>'; echo wpautop(wptexturize($html)); }
/** * Called when plugin is activated */ function mollie_wc_plugin_activation_hook() { // WooCommerce plugin not activated if (!is_plugin_active('woocommerce/woocommerce.php')) { $title = sprintf(__('Could not activate plugin %s', 'mollie-payments-for-woocommerce'), 'Mollie Payments for WooCommerce'); $message = '' . '<h1><strong>' . $title . '</strong></h1><br/>' . 'WooCommerce plugin not activated. Please activate WooCommerce plugin first.'; wp_die($message, $title, array('back_link' => true)); return; } // Register Mollie autoloader Mollie_WC_Autoload::register(); $status_helper = Mollie_WC_Plugin::getStatusHelper(); if (!$status_helper->isCompatible()) { $title = 'Could not activate plugin ' . Mollie_WC_Plugin::PLUGIN_TITLE; $message = '<h1><strong>Could not activate plugin ' . Mollie_WC_Plugin::PLUGIN_TITLE . '</strong></h1><br/>' . implode('<br/>', $status_helper->getErrors()); wp_die($message, $title, array('back_link' => true)); return; } }
/** * @throws Mollie_WC_Exception_CouldNotConnectToMollie */ public function getMollieApiStatus() { try { // Is test mode enabled? $test_mode = Mollie_WC_Plugin::getSettingsHelper()->isTestModeEnabled(); $api_helper = Mollie_WC_Plugin::getApiHelper(); $api_client = $api_helper->getApiClient($test_mode); // Try to load Mollie issuers $api_client->issuers->all(); } catch (Mollie_API_Exception $e) { throw new Mollie_WC_Exception_CouldNotConnectToMollie($e->getMessage(), 0, $e); } }
/** * @param WC_Order $order * @param Mollie_API_Object_Payment $payment * @param bool $admin_instructions * @param bool $plain_text * @return string|null */ protected function getInstructions(WC_Order $order, Mollie_API_Object_Payment $payment, $admin_instructions, $plain_text) { $instructions = ''; if (!$payment->details) { return null; } $data_helper = Mollie_WC_Plugin::getDataHelper(); if ($payment->isPaid()) { $instructions .= sprintf(__('Payment completed by <strong>%s</strong> (IBAN: %s, BIC: %s)', 'mollie-payments-for-woocommerce'), $payment->details->consumerName, implode(' ', str_split($payment->details->consumerAccount, 4)), $payment->details->consumerBic); } elseif ($data_helper->hasOrderStatus($order, 'on-hold')) { if (!$admin_instructions) { $instructions .= __('Please complete your payment by transferring the total amount to the following bank account:', 'mollie-payments-for-woocommerce') . "\n\n\n"; } /* translators: Placeholder 1: 'Stichting Mollie Payments' */ $instructions .= sprintf(__('Beneficiary: %s', 'mollie-payments-for-woocommerce'), $payment->details->bankName) . "\n"; $instructions .= sprintf(__('IBAN: <strong>%s</strong>', 'mollie-payments-for-woocommerce'), implode(' ', str_split($payment->details->bankAccount, 4))) . "\n"; $instructions .= sprintf(__('BIC: %s', 'mollie-payments-for-woocommerce'), $payment->details->bankBic) . "\n"; if ($admin_instructions) { /* translators: Placeholder 1: Payment reference e.g. RF49-0000-4716-6216 (SEPA) or +++513/7587/59959+++ (Belgium) */ $instructions .= sprintf(__('Payment reference: %s', 'mollie-payments-for-woocommerce'), $payment->details->transferReference) . "\n"; } else { /* translators: Placeholder 1: Payment reference e.g. RF49-0000-4716-6216 (SEPA) or +++513/7587/59959+++ (Belgium) */ $instructions .= sprintf(__('Please provide the payment reference <strong>%s</strong>', 'mollie-payments-for-woocommerce'), $payment->details->transferReference) . "\n"; } if (!empty($payment->expiryPeriod) && class_exists('DateTime') && class_exists('DateInterval')) { $expiry_date = DateTime::createFromFormat('U', time()); $expiry_date->add(new DateInterval($payment->expiryPeriod)); if ($admin_instructions) { $instructions .= "\n" . sprintf(__('The payment will expire on <strong>%s</strong>.', 'mollie-payments-for-woocommerce'), $expiry_date->format(wc_date_format())) . "\n"; } else { $instructions .= "\n" . sprintf(__('The payment will expire on <strong>%s</strong>. Please make sure you transfer the total amount before this date.', 'mollie-payments-for-woocommerce'), $expiry_date->format(wc_date_format())) . "\n"; } } } return $instructions; }
/** * @return bool */ protected function isValidApiKeyProvided() { $settings = Mollie_WC_Plugin::getSettingsHelper(); $test_mode = $settings->isTestModeEnabled(); $api_key = $settings->getApiKey($test_mode); return !empty($api_key) && preg_match('/^(live|test)_\\w+$/', $api_key); }
/** * @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(); }
/** * @param array $settings * @return array */ public function addGlobalSettingsFields(array $settings) { wp_register_script('mollie_wc_admin_settings', Mollie_WC_Plugin::getPluginUrl('/assets/js/settings.js'), array('jquery'), Mollie_WC_Plugin::PLUGIN_VERSION); wp_enqueue_script('mollie_wc_admin_settings'); $content = '' . $this->getPluginStatus() . $this->getMollieMethods(); /* translators: Default payment description. {order_number} and {order_date} are available tags. */ $default_payment_description = __('Order {order_number}', 'mollie-payments-for-woocommerce'); $payment_description_tags = '<code>{order_number}</code>, <code>{order_date}</code>'; $debug_desc = __('Log plugin events.', 'mollie-payments-for-woocommerce'); // For WooCommerce 2.2.0+ display view logs link if (version_compare(Mollie_WC_Plugin::getStatusHelper()->getWooCommerceVersion(), '2.2.0', ">=")) { $debug_desc .= ' <a href="' . $this->getLogsUrl() . '">' . __('View logs', 'mollie-payments-for-woocommerce') . '</a>'; } else { /* translators: Placeholder 1: Location of the log files */ $debug_desc .= ' ' . sprintf(__('Log files are saved to <code>%s</code>', 'mollie-payments-for-woocommerce'), defined('WC_LOG_DIR') ? WC_LOG_DIR : WC()->plugin_path() . '/logs/'); } // Global Mollie settings $mollie_settings = array(array('id' => $this->getSettingId('title'), 'title' => __('Mollie settings', 'mollie-payments-for-woocommerce'), 'type' => 'title', 'desc' => '<p id="' . Mollie_WC_Plugin::PLUGIN_ID . '">' . $content . '</p>' . '<p>' . __('The following options are required to use the plugin and are used by all Mollie payment methods', 'mollie-payments-for-woocommerce') . '</p>'), array('id' => $this->getSettingId('live_api_key'), 'title' => __('Live API key', 'mollie-payments-for-woocommerce'), 'default' => '', 'type' => 'text', 'desc' => sprintf(__('The API key is used to connect to Mollie. You can find your <strong>%s</strong> API key in your %sMollie profile%s', 'mollie-payments-for-woocommerce'), 'live', '<a href="https://www.mollie.com/beheer/account/profielen/" target="_blank">', '</a>'), 'css' => 'width: 350px', 'placeholder' => $live_placeholder = __('Live API key should start with live_', 'mollie-payments-for-woocommerce'), 'custom_attributes' => array('placeholder' => $live_placeholder, 'pattern' => '^live_\\w+$')), array('id' => $this->getSettingId('test_mode_enabled'), 'title' => __('Enable test mode', 'mollie-payments-for-woocommerce'), 'default' => 'no', 'type' => 'checkbox', 'desc_tip' => __('Enable test mode if you want to test the plugin without using real payments.', 'mollie-payments-for-woocommerce')), array('id' => $this->getSettingId('test_api_key'), 'title' => __('Test API key', 'mollie-payments-for-woocommerce'), 'default' => '', 'type' => 'text', 'desc' => sprintf(__('The API key is used to connect to Mollie. You can find your <strong>%s</strong> API key in your %sMollie profile%s', 'mollie-payments-for-woocommerce'), 'test', '<a href="https://www.mollie.com/beheer/account/profielen/" target="_blank">', '</a>'), 'css' => 'width: 350px', 'placeholder' => $test_placeholder = __('Test API key should start with test_', 'mollie-payments-for-woocommerce'), 'custom_attributes' => array('placeholder' => $test_placeholder, 'pattern' => '^test_\\w+$')), array('id' => $this->getSettingId('payment_description'), 'title' => __('Description', 'mollie-payments-for-woocommerce'), 'type' => 'text', 'desc' => sprintf(__('Payment description send to Mollie. Default <code>%s</code><br/>You can use the following tags: %s', 'mollie-payments-for-woocommerce'), $default_payment_description, $payment_description_tags), 'default' => $default_payment_description, 'css' => 'width: 350px'), array('id' => $this->getSettingId('payment_locale'), 'title' => __('Payment screen language', 'mollie-payments-for-woocommerce'), 'type' => 'select', 'options' => array('' => __('Detect using browser language', 'mollie-payments-for-woocommerce'), 'wp_locale' => sprintf(__('Send WordPress language (%s)', 'mollie-payments-for-woocommerce'), $this->getCurrentLocale()) . ' (' . __('default', 'mollie-payments-for-woocommerce') . ')', 'nl_NL' => __('Dutch', 'mollie-payments-for-woocommerce'), 'nl_BE' => __('Flemish (Belgium)', 'mollie-payments-for-woocommerce'), 'en' => __('English', 'mollie-payments-for-woocommerce'), 'de' => __('German', 'mollie-payments-for-woocommerce'), 'es' => __('Spanish', 'mollie-payments-for-woocommerce'), 'fr_FR' => __('French', 'mollie-payments-for-woocommerce'), 'fr_BE' => __('French (Belgium)', 'mollie-payments-for-woocommerce')), 'default' => 'wp_locale'), array('id' => $this->getSettingId('debug'), 'title' => __('Debug Log', 'mollie-payments-for-woocommerce'), 'type' => 'checkbox', 'desc' => $debug_desc, 'default' => 'yes'), array('id' => $this->getSettingId('sectionend'), 'type' => 'sectionend')); return $this->mergeSettings($settings, $mollie_settings); }
/** * @param WC_Order $order */ public static function onOrderDetails(WC_Order $order) { if (is_order_received_page()) { /** * Do not show instruction again below details on order received page * Instructions already displayed on top of order received page by $gateway->thankyou_page() * * @see Mollie_WC_Gateway_Abstract::thankyou_page */ return; } $gateway = Mollie_WC_Plugin::getDataHelper()->getWcPaymentGatewayByOrder($order); if (!$gateway || !$gateway instanceof Mollie_WC_Gateway_Abstract) { return; } /** @var Mollie_WC_Gateway_Abstract $gateway */ $gateway->displayInstructions($order); }