Webmu_DisableAutoInvoice - Version 0.1.0

Version Notes

Release notes:

v. 0.1.0
- initial public release of Disable Auto Invoice

Download this release

Release Info

Developer Webmu
Extension Webmu_DisableAutoInvoice
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/community/Webmu/DisableAutoInvoice/Helper/Data.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Webmu
16
+ * @package Webmu_DisableAutoInvoice
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+ class Webmu_DisableAutoInvoice_Helper_Data extends Mage_Core_Helper_Abstract
20
+ {
21
+ // General config
22
+ public function isEnabled()
23
+ {
24
+ return Mage::getStoreConfig('disableautoinvoice/general/status');
25
+ }
26
+ }
27
+
app/code/community/Webmu/DisableAutoInvoice/Model/Sales/Order/Payment.php ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Webmu
16
+ * @package Webmu_DisableAutoInvoice
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+ class Webmu_DisableAutoInvoice_Model_Sales_Order_Payment extends Mage_Sales_Model_Order_Payment
20
+ {
21
+ /**
22
+ * Capture the payment online
23
+ * Does not create invoice automatically for order
24
+ * Updates transactions hierarchy, if required
25
+ * Updates payment totals, updates order status and adds proper comments
26
+ *
27
+ * TODO: eliminate logic duplication with registerCaptureNotification()
28
+ *
29
+ * @return Mage_Sales_Model_Order_Payment
30
+ * @throws Mage_Core_Exception
31
+ */
32
+ public function capture($invoice)
33
+ {
34
+ if( !Mage::helper('disableautoinvoice')->isEnabled()){
35
+ return parent::capture($invoice);
36
+ }
37
+
38
+ $invoice = null;
39
+ $order = $this->getOrder();
40
+
41
+ $amountToCapture = $this->_formatAmount($order->getBaseGrandTotal());
42
+ $order = $this->getOrder();
43
+
44
+ $paidWorkaround = (float)$amountToCapture;
45
+ $this->_isCaptureFinal($paidWorkaround);
46
+
47
+ $this->_generateTransactionId(
48
+ Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE,
49
+ $this->getAuthorizationTransaction()
50
+ );
51
+
52
+ Mage::dispatchEvent('sales_order_payment_capture', array('payment' => $this, 'invoice' => $invoice));
53
+
54
+ $status = true;
55
+ if (!$this->getIsTransactionPending()) {
56
+ // attempt to capture: this can trigger "is_transaction_pending"
57
+ $this->getMethodInstance()->setStore($order->getStoreId())->capture($this, $amountToCapture);
58
+
59
+ $transaction = $this->_addTransaction(
60
+ Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE,
61
+ $invoice,
62
+ true
63
+ );
64
+
65
+ if ($this->getIsTransactionPending()) {
66
+ $message = Mage::helper('sales')->__('Capturing amount of %s is pending approval on gateway.', $this->_formatPrice($amountToCapture));
67
+ $state = Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW;
68
+ if ($this->getIsFraudDetected()) {
69
+ $status = Mage_Sales_Model_Order::STATUS_FRAUD;
70
+ }
71
+ } else { // normal online capture: invoice is marked as "paid"
72
+ $message = Mage::helper('sales')->__('Captured amount of %s online.', $this->_formatPrice($amountToCapture));
73
+ $state = Mage_Sales_Model_Order::STATE_PROCESSING;
74
+ $this->_updateTotals(array('base_amount_paid_online' => $amountToCapture));
75
+ }
76
+ if ($order->isNominal()) {
77
+ $message = $this->_prependMessage(Mage::helper('sales')->__('Nominal order registered.'));
78
+ } else {
79
+ $message = $this->_prependMessage($message);
80
+ $message = $this->_appendTransactionToMessage($transaction, $message);
81
+ }
82
+ $order->setState($state, $status, $message);
83
+
84
+ return $this;
85
+ }
86
+ Mage::throwException(
87
+ Mage::helper('sales')->__('The transaction "%s" cannot be captured yet.', $amountToCapture)
88
+ );
89
+ }
90
+
91
+ /**
92
+ * Process a capture notification from a payment gateway for specified amount
93
+ * Does not create an invoice automatically if the amount if the amount covers the order base grand total completely
94
+ * Updates transactions hierarchy, if required
95
+ * Prevents transaction double processing
96
+ * Updates payment totals, updates order status and adds proper comments
97
+ *
98
+ * TODO: eliminate logic duplication with capture()
99
+ *
100
+ * @param float $amount
101
+ * @param bool $skipFraudDetection
102
+ * @return Mage_Sales_Model_Order_Payment
103
+ */
104
+ public function registerCaptureNotification($amount, $skipFraudDetection = false)
105
+ {
106
+ if( !Mage::helper('disableautoinvoice')->isEnabled()){
107
+ return parent::registerCaptureNotification($amount, $skipFraudDetection );
108
+ }
109
+
110
+ $this->_generateTransactionId(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE,
111
+ $this->getAuthorizationTransaction()
112
+ );
113
+
114
+ $order = $this->getOrder();
115
+ $amount = (float)$amount;
116
+ $invoice = null;
117
+
118
+ // register new capture
119
+ if (!$invoice) {
120
+ $isSameCurrency = $this->_isSameCurrency();
121
+ if (!$isSameCurrency && !$this->_isCaptureFinal($amount)) {
122
+ if (!$skipFraudDetection || !$isSameCurrency) {
123
+ $this->setIsFraudDetected(true);
124
+ }
125
+ $this->_updateTotals(array('base_amount_paid_online' => $amount));
126
+ }
127
+ }
128
+
129
+ $status = true;
130
+ if ($this->getIsTransactionPending()) {
131
+ $message = Mage::helper('sales')->__('Capturing amount of %s is pending approval on gateway.', $this->_formatPrice($amount));
132
+ $state = Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW;
133
+ if ($this->getIsFraudDetected()) {
134
+ $message = Mage::helper('sales')->__('Order is suspended as its capture amount %s is suspected to be fraudulent.', $this->_formatPrice($amount, $this->getCurrencyCode()));
135
+ $status = Mage_Sales_Model_Order::STATUS_FRAUD;
136
+ }
137
+ } else {
138
+ $message = Mage::helper('sales')->__('Registered notification about captured amount of %s.', $this->_formatPrice($amount));
139
+ $state = Mage_Sales_Model_Order::STATE_PROCESSING;
140
+ if ($this->getIsFraudDetected()) {
141
+ $state = Mage_Sales_Model_Order::STATE_PAYMENT_REVIEW;
142
+ $message = Mage::helper('sales')->__('Order is suspended as its capture amount %s is suspected to be fraudulent.', $this->_formatPrice($amount, $this->getCurrencyCode()));
143
+ $status = Mage_Sales_Model_Order::STATUS_FRAUD;
144
+ }
145
+ }
146
+
147
+ $transaction = $this->_addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE, $invoice, true);
148
+ $message = $this->_prependMessage($message);
149
+ $message = $this->_appendTransactionToMessage($transaction, $message);
150
+ $order->setState($state, $status, $message);
151
+ return $this;
152
+ }
153
+ }
app/code/community/Webmu/DisableAutoInvoice/etc/adminhtml.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <admin>
6
+ <children>
7
+ <system>
8
+ <children>
9
+ <config>
10
+ <children>
11
+ <disableautoinvoice translate="title" module="disableautoinvoice">
12
+ <title>Disable Auto Invoice Section</title>
13
+ <sort_order>1111</sort_order>
14
+ </disableautoinvoice>
15
+ </children>
16
+ </config>
17
+ </children>
18
+ </system>
19
+ </children>
20
+ </admin>
21
+ </resources>
22
+ </acl>
23
+ </config>
app/code/community/Webmu/DisableAutoInvoice/etc/config.xml ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Webmu_DisableAutoInvoice>
5
+ <version>0.1.0</version>
6
+ </Webmu_DisableAutoInvoice>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <disableautoinvoice>
11
+ <class>Webmu_DisableAutoInvoice_Helper</class>
12
+ </disableautoinvoice>
13
+ </helpers>
14
+ <models>
15
+ <disableautoinvoice>
16
+ <class>Webmu_DisableAutoInvoice_Model</class>
17
+ <resourceModel>disableautoinvoice_mysql4</resourceModel>
18
+ </disableautoinvoice>
19
+ <sales>
20
+ <rewrite>
21
+ <order_payment>Webmu_DisableAutoInvoice_Model_Sales_Order_Payment</order_payment>
22
+ </rewrite>
23
+ </sales>
24
+ </models>
25
+ </global>
26
+ <default>
27
+ <disableautoinvoice>
28
+ <general>
29
+ <status>1</status>
30
+ </general>
31
+ </disableautoinvoice>
32
+ </default>
33
+ </config>
app/code/community/Webmu/DisableAutoInvoice/etc/system.xml ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <webmu translate="label" module="disableautoinvoice">
5
+ <label>WEBMU EXTENSIONS</label>
6
+ <sort_order>1600</sort_order>
7
+ </webmu>
8
+ </tabs>
9
+ <sections>
10
+ <disableautoinvoice translate="label" module="disableautoinvoice">
11
+ <label>Disable Auto Invoice</label>
12
+ <tab>webmu</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>1111</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>0</show_in_website>
17
+ <show_in_store>0</show_in_store>
18
+ <groups>
19
+ <general translate="label">
20
+ <label>Disable Auto Invoice Settings</label>
21
+ <frontend_type>text</frontend_type>
22
+ <expanded>1</expanded>
23
+ <sort_order>10</sort_order>
24
+ <show_in_default>1</show_in_default>
25
+ <show_in_website>0</show_in_website>
26
+ <show_in_store>0</show_in_store>
27
+ <fields>
28
+ <status translate="label">
29
+ <label>Enabled</label>
30
+ <frontend_type>select</frontend_type>
31
+ <source_model>adminhtml/system_config_source_yesno</source_model>
32
+ <sort_order>10</sort_order>
33
+ <show_in_default>1</show_in_default>
34
+ <show_in_website>0</show_in_website>
35
+ <show_in_store>0</show_in_store>
36
+ </status>
37
+ </fields>
38
+ </general>
39
+ </groups>
40
+ </disableautoinvoice>
41
+ </sections>
42
+ </config>
app/etc/modules/Webmu_DisableAutoInvoice.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Webmu_DisableAutoInvoice>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Webmu_DisableAutoInvoice>
8
+ </modules>
9
+ </config>
app/locale/en_US/Webmu_DisableAutoInvoice.csv ADDED
@@ -0,0 +1 @@
 
1
+ "Disable Auto Invoice","Disable Auto Invoice"
package.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Webmu_DisableAutoInvoice</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL 3.0)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Capture the payment for the order without create the invoice.</summary>
10
+ <description>In some cases it may be necessary to capture the amount of the order without creating an invoice. This module allows you to capture payment by credit card while maintaining the other operations.&#xD;
11
+ &#xD;
12
+ You can then create an invoice of the order from the backend.</description>
13
+ <notes>Release notes:&#xD;
14
+ &#xD;
15
+ v. 0.1.0&#xD;
16
+ - initial public release of Disable Auto Invoice</notes>
17
+ <authors><author><name>Webmu</name><user>webmu</user><email>info@webmu.it</email></author></authors>
18
+ <date>2016-02-18</date>
19
+ <time>14:07:19</time>
20
+ <contents><target name="magecommunity"><dir name="Webmu"><dir name="DisableAutoInvoice"><dir name="Helper"><file name="Data.php" hash="81d5fd053c0e017a699f0587c09cc7b8"/></dir><dir name="Model"><dir name="Sales"><dir name="Order"><file name="Payment.php" hash="7081a19d1c4ee209f83f6a6aac895a8e"/></dir></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="5fdb62808a78e7e4f2126b80e6841980"/><file name="config.xml" hash="21474094d7a89ee5ae88116e3a1a50e6"/><file name="system.xml" hash="a6d8a2a897d4e7d98fbac0717ea26ed2"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Webmu_DisableAutoInvoice.xml" hash="0440f3b5e18d5cca43aa365de7316eef"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Webmu_DisableAutoInvoice.csv" hash="bd7dbd60d1198f73b06af578ec471f99"/></dir></target></contents>
21
+ <compatible/>
22
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
23
+ </package>