Skip to content

Commit af1bf85

Browse files
committed
Fixes method ordering.
1 parent 8963a28 commit af1bf85

File tree

22 files changed

+371
-188
lines changed

22 files changed

+371
-188
lines changed

app/code/community/Mollie/Mpm/Block/Adminhtml/System/Config/Status.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* @category Mollie
2828
* @package Mollie_Mpm
2929
* @author Mollie B.V. ([email protected])
30-
* @version v4.0.0
30+
* @version v4.0.2
3131
* @copyright Copyright (c) 2012-2014 Mollie B.V. (https://www.mollie.nl)
3232
* @license http://www.opensource.org/licenses/bsd-license.php Berkeley Software Distribution License (BSD-License 2)
3333
*

app/code/community/Mollie/Mpm/Block/Payment/Api/Info.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* @category Mollie
2929
* @package Mollie_Mpm
3030
* @author Mollie B.V. ([email protected])
31-
* @version v4.0.0
31+
* @version v4.0.2
3232
* @copyright Copyright (c) 2012-2014 Mollie B.V. (https://www.mollie.nl)
3333
* @license http://www.opensource.org/licenses/bsd-license.php Berkeley Software Distribution License (BSD-License 2)
3434
*

app/code/community/Mollie/Mpm/Helper/Api.php

+69-24
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,45 @@
22

33
/**
44
* Copyright (c) 2012-2014, Mollie B.V.
5-
* All rights reserved.
6-
*
7-
* Redistribution and use in source and binary forms, with or without
8-
* modification, are permitted provided that the following conditions are met:
9-
*
10-
* - Redistributions of source code must retain the above copyright notice,
5+
* All rights reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* - Redistributions of source code must retain the above copyright notice,
1111
* this list of conditions and the following disclaimer.
12-
* - Redistributions in binary form must reproduce the above copyright
12+
* - Redistributions in binary form must reproduce the above copyright
1313
* notice, this list of conditions and the following disclaimer in the
1414
* documentation and/or other materials provided with the distribution.
15-
*
16-
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
17-
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19-
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
20-
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21-
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24-
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25-
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26-
* DAMAGE.
27-
*
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
17+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
20+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26+
* DAMAGE.
27+
*
2828
* ----------------------------------------------------------------------------------------------------
2929
*
3030
* @category Mollie
3131
* @package Mollie_Mpm
3232
* @author Mollie B.V. ([email protected])
33-
* @version v4.0.0
33+
* @version v4.0.2
3434
* @copyright Copyright (c) 2012-2014 Mollie B.V. (https://www.mollie.nl)
3535
* @license http://www.opensource.org/licenses/bsd-license.php Berkeley Software Distribution License (BSD-License 2)
36-
*
36+
*
3737
* ----------------------------------------------------------------------------------------------------
3838
*
3939
**/
4040

4141
class Mollie_Mpm_Helper_Api
4242
{
43-
const PLUGIN_VERSION = 'v4.0.0';
43+
const PLUGIN_VERSION = 'v4.0.2';
4444

4545
protected $api_key = null;
4646
protected $amount = 0;
@@ -287,7 +287,46 @@ public function getPaymentMethods()
287287
try
288288
{
289289
$api = $this->_getMollieAPi();
290-
return $api->methods->all();
290+
$api_methods = $api->methods->all();
291+
$all_methods = Mage::Helper('mpm/data')->getStoredMethods();
292+
293+
foreach ($all_methods as $i => $s)
294+
{
295+
$all_methods[$i]['available'] = FALSE;
296+
foreach ($api_methods as $c)
297+
{
298+
if ($s['method_id'] === $c->id)
299+
{
300+
$all_methods[$i]['available'] = TRUE;
301+
break;
302+
}
303+
}
304+
}
305+
foreach ($api_methods as $c)
306+
{
307+
$c->available = FALSE;
308+
foreach ($all_methods as $i => $s)
309+
{
310+
if ($c->id === $s['method_id'])
311+
{
312+
// recognised method, put in correct order
313+
$c->available = TRUE;
314+
$c->method_id = $c->id;
315+
$all_methods[$i] = (array) $c;
316+
break;
317+
}
318+
}
319+
if (!$c->available)
320+
{
321+
// newly added method, add to end of array
322+
$c->available = TRUE;
323+
$c->method_id = $c->id;
324+
$all_methods[] = (array) $c;
325+
}
326+
}
327+
328+
Mage::Helper('mpm/data')->setStoredMethods($all_methods);
329+
return $all_methods;
291330
}
292331
catch (Mollie_API_Exception $e)
293332
{
@@ -303,4 +342,10 @@ public function getPaymentMethods()
303342
}
304343
}
305344
}
345+
346+
public function getMethodByCode($code)
347+
{
348+
$method_id = (int) str_replace('mpm_void_', '', $code);
349+
return $this->methods[$method_id];
350+
}
306351
}

app/code/community/Mollie/Mpm/Helper/Data.php

+72-35
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,36 @@
22

33
/**
44
* Copyright (c) 2012-2014, Mollie B.V.
5-
* All rights reserved.
6-
*
7-
* Redistribution and use in source and binary forms, with or without
8-
* modification, are permitted provided that the following conditions are met:
9-
*
10-
* - Redistributions of source code must retain the above copyright notice,
5+
* All rights reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* - Redistributions of source code must retain the above copyright notice,
1111
* this list of conditions and the following disclaimer.
12-
* - Redistributions in binary form must reproduce the above copyright
12+
* - Redistributions in binary form must reproduce the above copyright
1313
* notice, this list of conditions and the following disclaimer in the
1414
* documentation and/or other materials provided with the distribution.
15-
*
16-
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
17-
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18-
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19-
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
20-
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21-
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24-
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25-
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26-
* DAMAGE.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
17+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
20+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26+
* DAMAGE.
2727
*
2828
* @category Mollie
2929
* @package Mollie_Mpm
3030
* @author Mollie B.V. ([email protected])
31-
* @version v4.0.0
31+
* @version v4.0.2
3232
* @copyright Copyright (c) 2012-2014 Mollie B.V. (https://www.mollie.nl)
3333
* @license http://www.opensource.org/licenses/bsd-license.php Berkeley Software Distribution License (BSD-License 2)
34-
*
34+
*
3535
**/
3636

3737
class Mollie_Mpm_Helper_Data extends Mage_Core_Helper_Abstract
@@ -47,12 +47,12 @@ public function getStatusById($transaction_id)
4747
/** @var $connection Varien_Db_Adapter_Interface */
4848
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
4949
$status = $connection->fetchAll(
50-
sprintf(
51-
"SELECT `bank_status` FROM `%s` WHERE `transaction_id` = %s",
52-
Mage::getSingleton('core/resource')->getTableName('mollie_payments'),
53-
$connection->quote($transaction_id)
54-
)
55-
);
50+
sprintf(
51+
"SELECT `bank_status` FROM `%s` WHERE `transaction_id` = %s",
52+
Mage::getSingleton('core/resource')->getTableName('mollie_payments'),
53+
$connection->quote($transaction_id)
54+
)
55+
);
5656

5757
return $status[0];
5858
}
@@ -67,12 +67,12 @@ public function getOrderIdByTransactionId($transaction_id)
6767
/** @var $connection Varien_Db_Adapter_Interface */
6868
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
6969
$id = $connection->fetchAll(
70-
sprintf(
71-
"SELECT `order_id` FROM `%s` WHERE `transaction_id` = %s",
72-
Mage::getSingleton('core/resource')->getTableName('mollie_payments'),
73-
$connection->quote($transaction_id)
74-
)
75-
);
70+
sprintf(
71+
"SELECT `order_id` FROM `%s` WHERE `transaction_id` = %s",
72+
Mage::getSingleton('core/resource')->getTableName('mollie_payments'),
73+
$connection->quote($transaction_id)
74+
)
75+
);
7676

7777
if (sizeof($id) > 0)
7878
{
@@ -105,6 +105,36 @@ public function getTransactionIdByOrderId($order_id)
105105
return NULL;
106106
}
107107

108+
public function getStoredMethods()
109+
{
110+
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
111+
//$connection->setFetchMode(Zend_Db::FETCH_OBJ);
112+
$methods = $connection->fetchAll(
113+
sprintf(
114+
"SELECT * FROM `%s`",
115+
Mage::getSingleton('core/resource')->getTableName('mollie_methods')
116+
)
117+
);
118+
return $methods;
119+
}
120+
121+
public function setStoredMethods($methods)
122+
{
123+
$connection = Mage::getSingleton('core/resource')->getConnection('core_write');
124+
$connection->query(sprintf('TRUNCATE TABLE `%s`', Mage::getSingleton('core/resource')->getTableName('mollie_methods')));
125+
foreach ($methods as $method)
126+
{
127+
$connection->insert(
128+
Mage::getSingleton('core/resource')->getTableName('mollie_methods'),
129+
array(
130+
'method_id' => $method['method_id'],
131+
'description' => $method['description'],
132+
)
133+
);
134+
}
135+
return $this;
136+
}
137+
108138
/**
109139
* Gets Api key from `config_core_data`
110140
*
@@ -125,7 +155,7 @@ public function getApiKey()
125155
*/
126156
public function getConfig($paymentmethod = NULL, $key = NULL)
127157
{
128-
$arr = array('active', 'apikey', 'description', 'skip_invoice', 'show_images');
158+
$arr = array('active', 'apikey', 'description', 'skip_invoice', 'show_images', 'webhook_tested');
129159
$paymentmethods = array('mollie');
130160

131161
if(in_array($key, $arr) && in_array($paymentmethod, $paymentmethods))
@@ -154,6 +184,7 @@ public function getModuleStatus($method_count, $method_limit)
154184
Mage::getRoot() .'/code/community/Mollie/Mpm/Helper/Data.php',
155185
Mage::getRoot() .'/code/community/Mollie/Mpm/Helper/Api.php',
156186
Mage::getRoot() .'/code/community/Mollie/Mpm/Model/Api.php',
187+
Mage::getRoot() .'/code/community/Mollie/Mpm/Model/Idl.php',
157188
Mage::getRoot() .'/code/community/Mollie/Mpm/Model/Void00.php',
158189

159190
Mage::getRoot() .'/design/adminhtml/default/default/template/mollie/system/config/status.phtml',
@@ -200,6 +231,13 @@ public function getModuleStatus($method_count, $method_limit)
200231
}
201232

202233

234+
// Check if webhook is set
235+
if (!Mage::Helper('mpm/data')->getConfig('mollie', 'webhook_tested'))
236+
{
237+
return '<b>'.$core->__('Webhook not set!').'</b><br /><span style="color:red;">'.$core->__('Warning: It seems you have not set a webhook in your Mollie profile.').'</span><br />';
238+
}
239+
240+
203241
// check deprecated files
204242
$deprFiles = array();
205243
$oldFiles = array(
@@ -208,7 +246,6 @@ public function getModuleStatus($method_count, $method_limit)
208246
Mage::getRoot() .'/code/community/Mollie/Mpm/Block/Payment/Idl/Info.php',
209247
Mage::getRoot() .'/code/community/Mollie/Mpm/controllers/IdlController.php',
210248
Mage::getRoot() .'/code/community/Mollie/Mpm/Helper/Idl.php',
211-
Mage::getRoot() .'/code/community/Mollie/Mpm/Model/Idl.php',
212249
Mage::getRoot() .'/design/frontend/base/default/template/mollie/form/idl.phtml',
213250
Mage::getRoot() .'/design/frontend/base/default/template/mollie/form/api.phtml',
214251
);

0 commit comments

Comments
 (0)