Created
April 5, 2017 11:30
-
-
Save lindskogen/3c09b3fd19671b1829ff0185c201ffc5 to your computer and use it in GitHub Desktop.
Swish Redirect
This file contains 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
<html> | |
<head> | |
<title>Swish redirect</title> | |
<script> | |
var search = window.location.search; | |
var params = search.substr(1).split('&').map(function(arg){ | |
return arg.split('=', 2); | |
}).reduce(function(acc, items) { | |
acc[items[0]] = decodeURIComponent(items[1]); | |
return acc; | |
}, {}); | |
var number = params.p | |
var sum = parseInt(params.a, 10) | |
var msg = params.m | |
var swishObj = { | |
version: 1, | |
payee: { | |
value: number | |
} | |
} | |
if (sum) { | |
swishObj.amount = { value: sum, editable: true } | |
} | |
if (msg) { | |
swishObj.message = { value: msg } | |
} | |
var jsonString = JSON.stringify(swishObj) | |
var url = "swish://payment?data=" + encodeURIComponent(jsonString) | |
window.location = url | |
</script> | |
</head> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment