-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: update readme, examples & diagrams
- Loading branch information
Showing
15 changed files
with
173 additions
and
529 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
{ | ||
"recommendations": [ | ||
"dprint.dprint", | ||
"editorconfig.editorconfig", | ||
"hediet.vscode-drawio", | ||
"editorconfig.editorconfig" | ||
"pomdtr.excalidraw-editor" | ||
] | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,40 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"/> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> | ||
<title>bysquare example</title> | ||
<script type="module" src="index.js"></script> | ||
</head> | ||
<body> | ||
<div> | ||
<div style="margin-right: 10px;"> | ||
<label style="display: block; margin-bottom: 5px;"> | ||
Amount: | ||
<br/> | ||
<input | ||
style="width: 210px;" | ||
type="number" | ||
name="amount" | ||
value="" | ||
/> | ||
</label> | ||
<label style="display: block; margin-bottom: 5px;"> | ||
IBAN: | ||
<br/> | ||
<input | ||
style="width: 210px;" | ||
name="iban" | ||
/> | ||
</label> | ||
<label style="display: block; margin-bottom: 5px;"> | ||
Variable: | ||
<br/> | ||
<input | ||
style="width: 210px;" | ||
type="number" | ||
name="variable" | ||
/> | ||
</label> | ||
<pre id="encodedText"></pre> | ||
<canvas | ||
height="200" | ||
width="200" | ||
id="canvas" | ||
></canvas> | ||
</div> | ||
</div> | ||
</body> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>bysquare example</title> | ||
|
||
<script type="module" src="index.js"></script> | ||
</head> | ||
|
||
<body> | ||
<div> | ||
<div style="margin-right: 10px"> | ||
<label style="display: block; margin-bottom: 5px"> | ||
Amount: | ||
<br /> | ||
<input | ||
style="width: 210px" | ||
type="number" | ||
name="amount" | ||
value="" | ||
/> | ||
</label> | ||
<label style="display: block; margin-bottom: 5px"> | ||
IBAN: | ||
<br /> | ||
<input style="width: 210px" name="iban" /> | ||
</label> | ||
<label style="display: block; margin-bottom: 5px"> | ||
Variable: | ||
<br /> | ||
<input style="width: 210px" type="number" name="variable" /> | ||
</label> | ||
<pre id="encodedText"></pre> | ||
<div style="width: 200px" id="qrcode"></div> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,70 @@ | ||
import { QRCode } from "https://esm.sh/@lostinbrittany/qr-esm@latest"; | ||
import { | ||
CurrencyCode, | ||
encode, | ||
PaymentOptions, | ||
} from "https://esm.sh/bysquare@latest/"; | ||
import { qrcanvas } from "https://esm.sh/qrcanvas@3.1.2/"; | ||
|
||
function getEncodedText(iban, amount, variable) { | ||
return encode({ | ||
invoiceId: new Date().toLocaleDateString("sk"), | ||
payments: [ | ||
{ | ||
class BysquareQR { | ||
constructor() { | ||
this.amountInput = null; | ||
this.ibanInput = null; | ||
this.variableInput = null; | ||
this.encodedTextDiv = null; | ||
this.qrContainer = null; | ||
} | ||
|
||
getEncodedText(iban, amount, variable) { | ||
return encode({ | ||
invoiceId: new Date().toLocaleDateString("sk"), | ||
payments: [{ | ||
type: PaymentOptions.PaymentOrder, | ||
amount: amount, | ||
bankAccounts: [{ iban: iban }], | ||
currencyCode: CurrencyCode.EUR, | ||
variableSymbol: variable, | ||
}, | ||
], | ||
}); | ||
} | ||
}], | ||
}); | ||
} | ||
|
||
function renderOnCanvas(canvasEl, encodedText) { | ||
if (canvasEl) { | ||
const ctx = canvasEl.getContext("2d"); | ||
if (ctx) { | ||
ctx.clearRect(0, 0, canvasEl.width, canvasEl.height); | ||
qrcanvas({ | ||
data: encodedText, | ||
canvas: canvasEl, | ||
}); | ||
} | ||
renderQrCode(container, encodedText) { | ||
container.innerHTML = ""; | ||
const svgQr = QRCode.generateSVG(encodedText); | ||
console.log(svgQr); | ||
container.appendChild(svgQr); | ||
} | ||
} | ||
|
||
function init() { | ||
const amountInput = document.querySelector('input[name="amount"]'); | ||
const ibanInput = document.querySelector('input[name="iban"]'); | ||
const variableInput = document.querySelector('input[name="variable"]'); | ||
const encodedTextDiv = document.querySelector("#encodedText"); | ||
const canvasEl = document.querySelector("#canvas"); | ||
|
||
amountInput.value = "100"; | ||
ibanInput.value = "SK9611000000002918599669"; | ||
variableInput.value = "123"; | ||
|
||
function render() { | ||
const encodedText = getEncodedText(ibanInput.value, amountInput.value, variableInput.value); | ||
encodedTextDiv.innerText = encodedText; | ||
renderOnCanvas(canvasEl, encodedText); | ||
init() { | ||
this.amountInput = document.querySelector('input[name="amount"]'); | ||
this.ibanInput = document.querySelector('input[name="iban"]'); | ||
this.variableInput = document.querySelector('input[name="variable"]'); | ||
this.encodedTextDiv = document.querySelector("#encodedText"); | ||
this.qrContainer = document.querySelector("#qrcode"); | ||
|
||
this.amountInput.value = "100"; | ||
this.ibanInput.value = "SK9611000000002918599669"; | ||
this.variableInput.value = "123"; | ||
|
||
this.amountInput.addEventListener("input", this.render); | ||
this.ibanInput.addEventListener("input", this.render); | ||
this.variableInput.addEventListener("input", this.render); | ||
|
||
this.render(); | ||
} | ||
|
||
amountInput.addEventListener("input", render); | ||
ibanInput.addEventListener("input", render); | ||
variableInput.addEventListener("input", render); | ||
render = () => { | ||
const encodedText = this.getEncodedText( | ||
this.ibanInput.value, | ||
this.amountInput.value, | ||
this.variableInput.value, | ||
); | ||
|
||
render(); | ||
this.encodedTextDiv.innerText = encodedText; | ||
this.renderQrCode(this.qrContainer, encodedText); | ||
}; | ||
} | ||
|
||
window.addEventListener("load", init); | ||
window.addEventListener("load", () => { | ||
const bysquareQR = new BysquareQR(); | ||
bysquareQR.init(); | ||
}); |
Oops, something went wrong.