diff --git a/.gitignore b/.gitignore index af0faab..5e7c6ec 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *~ .DS_Store *.swp +/node_modules +/build diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..efccdfc --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,60 @@ +/*global module require */ + +module.exports = function(grunt) { + "use strict"; + + // load all grunt tasks + require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); + // load uglify + grunt.loadNpmTasks('grunt-contrib-uglify'); + + // Project configuration. + grunt.initConfig({ + uglify: { + options: { + mangle: true + }, + svea: { + files: { + 'build/js/svea.min.js': ['src/js/svea.js'] + } + } + }, + jasmine : { + // Project's source files + test: { + options: { + vendor: [ + + // jquery and jasmine-jquery used in testing + 'tests/js/bower_components/jquery/dist/jquery.js', + 'tests/js/bower_components/jasmine-jquery/lib/jasmine-jquery.js', + 'tests/js/dependencies/jquery-noconflict.js', // Calls jQuery.noConflict() + + // Libraries that are loaded by magento + "tests/js/dependencies/js/prototype/prototype.js", + "tests/js/dependencies/js/lib/ccard.js", + "tests/js/dependencies/js/prototype/validation.js", + "tests/js/dependencies/js/scriptaculous/builder.js", + "tests/js/dependencies/js/scriptaculous/effects.js", + "tests/js/dependencies/js/scriptaculous/dragdrop.js", + "tests/js/dependencies/js/scriptaculous/controls.js", + "tests/js/dependencies/js/scriptaculous/slider.js", + "tests/js/dependencies/js/varien/js.js", + "tests/js/dependencies/js/varien/form.js", + "tests/js/dependencies/js/varien/menu.js", + "tests/js/dependencies/js/mage/translate.js", + "tests/js/dependencies/js/mage/cookies.js", + + "tests/js/dependencies/js/event.simulate.js", + + 'src/js/svea.js', // svea library + ], + specs: 'tests/js/spec/**/*.spec.js', + helpers: 'tests/js/spec/**/*.helper.js' + } + } + } + }); + +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..fabb2f1 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "svea-webpay", + "description": "SVEA webpay", + "version": "0.1.0", + "devDependencies": { + "grunt": "^0.4.5", + "grunt-cli": "^0.1.13", + "grunt-contrib-jasmine": "^0.8.1", + "grunt-contrib-uglify": "^0.6.0", + "matchdep": "^0.3.0" + } +} diff --git a/src/app/code/Svea/WebPay/Block/Payment/Abstract.php b/src/app/code/Svea/WebPay/Block/Payment/Abstract.php index c1f02f9..ef75b3d 100644 --- a/src/app/code/Svea/WebPay/Block/Payment/Abstract.php +++ b/src/app/code/Svea/WebPay/Block/Payment/Abstract.php @@ -66,56 +66,28 @@ public function getCountry() } /** - * Loads the svea.js file and instantiates the svea payment object + * Get URL to svea.js * * @return string */ - protected function _toHtml() + public function getScriptUrl() { - $scriptUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS, - true) . 'svea.js'; - $scriptUrl = Mage::helper('core')->jsonEncode($scriptUrl); + return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS, true) . 'svea.js'; + } - $parameters = Mage::helper('core')->jsonEncode(array( + /** + * Get parameters for the javascript Svea class + * + * @return array + */ + public function getSveaJsParameters() + { + return array( 'baseUrl' => Mage::getUrl('', array( - '_secure' => true - )), + '_secure' => true + )), 'checkoutType' => $this->_getCheckoutType(), - )); - - $html = parent::_toHtml(); - $html .= << -var svea; -window.svea = svea; -(function () { - if (!window.svea) { - // Set this in the beginning because, well, concurrency and stuff - window.svea = true; - - var head = document.getElementsByTagName('head')[0]; - var script = document.createElement('script'); - script.type = 'text/javascript'; - script.src = $scriptUrl; - - var callback = function () { - window.svea = new Svea($parameters); - } - - // Then bind the event to the callback function. - // There are several events for cross browser compatibility. - script.onreadystatechange = callback; - script.onload = callback; - - // Fire the loading - head.appendChild(script); - } else { - window.svea.displayCountrySpecificFields(); + ); } -})(); - -EOF; - return $html; - } } \ No newline at end of file diff --git a/src/app/code/Svea/WebPay/Model/Payment/Service/Invoice.php b/src/app/code/Svea/WebPay/Model/Payment/Service/Invoice.php index bbd9b9a..afa0338 100644 --- a/src/app/code/Svea/WebPay/Model/Payment/Service/Invoice.php +++ b/src/app/code/Svea/WebPay/Model/Payment/Service/Invoice.php @@ -22,6 +22,41 @@ class Svea_WebPay_Model_Payment_Service_Invoice protected $_code = 'svea_invoice'; protected $_formBlockType = 'svea_webpay/payment_service_invoice'; + /** + * Check if this method is valid for a specific country + * + * This makes sure that only countries that are valid according + * to the current store configuration can be used for a specific country. + * + * @see Mage_Payment_Model_Method_Abstract::canUseForCountry() + * + * @return bool + */ + public function canUseForCountry($country) + { + $country = strtolower($country); + + // Required configuration options for an invoice method + // It seems like the 'active' configuration option is checked somewhere + // else, so there is no need to check it here + $requiredConfigOptions = array( + "{$country}/client_number", + "{$country}/username", + "{$country}/password", + ); + + foreach ($requiredConfigOptions as $requiredConfigOption) { + $configValue = $this->getConfigData($requiredConfigOption); + + if ($configValue === null || $configValue === '') { + return false; + } + + } + + return parent::canUseForCountry($country); + } + /** * Authorize payment for later capture * diff --git a/src/app/design/frontend/template/svea/payment/service/invoice.phtml b/src/app/design/frontend/template/svea/payment/service/invoice.phtml index 89a6db3..909c202 100644 --- a/src/app/design/frontend/template/svea/payment/service/invoice.phtml +++ b/src/app/design/frontend/template/svea/payment/service/invoice.phtml @@ -11,6 +11,9 @@ getMethod()->getInfoInstance()->getQuote() ?>