-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
example_minimal.php
65 lines (55 loc) · 1.75 KB
/
example_minimal.php
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
<?php declare(strict_types=1);
use Sprain\SwissQrBill as QrBill;
require __DIR__ . '/../vendor/autoload.php';
// This is an example how to create a minimal qr bill:
// - no defined amount
// - no defined debtor
// - no reference number
// Create a new instance of QrBill, containing default headers with fixed values
$qrBill = QrBill\QrBill::create();
// Add creditor information
// Who will receive the payment and to which bank account?
$qrBill->setCreditor(
QrBill\DataGroup\Element\CombinedAddress::create(
'Robert Schneider AG',
'Rue du Lac 1268',
'2501 Biel',
'CH'
)
);
$qrBill->setCreditorInformation(
QrBill\DataGroup\Element\CreditorInformation::create(
'CH9300762011623852957' // This is a classic iban. QR-IBANs will not be valid in this minmal setup.
)
);
// Add payment amount information
// The currency must be defined.
$qrBill->setPaymentAmountInformation(
QrBill\DataGroup\Element\PaymentAmountInformation::create(
'CHF'
)
);
// Add payment reference
// Explicitly define that no reference number will be used by setting TYPE_NON.
$qrBill->setPaymentReference(
QrBill\DataGroup\Element\PaymentReference::create(
QrBill\DataGroup\Element\PaymentReference::TYPE_NON
)
);
// Time to output something!
//
// Get the QR code image …
try {
$qrBill->getQrCode()->writeFile(__DIR__ . '/qr.png');
$qrBill->getQrCode()->writeFile(__DIR__ . '/qr.svg');
} catch (Exception) {
foreach ($qrBill->getViolations() as $violation) {
print $violation->getMessage()."\n";
}
exit;
}
// Next: Output full payment parts, depending on the format you want to use:
//
// - FpdfOutput/fpdf-example.php
// - HtmlOutput/html-example.php
// - TcPdfOutput/tcpdf-example.php