Instamojo_Imojo - Version 0.0.8

Version Notes

- Fixed issue with signature in URL.
- Fixed sorting issue related to older PHP versions.
- Fixed logging issue.

Download this release

Release Info

Developer Instamojo
Extension Instamojo_Imojo
Version 0.0.8
Comparing to
See all releases


Code changes from version 0.0.7 to 0.0.8

app/code/community/Instamojo/Imojo/Model/PaymentMethod.php CHANGED
@@ -2,12 +2,14 @@
2
  // This module is more than a normal payment gateway
3
  // It needs dashboard and all
4
 
5
- $LOG_FILE_NAME = 'imojo.log';
6
 
7
  class Instamojo_Imojo_Model_PaymentMethod extends Mage_Payment_Model_Method_Abstract{
8
  /**
9
  * Availability options
10
  */
 
 
 
11
  protected $_code = 'imojo';
12
 
13
  protected $_isGateway = true;
@@ -21,10 +23,6 @@ class Instamojo_Imojo_Model_PaymentMethod extends Mage_Payment_Model_Method_Abst
21
  protected $_canUseForMultishipping = true;
22
  protected $_canSaveCc = false;
23
  protected $_isInitializeNeeded = false;
24
-
25
- // TO DO NOTES
26
- // Implement safer signed links
27
- // Create link first? Manually created in this case.
28
 
29
  /**
30
  * @return Mage_Checkout_Model_Session
@@ -37,42 +35,22 @@ class Instamojo_Imojo_Model_PaymentMethod extends Mage_Payment_Model_Method_Abst
37
  // Construct the redirect URL
38
  public function getOrderPlaceRedirectUrl()
39
  {
40
- global $LOG_FILE_NAME;
41
  $redirect_url = Mage::getUrl('imojo/payment/redirect');
42
- Mage::Log('Step 2 Process: Getting the redirect URL: $redirect_url', Zend_Log::DEBUG, $LOG_FILE_NAME);
43
  return $redirect_url;
44
  }
45
 
46
- // Check why capture is not working. I clearly specified it in the config.xml file. WTF!
47
- // Need to look back into this issue more cleanly
48
  public function authorize(Varien_Object $payment, $amount){
49
- global $LOG_FILE_NAME;
50
- Mage::Log('Step 0 Process: Authorize', Zend_Log::DEBUG, $LOG_FILE_NAME);
51
- // Haha interestingly this is working. Lolapa
52
- // $order = $payment->getOrder();
53
- // Create and capture transaction. How do we use it? Lets see.\
54
- // $transactionId = time();
55
- // $payment->setTransactionId($transactionId) // Make it unique. This is Rentomojo Transaction ID
56
- // ->setIsTransactionClosed(0) // Close the transaction on return?
57
- // ->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('Context'=>'Token payment','Amount'=>'900','Status'=>0));
58
  return $this;
59
  }
60
- // I think Instamojo can do this :). We need to authorize and capture for later reference
61
  /**
62
  * this method is called if we are authorising AND
63
  * capturing a transaction
64
  */
65
  public function capture(Varien_Object $payment, $amount)
66
  {
67
- global $LOG_FILE_NAME;
68
- Mage::Log('Step 1 Process: Create and capture the process', Zend_Log::DEBUG, $LOG_FILE_NAME);
69
- // parent::capture();
70
- // $order = $payment->getOrder();
71
- // Create and capture transaction. How do we use it? Lets see.\
72
- // $transactionId = time();
73
- // $payment->setTransactionId($transactionId) // Make it unique. This is Rentomojo Transaction ID
74
- // ->setIsTransactionClosed(0) // Close the transaction on return?
75
- // ->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('key1'=>'value1','key2'=>'value2'));
76
  return $this;
77
  }
78
 
2
  // This module is more than a normal payment gateway
3
  // It needs dashboard and all
4
 
 
5
 
6
  class Instamojo_Imojo_Model_PaymentMethod extends Mage_Payment_Model_Method_Abstract{
7
  /**
8
  * Availability options
9
  */
10
+
11
+ private $LOG_FILE_NAME = 'imojo.log';
12
+
13
  protected $_code = 'imojo';
14
 
15
  protected $_isGateway = true;
23
  protected $_canUseForMultishipping = true;
24
  protected $_canSaveCc = false;
25
  protected $_isInitializeNeeded = false;
 
 
 
 
26
 
27
  /**
28
  * @return Mage_Checkout_Model_Session
35
  // Construct the redirect URL
36
  public function getOrderPlaceRedirectUrl()
37
  {
 
38
  $redirect_url = Mage::getUrl('imojo/payment/redirect');
39
+ Mage::Log('Step 2 Process: Getting the redirect URL: $redirect_url', Zend_Log::DEBUG, $this->LOG_FILE_NAME);
40
  return $redirect_url;
41
  }
42
 
 
 
43
  public function authorize(Varien_Object $payment, $amount){
44
+ Mage::Log('Step 0 Process: Authorize', Zend_Log::DEBUG, $this->LOG_FILE_NAME);
 
 
 
 
 
 
 
 
45
  return $this;
46
  }
 
47
  /**
48
  * this method is called if we are authorising AND
49
  * capturing a transaction
50
  */
51
  public function capture(Varien_Object $payment, $amount)
52
  {
53
+ Mage::Log('Step 1 Process: Create and capture the process', Zend_Log::DEBUG, $this->LOG_FILE_NAME);
 
 
 
 
 
 
 
 
54
  return $this;
55
  }
56
 
app/code/community/Instamojo/Imojo/controllers/PaymentController.php CHANGED
@@ -1,15 +1,15 @@
1
  <?php
2
 
3
- $LOG_FILE_NAME = 'imojo.log';
4
 
5
  class Instamojo_Imojo_PaymentController extends Mage_Core_Controller_Front_Action
6
  {
7
  // Redirect to instamojo
 
 
8
  public function redirectAction()
9
  {
10
- global $LOG_FILE_NAME;
11
  try {
12
- Mage::Log('Step 5 Process: Loading the redirect.html page', Zend_Log::DEBUG, $LOG_FILE_NAME);
13
  $this->loadLayout();
14
  // Get latest order data
15
  $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
@@ -36,7 +36,7 @@ class Instamojo_Imojo_PaymentController extends Mage_Core_Controller_Front_Actio
36
  $custom_field = Mage::getStoreConfig('payment/imojo/custom_field');
37
 
38
  // Mage::helper('imojo')->myLog("Data from Backend: $url | $api_key | $auth_token | $private_salt | $custom_field");
39
- Mage::log("Data from Backend: $url | $api_key | $auth_token | $private_salt | $custom_field", Zend_Log::DEBUG, $LOG_FILE_NAME);
40
 
41
  $data = Array();
42
  $data['data_email'] = substr($email, 0, 75);
@@ -47,17 +47,26 @@ class Instamojo_Imojo_PaymentController extends Mage_Core_Controller_Front_Actio
47
 
48
  // Mage::helper('imojo')->myLog("Transaction-order ID: " . ($rmTranid . "-". $orderId));
49
 
50
- Mage::log("Transaction-order ID: " . ($rmTranid . "-". $orderId), Zend_Log::DEBUG, $LOG_FILE_NAME);
 
 
 
 
 
 
 
 
 
 
51
 
52
- ksort($data, SORT_STRING | SORT_FLAG_CASE);
53
  $message = implode('|', $data);
54
  $sign = hash_hmac("sha1", $message, $private_salt);
55
  $data['data_sign'] = $sign;
56
 
57
  // Mage::helper('imojo')->myLog("Signature is: $sign");
58
- Mage::log("Signature is: $sign", Zend_Log::DEBUG, $LOG_FILE_NAME);
59
 
60
- $link= $url . "?intent=buy&";
61
  $link .= "data_readonly=data_email&data_readonly=data_amount&data_readonly=data_phone&data_readonly=data_name&data_readonly=data_$custom_field&data_hidden=data_$custom_field";
62
  $link.="&data_amount=$amount&data_name=$name&data_email=$email&data_phone=$phone&data_$custom_field=$custom_field&data_sign=$sign";
63
  $payment = $order->getPayment();
@@ -81,7 +90,7 @@ class Instamojo_Imojo_PaymentController extends Mage_Core_Controller_Front_Actio
81
  $this->renderLayout();
82
  } catch (Exception $e){
83
  Mage::logException($e);
84
- Mage::log($e, Zend_Log::ERR, $LOG_FILE_NAME);
85
  parent::_redirect('checkout/cart');
86
  }
87
  }
@@ -90,25 +99,23 @@ class Instamojo_Imojo_PaymentController extends Mage_Core_Controller_Front_Actio
90
  // The response action is triggered when your gateway sends back a response after processing the customer's payment
91
  public function responseAction() {
92
 
93
- global $LOG_FILE_NAME;
94
-
95
- Mage::log("Running response action", Zend_Log::DEBUG, $LOG_FILE_NAME);
96
 
97
  $custom_field = Mage::getStoreConfig('payment/imojo/custom_field');
98
  $status = $this->getRequest()->getParam('status');
99
  $insta_id = $this->getRequest()->getParam('payment_id');
100
  $this->loadLayout();
101
 
102
- Mage::log("Status: $status| Payment ID: $insta_id", Zend_Log::DEBUG, $LOG_FILE_NAME);
103
  // Do curl here to get order id and information from instamojo;
104
  $data = $this->_getcurlInfo($insta_id);
105
  $payment_status = $data['payment']['status'];
106
 
107
  // What if Id or status doesnt exit?
108
  if($payment_status === "Credit"){
109
- Mage::log("Payment was successfull for $insta_id", Zend_Log::DEBUG, $LOG_FILE_NAME);
110
  $tr_ord_id = $data['payment']['custom_fields'][$custom_field]['value'];
111
- Mage::log("Value of Tran-order ID: $tr_ord_id", Zend_Log::DEBUG, $LOG_FILE_NAME);
112
  $order_tran_id = explode('-', $tr_ord_id);
113
  $transactionId = $order_tran_id[0];
114
  $orderId = $order_tran_id[1];
@@ -120,7 +127,7 @@ class Instamojo_Imojo_PaymentController extends Mage_Core_Controller_Front_Actio
120
  $this->_processInvoice($orderId);
121
  $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)->save();
122
  $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, false)->save();
123
- Mage::log("Pending payment is set to False", Zend_Log::DEBUG, $LOG_FILE_NAME);
124
  $order->sendNewOrderEmail();
125
  $order->setEmailSent(true);
126
 
@@ -159,8 +166,6 @@ class Instamojo_Imojo_PaymentController extends Mage_Core_Controller_Front_Actio
159
 
160
  private function _processInvoice($orderId){
161
 
162
- global $LOG_FILE_NAME;
163
-
164
  $order = Mage::getModel("sales/order")->load($orderId);
165
 
166
  try {
@@ -195,7 +200,6 @@ class Instamojo_Imojo_PaymentController extends Mage_Core_Controller_Front_Actio
195
 
196
  // Get the order id from Instamojo based the transaction id
197
  private function _getcurlInfo($iTransactionId){
198
- global $LOG_FILE_NAME;
199
  try {
200
 
201
  $cUrl = 'https://www.instamojo.com/api/1.1/payments/' . $iTransactionId;
@@ -214,7 +218,7 @@ class Instamojo_Imojo_PaymentController extends Mage_Core_Controller_Front_Actio
214
  curl_close($ch);
215
  } catch (Exception $e) {
216
  Mage::logException($e);
217
- Mage::log($e, Zend_Log::ERR, $LOG_FILE_NAME);
218
  throw $e;
219
  }
220
  return $res;
1
  <?php
2
 
 
3
 
4
  class Instamojo_Imojo_PaymentController extends Mage_Core_Controller_Front_Action
5
  {
6
  // Redirect to instamojo
7
+ private $LOG_FILE_NAME = 'imojo.log';
8
+
9
  public function redirectAction()
10
  {
 
11
  try {
12
+ Mage::Log('Step 5 Process: Loading the redirect.html page', Zend_Log::DEBUG, $this->LOG_FILE_NAME);
13
  $this->loadLayout();
14
  // Get latest order data
15
  $orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
36
  $custom_field = Mage::getStoreConfig('payment/imojo/custom_field');
37
 
38
  // Mage::helper('imojo')->myLog("Data from Backend: $url | $api_key | $auth_token | $private_salt | $custom_field");
39
+ Mage::log("Data from Backend: $url | $api_key | $auth_token | $private_salt | $custom_field", Zend_Log::DEBUG, $this->LOG_FILE_NAME);
40
 
41
  $data = Array();
42
  $data['data_email'] = substr($email, 0, 75);
47
 
48
  // Mage::helper('imojo')->myLog("Transaction-order ID: " . ($rmTranid . "-". $orderId));
49
 
50
+ Mage::log("Transaction-order ID: " . ($rmTranid . "-". $orderId), Zend_Log::DEBUG, $this->LOG_FILE_NAME);
51
+
52
+ $ver = explode('.', phpversion());
53
+ $major = (int) $ver[0];
54
+ $minor = (int) $ver[1];
55
+ if($major >= 5 and $minor >= 4){
56
+ ksort($data, SORT_STRING | SORT_FLAG_CASE);
57
+ }
58
+ else{
59
+ uksort($data, 'strcasecmp');
60
+ }
61
 
 
62
  $message = implode('|', $data);
63
  $sign = hash_hmac("sha1", $message, $private_salt);
64
  $data['data_sign'] = $sign;
65
 
66
  // Mage::helper('imojo')->myLog("Signature is: $sign");
67
+ Mage::log("Signature is: $sign", Zend_Log::DEBUG, $this->LOG_FILE_NAME);
68
 
69
+ $link= $url . "?embed=form&";
70
  $link .= "data_readonly=data_email&data_readonly=data_amount&data_readonly=data_phone&data_readonly=data_name&data_readonly=data_$custom_field&data_hidden=data_$custom_field";
71
  $link.="&data_amount=$amount&data_name=$name&data_email=$email&data_phone=$phone&data_$custom_field=$custom_field&data_sign=$sign";
72
  $payment = $order->getPayment();
90
  $this->renderLayout();
91
  } catch (Exception $e){
92
  Mage::logException($e);
93
+ Mage::log($e, Zend_Log::ERR, $this->LOG_FILE_NAME);
94
  parent::_redirect('checkout/cart');
95
  }
96
  }
99
  // The response action is triggered when your gateway sends back a response after processing the customer's payment
100
  public function responseAction() {
101
 
102
+ Mage::log("Running response action", Zend_Log::DEBUG, $this->LOG_FILE_NAME);
 
 
103
 
104
  $custom_field = Mage::getStoreConfig('payment/imojo/custom_field');
105
  $status = $this->getRequest()->getParam('status');
106
  $insta_id = $this->getRequest()->getParam('payment_id');
107
  $this->loadLayout();
108
 
109
+ Mage::log("Status: $status| Payment ID: $insta_id", Zend_Log::DEBUG, $this->LOG_FILE_NAME);
110
  // Do curl here to get order id and information from instamojo;
111
  $data = $this->_getcurlInfo($insta_id);
112
  $payment_status = $data['payment']['status'];
113
 
114
  // What if Id or status doesnt exit?
115
  if($payment_status === "Credit"){
116
+ Mage::log("Payment was successfull for $insta_id", Zend_Log::DEBUG, $this->LOG_FILE_NAME);
117
  $tr_ord_id = $data['payment']['custom_fields'][$custom_field]['value'];
118
+ Mage::log("Value of Tran-order ID: $tr_ord_id", Zend_Log::DEBUG, $this->LOG_FILE_NAME);
119
  $order_tran_id = explode('-', $tr_ord_id);
120
  $transactionId = $order_tran_id[0];
121
  $orderId = $order_tran_id[1];
127
  $this->_processInvoice($orderId);
128
  $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true)->save();
129
  $order->setState(Mage_Sales_Model_Order::STATE_PENDING_PAYMENT, false)->save();
130
+ Mage::log("Pending payment is set to False", Zend_Log::DEBUG, 'imojo.log');
131
  $order->sendNewOrderEmail();
132
  $order->setEmailSent(true);
133
 
166
 
167
  private function _processInvoice($orderId){
168
 
 
 
169
  $order = Mage::getModel("sales/order")->load($orderId);
170
 
171
  try {
200
 
201
  // Get the order id from Instamojo based the transaction id
202
  private function _getcurlInfo($iTransactionId){
 
203
  try {
204
 
205
  $cUrl = 'https://www.instamojo.com/api/1.1/payments/' . $iTransactionId;
218
  curl_close($ch);
219
  } catch (Exception $e) {
220
  Mage::logException($e);
221
+ Mage::log($e, Zend_Log::ERR, $this->LOG_FILE_NAME);
222
  throw $e;
223
  }
224
  return $res;
app/design/frontend/base/default/template/imojo/redirect.phtml CHANGED
@@ -26,7 +26,9 @@ $custom_field = $$custom_field_name;
26
  <input type="hidden" name="data_readonly" value="data_name">
27
  <input type="hidden" name="data_readonly" value="data_amount">
28
  <input type="hidden" name="data_readonly" value="data_phone">
 
29
  <input type="hidden" name="data_hidden" value="<?php echo $custom_field_name;?>">
 
30
  </form>
31
  <script type="text/javascript">
32
  document.instamojo.submit();
26
  <input type="hidden" name="data_readonly" value="data_name">
27
  <input type="hidden" name="data_readonly" value="data_amount">
28
  <input type="hidden" name="data_readonly" value="data_phone">
29
+ <input type="hidden" name="data_readonly" value="<?php echo $custom_field_name;?>">
30
  <input type="hidden" name="data_hidden" value="<?php echo $custom_field_name;?>">
31
+ <input type="hidden" name="data_sign" value="<?php echo $data_sign;?>">
32
  </form>
33
  <script type="text/javascript">
34
  document.instamojo.submit();
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Instamojo_Imojo</name>
4
- <version>0.0.7</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/MIT">MIT</license>
7
  <channel>community</channel>
@@ -9,13 +9,14 @@
9
  <summary>Collect Payments Instantly with a Link</summary>
10
  <description>Instamojo lets you collect payments instantly. Start simply by creating a link by adding details. Share with your audience, through a link. And start collecting payments in minutes!&#xD;
11
  &#xD;
12
- We provide you an out-of-the-box e-commerce framework that takes care of mundane stuff from payments to delivery. All you need to do is share a link wherever your audience is.&#xD;
13
- </description>
14
- <notes>FIxed issue with URL.</notes>
 
15
  <authors><author><name>Instamojo</name><user>Instamojo</user><email>dev@instamojo.com</email></author></authors>
16
- <date>2015-04-17</date>
17
- <time>12:43:43</time>
18
- <contents><target name="magecommunity"><dir name="Instamojo"><dir name="Imojo"><dir name="Helper"><file name="Data.php" hash="e53c6598fa917d8791e046b20d76d221"/></dir><dir name="Model"><file name="PaymentMethod.php" hash="3eb0e176696408fd756ca40ba022b1f3"/></dir><dir name="controllers"><file name="PaymentController.php" hash="d2010587021f9757f7e8f02edc55295a"/></dir><dir name="etc"><file name="config.xml" hash="b2bc18242ac0e1b038ccce4636696792"/><file name="system.xml" hash="428898819cd38b15ab4a222964179e65"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="imojo"><file name="deposit_failure.phtml" hash="a01f8d2f503ccaf5d3f6a4682b9caf2b"/><file name="deposit_success.phtml" hash="6952afc4383fbf0eab18ee94e185f329"/><file name="redirect.phtml" hash="dd912eaefc1cd8f5ebba0bb8f6e4a383"/><file name="success.phtml" hash="ad5d2318608673f5ba6ea85bd784198f"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Instamojo_Imojo.xml" hash="9a80f70915e53671e26ea6476fdbe6a4"/></dir></target></contents>
19
  <compatible/>
20
  <dependencies><required><php><min>5.3.0</min><max>5.6.6</max></php></required></dependencies>
21
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Instamojo_Imojo</name>
4
+ <version>0.0.8</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/MIT">MIT</license>
7
  <channel>community</channel>
9
  <summary>Collect Payments Instantly with a Link</summary>
10
  <description>Instamojo lets you collect payments instantly. Start simply by creating a link by adding details. Share with your audience, through a link. And start collecting payments in minutes!&#xD;
11
  &#xD;
12
+ We provide you an out-of-the-box e-commerce framework that takes care of mundane stuff from payments to delivery. All you need to do is share a link wherever your audience is.</description>
13
+ <notes>- Fixed issue with signature in URL.&#xD;
14
+ - Fixed sorting issue related to older PHP versions.&#xD;
15
+ - Fixed logging issue.</notes>
16
  <authors><author><name>Instamojo</name><user>Instamojo</user><email>dev@instamojo.com</email></author></authors>
17
+ <date>2015-04-22</date>
18
+ <time>13:29:54</time>
19
+ <contents><target name="magecommunity"><dir name="Instamojo"><dir name="Imojo"><dir name="Helper"><file name="Data.php" hash="e53c6598fa917d8791e046b20d76d221"/></dir><dir name="Model"><file name="PaymentMethod.php" hash="d74bacadcfd639ed0bfa09cce7ee6c38"/></dir><dir name="controllers"><file name="PaymentController.php" hash="c041c42bad2234cd050524d1fa6b0b14"/></dir><dir name="etc"><file name="config.xml" hash="b2bc18242ac0e1b038ccce4636696792"/><file name="system.xml" hash="428898819cd38b15ab4a222964179e65"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="imojo"><file name="deposit_failure.phtml" hash="a01f8d2f503ccaf5d3f6a4682b9caf2b"/><file name="deposit_success.phtml" hash="6952afc4383fbf0eab18ee94e185f329"/><file name="redirect.phtml" hash="3e020d960f533b2e71e68c169bb90f22"/><file name="success.phtml" hash="ad5d2318608673f5ba6ea85bd784198f"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Instamojo_Imojo.xml" hash="9a80f70915e53671e26ea6476fdbe6a4"/></dir></target></contents>
20
  <compatible/>
21
  <dependencies><required><php><min>5.3.0</min><max>5.6.6</max></php></required></dependencies>
22
  </package>