1

The designers of the Swish QR Code API have chosen to use POST as the method for generating and fetching QR codes. I do not understand this choice, but that's how it is. Consuming the API would be trivial if they had opted to utilize the GET method instead. But as it is, you need to write your own proxy to translate a GET to POST if you need to generate Swish payment QR Codes on the fly.

This is how I would like to use the API:

<img src="qr.asp?payee=9006032&amount=200">

How do you accomplish this using Classic ASP?

Background information:

Swish is a Swedish mobile payment provider and the QR codes are used to initiate a payment. In the QR code, the payee (mobile phone number for private individuals), the amount, and a message to the payee (for example an order number) may be specified.

user692942
  • 16,398
  • 7
  • 76
  • 175
Tomas Eklund
  • 573
  • 1
  • 4
  • 16
  • 1
    It makes sense to use POST because the heavy lifting of returning the QR code should come from the server-side via a server to server interaction using XHR. If a GET was used for this the data would be exposed on the querystring and reported in server web logs. – user692942 Mar 07 '21 at 09:33

1 Answers1

3

Use the XMLHTTP component to connect to the Swish API server. Build the appropriate JSON request and stream the response to the client.

This example uses JScript as the scripting language.

<%@ codepage=65001 language="jscript" %>
<%

var payee       = Request.QueryString('payee');
var amount      = Request.QueryString('amount');
var message     = Request.QueryString('message');

var format      = 'png'; // Can also be 'jpg' or 'svg'
var size        = 400; // Between 300 and 2000
var border      = 2; // Between 0 and 4 (measured in blocks, not pixels)
var transparent = 'true'; // Must be 'false' for 'jpg'

var json = '{'
    + '"payee":{"value":"' + payee + '","editable":false},'
    + '"amount":{"value":' + amount + ',"editable":false},'
    + '"message":{"value":"' + message + '","editable":false},'
    + '"format":"' + format + '",'
    + '"size":' + size + ','
    + '"border":' + border + ','
    + '"transparent":' + transparent
    + '}';


var http = new ActiveXObject('MSXML2.Serverhttp');
http.open('POST', 'https://mpc.getswish.net/qrg-swish/api/v1/prefilled', false);
http.setRequestHeader('content-type', 'application/json');
http.send(json);

if (http.status != 200) {
    Response.ContentType = 'text/plain';
    Response.Write('HTTP ' + http.status + '\n' + http.statusText + '\n' + http.responseText);
} else {
    Response.ContentType = 'image/png';
    Response.BinaryWrite(http.responseBody);
    Response.End();
}

%>
Tomas Eklund
  • 573
  • 1
  • 4
  • 16