Cashu_Paymentmethod - Version 1.0.0

Version Notes

First cashu extension release

Download this release

Release Info

Developer Moe
Extension Cashu_Paymentmethod
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/Cashu/Paymentmethod/Adminhtml/Model/System/Config/Source/Currencyoptions.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Cashu_Paymentmethod_Adminhtml_Model_System_Config_Source_Currencyoptions {
4
+ /***/
5
+
6
+ /**
7
+ * Options getter
8
+ *
9
+ * @return array
10
+ */
11
+ public function toOptionArray()
12
+ {
13
+ return array(
14
+ array('value' => 'usd', 'label'=>Mage::helper('adminhtml')->__('USD')),
15
+ array('value' => 'csh', 'label'=>Mage::helper('adminhtml')->__('CSH')),
16
+ array('value' => 'aed', 'label'=>Mage::helper('adminhtml')->__('AED')),
17
+ array('value' => 'eur', 'label'=>Mage::helper('adminhtml')->__('EUR')),
18
+ array('value' => 'jod', 'label'=>Mage::helper('adminhtml')->__('JOD')),
19
+ array('value' => 'egp', 'label'=>Mage::helper('adminhtml')->__('EGP')),
20
+ array('value' => 'sar', 'label'=>Mage::helper('adminhtml')->__('SAR')),
21
+ array('value' => 'dzd', 'label'=>Mage::helper('adminhtml')->__('DZD')),
22
+ array('value' => 'lbp', 'label'=>Mage::helper('adminhtml')->__('LBP')),
23
+ array('value' => 'mad', 'label'=>Mage::helper('adminhtml')->__('MAD')),
24
+ array('value' => 'qar', 'label'=>Mage::helper('adminhtml')->__('QAR')),
25
+ array('value' => 'try', 'label'=>Mage::helper('adminhtml')->__('TRY')),
26
+ array('value' => 'kwd', 'label'=>Mage::helper('adminhtml')->__('KWD')),
27
+ array('value' => 'bhd', 'label'=>Mage::helper('adminhtml')->__('BHD')),
28
+ array('value' => 'omr', 'label'=>Mage::helper('adminhtml')->__('OMR')),
29
+ );
30
+ }
31
+
32
+ }
app/code/local/Cashu/Paymentmethod/Adminhtml/Model/System/Config/Source/Languageoptions.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Cashu_Paymentmethod_Adminhtml_Model_System_Config_Source_Languageoptions {
4
+ /***/
5
+
6
+ /**
7
+ * Options getter
8
+ *
9
+ * @return array
10
+ */
11
+ public function toOptionArray()
12
+ {
13
+ return array(
14
+ array('value' => 'en', 'label'=>Mage::helper('adminhtml')->__('en')),
15
+ array('value' => 'ar', 'label'=>Mage::helper('adminhtml')->__('ar')),
16
+ );
17
+ }
18
+
19
+ }
app/code/local/Cashu/Paymentmethod/Helper/Data.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class Cashu_Paymentmethod_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+
5
+ }
app/code/local/Cashu/Paymentmethod/Model/Pay.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Cashu_Paymentmethod_Model_Pay extends Mage_Payment_Model_Method_Abstract {
3
+ protected $_code = 'paymentmethod';
4
+
5
+ protected $_isInitializeNeeded = true;
6
+ protected $_canUseInternal = true;
7
+ protected $_canUseForMultishipping = false;
8
+
9
+ public function getOrderPlaceRedirectUrl() {
10
+ return Mage::getUrl('paymentmethod/payment/redirect', array('_secure' => true));
11
+ }
12
+ }
app/code/local/Cashu/Paymentmethod/controllers/PaymentController.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Cashu_Paymentmethod_PaymentController extends Mage_Core_Controller_Front_Action {
4
+ // The redirect action is triggered when someone places an order
5
+ public function redirectAction() {
6
+ $this->loadLayout();
7
+ $block = $this->getLayout()->createBlock('Mage_Core_Block_Template','paymentmethod',array('template' => 'cashu/redirect.phtml'));
8
+ $this->getLayout()->getBlock('content')->append($block);
9
+ $this->renderLayout();
10
+ }
11
+
12
+ // The response action is triggered when your gateway sends back a response after processing the customer's payment
13
+ public function responseAction() {
14
+ if($this->getRequest()->isPost()) {
15
+
16
+ /*
17
+ /* Your gateway's code to make sure the reponse you
18
+ /* just got is from the gatway and not from some weirdo.
19
+ /* This generally has some checksum or other checks,
20
+ /* and is provided by the gateway.
21
+ /* For now, we assume that the gateway's response is valid
22
+ */
23
+
24
+ //extract($_POST);
25
+
26
+ $validated = true;
27
+ $orderId = $_POST['txt1']; // Generally sent by gateway
28
+
29
+ //var_dump($orderId);
30
+
31
+ if($validated) {
32
+
33
+ // Payment was successful, so update the order's state, send order email and move to the success page
34
+ $order = Mage::getModel('sales/order');
35
+ $order->loadByIncrementId($orderId);
36
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true, 'Gateway has authorized the payment.');
37
+
38
+ $order->sendNewOrderEmail();
39
+ $order->setEmailSent(true);
40
+
41
+ $order->save();
42
+
43
+ //Mage::getSingleton('checkout/session')->unsQuoteId();
44
+
45
+ //header('location: http://test.shopgo.me/cashument/payment/success');
46
+ //Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/success', array('_secure'=>true));
47
+ //echo $orderId;
48
+ //$this->getLayout()->helper('page/layout')->applyTemplate('two_columns_left');
49
+
50
+ $block = $this->getLayout()->createBlock('Mage_Core_Block_Template','paymentmethod_block',array('template' => 'cashu/success.phtml'))->setData('order', $orderId);
51
+
52
+
53
+ $this->loadLayout()->getLayout()->getBlock('root')->setTemplate('page/2columns-left.phtml');
54
+
55
+
56
+ $this->loadLayout()->getLayout()->getBlock('content')->append($block);
57
+
58
+
59
+ $this->renderLayout();
60
+
61
+
62
+ }
63
+ else {
64
+ // There is a problem in the response we got
65
+ $this->cancelAction();
66
+ Mage_Core_Controller_Varien_Action::_redirect('checkout/onepage/failure', array('_secure'=>true));
67
+ }
68
+ }
69
+ else
70
+ Mage_Core_Controller_Varien_Action::_redirect('');
71
+ }
72
+
73
+ // The cancel action is triggered when an order is to be cancelled
74
+ public function cancelAction() {
75
+ if (Mage::getSingleton('checkout/session')->getLastRealOrderId()) {
76
+ $order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
77
+ if($order->getId()) {
78
+ // Flag the order as 'cancelled' and save it
79
+ $order->cancel()->setState(Mage_Sales_Model_Order::STATE_CANCELED, true, 'Gateway has declined the payment.')->save();
80
+ }
81
+ }
82
+ }
83
+
84
+ public function successAction(){
85
+ /**/
86
+
87
+ }
88
+ }
app/code/local/Cashu/Paymentmethod/etc/config.xml ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Cashu_Paymentmethod>
5
+ <version>1.0.0</version>
6
+ </Cashu_Paymentmethod>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <paymentmethod>
11
+ <class>Cashu_Paymentmethod_Block</class>
12
+ </paymentmethod>
13
+ </blocks>
14
+ <helpers>
15
+ <paymentmethod>
16
+ <class>Cashu_Paymentmethod_Helper</class>
17
+ </paymentmethod>
18
+ </helpers>
19
+ <models>
20
+ <paymentmethod>
21
+ <class>Cashu_Paymentmethod_Model</class>
22
+ </paymentmethod>
23
+ <paymentmethod_adminhtml>
24
+ <class>Cashu_Paymentmethod_Adminhtml_Model</class>
25
+ </paymentmethod_adminhtml>
26
+ </models>
27
+ <resources>
28
+ <paymentmethod_setup>
29
+ <setup>
30
+ <module>Cashu_Paymentmethod</module>
31
+ </setup>
32
+ <connection>
33
+ <use>core_setup</use>
34
+ </connection>
35
+ </paymentmethod_setup>
36
+ <paymentmethod_write>
37
+ <connection>
38
+ <use>core_write</use>
39
+ </connection>
40
+ </paymentmethod_write>
41
+ <paymentmethod_read>
42
+ <connection>
43
+ <use>core_read</use>
44
+ </connection>
45
+ </paymentmethod_read>
46
+ </resources>
47
+ </global>
48
+ <default>
49
+ <payment>
50
+ <paymentmethod>
51
+ <active>1</active>
52
+
53
+ <order_status>pending</order_status>
54
+
55
+ <model>paymentmethod/pay</model>
56
+
57
+ <title>Cashu Payment Method</title>
58
+
59
+ <payment_action>sale</payment_action>
60
+
61
+ <allowspecific>0</allowspecific>
62
+
63
+ <sort_order>1</sort_order>
64
+ </paymentmethod>
65
+ </payment>
66
+ </default>
67
+ <frontend>
68
+ <routers>
69
+ <paymentmethod>
70
+ <use>standard</use>
71
+ <args>
72
+ <module>Cashu_Paymentmethod</module>
73
+ <frontName>paymentmethod</frontName>
74
+ </args>
75
+ </paymentmethod>
76
+ </routers>
77
+ </frontend>
78
+ </config>
app/code/local/Cashu/Paymentmethod/etc/system.xml ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <payment>
5
+ <groups>
6
+ <paymentmethod translate="label" module="paygate">
7
+ <label>Cashu Payment Method</label>
8
+ <sort_order>670</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>0</show_in_store>
12
+ <fields>
13
+ <active translate="label">
14
+ <label>Enabled</label>
15
+ <frontend_type>select</frontend_type>
16
+ <source_model>adminhtml/system_config_source_yesno</source_model>
17
+ <sort_order>1</sort_order>
18
+ <show_in_default>1</show_in_default>
19
+ <show_in_website>1</show_in_website>
20
+ <show_in_store>0</show_in_store>
21
+ </active>
22
+ <order_status translate="label">
23
+ <label>New order status</label>
24
+ <frontend_type>select</frontend_type>
25
+ <source_model>adminhtml/system_config_source_order_status_processing</source_model>
26
+ <sort_order>4</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>0</show_in_store>
30
+ </order_status>
31
+ <title translate="label">
32
+ <label>Title</label>
33
+ <frontend_type>text</frontend_type>
34
+ <sort_order>2</sort_order>
35
+ <show_in_default>1</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>0</show_in_store>
38
+ </title>
39
+ <merchant_id translate="label">
40
+ <label>merchant_id</label>
41
+ <frontend_type>text</frontend_type>
42
+ <sort_order>3</sort_order>
43
+ <show_in_default>1</show_in_default>
44
+ <show_in_website>1</show_in_website>
45
+ <show_in_store>0</show_in_store>
46
+ </merchant_id>
47
+ <currency translate="label">
48
+ <label>currency</label>
49
+ <frontend_type>select</frontend_type>
50
+ <source_model>paymentmethod_adminhtml/system_config_source_currencyoptions</source_model>
51
+ <sort_order>4</sort_order>
52
+ <show_in_default>1</show_in_default>
53
+ <show_in_website>1</show_in_website>
54
+ <show_in_store>0</show_in_store>
55
+ </currency>
56
+ <language translate="label">
57
+ <label>language</label>
58
+ <frontend_type>select</frontend_type>
59
+ <source_model>paymentmethod_adminhtml/system_config_source_languageoptions</source_model>
60
+ <sort_order>5</sort_order>
61
+ <show_in_default>1</show_in_default>
62
+ <show_in_website>1</show_in_website>
63
+ <show_in_store>0</show_in_store>
64
+ </language>
65
+ <!--<display_text translate="label">
66
+ <label>Transaction Description</label>
67
+ <frontend_type>textarea</frontend_type>
68
+ <sort_order>6</sort_order>
69
+ <show_in_default>1</show_in_default>
70
+ <show_in_website>1</show_in_website>
71
+ <show_in_store>0</show_in_store>
72
+ </display_text>-->
73
+ <payment_gateway_url translate="label">
74
+ <label>payment gateway url (staging or live)</label>
75
+ <frontend_type>text</frontend_type>
76
+ <sort_order>7</sort_order>
77
+ <show_in_default>1</show_in_default>
78
+ <show_in_website>1</show_in_website>
79
+ <show_in_store>0</show_in_store>
80
+ </payment_gateway_url>
81
+ <encryption_keyword translate="label">
82
+ <label>encryption keyword</label>
83
+ <frontend_type>text</frontend_type>
84
+ <sort_order>8</sort_order>
85
+ <show_in_default>1</show_in_default>
86
+ <show_in_website>1</show_in_website>
87
+ <show_in_store>0</show_in_store>
88
+ </encryption_keyword>
89
+ <return_url>
90
+ <label>Note : you need to specify your Return URL http://example.com/paymentmethod/payment/response</label>
91
+ <frontend_type>label</frontend_type>
92
+ <sort_order>9</sort_order>
93
+ <show_in_default>1</show_in_default>
94
+ <show_in_website>1</show_in_website>
95
+ <show_in_store>0</show_in_store>
96
+ </return_url>
97
+ </fields>
98
+ </paymentmethod>
99
+ </groups>
100
+ </payment>
101
+ </sections>
102
+ </config>
app/design/frontend/default/default/template/cashu/redirect.phtml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ // Retrieve order
3
+ $_order = new Mage_Sales_Model_Order();
4
+ $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
5
+ $_order->loadByIncrementId($orderId);
6
+
7
+ //var_dump($_order->getAllItems());
8
+ $items_description = '';
9
+
10
+ $items = $_order->getAllItems();
11
+
12
+ foreach($items as $item){
13
+
14
+ $items_description .= $item->getName();
15
+
16
+ }
17
+
18
+ //var_dump($items_description);
19
+
20
+ $encryption_keyword = Mage::getStoreConfig('payment/paymentmethod/encryption_keyword',Mage::app()->getStore());
21
+ $payment_gateway_url = Mage::getStoreConfig('payment/paymentmethod/payment_gateway_url',Mage::app()->getStore());
22
+ $language = Mage::getStoreConfig('payment/paymentmethod/language',Mage::app()->getStore());
23
+ $currency = Mage::getStoreConfig('payment/paymentmethod/currency',Mage::app()->getStore());
24
+ $merchant_id = Mage::getStoreConfig('payment/paymentmethod/merchant_id',Mage::app()->getStore());
25
+
26
+ //exit();
27
+ ?>
28
+ <form name="cashupaymentform" action="<?php echo $payment_gateway_url;?>" method="post">
29
+ <input type="hidden" name="merchant_id" value="<?php echo $merchant_id;?>">
30
+ <input type="hidden" name="token" value="<?php echo md5($merchant_id.':'.round($_order->getBaseGrandTotal(),2).':'.$currency.':'.$encryption_keyword);?>">
31
+ <input type="hidden" name="display_text" value="<?php echo $items_description;?>">
32
+ <input type="hidden" name="currency" value="<?php echo $currency;?>">
33
+ <input type="hidden" name="amount" value="<?php echo round($_order->getBaseGrandTotal(),2);?>">
34
+ <input type="hidden" name="language" value="<?php echo $language;?>">
35
+ <input type="hidden" name="session_id" value="asdasd-234-asdasd">
36
+ <input type="hidden" name="txt1" value="<?php echo $orderId; ?>">
37
+ </form>
38
+ <script type="text/javascript">
39
+ document.cashupaymentform.submit();
40
+ </script>
app/design/frontend/default/default/template/cashu/success.phtml ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ $_order = new Mage_Sales_Model_Order();
4
+ $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
5
+ $_order->loadByIncrementId($orderId);
6
+ */
7
+ $orderId = $this->getOrder();
8
+ $home_url = Mage::helper('core/url')->getHomeUrl();
9
+
10
+ //$checkout_order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
11
+ $current_order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
12
+
13
+ ?>
14
+ <?php if($this->helper('customer')->isLoggedIn()): ?>
15
+ <div class="col-main">
16
+ <div class="page-title">
17
+ <h1>Your order has been received.</h1>
18
+ </div>
19
+ <h2 class="sub-title">Thank you for your purchase!</h2>
20
+ <p>Your order # is: <a href="<?php echo $home_url;?>sales/order/view/order_id/<?php echo $current_order->getId();?>"><?php echo $orderId;?></a>.</p>
21
+ <p>You will receive an order confirmation email with details of your order and a link to track its progress.</p>
22
+ <p>Click <a href="<?php echo $home_url;?>sales/order/print/order_id/<?php echo $current_order->getId();?>" onclick="this.target='_blank'">here to print</a> a copy of your order confirmation. </p>
23
+ <div class="buttons-set">
24
+ <button type="button" class="button" title="Continue Shopping" onclick="window.location='<?php echo $home_url;?>'"><span><span>Continue Shopping</span></span></button>
25
+ </div>
26
+ </div>
27
+ <?php else: ?>
28
+ <div class="col-main">
29
+ <div class="page-title">
30
+ <h1>Your order has been received.</h1>
31
+ </div>
32
+ <h2 class="sub-title">Thank you for your purchase!</h2>
33
+ <p>Your order # is: <?php echo $orderId;?>.</p>
34
+ <p>You will receive an order confirmation email with details of your order and a link to track its progress.</p>
35
+ <div class="buttons-set">
36
+ <button type="button" class="button" title="Continue Shopping" onclick="window.location='<?php echo $home_url;?>'"><span><span>Continue Shopping</span></span></button>
37
+ </div>
38
+ </div>
39
+ <?php endif; ?>
app/etc/modules/Cashu_Paymentmethod.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Cashu_Paymentmethod>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ <depends>
8
+ <Mage_Payment />
9
+ </depends>
10
+ </Cashu_Paymentmethod>
11
+ </modules>
12
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Cashu_Paymentmethod</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Cashu integration for magento</summary>
10
+ <description>it allow users to use Cashu payment gateway in magento</description>
11
+ <notes>First cashu extension release</notes>
12
+ <authors><author><name>Moe</name><user>Ghashim</user><email>moe@shopgo.me</email></author></authors>
13
+ <date>2012-07-26</date>
14
+ <time>07:38:25</time>
15
+ <contents><target name="magelocal"><dir name="Cashu"><dir name="Paymentmethod"><dir name="Adminhtml"><dir name="Model"><dir name="System"><dir name="Config"><dir name="Source"><file name="Currencyoptions.php" hash="8dcf73dc698c933a22682b12bff67983"/><file name="Languageoptions.php" hash="4e58fddaae9cccce1850d8dfe2ff28c7"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="627c69e6846849f116c17f179be4bb86"/></dir><dir name="Model"><file name="Pay.php" hash="23ba17975e2836e0e582d4430e4bbab7"/></dir><dir name="controllers"><file name="PaymentController.php" hash="b11809b945f1daae3f4996fd6e36f9d1"/></dir><dir name="etc"><file name="config.xml" hash="2f89ffe89a66e2211efd6892f61a3dcd"/><file name="system.xml" hash="f060d0c076da9b6854c434a2d443672f"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="default"><dir name="default"><dir name="template"><dir name="cashu"><file name="redirect.phtml" hash="55eedb2d8d726cdfc069fcd89fc060f9"/><file name="success.phtml" hash="857f02535c3b6908da9de15013cf4df5"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Cashu_Paymentmethod.xml" hash="5182f969b96434d61f9047f849443b44"/></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>