-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
73 lines (56 loc) · 1.46 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"fmt"
"os"
"time"
bsqr2 "github.com/kravemir/go-paybysquare/bsqr"
"github.com/kravemir/go-paybysquare/bsqrbuilder"
"github.com/kravemir/go-paybysquare/image/electronic"
)
const OUTPUTS_DIR = "output/examples"
func main() {
ensureOutputsDirectory()
oneTimePaymentExample()
}
func oneTimePaymentExample() {
NixOSDonation := bsqrbuilder.OneTimePayment{
IBAN: "NL13 BUNQ 2061 2530 32",
BIC: "BUNQNL2AXXX",
Amount: "5.00",
CurrencyCode: "EUR",
DueDate: time.Now(),
VariableSymbol: "",
ConstantSymbol: "",
SpecificSymbol: "",
Note: "NixOS: humble donation",
BeneficiaryName: "Stichting NixOS Foundation",
BeneficiaryAddressLine1: "",
BeneficiaryAddressLine2: "Frederiksoord",
}
sequenceData := NixOSDonation.BuildSequenceDataModelText()
bsqrTextContent, err := bsqr2.EncodeSequence(sequenceData)
assertNilError(err)
bsqr, err := electronic.NewBSQRImage(bsqrTextContent, electronic.ImageOptions{
PointSizePX: 3,
})
assertNilError(err)
err = bsqr.WritePNGFile(exampleOutputFilePath("one-time-payment.png"))
assertNilError(err)
}
func exampleOutputFilePath(filename string) string {
return fmt.Sprintf("%s/%s.png", OUTPUTS_DIR, filename)
}
func ensureOutputsDirectory() {
os.RemoveAll(OUTPUTS_DIR)
if _, err := os.Stat(OUTPUTS_DIR); os.IsNotExist(err) {
err := os.MkdirAll(OUTPUTS_DIR, 0775)
if err != nil {
panic(err)
}
}
}
func assertNilError(err error) {
if err != nil {
panic(err)
}
}