Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat remake #6

Open
wants to merge 19 commits into
base: feat_remake
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*~
.DS_Store
*.swp
/node_modules
/build
60 changes: 60 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -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'
}
}
}
});

};
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
58 changes: 15 additions & 43 deletions src/app/code/Svea/WebPay/Block/Payment/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 .= <<<EOF
<script type="text/javascript">
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();
);
}
})();
</script>
EOF;

return $html;
}
}
35 changes: 35 additions & 0 deletions src/app/code/Svea/WebPay/Model/Payment/Service/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<?php $_typeCompany = Svea_WebPay_Helper_Data::TYPE_COMPANY ?>
<?php $_quote = $this->getMethod()->getInfoInstance()->getQuote() ?>
<div id="payment_form_<?php echo $this->getMethodCode() ?>" style="display:none;">
<div id="svea-invoice-payment-not-available" style="display:none;">
<?php echo Mage::helper('svea_webpay')->__('This payment method cannot be used.'); ?>
</div>
<div id="svea-invoice-payment-information" class="svea-payment-se svea-payment-dk svea-payment-no svea-payment-fi svea-payment-nl svea-payment-de">
<!-- This input needs to be populated and transmitted to the backend,
because we validate it against the items fetched from getAddress
Expand Down Expand Up @@ -167,3 +170,33 @@
</div>
</div>
</div>

<script type="text/javascript">
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 = <?php echo Mage::helper('core')->jsonEncode($this->getScriptUrl()) ?>;

var callback = function () {
window.svea = new Svea(<?php echo Mage::helper('core')->jsonEncode($this->getSveaJsParameters()) ?>);
}

// 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();
}
})();
</script>
Loading