NoFraud_TegraDirect - Version 1.0.0

Version Notes

Notes: uses cURL to send information to NoFraud Service.

Requires NoFraud service account in order to work.

Configure is set in System > Configuration > Payment Services

Download this release

Release Info

Developer Blumi Gross
Extension NoFraud_TegraDirect
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/NoFraud/TegraDirect/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class NoFraud_TegraDirect_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ }
app/code/community/NoFraud/TegraDirect/Model/Observer.php ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class NoFraud_TegraDirect_Model_Observer {
4
+
5
+ private static $last_transaction;
6
+
7
+ public function salesOrderPaymentPlaceStart(Varien_Event_Observer $observer){
8
+ $is_active = $this->getConfigData('active');
9
+
10
+ if($is_active){
11
+ $payment = $observer->getEvent()->getPayment();
12
+ $order = $payment->getOrder();
13
+
14
+ $this->last_transaction = Mage::getSingleton('core/session')->getNfLastTransaction();
15
+
16
+ if(!empty($this->last_transaction)){
17
+ //Mage::log(var_export($this->last_transaction,true),null,'tegra-direct.log');
18
+ $request = $this->_buildGatewayResponseRequest($this->last_transaction['id'],$payment);
19
+ //Mage::log(var_export($request,true),null,'tegra-direct.log');
20
+ $response = $this->_sendRequest($request,$this->getURL('gateway_response'));
21
+ //Mage::log(var_export($response,true),null,'tegra-direct.log');
22
+ $this->last_transaction = "";
23
+ Mage::getSingleton('core/session')->unsNfLastTransaction();
24
+ } else {
25
+ Mage::log("\$this->last_transaction is empty. Skipping.",null,'tegra-direct.log');
26
+ }
27
+
28
+ $request = $this->_buildRequest($order,$payment);
29
+ //Mage::log(var_export($request,true),null,'tegra-direct.log');
30
+ $result = $this->_sendRequest($request,$this->getURL());
31
+ //Mage::log(var_export($result,true),null,'tegra-direct.log');
32
+ $comment = "NoFraud was unable to render a result on this transaction due to an error.";
33
+ if(!isset($result['id'])){
34
+ Mage::log(var_export($result,true),null,'tegra-direct.log');
35
+ } else {
36
+ $comment = "NoFraud rendered a result of \"{$result['decision']}\" for this transaction giving it the ID of <a href=\"https://portal.nofraud.com/transaction/{$result['id']}\" target=\"_blank\">{$result['id']}</a>";
37
+ if($result['decision'] == "review"){
38
+ $comment .= "\nFor Review results, we're on it already looking into it on your behalf.";
39
+ }
40
+ $this->last_transaction = $result;
41
+ //Mage::log(var_export($this->last_transaction,true),null,'tegra-direct.log');
42
+ Mage::getSingleton('core/session')->setNfLastTransaction($result);
43
+ }
44
+ $order->addStatusHistoryComment("{$comment}");
45
+ $order->save();
46
+
47
+ if(isset($result['decision']) && $result['decision'] == "fail"){
48
+ $this->last_transaction = "";
49
+ Mage::getSingleton('core/session')->unsNfLastTransaction();
50
+ $message = $result['message'] || "Declined";
51
+ Mage::throwException(Mage::helper('paygate')->__($message));
52
+ }
53
+ }
54
+ }
55
+
56
+ public function CheckoutSubmitAllAfter(Varien_Event_Observer $observer){
57
+ $is_active = $this->getConfigData('active');
58
+
59
+ if($is_active){
60
+ $order = $observer->getEvent()->getOrder();
61
+ $payment = $order->getPayment();
62
+
63
+ if(!empty($this->last_transaction)){
64
+ $request = $this->_buildGatewayResponseRequest($this->last_transaction['id'],$payment);
65
+ //Mage::log(var_export($request,true),null,'tegra-direct.log');
66
+ $response = $this->_sendRequest($request,$this->getURL("gateway_response"));
67
+
68
+ if($this->last_transaction['decision'] == "review"){
69
+ if(!$payment->getIsFraudDetected()){
70
+ $payment->setIsTransactionPending(true);
71
+ $payment->setIsFraudDetected(true);
72
+ $order->setState($order->getState(),Mage_Sales_Model_Order::STATUS_FRAUD);
73
+ $payment->save();
74
+ $order->save();
75
+ }
76
+ }
77
+
78
+ $this->last_transaction = "";
79
+ Mage::getSingleton('core/session')->unsNfLastTransaction();
80
+ Mage::log(var_export($this->last_transaction,true),null,'tegra-direct.log');
81
+ }
82
+ }
83
+ }
84
+
85
+ private function _buildGatewayResponseRequest($id,$payment){
86
+ $order = $payment->getOrder();
87
+
88
+ $gateway_status = "fail";
89
+ if($payment->getIsFraudDetected()){
90
+ $gateway_status = "review";
91
+ }
92
+ if($order->getBaseTotalDue() == 0){
93
+ $gateway_status = "pass";
94
+ }
95
+
96
+ $params = [];
97
+ $params['nf-token'] = $this->getConfigData('nftoken');
98
+ $params['nf-id'] = $id;
99
+ $params['gateway-response'] = [];
100
+ $params['gateway-response']['result'] = $gateway_status;
101
+
102
+ if(!empty($payment->getLastTransId())){
103
+ $params['gateway-response']['transaction-id'] = $payment->getLastTransId();
104
+ }
105
+
106
+ return $params;
107
+ }
108
+
109
+ private function _buildRequest($order, $payment){
110
+ $billing = $order->getBillingAddress();
111
+ $shipping = $order->getShippingAddress();
112
+
113
+ $billing_region = Mage::getModel('directory/region')->load($billing->getRegion_id());
114
+ $shipping_region = Mage::getModel('directory/region')->load($shipping->getRegion_id());
115
+
116
+ $params = [];
117
+ $params['nf-token'] = $this->getConfigData('nftoken');
118
+ $params['amount'] = Mage::getModel('directory/currency')->formatTxt($order->getGrandTotal(), array('display' => Zend_Currency::NO_SYMBOL));
119
+ $params['customerIP'] = $order->getRemoteIp();
120
+
121
+ if($order->getShippingAmount() > 0){
122
+ $params['shippingAmount'] = Mage::getModel('directory/currency')->formatTxt($order->getShippingAmount(), array('display' => Zend_Currency::NO_SYMBOL));
123
+ }
124
+
125
+ if(!empty($payment->getCcAvsStatus())){
126
+ $params['avsResultCode'] = $payment->getCcAvsStatus();
127
+ }
128
+ if(!empty($payment->getCcCidStatus())){
129
+ $params['cvvResultCode'] = $payment->getCcCidStatus();
130
+ }
131
+
132
+ $params['billTo'] = [];
133
+ $params['billTo']['firstName'] = $billing->getFirstname();
134
+ $params['billTo']['lastName'] = $billing->getLastname();
135
+ $params['billTo']['address'] = $billing->getStreet(1)." ".$billing->getStreet(2);
136
+ $params['billTo']['city'] = $billing->getCity();
137
+ $params['billTo']['state'] =$billing_region->getCode();
138
+ $params['billTo']['zip'] = $billing->getPostcode();
139
+ $params['billTo']['country'] = $billing->getCountry();
140
+ $params['billTo']['phoneNumber'] = $billing->getTelephone();
141
+
142
+ if(!empty($shipping)){
143
+ $params['shipTo'] = [];
144
+ $params['shipTo']['firstName'] = $shipping->getFirstname();
145
+ $params['shipTo']['lastName'] = $shipping->getLastname();
146
+ $params['shipTo']['address'] = $shipping->getStreet(1)." ".$shipping->getStreet(2);
147
+ $params['shipTo']['city'] = $shipping->getCity();
148
+ $params['shipTo']['state'] = $shipping_region->getCode();
149
+ $params['shipTo']['zip'] = $shipping->getPostcode();
150
+ $params['shipTo']['country'] = $shipping->getCountry();
151
+ }
152
+
153
+ $params['customer'] = [];
154
+ $params['customer']['email'] = $order->getCustomerEmail();
155
+
156
+
157
+ $expirDate;
158
+ if(strlen($payment->getCcExpMonth()) == 1){
159
+ $expirDate = "0".$payment->getCcExpMonth();
160
+ } else {
161
+ $expirDate = $payment->getCcExpMonth();
162
+ }
163
+
164
+ if(strlen($payment->getCcExpYear()) == 4){
165
+ $expirDate .= substr($payment->getCcExpYear(), 2);
166
+ } else if(strlen($payment->getCcExpYear()) == 2){
167
+ $expirDate .= $payment->getCcExpYear();
168
+ }
169
+
170
+
171
+ if(!empty($payment->getCcNumber())){
172
+ $params['payment'] = [];
173
+ $params['payment']['creditCard']['cardNumber'] = $payment->getCcNumber();
174
+ $params['payment']['creditCard']['expirationDate'] = $expirDate;
175
+
176
+ if(!empty($payment->getCcCid())){
177
+ $params['payment']['creditCard']['cardCode'] = $payment->getCcCid();
178
+ }
179
+ }
180
+
181
+ //This is for the next Deployment of Direct API.
182
+ //$params['order'] = [];
183
+ //$params['order']['invoiceNumber'] = $order->getIncrementId();
184
+
185
+ $params['userFields'] = [];
186
+ $params['userFields']['orderId'] = $order->getIncrementId();
187
+
188
+ return $params;
189
+ }
190
+
191
+ private function _sendRequest($request,$nfurl){
192
+ $body = json_encode($request);
193
+ $ch = curl_init();
194
+ curl_setopt($ch, CURLOPT_POST, true);
195
+ curl_setopt($ch, CURLOPT_URL, $nfurl);
196
+ curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
197
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($body)));
198
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
199
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
200
+
201
+ $result = curl_exec($ch);
202
+ //$info = curl_getinfo($ch);
203
+
204
+ $res_obj = json_decode($result,true);
205
+
206
+ return $res_obj;
207
+ }
208
+
209
+ private function getConfigData($datapoint){
210
+ $data = Mage::getStoreConfig('payment_services/TegraDirect/'.$datapoint,Mage::app()->getStore());
211
+
212
+ if(strcmp($datapoint,"nftoken") == 0){
213
+ $data = Mage::helper('core')->decrypt($data);
214
+ }
215
+
216
+ //Mage::log("{$datapoint} == {$data}",null,'tegra-direct.log');
217
+ return $data;
218
+ }
219
+
220
+ private function getURL($addition = ""){
221
+ $url = 'https://api.nofraud.com/'.$addition;
222
+ //$url = 'https://60c64d03.ngrok.io/'.$addition;
223
+
224
+ if($this->getConfigData('sandbox')){
225
+ $url = 'https://apitest.nofraud.com/'.$addition;
226
+ }
227
+
228
+ //Mage::log(var_export($url,true),null,'tegra-direct.log');
229
+ return $url;
230
+ }
231
+ }
232
+ ?>
app/code/community/NoFraud/TegraDirect/etc/config.xml ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <NoFraud_TegraDirect>
5
+ <version>1.0.0</version>
6
+ </NoFraud_TegraDirect>
7
+ </modules>
8
+
9
+ <global>
10
+ <models>
11
+ <NoFraud_TegraDirect>
12
+ <class>NoFraud_TegraDirect_Model</class>
13
+ </NoFraud_TegraDirect>
14
+ </models>
15
+ <resources>
16
+ <TegraDirect_setup>
17
+ <setup>
18
+ <module>NoFraud_TegraDirect</module>
19
+ </setup>
20
+ <connection>
21
+ <use>core_setup</use>
22
+ </connection>
23
+ </TegraDirect_setup>
24
+ <TegraDirect_write>
25
+ <connection>
26
+ <use>core_write</use>
27
+ </connection>
28
+ </TegraDirect_write>
29
+ <TegraDirect_read>
30
+ <connection>
31
+ <use>core_read</use>
32
+ </connection>
33
+ </TegraDirect_read>
34
+ </resources>
35
+ <helpers>
36
+ <TegraDirect>
37
+ <class>NoFraud_TegraDirect_Helper</class>
38
+ </TegraDirect>
39
+ </helpers>
40
+ <events>
41
+ <sales_order_payment_place_start>
42
+ <observers>
43
+ <NoFraud_TegraDirect_Model_Log2>
44
+ <class>NoFraud_TegraDirect/observer</class>
45
+ <method>salesOrderPaymentPlaceStart</method>
46
+ </NoFraud_TegraDirect_Model_Log2>
47
+ </observers>
48
+ </sales_order_payment_place_start>
49
+ <checkout_submit_all_after>
50
+ <observers>
51
+ <NoFraud_TegraDirect_Model_Observer>
52
+ <class>NoFraud_TegraDirect/observer</class>
53
+ <method>CheckoutSubmitAllAfter</method>
54
+ </NoFraud_TegraDirect_Model_Observer>
55
+ </observers>
56
+ </checkout_submit_all_after>
57
+ </events>
58
+ </global>
59
+
60
+ <default>
61
+ <payment_services>
62
+ <NoFraud_TegraDirect>
63
+ <active>1</active>
64
+ <nftoken backend_model="adminhtml/system_config_backend_encrypted" />
65
+ <sandbox>1</sandbox>
66
+ </NoFraud_TegraDirect>
67
+ </payment_services>
68
+ </default>
69
+ </config>
app/code/community/NoFraud/TegraDirect/etc/system.xml ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <payment_services>
5
+ <groups>
6
+ <TegraDirect translate="label" module="TegraDirect">
7
+ <label>NoFraud Direct API</label>
8
+ <frontend_type>text</frontend_type>
9
+ <sort_order>2</sort_order>
10
+ <show_in_default>1</show_in_default>
11
+ <show_in_website>0</show_in_website>
12
+ <show_in_store>1</show_in_store>
13
+ <comment><![CDATA[<a href="https://www.nofraud.com/" target="_blank">Sign up for a NoFraud account here</a>]]></comment>
14
+ <fields>
15
+ <active translate="label">
16
+ <label>Enabled</label>
17
+ <frontend_type>select</frontend_type>
18
+ <source_model>adminhtml/system_config_source_yesno</source_model>
19
+ <sort_order>1</sort_order>
20
+ <show_in_default>1</show_in_default>
21
+ <show_in_website>0</show_in_website>
22
+ <show_in_store>1</show_in_store>
23
+ </active>
24
+ <nftoken translate="label">
25
+ <label>NoFraud Direct API Key</label>
26
+ <frontend_type>obscure</frontend_type>
27
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
28
+ <sort_order>10</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ <show_in_website>0</show_in_website>
31
+ <show_in_store>1</show_in_store>
32
+ </nftoken>
33
+ <sandbox translate="label">
34
+ <label>Use Sandbox?</label>
35
+ <frontend_type>select</frontend_type>
36
+ <source_model>adminhtml/system_config_source_yesno</source_model>
37
+ <sort_order>20</sort_order>
38
+ <show_in_default>1</show_in_default>
39
+ <show_in_website>0</show_in_website>
40
+ <show_in_store>1</show_in_store>
41
+ </sandbox>
42
+ <model>
43
+ </model>
44
+ </fields>
45
+ </TegraDirect>
46
+ </groups>
47
+ </payment_services>
48
+ </sections>
49
+ </config>
app/code/community/NoFraud/TegraDirect/sql/tegradirect_setup/install-1.0.0.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+ $installer = $this;
3
+
4
+ $installer->startSetup();
5
+
6
+ $installer->endSetup();
7
+ ?>
app/etc/modules/NoFraud_TegraDirect.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <NoFraud_TegraDirect>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </NoFraud_TegraDirect>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>NoFraud_TegraDirect</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="https://opensource.org/licenses/afl-3.0">Academic Free License</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>The #1 most effective end-to-end fraud prevention solution for eCommerce businesses.</summary>
10
+ <description>NoFraud is a full-service solution. AVS/CVV is built-in, it works in real-time, has a live cardholder verification team, and provides merchants with white/black lists. Setup is simple and pricing is transaction based with no additional fees. NoFraud is certified as PCI compliant at the highest level.</description>
11
+ <notes>Notes: uses cURL to send information to NoFraud Service.&#xD;
12
+ &#xD;
13
+ Requires NoFraud service account in order to work.&#xD;
14
+ &#xD;
15
+ Configure is set in System &gt; Configuration &gt; Payment Services</notes>
16
+ <authors><author><name>Blumi Gross</name><user>BlumiNoFraud</user><email>blumi@nofraud.com</email></author><author><name>Michael Esposito</name><user>mesposito</user><email>mesposito@nofraud.com</email></author></authors>
17
+ <date>2016-05-13</date>
18
+ <time>13:31:06</time>
19
+ <contents><target name="magecommunity"><dir name="NoFraud"><dir name="TegraDirect"><dir name="Helper"><file name="Data.php" hash="9575aac8a692bf4f66c5fb62a14a2167"/></dir><dir name="Model"><file name="Observer.php" hash="30eaa99dc0182f24732855b5844db584"/></dir><dir name="etc"><file name="config.xml" hash="cb2a3a1f76b9f1675f2959137a4f1bbe"/><file name="system.xml" hash="57d0d0d658acf9aad00e13377f53d061"/></dir><dir name="sql"><dir name="tegradirect_setup"><file name="install-1.0.0.php" hash="e894527bb612d9748cf8212f1e38f459"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="NoFraud_TegraDirect.xml" hash="5611cb98606f5f733e0820bb47d8418e"/></dir></target></contents>
20
+ <compatible/>
21
+ <dependencies><required><php><min>5.0.0</min><max>5.6.0</max></php><extension><name>curl</name><min>7.35.0</min><max/></extension></required></dependencies>
22
+ </package>