Thecoderin_VatLayer - Version 0.1.0

Version Notes

Site-wide testing needed with all versions of Magento.

Download this release

Release Info

Developer Anish Karim
Extension Thecoderin_VatLayer
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/local/Thecoderin/VatLayer/Helper/Data.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Thecoderin_VatLayer_Helper_Data extends Mage_Core_Helper_Abstract {
3
+ const VLURL = "http://apilayer.net/api/validate";
4
+ public function validateVAT($apikey, $vatnum) {
5
+ $request = self::VLURL."?access_key=".$apikey."&vat_number=".$vatnum;
6
+ $ch = curl_init();
7
+ curl_setopt_array($ch, array(
8
+ CURLOPT_URL => $request,
9
+ CURLOPT_HTTPHEADER => array('Accept: application/json'),
10
+ CURLOPT_RETURNTRANSFER => true
11
+ ));
12
+ $result = curl_exec($ch);
13
+ curl_close($ch);
14
+ Mage::log($result);
15
+ return $result;
16
+ }
17
+ }
18
+
app/code/local/Thecoderin/VatLayer/Model/Vatlayer.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Thecoderin_VatLayer_Model_Vatlayer {
3
+ const LOG = 'thecoderin_vatlayer.log';
4
+ const API = 'thecoderin/thecoderin_vatlayer/apikey';
5
+
6
+ public function VATcheck($vat) {
7
+ $output = array();
8
+ if (empty($vat)) {
9
+ Mage::log ("VAT Field is Empty", NULL, self::LOG);
10
+ $output = array('status'=>0, 'msg'=> 'VAT field is NULL');
11
+ } else {
12
+ $apikey = Mage::getStoreConfig(self::API, Mage::app()->getStore());
13
+ if (empty(trim($apikey))) {
14
+ Mage::log ("API Key Missing", NULL, self::LOG);
15
+ $output = array('status'=>1, 'msg'=> 'Missing API Key');
16
+ } else{
17
+ $response = Mage::helper('vatlayer')->validateVAT($apikey, $vat);
18
+ $respObj = json_decode($response);
19
+ if ($respObj->valid == true) {
20
+ $msg = "Success";
21
+ } else {
22
+ $msg = "Invalid VAT Number. Should include the country code along with the VAT number(Eg.GBxxxxxxxxx).";
23
+ }
24
+ $output = array(
25
+ 'status' => $respObj->valid?1:0,
26
+ 'vat' => $respObj->query,
27
+ 'msg' => $msg,
28
+ 'company' => $respObj->company_name
29
+ );
30
+ }
31
+ }
32
+ return $output;
33
+ }
34
+ }
app/code/local/Thecoderin/VatLayer/controllers/AjaxController.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Thecoderin_VatLayer_AjaxController extends Mage_Core_Controller_Front_Action {
3
+ public function indexAction(){
4
+ $vatnum = preg_replace('/\s+/', '',$this->getRequest()->getParam('vat'));
5
+ $model = Mage::getModel('vatlayer/vatlayer');
6
+ print json_encode($model->VATcheck($vatnum)); exit;
7
+ }
8
+ }
app/code/local/Thecoderin/VatLayer/etc/adminhtml.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <acl>
4
+ <resources>
5
+ <admin>
6
+ <children>
7
+ <system>
8
+ <children>
9
+ <config>
10
+ <children>
11
+ <thecoderin translate="title" module="vatlayer">
12
+ <title>Thecoderin Modules Section</title>
13
+ <sort_order>100</sort_order>
14
+ </thecoderin>
15
+ </children>
16
+ </config>
17
+ </children>
18
+ </system>
19
+ </children>
20
+ </admin>
21
+ </resources>
22
+ </acl>
23
+ </config>
app/code/local/Thecoderin/VatLayer/etc/config.xml ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Thecoderin_VatLayer>
5
+ <version>0.1.0</version>
6
+ </Thecoderin_VatLayer>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <vatlayer>
11
+ <class>Thecoderin_VatLayer_Helper</class>
12
+ </vatlayer>
13
+ </helpers>
14
+ <models>
15
+ <vatlayer>
16
+ <class>Thecoderin_VatLayer_Model</class>
17
+ </vatlayer>
18
+ </models>
19
+ </global>
20
+ <frontend>
21
+ <routers>
22
+ <thecoderin_vatlayer>
23
+ <use>standard</use>
24
+ <args>
25
+ <module>Thecoderin_VatLayer</module>
26
+ <frontName>vatlayer</frontName>
27
+ </args>
28
+ </thecoderin_vatlayer>
29
+ </routers>
30
+ <layout>
31
+ <updates>
32
+ <vatlayer>
33
+ <file>vatlayer.xml</file>
34
+ </vatlayer>
35
+ </updates>
36
+ </layout>
37
+ </frontend>
38
+ </config>
app/code/local/Thecoderin/VatLayer/etc/system.xml ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <thecoderin translate="label" module="vatlayer">
5
+ <label>Thecoderin</label>
6
+ <sort_order>150</sort_order>
7
+ </thecoderin>
8
+ </tabs>
9
+ <sections>
10
+ <thecoderin translate="label" module="vatlayer">
11
+ <label>Thecoderin Modules</label>
12
+ <tab>thecoderin</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>100</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+ <thecoderin_vatlayer translate="label">
20
+ <label>VATLayerAPI</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>10</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>1</show_in_store>
26
+ <fields>
27
+ <apikey translate="label">
28
+ <label>VATLayer API Key</label>
29
+ <frontend_type>text</frontend_type>
30
+ <sort_order>10</sort_order>
31
+ <show_in_default>1</show_in_default>
32
+ <show_in_website>1</show_in_website>
33
+ <show_in_store>1</show_in_store>
34
+ <comment><![CDATA[Please create an account in <a href='https://vatlayer.com/' target='_blank'>VAT Layer</a> and generate an <b style='color:red'>API key</b>.]]></comment>
35
+ </apikey>
36
+ </fields>
37
+ </thecoderin_vatlayer>
38
+ </groups>
39
+ </thecoderin>
40
+ </sections>
41
+ </config>
app/design/frontend/base/default/layout/vatlayer.xml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * thecoderin_vatlayer.xml
5
+ *
6
+ * Layout implementation for VAT Layer Vat Checking API
7
+ *
8
+ * @category Thecoderin
9
+ * @package VatLayer
10
+ * @copyright Copyright (c) 2015 Anish Karim C.
11
+ */
12
+ -->
13
+ <layout version="0.1.0">
14
+ <checkout_onepage_index>
15
+ <reference name="head">
16
+ <action method="addItem"><type>skin_js</type><name>js/thecoderin/includejQ.js</name></action>
17
+ <block type="core/template" name="vatlayerjs" template="thecoderin/vatlayerjs.phtml" />
18
+ </reference>
19
+ </checkout_onepage_index>
20
+ </layout>
app/design/frontend/base/default/template/thecoderin/vatlayerjs.phtml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <script>
2
+ var BASE_URL='<?php echo Mage::getBaseUrl();?>';
3
+ </script>
4
+ <script type="text/javascript" src="<?php echo $this->getSkinUrl('js/thecoderin/vatlayer.js');?>"></script>
app/etc/modules/Thecoderin_VatLayer.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Thecoderin_VatLayer>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ <version>0.1.0</version>
8
+ </Thecoderin_VatLayer>
9
+ </modules>
10
+ </config>
package.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Thecoderin_VatLayer</name>
4
+ <version>0.1.0</version>
5
+ <stability>beta</stability>
6
+ <license uri="https://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Thecoderin VatLayer is a real-time VAT Number Validation package using the APIs provided by https://vatlayer.com/</summary>
10
+ <description>Thecoderin VatLayer is a real-time VAT Number Validation package using the APIs provided by https://vatlayer.com/&#xD;
11
+ Once the extension is installed on the system, you need to configure the same with the VAT Layer API Key, which can be obtained from their site. On enabling the VAT field on the checkout (Configurations &gt; Customer &gt; Customer Configuration &gt; Name and Address Options, Show Tax/VAT Number)</description>
12
+ <notes>Site-wide testing needed with all versions of Magento.</notes>
13
+ <authors><author><name>Anish Karim</name><user>Thecoderin</user><email>thecoderin@gmail.com</email></author></authors>
14
+ <date>2016-03-03</date>
15
+ <time>05:20:51</time>
16
+ <contents><target name="magelocal"><dir name="Thecoderin"><dir name="VatLayer"><dir name="Helper"><file name="Data.php" hash="131115b5df46bfc2aa4e325fb4703b7c"/></dir><dir name="Model"><file name="Vatlayer.php" hash="d2db7b02138a4a29cc8de8048b18b0d7"/></dir><dir name="controllers"><file name="AjaxController.php" hash="3569ed3af63364ac47e6ac9ce6669fd3"/></dir><dir name="etc"><file name="adminhtml.xml" hash="fd6d22a2b7e344ac0a2c5f22b8ee6edd"/><file name="config.xml" hash="2fb1375a6d98628519e9f0751415cd66"/><file name="system.xml" hash="33e2ca6c252fca3a0071a8bdc2db5782"/></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="vatlayer.xml" hash="54efd925228c726b453c657e58c9e787"/></dir><dir name="template"><dir name="thecoderin"><file name="vatlayerjs.phtml" hash="83837c832b14d4db8f3fe478fdf248cd"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Thecoderin_VatLayer.xml" hash="3d79c2e8b9d022a2def625cd9791c164"/></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="js"><dir name="thecoderin"><file name="includejQ.js" hash="0905730c859a7d4e0e9db0e7bed2c6de"/><file name="vatlayer.js" hash="9d3d7e6e76860abbf59ca2f210a7b512"/></dir></dir></dir></dir></dir></target></contents>
17
+ <compatible/>
18
+ <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
19
+ </package>
skin/frontend/base/default/js/thecoderin/includejQ.js ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //jQuery checking and including
2
+ if ( (typeof jQuery === 'undefined') && !window.jQuery ) {
3
+ document.write(unescape("%3Cscript type='text/javascript' src='//code.jquery.com/jquery-1.11.3.min.js'%3E%3C/script%3E"));
4
+ } else {
5
+ if((typeof jQuery === 'undefined') && window.jQuery) {
6
+ jQuery = window.jQuery;
7
+ } else if((typeof jQuery !== 'undefined') && !window.jQuery) {
8
+ window.jQuery = jQuery;
9
+ }
10
+ }
11
+
12
+ // jQuery.noConflict();
skin/frontend/base/default/js/thecoderin/vatlayer.js ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Validation.add('vatlayer-validate', 'Please enter valid VAT Number', function(v){
2
+ // alert(v);
3
+ if (v == 'undefined' || v == '' || v == 'NA') {
4
+ return true;
5
+ } else {
6
+ var URL = BASE_URL + 'vatlayer/ajax/index/vat/'+encodeURIComponent(v);
7
+ var ok = false;
8
+ new Ajax.Request(URL, {
9
+ method: 'get',
10
+ asynchronous: false,
11
+ onSuccess: function(transport) {
12
+ var obj = response = eval('(' + transport.responseText + ')');
13
+ validateTrueEmailMsg = obj.msg;
14
+ if (obj.status == false) {
15
+ Validation.get('vatlayer-validate').error = validateTrueEmailMsg;
16
+ ok = false;
17
+ } else {
18
+ ok = true;
19
+ }
20
+ },
21
+ onComplete: function() {
22
+ if ($('advice-vatlayer-validate-billing:taxvat')) {
23
+ $('advice-vatlayer-validate-billing:taxvat').remove();
24
+ }
25
+ }
26
+ });
27
+ return ok;
28
+ }
29
+ });