Sumankcdotcom_Esewa - Version 1.0.0

Version Notes

Stable version

Download this release

Release Info

Developer Suman K.C
Extension Sumankcdotcom_Esewa
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/Sumankcdotcom/Esewa/Helper/Data.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Sumankcdotcom_Esewa extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
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/mit-license.php
11
+ *
12
+ * @package Sumankcdotcom_Esewa
13
+ * @copyright Copyright (c) 2016
14
+ * @license http://opensource.org/licenses/mit-license.php MIT License
15
+ */
16
+ class Sumankcdotcom_Esewa_Helper_Data extends Mage_Core_Helper_Abstract
17
+ {
18
+
19
+ }
app/code/local/Sumankcdotcom/Esewa/Model/Standard.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Sumankcdotcom_Esewa extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
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/mit-license.php
11
+ *
12
+ * @package Sumankcdotcom_Esewa
13
+ * @copyright Copyright (c) 2016
14
+ * @license http://opensource.org/licenses/mit-license.php MIT License
15
+ */
16
+ class Sumankcdotcom_Esewa_Model_Standard extends Mage_Payment_Model_Method_Abstract {
17
+ protected $_code = 'esewa';
18
+ protected $_isInitializeNeeded = true;
19
+ protected $_canUseInternal = true;
20
+ protected $_canUseForMultishipping = false;
21
+ public function getOrderPlaceRedirectUrl() {
22
+ return Mage::getUrl('esewa/payment/redirect', array('_secure' => true));
23
+ }
24
+ }
25
+ ?>
app/code/local/Sumankcdotcom/Esewa/controllers/PaymentController.php ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Sumankcdotcom_Esewa extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
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/mit-license.php
11
+ *
12
+ * @package Sumankcdotcom_Esewa
13
+ * @copyright Copyright (c) 2016
14
+ * @license http://opensource.org/licenses/mit-license.php MIT License
15
+ */
16
+ class Sumankcdotcom_Esewa_PaymentController extends Mage_Core_Controller_Front_Action {
17
+ // The redirect action is triggered when someone places an order
18
+ public function redirectAction() {
19
+ $this->loadLayout();
20
+ $block = $this->getLayout()->createBlock('Mage_Core_Block_Template','esewa',array('template' => 'sumankcdotcom_esewa/redirect.phtml'));
21
+ $this->getLayout()->getBlock('content')->append($block);
22
+ $this->renderLayout();
23
+ }
24
+
25
+ // The response action is triggered when your gateway sends back a response after processing the customer's payment
26
+ public function responseAction() {
27
+ if($response = $this->getRequest()->getParams()) {
28
+ $validate = $response['q'];
29
+ $orderId = $response['oid'];
30
+
31
+ if($validate=='su') {
32
+ // Payment was successful, so update the order's state, send order email and move to the success page
33
+ $order = Mage::getModel('sales/order');
34
+ $order->loadByIncrementId($orderId);
35
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, 'Payment with Esewa authorized.');
36
+ $order->addStatusHistoryComment("Esewa payment reference id : ".$response['refId'], false);
37
+
38
+ $order->sendNewOrderEmail();
39
+ $order->setEmailSent(true);
40
+
41
+ $order->save();
42
+ $this->invoiceorder($order);
43
+ Mage::getSingleton('checkout/session')->unsQuoteId();
44
+
45
+ Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/success', array('_secure'=>true));
46
+ }
47
+ else {
48
+ // There is a problem in the response we got
49
+ $this->cancelAction();
50
+ Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/failure', array('_secure'=>true));
51
+ }
52
+ }
53
+ else
54
+ Mage_Core_Controller_Varien_Action::_redirect('');
55
+ }
56
+
57
+ // The cancel action is triggered when an order is to be cancelled
58
+ public function cancelAction() {
59
+ if (Mage::getSingleton('checkout/session')->getLastRealOrderId()) {
60
+ $order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
61
+ if($order->getId()) {
62
+ // Flag the order as 'cancelled' and save it
63
+ $order->cancel()->setState(Mage_Sales_Model_Order::STATE_CANCELED, true, 'Esewa has declined the payment.')->save();
64
+ }
65
+ }
66
+ }
67
+ /*Invoice an order*/
68
+ public function invoiceorder($order){
69
+ try{
70
+ if($order->canInvoice() && $order->getIncrementId()){
71
+
72
+ $items = array();
73
+ foreach ($order->getAllItems() as $item) {
74
+ $items[$item->getId()] = $item->getQtyOrdered();
75
+ }
76
+
77
+ $invoiceId=Mage::getModel('sales/order_invoice_api')->create($order->getIncrementId(),$items,null,false,true);
78
+ Mage::getModel('sales/order_invoice_api')->capture($invoiceId);
79
+ }
80
+ return true;
81
+ }catch(Mage_Core_Exception $e) {}
82
+ }
83
+ }
app/code/local/Sumankcdotcom/Esewa/etc/config.xml ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Sumankcdotcom_Esewa>
5
+ <version>0.1.0</version>
6
+ </Sumankcdotcom_Esewa>
7
+ </modules>
8
+ <global>
9
+ <models>
10
+ <esewa>
11
+ <class>Sumankcdotcom_Esewa_Model</class>
12
+ </esewa>
13
+ </models>
14
+ <helpers>
15
+ <esewa>
16
+ <class>Sumankcdotcom_Esewa_Helper</class>
17
+ </esewa>
18
+ </helpers>
19
+ <blocks>
20
+ <esewa>
21
+ <class>Sumankcdotcom_Esewa_Block</class>
22
+ </esewa>
23
+ </blocks>
24
+ </global>
25
+ <default>
26
+ <payment>
27
+ <esewa>
28
+ <model>esewa/standard</model>
29
+ <active>1</active>
30
+ <order_status>pending</order_status>
31
+ <title>Esewa</title>
32
+ <payment_action>sale</payment_action>
33
+ <allowspecific>0</allowspecific>
34
+ <sort_order>1</sort_order>
35
+ </esewa>
36
+ </payment>
37
+ </default>
38
+ <frontend>
39
+ <routers>
40
+ <esewa>
41
+ <use>standard</use>
42
+ <args>
43
+ <module>Sumankcdotcom_Esewa</module>
44
+ <frontName>esewa</frontName>
45
+ </args>
46
+ </esewa>
47
+ </routers>
48
+ </frontend>
49
+ </config>
app/code/local/Sumankcdotcom/Esewa/etc/system.xml ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <esewa translate="label comment" module="paygate">
7
+ <label>Esewa Payment</label>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>100</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>1</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <fields>
14
+ <field_notification translate="label comment">
15
+ <label>
16
+ <![CDATA[
17
+ Esewa payment gateway : eSewa is the online payment gateway of Nepal.. <a href="https://esewa.com.np/static/faq">(more about esewa)</a><br />
18
+ - You need to register at <a href="https://esewa.com.np" target="_blank">esewa</a> and get Service code/Merchant id for your business.<br />
19
+ For customization & Support : <a target="_blank" href="http://sumankc.com/contact">Contact here</a>
20
+ ]]>
21
+ </label>
22
+ <frontend_type>label</frontend_type>
23
+ <frontend_model>lowstocknotify/adminhtml_system_config_notification</frontend_model>
24
+ <margin_top>0px</margin_top>
25
+ <sort_order>1</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>1</show_in_store>
29
+ <comment></comment>
30
+ </field_notification>
31
+ <active translate="label">
32
+ <label>Enabled</label>
33
+ <frontend_type>select</frontend_type>
34
+ <source_model>adminhtml/system_config_source_yesno</source_model>
35
+ <sort_order>10</sort_order>
36
+ <show_in_default>1</show_in_default>
37
+ <show_in_website>1</show_in_website>
38
+ <show_in_store>0</show_in_store>
39
+ </active>
40
+ <title translate="label">
41
+ <label>Title</label>
42
+ <frontend_type>text</frontend_type>
43
+ <sort_order>20</sort_order>
44
+ <show_in_default>1</show_in_default>
45
+ <show_in_website>1</show_in_website>
46
+ <show_in_store>1</show_in_store>
47
+ </title>
48
+ <test_mode translate="label">
49
+ <label>Test Mode</label>
50
+ <frontend_type>select</frontend_type>
51
+ <source_model>adminhtml/system_config_source_yesno</source_model>
52
+ <sort_order>25</sort_order>
53
+ <show_in_default>1</show_in_default>
54
+ <show_in_website>1</show_in_website>
55
+ <show_in_store>0</show_in_store>
56
+ </test_mode>
57
+ <service_code translate="label">
58
+ <label>Service code / Merchant id</label>
59
+ <frontend_type>text</frontend_type>
60
+ <sort_order>26</sort_order>
61
+ <show_in_default>1</show_in_default>
62
+ <show_in_website>1</show_in_website>
63
+ <show_in_store>1</show_in_store>
64
+ </service_code>
65
+ <order_status translate="label">
66
+ <label>New Order Status</label>
67
+ <frontend_type>select</frontend_type>
68
+ <source_model>adminhtml/system_config_source_order_status</source_model>
69
+ <sort_order>50</sort_order>
70
+ <show_in_default>1</show_in_default>
71
+ <show_in_website>1</show_in_website>
72
+ <show_in_store>0</show_in_store>
73
+ </order_status>
74
+ <allowspecific translate="label">
75
+ <label>Payment Applicable From</label>
76
+ <frontend_type>select</frontend_type>
77
+ <sort_order>61</sort_order>
78
+ <source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
79
+ <show_in_default>1</show_in_default>
80
+ <show_in_website>1</show_in_website>
81
+ <show_in_store>0</show_in_store>
82
+ </allowspecific>
83
+ <specificcountry translate="label">
84
+ <label>Countries Payment Applicable From</label>
85
+ <frontend_type>multiselect</frontend_type>
86
+ <sort_order>70</sort_order>
87
+ <source_model>adminhtml/system_config_source_country</source_model>
88
+ <show_in_default>1</show_in_default>
89
+ <show_in_website>1</show_in_website>
90
+ <show_in_store>0</show_in_store>
91
+ <depends>
92
+ <allowspecific>1</allowspecific>
93
+ </depends>
94
+ </specificcountry>
95
+ <sort_order translate="label">
96
+ <label>Sort Order</label>
97
+ <frontend_type>text</frontend_type>
98
+ <sort_order>100</sort_order>
99
+ <show_in_default>1</show_in_default>
100
+ <show_in_website>1</show_in_website>
101
+ <show_in_store>0</show_in_store>
102
+ </sort_order>
103
+ </fields>
104
+ </esewa>
105
+ </groups>
106
+ </payment>
107
+ </sections>
108
+ </config>
app/design/frontend/base/default/template/sumankcdotcom_esewa/redirect.phtml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Sumankcdotcom_Esewa extension
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the MIT License
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/mit-license.php
11
+ *
12
+ * @package Sumankcdotcom_Esewa
13
+ * @copyright Copyright (c) 2016
14
+ * @license http://opensource.org/licenses/mit-license.php MIT License
15
+ */
16
+ $_order = new Mage_Sales_Model_Order();
17
+ $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
18
+ $_order->loadByIncrementId($orderId);
19
+ $action = Mage::getStoreConfig('payment/esewa/test_mode')==1?'http://dev.esewa.com.np/epay/main':'http://esewa.com.np/epay/main';
20
+ $service_code = Mage::getStoreConfig('payment/esewa/service_code');
21
+ ?>
22
+ <h3>Redirecting to esewa...</h3>
23
+ <form name="esewaform" method="post" action="<?php echo $action;?>">
24
+ <input value="<?php echo $_order->getBaseGrandTotal(); ?>" name="tAmt" type="hidden">
25
+ <input value="<?php echo $_order->getSubtotal(); ?>" name="amt" type="hidden"> <!--/ total amount-->
26
+ <input value="<?php echo $_order->getTaxAmount(); ?>" name="txAmt" type="hidden"> <!--/ tax amount -->
27
+ <input value="0" name="psc" type="hidden"> <!--/ product service charge -->
28
+ <input value="<?php echo $_order->getBaseShippingAmount(); ?>" name="pdc" type="hidden"> <!--/product delivery code -->
29
+ <input value="<?php echo $service_code; ?>" name="scd" type="hidden"> <!--/service code -->
30
+ <input value="<?php echo $orderId; ?>" name="pid" type="hidden"> <!--/unique id -->
31
+ <input value="<?php echo Mage::getBaseUrl(); ?>esewa/payment/response?q=su" type="hidden" name="su">
32
+ <input value="<?php echo Mage::getBaseUrl(); ?>esewa/payment/response?q=fu" type="hidden" name="fu">
33
+ </form>
34
+ <script type="text/javascript">
35
+ document.esewaform.submit();
36
+ </script>
app/etc/modules/Sumankcdotcom_Esewa.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Sumankcdotcom_Esewa>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Sumankcdotcom_Esewa>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Sumankcdotcom_Esewa</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/mit-license.php">MIT License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Payment gateway esewa integration </summary>
10
+ <description>Payment gateway esewa integration in magento. esewa is one of the payment gateway in Nepal.</description>
11
+ <notes>Stable version</notes>
12
+ <authors><author><name>Suman K.C</name><user>sumankc</user><email>sumankc55@gmail.com</email></author></authors>
13
+ <date>2016-03-15</date>
14
+ <time>10:53:54</time>
15
+ <contents><target name="magelocal"><dir name="Sumankcdotcom"><dir name="Esewa"><dir name="Helper"><file name="Data.php" hash="8f0f876a4fef2673c153e98f417d04dc"/></dir><dir name="Model"><file name="Standard.php" hash="d208edc878fda5163f0da82f37589687"/></dir><dir name="controllers"><file name="PaymentController.php" hash="ed38f5ae233ccb3c7347f9a0d02650ea"/></dir><dir name="etc"><file name="config.xml" hash="90952cab840121ecdb2bd056e09b91fe"/><file name="system.xml" hash="2dbd77f10e5b784efee69d7138d7fb1b"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Sumankcdotcom_Esewa.xml" hash="1e95398348916bae495e62966d357646"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="sumankcdotcom_esewa"><file name="redirect.phtml" hash="87c05456d0530faa36b7a091d1b2f251"/></dir></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>