Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
widoz committed Dec 5, 2019
2 parents 4c75678 + a54f21a commit fae343c
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 12 deletions.
6 changes: 5 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
== Changelog ==

= 5.4.0 - 02-12-2019 =
= 5.4.1 - 05-12-2019 =

* Fix - Mollie Components request multiple times the merchant profile ID via API

= 5.4.0 - 04-12-2019 =

* Fix - Apple Pay Gateway is removed from available gateways during WooCommerce Api calls
* Fix - Giftcard Gateway does not show the right payment icon in checkout page
Expand Down
28 changes: 25 additions & 3 deletions inc/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function merchantProfile()
{
static $profile = null;

if (null === $profile) {
if ($profile === null) {
$isTestMode = isTestModeEnabled();

$apiHelper = Mollie_WC_Plugin::getApiHelper();
Expand All @@ -67,9 +67,31 @@ function merchantProfile()
*/
function merchantProfileId()
{
$merchantProfile = merchantProfile();
static $merchantProfileId = null;
$merchantProfileIdOptionKey = Mollie_WC_Plugin::PLUGIN_ID . '_merchant_profile_id';

return isset($merchantProfile->id) ? $merchantProfile->id : 0;
if ($merchantProfileId === null) {
$merchantProfileId = get_option($merchantProfileIdOptionKey, '');

/*
* Try to retrieve the merchant profile ID from an Api Request if not stored already,
* then store it into the database
*/
if (!$merchantProfileId) {
try {
$merchantProfile = merchantProfile();
$merchantProfileId = isset($merchantProfile->id) ? $merchantProfile->id : '';
} catch (ApiException $exception) {
$merchantProfileId = '';
}

if ($merchantProfileId) {
update_option($merchantProfileIdOptionKey, $merchantProfileId, false);
}
}
}

return $merchantProfileId;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion mollie-payments-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Mollie Payments for WooCommerce
* Plugin URI: https://www.mollie.com
* Description: Accept payments in WooCommerce with the official Mollie plugin
* Version: 5.4.0
* Version: 5.4.1
* Author: Mollie
* Author URI: https://www.mollie.com
* Requires at least: 3.8
Expand Down
50 changes: 44 additions & 6 deletions src/Mollie/WC/Helper/Settings.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use Mollie\Api\Exceptions\ApiException;

class Mollie_WC_Helper_Settings
{
const FILTER_ALLOWED_LANGUAGE_CODE_SETTING = 'mollie.allowed_language_code_setting';
Expand Down Expand Up @@ -51,7 +54,14 @@ public function getApiKey($test_mode = false)
{
$setting_id = $test_mode ? 'test_api_key' : 'live_api_key';

return trim(get_option($this->getSettingId($setting_id)));
$apiKeyId = $this->getSettingId($setting_id);
$apiKey = get_option($apiKeyId);

if (!$apiKey && is_admin()) {
$apiKey = filter_input(INPUT_POST, $apiKeyId, FILTER_SANITIZE_STRING);
}

return trim($apiKey);
}

/**
Expand Down Expand Up @@ -133,11 +143,37 @@ public function getGlobalSettingsUrl ()
/**
* @return string
*/
public function getLogsUrl ()
public function getLogsUrl()
{
return admin_url('admin.php?page=wc-status&tab=logs');
}

public function updateMerchantIdOnApiKeyChanges($optionValue, $optionName)
{
$optionId = isset($optionName['id']) ? $optionName['id'] : '';
$allowedOptionsId = [
$this->getSettingId('live_api_key'),
$this->getSettingId('test_api_key'),
];

if (!in_array($optionId, $allowedOptionsId, true)) {
return $optionValue;
}

$merchantProfileIdOptionKey = Mollie_WC_Plugin::PLUGIN_ID . '_merchant_profile_id';

try {
$merchantProfile = merchantProfile();
$merchantProfileId = isset($merchantProfile->id) ? $merchantProfile->id : '';
} catch (ApiException $exception) {
$merchantProfileId = '';
}

update_option($merchantProfileIdOptionKey, $merchantProfileId, false);

return $optionValue;
}

/**
* Get plugin status
*
Expand All @@ -146,16 +182,18 @@ public function getLogsUrl ()
*
* @return string
*/
protected function getPluginStatus ()
protected function getPluginStatus()
{
$status = Mollie_WC_Plugin::getStatusHelper();

if (!$status->isCompatible())
{
if (!$status->isCompatible()) {
// Just stop here!
return ''
. '<div class="notice notice-error">'
. '<p><strong>' . __('Error', 'mollie-payments-for-woocommerce') . ':</strong> ' . implode('<br/>', $status->getErrors())
. '<p><strong>' . __(
'Error',
'mollie-payments-for-woocommerce'
) . ':</strong> ' . implode('<br/>', $status->getErrors())
. '</p></div>';
}

Expand Down
8 changes: 7 additions & 1 deletion src/Mollie/WC/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Mollie_WC_Plugin
{
const PLUGIN_ID = 'mollie-payments-for-woocommerce';
const PLUGIN_TITLE = 'Mollie Payments for WooCommerce';
const PLUGIN_VERSION = '5.4.0';
const PLUGIN_VERSION = '5.4.1';

const DB_VERSION = '1.0';
const DB_VERSION_PARAM_NAME = 'mollie-db-version';
Expand Down Expand Up @@ -205,6 +205,12 @@ function () {
}
}
);
add_action(
'woocommerce_admin_settings_sanitize_option',
[$settings_helper, 'updateMerchantIdOnApiKeyChanges'],
10,
2
);

// Add settings link to plugins page
add_filter( 'plugin_action_links_' . $plugin_basename, array ( __CLASS__, 'addPluginActionLinks' ) );
Expand Down

0 comments on commit fae343c

Please sign in to comment.