Icepay_AutoCapture - Version 1.0.2

Version Notes

- Fixed AutoCapture not being triggered when shipping is done through the Magento API.
- Merged webservice settings with Advanced module
- Module now requires ICEPAY Advanced 1.1.9 as minimum.

Download this release

Release Info

Developer ICEPAY
Extension Icepay_AutoCapture
Version 1.0.2
Comparing to
See all releases


Code changes from version 1.0.1 to 1.0.2

app/code/community/Icepay/AutoCapture/Helper/Data.php CHANGED
@@ -16,33 +16,39 @@
16
  */
17
  class Icepay_AutoCapture_Helper_Data extends Mage_Core_Helper_Abstract {
18
 
19
- private $_version = '1.0.1';
20
- private $_minAdvancedVersion = '1.1.7';
21
 
22
- public function getCompatiblityVersion() {
 
23
  return $this->_minAdvancedVersion;
24
  }
25
 
26
- public function getVersion() {
 
27
  return $this->_version;
28
  }
29
 
30
- public function isCompatible() {
31
- return (Mage::Helper('iceadvanced')->version >= $this->_minAdvancedVersion);
 
32
  }
33
-
34
- public function isAutoCaptureActive($storeID) {
35
- return (bool)Mage::getStoreConfig('icepay_autocapture/settings/active', $storeID);
 
36
  }
37
-
38
- public function isIcepayOrder($orderID) {
 
39
  $order = Mage::getModel('sales/order')->loadByIncrementId($orderID);
40
  $paymentCode = $order->getPayment()->getMethodInstance()->getCode();
41
 
42
  return (strpos($paymentCode, 'icepayadv_') !== false) ? true : false;
43
  }
44
-
45
- public function doChecks() {
 
46
  $lines = array();
47
 
48
  $soapCheck = Mage::helper('icecore')->hasSOAP();
@@ -57,4 +63,5 @@ class Icepay_AutoCapture_Helper_Data extends Mage_Core_Helper_Abstract {
57
 
58
  return $lines;
59
  }
 
60
  }
16
  */
17
  class Icepay_AutoCapture_Helper_Data extends Mage_Core_Helper_Abstract {
18
 
19
+ private $_version = '1.0.2';
20
+ private $_minAdvancedVersion = '1.1.9';
21
 
22
+ public function getCompatiblityVersion()
23
+ {
24
  return $this->_minAdvancedVersion;
25
  }
26
 
27
+ public function getVersion()
28
+ {
29
  return $this->_version;
30
  }
31
 
32
+ public function isCompatible()
33
+ {
34
+ return version_compare(Mage::Helper('iceadvanced')->version, $this->_minAdvancedVersion, '>=');
35
  }
36
+
37
+ public function isAutoCaptureActive($storeID)
38
+ {
39
+ return (bool) Mage::getStoreConfig('icepay_autocapture/settings/active', $storeID);
40
  }
41
+
42
+ public function isIcepayOrder($orderID)
43
+ {
44
  $order = Mage::getModel('sales/order')->loadByIncrementId($orderID);
45
  $paymentCode = $order->getPayment()->getMethodInstance()->getCode();
46
 
47
  return (strpos($paymentCode, 'icepayadv_') !== false) ? true : false;
48
  }
49
+
50
+ public function doChecks()
51
+ {
52
  $lines = array();
53
 
54
  $soapCheck = Mage::helper('icecore')->hasSOAP();
63
 
64
  return $lines;
65
  }
66
+
67
  }
app/code/community/Icepay/AutoCapture/Model/Observer.php CHANGED
@@ -16,50 +16,48 @@
16
  */
17
  class Icepay_AutoCapture_Model_Observer {
18
 
19
- public function sales_order_save_after(Varien_Event_Observer $observer) {
 
20
  $order = $observer->getEvent()->getOrder();
21
 
22
  $apiRunning = Mage::getSingleton('api/server')->getAdapter() != null;
23
-
24
- if (!$apiRunning && Mage::app()->getFrontController()->getRequest()->getControllerName() != 'sales_order_shipment')
25
- return;
26
-
27
- Mage::Helper('icecore')->log('[AutoCapture] 1');
28
-
29
- // Check if ICEPAY order
30
- if (!Mage::Helper('icepay_autocapture')->isIcepayOrder($order->getIncrementId()))
31
- return;
32
-
33
- Mage::Helper('icecore')->log('AutoCapture] 2');
34
-
35
- $iceCoreModel = Mage::getModel('icecore/mysql4_iceCore');
36
- $ic_order = $iceCoreModel->loadPaymentByID($order->getIncrementId());
37
-
38
- $storeID = $ic_order['store_id'];
39
-
40
- // Check if auto capture is active
41
- if (!Mage::Helper('icepay_autocapture')->isAutoCaptureActive($storeID))
42
- return;
43
 
44
- $iceAdvancedModel = Mage::getModel('iceadvanced/mysql4_iceadvanced');
45
- $iceAdvancedModel->setScope($storeID);
46
- $paymentMethodData = $iceAdvancedModel->getPaymentMethodDataArrayByReference($ic_order['model']);
47
 
48
- if (empty($paymentMethodData)) {
49
- $iceAdvancedModel->setScope(0);
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  $paymentMethodData = $iceAdvancedModel->getPaymentMethodDataArrayByReference($ic_order['model']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  }
52
-
53
- // Check if payment method is Afterpay
54
- if ($paymentMethodData['pm_code'] != 'afterpay')
55
- return;
56
-
57
- $merchantID = Mage::getStoreConfig('icecore/settings/merchant_id', $storeID);
58
- $secretCode = Mage::getStoreConfig('icecore/settings/merchant_secret', $storeID);
59
-
60
- $service = Mage::getModel('Icepay_AutoCapture_Model_Webservice');
61
- $service->init($merchantID, $secretCode);
62
-
63
- $service->captureFull($ic_order['transaction_id']);
64
  }
 
65
  }
16
  */
17
  class Icepay_AutoCapture_Model_Observer {
18
 
19
+ public function sales_order_save_after(Varien_Event_Observer $observer)
20
+ {
21
  $order = $observer->getEvent()->getOrder();
22
 
23
  $apiRunning = Mage::getSingleton('api/server')->getAdapter() != null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
+ if (($apiRunning) || (Mage::app()->getFrontController()->getRequest()->getControllerName() == 'sales_order_shipment')) {
 
 
26
 
27
+ // Check if ICEPAY order
28
+ if (!Mage::Helper('icepay_autocapture')->isIcepayOrder($order->getIncrementId()))
29
+ return;
30
+
31
+ $iceCoreModel = Mage::getModel('icecore/mysql4_iceCore');
32
+ $ic_order = $iceCoreModel->loadPaymentByID($order->getIncrementId());
33
+
34
+ $storeID = $ic_order['store_id'];
35
+
36
+ // Check if auto capture is active
37
+ if (!Mage::Helper('icepay_autocapture')->isAutoCaptureActive($storeID))
38
+ return;
39
+
40
+ $iceAdvancedModel = Mage::getModel('iceadvanced/mysql4_iceadvanced');
41
+ $iceAdvancedModel->setScope($storeID);
42
  $paymentMethodData = $iceAdvancedModel->getPaymentMethodDataArrayByReference($ic_order['model']);
43
+
44
+ if (empty($paymentMethodData)) {
45
+ $iceAdvancedModel->setScope(0);
46
+ $paymentMethodData = $iceAdvancedModel->getPaymentMethodDataArrayByReference($ic_order['model']);
47
+ }
48
+
49
+ // Check if payment method is Afterpay
50
+ if (strtoupper($paymentMethodData['pm_code']) != 'AFTERPAY')
51
+ return;
52
+
53
+ $merchantID = Mage::getStoreConfig('icecore/settings/merchant_id', $storeID);
54
+ $secretCode = Mage::getStoreConfig('icecore/settings/merchant_secret', $storeID);
55
+
56
+ $service = Mage::getModel('Icepay_AutoCapture_Model_Webservice_AutoCapture');
57
+ $service->init($merchantID, $secretCode);
58
+
59
+ $service->captureFull($ic_order['transaction_id']);
60
  }
 
 
 
 
 
 
 
 
 
 
 
 
61
  }
62
+
63
  }
app/code/community/Icepay/AutoCapture/Model/Webservice.php DELETED
@@ -1,60 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * ICEPAY AutoCapture - Webservice Model
5
- *
6
- * @version 1.0.0
7
- * @author Wouter van Tilburg <wouter@icepay.eu>
8
- * @copyright ICEPAY <www.icepay.com>
9
- *
10
- * Disclaimer:
11
- * The merchant is entitled to change de ICEPAY plug-in code,
12
- * any changes will be at merchant's own risk.
13
- * Requesting ICEPAY support for a modified plug-in will be
14
- * charged in accordance with the standard ICEPAY tariffs.
15
- *
16
- */
17
- class Icepay_AutoCapture_Model_Webservice {
18
-
19
- private $_client;
20
- private $_merchantID;
21
- private $_secretCode;
22
- private $_url = 'https://connect.icepay.com/webservice2/APCapture.svc?wsdl';
23
-
24
- public function init($merchantID, $secretCode) {
25
- $this->_merchantID = (int) $merchantID;
26
- $this->_secretCode = (string) $secretCode;
27
-
28
- $this->_client = new SoapClient($this->_url, array('cache_wsdl' => 'WSDL_CACHE_NONE', 'encoding' => 'utf-8'));
29
- }
30
-
31
- public function captureFull($paymentID, $amount = 0, $currency = '') {
32
- $obj = new stdClass();
33
-
34
- $obj->MerchantID = $this->_merchantID;
35
- $obj->Timestamp = gmdate("Y-m-d\TH:i:s\Z");
36
- $obj->amount = $amount;
37
- $obj->currency = $currency;
38
- $obj->PaymentID = $paymentID;
39
-
40
- $obj->Checksum = $this->generateChecksum($obj);
41
-
42
- try {
43
- $this->_client->CaptureFull($obj);
44
- Mage::Helper('icecore')->log(sprintf(__('[AutoCapture] Captured payment: #%s'), $paymentID));
45
- } catch (Exception $e) {
46
- Mage::Helper('icecore')->log(sprintf(__('[AutoCapture] Failed to capture payment: #%s'), $e->getMessage()));
47
- }
48
- }
49
-
50
- private function generateChecksum($obj) {
51
- $arr = array();
52
- array_push($arr, $this->_secretCode);
53
-
54
- foreach ($obj as $val) {
55
- array_push($arr, $val);
56
- }
57
-
58
- return sha1(implode('|', $arr));
59
- }
60
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Icepay/AutoCapture/Model/Webservice/AutoCapture.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ICEPAY AutoCapture - Webservice Model
5
+ *
6
+ * @version 1.0.0
7
+ * @author Wouter van Tilburg <wouter@icepay.eu>
8
+ * @copyright ICEPAY <www.icepay.com>
9
+ *
10
+ * Disclaimer:
11
+ * The merchant is entitled to change de ICEPAY plug-in code,
12
+ * any changes will be at merchant's own risk.
13
+ * Requesting ICEPAY support for a modified plug-in will be
14
+ * charged in accordance with the standard ICEPAY tariffs.
15
+ *
16
+ */
17
+ class Icepay_AutoCapture_Model_Webservice_AutoCapture extends Icepay_IceCore_Model_Webservice_Core {
18
+
19
+ protected $serviceURL = 'https://connect.icepay.com/webservice/APCapture.svc?wsdl';
20
+
21
+ public function captureFull($paymentID, $amount = 0, $currency = '') {
22
+ $obj = new stdClass();
23
+
24
+ $obj->MerchantID = $this->merchantID;
25
+ $obj->Timestamp = $this->getTimestamp();
26
+ $obj->amount = $amount;
27
+ $obj->currency = $currency;
28
+ $obj->PaymentID = $paymentID;
29
+
30
+ $obj->Checksum = $this->generateChecksum($obj, $this->secretCode);
31
+
32
+ try {
33
+ $this->client->CaptureFull($obj);
34
+ Mage::Helper('icecore')->log(sprintf(__('[AutoCapture] Captured payment: #%s'), $paymentID));
35
+ } catch (Exception $e) {
36
+ Mage::Helper('icecore')->log(sprintf(__('[AutoCapture] Failed to capture payment: #%s'), $e->getMessage()));
37
+ }
38
+ }
39
+ }
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Icepay_AutoCapture</name>
4
- <version>1.0.1</version>
5
  <stability>stable</stability>
6
  <license>Commercial</license>
7
  <channel>community</channel>
@@ -11,11 +11,13 @@ www.icepay.com</summary>
11
  <description>Captures Afterpay transactions upon shipping.&#xD;
12
  &#xD;
13
  Requires ICEPAY Advanced.</description>
14
- <notes>- Fixed AutoCapture not being triggered when shipping is done through the Magento API.</notes>
 
 
15
  <authors><author><name>ICEPAY</name><user>ICEPAY_PSP</user><email>it@icepay.com</email></author><author><name>Wouter van Tilburg</name><user>wvantilburg</user><email>wouter@icepay.eu</email></author></authors>
16
- <date>2013-07-26</date>
17
- <time>12:28:50</time>
18
- <contents><target name="magecommunity"><dir name="Icepay"><dir name="AutoCapture"><dir><dir name="Block"><dir name="Adminhtml"><dir name="Grid"><file name="Moduleinfo.php" hash="fdc55156394912cfb6b0cc9ffe291c0b"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="2944c3b9625d07a4876b972cffa1ea21"/></dir><dir name="Model"><file name="Observer.php" hash="7e528862f8feee123d752dd417dc4458"/><file name="Settings.php" hash="853c0f07b95090000d0becf50bb0256a"/><file name="Webservice.php" hash="94eb0658d9c3a40482058b5a662390f5"/></dir><dir name="etc"><file name="config.xml" hash="e4ddbd4cb87825f612302492e8f83824"/><file name="system.xml" hash="ae6d6173b53715f443267cac98f26244"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Icepay_AutoCapture.xml" hash="4639ada113edc2b2ed5596ec40cb184b"/></dir></target><target name="magelocale"><dir><dir name="nl_NL"><file name="Icepay_AutoCapture.csv" hash="c0a4b03f36b10f43b2ab2f7399fd9653"/></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="icepayautocapture"><file name="module_information.phtml" hash="5994ac5b0012297064e23d976b667928"/></dir></dir></dir></dir></dir></target></contents>
19
  <compatible/>
20
- <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><package><name>Icepay_IceAdvanced</name><channel>community</channel><min>1.1.7</min><max>9.0.0</max></package><extension><name>soap</name><min></min><max></max></extension></required></dependencies>
21
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Icepay_AutoCapture</name>
4
+ <version>1.0.2</version>
5
  <stability>stable</stability>
6
  <license>Commercial</license>
7
  <channel>community</channel>
11
  <description>Captures Afterpay transactions upon shipping.&#xD;
12
  &#xD;
13
  Requires ICEPAY Advanced.</description>
14
+ <notes>- Fixed AutoCapture not being triggered when shipping is done through the Magento API.&#xD;
15
+ - Merged webservice settings with Advanced module&#xD;
16
+ - Module now requires ICEPAY Advanced 1.1.9 as minimum.</notes>
17
  <authors><author><name>ICEPAY</name><user>ICEPAY_PSP</user><email>it@icepay.com</email></author><author><name>Wouter van Tilburg</name><user>wvantilburg</user><email>wouter@icepay.eu</email></author></authors>
18
+ <date>2013-08-14</date>
19
+ <time>11:15:13</time>
20
+ <contents><target name="magecommunity"><dir name="Icepay"><dir name="AutoCapture"><dir><dir name="Block"><dir name="Adminhtml"><dir name="Grid"><file name="Moduleinfo.php" hash="fdc55156394912cfb6b0cc9ffe291c0b"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="14be30ad89c84e3ed1497b0ab1cf7c4b"/></dir><dir name="Model"><file name="Observer.php" hash="eb7219264d03ad874fc510cd7ff3eb88"/><file name="Settings.php" hash="853c0f07b95090000d0becf50bb0256a"/><dir name="Webservice"><file name="AutoCapture.php" hash="8dceb1e2578dd8fea93ce7134ca34f6a"/></dir></dir><dir name="etc"><file name="config.xml" hash="e4ddbd4cb87825f612302492e8f83824"/><file name="system.xml" hash="ae6d6173b53715f443267cac98f26244"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Icepay_AutoCapture.xml" hash="4639ada113edc2b2ed5596ec40cb184b"/></dir></target><target name="magelocale"><dir><dir name="nl_NL"><file name="Icepay_AutoCapture.csv" hash="c0a4b03f36b10f43b2ab2f7399fd9653"/></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="icepayautocapture"><file name="module_information.phtml" hash="5994ac5b0012297064e23d976b667928"/></dir></dir></dir></dir></dir></target></contents>
21
  <compatible/>
22
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><package><name>Icepay_IceAdvanced</name><channel>community</channel><min>1.1.9</min><max>9.0.0</max></package><extension><name>soap</name><min></min><max></max></extension></required></dependencies>
23
  </package>