Instamojo_Imojo - Version 0.1.0

Version Notes

- Removed buggy invoice generation code.
- Fixed issue related to orders not showing up in my orders.
- Plugin will now handle failed payments as well.
- Fixed redirection URL.
- Added and fixed some log messages.

Download this release

Release Info

Developer Instamojo
Extension Instamojo_Imojo
Version 0.1.0
Comparing to
See all releases


Code changes from version 0.0.9 to 0.1.0

app/code/community/Instamojo/Imojo/Model/PaymentMethod.php CHANGED
@@ -36,7 +36,7 @@ class Instamojo_Imojo_Model_PaymentMethod extends Mage_Payment_Model_Method_Abst
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
 
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
 
app/code/community/Instamojo/Imojo/controllers/PaymentController.php CHANGED
@@ -35,7 +35,6 @@ class Instamojo_Imojo_PaymentController extends Mage_Core_Controller_Front_Actio
35
  $private_salt = Mage::getStoreConfig('payment/imojo/private_salt');
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();
@@ -45,8 +44,6 @@ class Instamojo_Imojo_PaymentController extends Mage_Core_Controller_Front_Actio
45
  $data['data_amount'] = $amount;
46
  $data['data_' . $custom_field] = $rmTranid . "-". $orderId;
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());
@@ -63,7 +60,6 @@ class Instamojo_Imojo_PaymentController extends Mage_Core_Controller_Front_Actio
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&";
@@ -107,13 +103,11 @@ class Instamojo_Imojo_PaymentController extends Mage_Core_Controller_Front_Actio
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);
@@ -124,85 +118,62 @@ class Instamojo_Imojo_PaymentController extends Mage_Core_Controller_Front_Actio
124
  // Get order details
125
  $order = Mage::getModel('sales/order');
126
  $order->loadByIncrementId($orderId);
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
-
134
- // Close the transaction
135
- $payment = $order->getPayment();
136
- $transaction = $payment->getTransaction($transactionId);
137
- $data = $transaction->getAdditionalInformation();
138
- $url = $data['raw_details_info']['Url'];
139
- $transaction->setAdditionalInformation(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS,
140
- array('InstmojoId'=> $insta_id,
141
- 'Context'=>'Token payment',
142
- 'Amount'=>$amount,
143
- 'Status'=>1,
144
- 'Url'=>$url))->save();
145
- $transaction->setParentTxnId($insta_id)->save();
146
- $payment->setIsTransactionClosed(1);
147
- // $this->_processInvoice($orderId);
148
- $block = $this->getLayout()->createBlock('Mage_Core_Block_Template',
149
- 'imojo',
150
- array('template' => 'imojo/success.phtml'))->assign(array('instaId'=> $insta_id));
151
- // Curl fetch status information to cross compare
152
- }else{
153
- $block = $this->getLayout()->createBlock('Mage_Core_Block_Template',
154
- 'imojo',
155
- array('template' => 'imojo/failure.phtml'))->assign(array('instaId'=> $insta_id));
156
- }
157
- $this->getLayout()->getBlock('content')->append($block);
158
- $this->renderLayout();
159
-
160
- // Trigger emails for success / failure - Sending desposit email
161
- // $this->depositEmail($orderId);
162
-
163
- // Trigger a order invoice after that?
164
-
165
- }
166
 
167
- private function _processInvoice($orderId){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
 
169
- $order = Mage::getModel("sales/order")->load($orderId);
 
 
 
170
 
171
- try {
172
- if(!$order->canInvoice())
173
- {
174
- Mage::throwException(Mage::helper("core")->__("Cannot create an invoice"));
175
  }
176
- $invoice = Mage::getModel("sales/service_order", $order)->prepareInvoice();
177
- if (!$invoice->getTotalQty()) {
178
- Mage::throwException(Mage::helper("core")->__("Cannot create an invoice without products."));
 
 
 
179
  }
180
- $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_OFFLINE);
181
- $invoice->register();
182
- $transactionSave = Mage::getModel("core/resource_transaction")
183
- ->addObject($invoice)
184
- ->addObject($invoice->getOrder());
185
- $transactionSave->save();
186
- $invoice->sendEmail();
187
-
188
- /* SET Order Status Here */
189
- $orderModel = Mage::getModel("sales/order");
190
- $orderModel->load($orderId);
191
- $orderModel->setStatus("complete")
192
- ->save();
193
 
194
  }
195
- catch (Mage_Core_Exception $e) {
196
- echo $e->getMessage();
 
 
 
 
 
 
 
197
  }
198
-
199
  }
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;
206
  $api_key = Mage::getStoreConfig('payment/imojo/api_key');
207
  $auth_token = Mage::getStoreConfig('payment/imojo/auth_token');
208
 
@@ -214,6 +185,13 @@ class Instamojo_Imojo_PaymentController extends Mage_Core_Controller_Front_Actio
214
  curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Api-Key:$api_key",
215
  "X-Auth-Token:$auth_token"));
216
  $response = curl_exec($ch);
 
 
 
 
 
 
 
217
  $res = json_decode($response, true);
218
  curl_close($ch);
219
  } catch (Exception $e) {
35
  $private_salt = Mage::getStoreConfig('payment/imojo/private_salt');
36
  $custom_field = Mage::getStoreConfig('payment/imojo/custom_field');
37
 
 
38
  Mage::log("Data from Backend: $url | $api_key | $auth_token | $private_salt | $custom_field", Zend_Log::DEBUG, $this->LOG_FILE_NAME);
39
 
40
  $data = Array();
44
  $data['data_amount'] = $amount;
45
  $data['data_' . $custom_field] = $rmTranid . "-". $orderId;
46
 
 
 
47
  Mage::log("Transaction-order ID: " . ($rmTranid . "-". $orderId), Zend_Log::DEBUG, $this->LOG_FILE_NAME);
48
 
49
  $ver = explode('.', phpversion());
60
  $sign = hash_hmac("sha1", $message, $private_salt);
61
  $data['data_sign'] = $sign;
62
 
 
63
  Mage::log("Signature is: $sign", Zend_Log::DEBUG, $this->LOG_FILE_NAME);
64
 
65
  $link= $url . "?embed=form&";
103
  $this->loadLayout();
104
 
105
  Mage::log("Status: $status| Payment ID: $insta_id", Zend_Log::DEBUG, $this->LOG_FILE_NAME);
106
+
107
  $data = $this->_getcurlInfo($insta_id);
108
  $payment_status = $data['payment']['status'];
109
+
110
+ if($payment_status === "Credit" || $payment_status === "Failed" || $payment_status === "Initiated"){
 
 
111
  $tr_ord_id = $data['payment']['custom_fields'][$custom_field]['value'];
112
  Mage::log("Value of Tran-order ID: $tr_ord_id", Zend_Log::DEBUG, $this->LOG_FILE_NAME);
113
  $order_tran_id = explode('-', $tr_ord_id);
118
  // Get order details
119
  $order = Mage::getModel('sales/order');
120
  $order->loadByIncrementId($orderId);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
 
122
+ if($payment_status === "Credit"){
123
+ Mage::log("Payment was successfull for $insta_id", Zend_Log::DEBUG, $this->LOG_FILE_NAME);
124
+ $order->setState(Mage_Sales_Model_Order::STATE_PROCESSING, true);
125
+ Mage::log("Pending payment is set to False", Zend_Log::DEBUG, $this->LOG_FILE_NAME);
126
+ $order->sendNewOrderEmail();
127
+ $order->setEmailSent(true);
128
+ $order->save();
129
+
130
+ $payment = $order->getPayment();
131
+ $transaction = $payment->getTransaction($transactionId);
132
+ $data = $transaction->getAdditionalInformation();
133
+ $url = $data['raw_details_info']['Url'];
134
+ $transaction->setAdditionalInformation(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS,
135
+ array('InstmojoId'=> $insta_id,
136
+ 'Context'=>'Token payment',
137
+ 'Amount'=>$amount,
138
+ 'Status'=>1,
139
+ 'Url'=>$url))->save();
140
+ $transaction->setParentTxnId($insta_id)->save();
141
+ $payment->setIsTransactionClosed(1);
142
+ $this->_redirect('checkout/onepage/success', array('_secure'=>true));
143
 
144
+ }
145
+ else if($payment_status === "Failed"){
146
+ $order->cancel()->setState(Mage_Sales_Model_Order::STATE_CANCELED, true, 'Payment failed.')->save();
147
+ $this->_redirect('checkout/onepage/failure', array('_secure'=>true));
148
 
 
 
 
 
149
  }
150
+ else if($payment_status === "Initiated"){
151
+ $order->cancel()->setState(Mage_Sales_Model_Order::STATE_CANCELED, true, 'Payment was initiated but never completed.')->save();
152
+ $this->_redirect('checkout/onepage/failure', array('_secure'=>true));
153
+ }
154
+ else{
155
+ $this->_redirect('checkout/onepage/failure', array('_secure'=>true));
156
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
157
 
158
  }
159
+ else{
160
+ if (Mage::getSingleton('checkout/session')->getLastRealOrderId()) {
161
+ $order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
162
+ if($order->getId()) {
163
+ $order->cancel()->setState(Mage_Sales_Model_Order::STATE_CANCELED, true, 'Invalid transaction ID or request.')->save();
164
+ }
165
+ }
166
+ $this->_redirect('');
167
+
168
  }
169
+
170
  }
171
 
172
  // Get the order id from Instamojo based the transaction id
173
  private function _getcurlInfo($iTransactionId){
174
  try {
175
 
176
+ $cUrl = 'https://www.instamojo.com/api/1.1/payments/' . $iTransactionId . '/';
177
  $api_key = Mage::getStoreConfig('payment/imojo/api_key');
178
  $auth_token = Mage::getStoreConfig('payment/imojo/auth_token');
179
 
185
  curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Api-Key:$api_key",
186
  "X-Auth-Token:$auth_token"));
187
  $response = curl_exec($ch);
188
+ $error_number = curl_errno($ch);
189
+ $error_message = curl_error($ch);
190
+ $response_obj = json_decode($response, true);
191
+
192
+ Mage::log("Error number: $error_number", Zend_Log::ERR, $this->LOG_FILE_NAME);
193
+ Mage::log("Error number: $error_message", Zend_Log::ERR, $this->LOG_FILE_NAME);
194
+
195
  $res = json_decode($response, true);
196
  curl_close($ch);
197
  } catch (Exception $e) {
package.xml CHANGED
@@ -1,27 +1,84 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Instamojo_Imojo</name>
4
- <version>0.0.9</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/MIT">MIT</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Collect Payments Instantly with a Link</summary>
10
- <description>This extension allows you to use Instamojo as Payment Gateway.&#xD;
11
  &#xD;
12
- Brief steps:&#xD;
 
13
  &#xD;
14
- - Create Payment link on Instamojo website.&#xD;
15
- - Fill up extension's configuration in Magento's admin backend under Payment methods.&#xD;
16
- - Select Instamojo during checkout.&#xD;
17
  &#xD;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  &#xD;
19
  For detailed steps with screenshots visit our GitHub page: https://github.com/Instamojo/Instamojo-Magento</description>
20
- <notes>Updated PHP version range from 5.3.0 - 5.6.6 to 5.2.0 - 5.6.8</notes>
 
 
 
 
21
  <authors><author><name>Instamojo</name><user>Instamojo</user><email>dev@instamojo.com</email></author></authors>
22
- <date>2015-05-07</date>
23
- <time>22:01:40</time>
24
- <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="b829d8aa887ce2461fb050cecbce4099"/><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>
25
  <compatible/>
26
  <dependencies><required><php><min>5.2.0</min><max>5.6.8</max></php></required></dependencies>
27
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Instamojo_Imojo</name>
4
+ <version>0.1.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/MIT">MIT</license>
7
  <channel>community</channel>
8
  <extends/>
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
+ &lt;br /&gt;&#xD;
13
+ &lt;br /&gt;&#xD;
14
  &#xD;
15
+ This extension allows you to use Instamojo as Payment Gateway.&#xD;
 
 
16
  &#xD;
17
+ &lt;br /&gt;&#xD;
18
+ &lt;br /&gt;&#xD;
19
+ &#xD;
20
+ &lt;h3&gt;Steps:&lt;/h3&gt;&#xD;
21
+ &lt;br /&gt;&#xD;
22
+ &#xD;
23
+ &lt;ul&gt;&#xD;
24
+ &lt;li&gt; Create a payment link of type Services/membership on our website http://www.instamojo.com&lt;/li&gt;&#xD;
25
+ &lt;li&gt;Set its base price as 10 and check &amp;quot;Use 'Pay What You Want'&amp;quot; option.&#xD;
26
+ &lt;/li&gt;&#xD;
27
+ &lt;li&gt;&#xD;
28
+ If your website is say http://www.example.com then use http://www.example.com/index.php/imojo/payment/response/ as Custom Redirection URL. This is required to mark the payment as completed after redirection.&#xD;
29
+ &lt;/li&gt;&#xD;
30
+ &lt;li&gt;&#xD;
31
+ Now save the Payment link and go to More Options -&amp;gt; Custom Fields.&#xD;
32
+ &lt;/li&gt;&#xD;
33
+ &lt;li&gt;&#xD;
34
+ Create a custom field, let's say you named it &amp;quot;Orderd ID&amp;quot; and save it. The name is not important, the actual field name of this Custom Field will show up when you hover over that field, it has the format of &lt;b&gt;Field_xxxxx&lt;/b&gt;, where &amp;quot;xxxxx&amp;quot; are numbers.&#xD;
35
+ This is what we are going to enter in the plugin's settings in Magento backend.&#xD;
36
+ &lt;/li&gt;&#xD;
37
+ &lt;/ul&gt;&#xD;
38
+ &lt;br /&gt;&#xD;
39
+ &lt;br /&gt;&#xD;
40
+ &#xD;
41
+ &lt;h3&gt;Magento plugin settings:&lt;/h3&gt;&#xD;
42
+ &lt;ul&gt;&#xD;
43
+ &lt;li&gt;&#xD;
44
+ &lt;b&gt;Enabled:&lt;/b&gt; Yes&#xD;
45
+ &lt;/li&gt;&#xD;
46
+ &lt;li&gt;&#xD;
47
+ &lt;b&gt;Payment Action:&lt;/b&gt; Authorize and Capture&#xD;
48
+ &lt;/li&gt;&#xD;
49
+ &lt;li&gt;&#xD;
50
+ &lt;b&gt;New Order status:&lt;/b&gt; Processing&#xD;
51
+ &lt;/li&gt;&#xD;
52
+ &lt;li&gt;&#xD;
53
+ &lt;b&gt;API Key:&lt;/b&gt; Get this from http://www.instamojo.com/developers&#xD;
54
+ &lt;/li&gt;&#xD;
55
+ &lt;li&gt;&#xD;
56
+ &lt;b&gt;Auth Token:&lt;/b&gt; Get this from http://www.instamojo.com/developers&#xD;
57
+ &lt;/li&gt;&#xD;
58
+ &lt;li&gt;&#xD;
59
+ &lt;b&gt;Private Salt:&lt;/b&gt; Get this from http://www.instamojo.com/developers&#xD;
60
+ &lt;/li&gt;&#xD;
61
+ &lt;li&gt;&#xD;
62
+ &lt;b&gt;Payment URL:&lt;/b&gt; Payment link's URL&#xD;
63
+ &lt;/li&gt;&#xD;
64
+ &lt;li&gt;&#xD;
65
+ &lt;b&gt;Custom Field:&lt;/b&gt; Field_xxxx format field name we got from hovering over the Custom field.&#xD;
66
+ &lt;/li&gt;&#xD;
67
+ &lt;/ul&gt;&#xD;
68
+ &#xD;
69
+ &lt;br /&gt;&#xD;
70
+ &lt;br /&gt;&#xD;
71
  &#xD;
72
  For detailed steps with screenshots visit our GitHub page: https://github.com/Instamojo/Instamojo-Magento</description>
73
+ <notes>- Removed buggy invoice generation code.&#xD;
74
+ - Fixed issue related to orders not showing up in my orders.&#xD;
75
+ - Plugin will now handle failed payments as well.&#xD;
76
+ - Fixed redirection URL.&#xD;
77
+ - Added and fixed some log messages.</notes>
78
  <authors><author><name>Instamojo</name><user>Instamojo</user><email>dev@instamojo.com</email></author></authors>
79
+ <date>2015-09-06</date>
80
+ <time>23:31:08</time>
81
+ <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="43002098206ee603c86b0b166d359f11"/></dir><dir name="controllers"><file name="PaymentController.php" hash="2264edbe39f374b9992f16d7e068bc6c"/></dir><dir name="etc"><file name="config.xml" hash="b829d8aa887ce2461fb050cecbce4099"/><file name="system.xml" hash="428898819cd38b15ab4a222964179e65"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Instamojo_Imojo.xml" hash="9a80f70915e53671e26ea6476fdbe6a4"/></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></contents>
82
  <compatible/>
83
  <dependencies><required><php><min>5.2.0</min><max>5.6.8</max></php></required></dependencies>
84
  </package>