Last active
August 29, 2015 14:04
-
-
Save matjaz/5b8810a6fb50f9d4d5ca to your computer and use it in GitHub Desktop.
http://www.bezahlcode.de autofill bank SEPA form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://www.bezahlcode.de | |
(function() { | |
var parseBezahlCode = function(uri) { | |
if (uri.slice(0, 25) === 'bank://singlepaymentsepa?') { | |
var data = {}; | |
var parts = uri.slice(25).split('&'); | |
for (var i = 0, len = parts.length; i < len; i++) { | |
var prop = parts[i].split('='); | |
data[decodeURIComponent(prop[0])] = decodeURIComponent(prop[1]); | |
} | |
return data; | |
} | |
}; | |
var fillForm = function(data) { | |
var inputMap = { | |
name: '#type_ime2', | |
iban: '#type_iban2', | |
bic: '#type_bic_banka_prejemnika', | |
amount: '#type_znesek2', | |
reason: '#type_namen_rok_placila2' | |
}; | |
for (var prop in data) { | |
if (inputMap[prop]) { | |
var f = document.querySelector(inputMap[prop]); | |
if (f) { | |
if (prop === 'amount') { | |
// comma decimal separator | |
data[prop] = data[prop].replace('.', ','); | |
} | |
f.value = data[prop]; | |
} | |
} | |
} | |
}; | |
var code = prompt('Enter BezahlCode:'); | |
if (code) { | |
var data = parseBezahlCode(code); | |
if (data) { | |
fillForm(data); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment