Skip to content

Instantly share code, notes, and snippets.

@lindskogen
Created April 5, 2017 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lindskogen/3c09b3fd19671b1829ff0185c201ffc5 to your computer and use it in GitHub Desktop.
Save lindskogen/3c09b3fd19671b1829ff0185c201ffc5 to your computer and use it in GitHub Desktop.
Swish Redirect
<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