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(
|
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 |
-
|
111 |
$data = $this->_getcurlInfo($insta_id);
|
112 |
$payment_status = $data['payment']['status'];
|
113 |
-
|
114 |
-
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
|
169 |
-
|
|
|
|
|
|
|
170 |
|
171 |
-
try {
|
172 |
-
if(!$order->canInvoice())
|
173 |
-
{
|
174 |
-
Mage::throwException(Mage::helper("core")->__("Cannot create an invoice"));
|
175 |
}
|
176 |
-
$
|
177 |
-
|
178 |
-
|
|
|
|
|
|
|
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 |
-
|
196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
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>
|
11 |

|
12 |
-
|
|
|
13 |

|
14 |
-
|
15 |
-
- Fill up extension's configuration in Magento's admin backend under Payment methods.
|
16 |
-
- Select Instamojo during checkout.
|
17 |

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |

|
19 |
For detailed steps with screenshots visit our GitHub page: https://github.com/Instamojo/Instamojo-Magento</description>
|
20 |
-
<notes
|
|
|
|
|
|
|
|
|
21 |
<authors><author><name>Instamojo</name><user>Instamojo</user><email>dev@instamojo.com</email></author></authors>
|
22 |
-
<date>2015-
|
23 |
-
<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="
|
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!
|
11 |

|
12 |
+
<br />
|
13 |
+
<br />
|
14 |

|
15 |
+
This extension allows you to use Instamojo as Payment Gateway.
|
|
|
|
|
16 |

|
17 |
+
<br />
|
18 |
+
<br />
|
19 |
+

|
20 |
+
<h3>Steps:</h3>
|
21 |
+
<br />
|
22 |
+

|
23 |
+
<ul>
|
24 |
+
<li> Create a payment link of type Services/membership on our website http://www.instamojo.com</li>
|
25 |
+
<li>Set its base price as 10 and check &quot;Use 'Pay What You Want'&quot; option.
|
26 |
+
</li>
|
27 |
+
<li>
|
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.
|
29 |
+
</li>
|
30 |
+
<li>
|
31 |
+
Now save the Payment link and go to More Options -&gt; Custom Fields.
|
32 |
+
</li>
|
33 |
+
<li>
|
34 |
+
Create a custom field, let's say you named it &quot;Orderd ID&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 <b>Field_xxxxx</b>, where &quot;xxxxx&quot; are numbers.
|
35 |
+
This is what we are going to enter in the plugin's settings in Magento backend.
|
36 |
+
</li>
|
37 |
+
</ul>
|
38 |
+
<br />
|
39 |
+
<br />
|
40 |
+

|
41 |
+
<h3>Magento plugin settings:</h3>
|
42 |
+
<ul>
|
43 |
+
<li>
|
44 |
+
<b>Enabled:</b> Yes
|
45 |
+
</li>
|
46 |
+
<li>
|
47 |
+
<b>Payment Action:</b> Authorize and Capture
|
48 |
+
</li>
|
49 |
+
<li>
|
50 |
+
<b>New Order status:</b> Processing
|
51 |
+
</li>
|
52 |
+
<li>
|
53 |
+
<b>API Key:</b> Get this from http://www.instamojo.com/developers
|
54 |
+
</li>
|
55 |
+
<li>
|
56 |
+
<b>Auth Token:</b> Get this from http://www.instamojo.com/developers
|
57 |
+
</li>
|
58 |
+
<li>
|
59 |
+
<b>Private Salt:</b> Get this from http://www.instamojo.com/developers
|
60 |
+
</li>
|
61 |
+
<li>
|
62 |
+
<b>Payment URL:</b> Payment link's URL
|
63 |
+
</li>
|
64 |
+
<li>
|
65 |
+
<b>Custom Field:</b> Field_xxxx format field name we got from hovering over the Custom field.
|
66 |
+
</li>
|
67 |
+
</ul>
|
68 |
+

|
69 |
+
<br />
|
70 |
+
<br />
|
71 |

|
72 |
For detailed steps with screenshots visit our GitHub page: https://github.com/Instamojo/Instamojo-Magento</description>
|
73 |
+
<notes>- Removed buggy invoice generation code.
|
74 |
+
- Fixed issue related to orders not showing up in my orders.
|
75 |
+
- Plugin will now handle failed payments as well.
|
76 |
+
- Fixed redirection URL.
|
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>
|