1

I am developing my own plugin that handles PDF generating (invoices, pro-formas etc.). I would like to include QR code that if user scans in the Bank app it will set the payment data for them (name, IBAN, variable symbol, amount for pay etc.).

I am using TCPDF to generate QR code, but content of the QR code needs to be set to specific string (probably hashed data with payment information).

So that brings me to my question, is there a way how I can generate this code that will be output in form of QR code so customers can open their bank APP and scan it to automatically set the payment data? Using PHP in Wordpress site.

I am new to this topic so I am trying to find out if this stuff is even possible.

// Create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    
// Set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Your Name');
$pdf->SetTitle('Scan and Pay QR Code Example');

// Add a page
$pdf->AddPage();

// Set QR code style
$style = array(
    'border' => 2,
    'vpadding' => 'auto',
    'hpadding' => 'auto',
    'fgcolor' => array(0,0,0),
    'bgcolor' => false, // No background color
    'module_width' => 1, // Width of a single module in points
    'module_height' => 1 // Height of a single module in points
);

// Define the content of the QR code that includes a variable symbol and an amount
$variableSymbol = "1111";
$amount = "1 EUR";
$merchantCode = "123456789012";
$transactionCurrency = "978"; // EUR's numeric code

// This is the string that should be formatted in a way that bank apps can read it. HERE IS THE PROBLEM
$codeContents = "TXN:".$variableSymbol."-AMT:".$amount."-MCC:".$merchantCode."-CUR:".$transactionCurrency;

// Print a QR code
$pdf->write2DBarcode($codeContents, 'QRCODE,H', 20, 20, 50, 50, $style, 'N');

// Close and output PDF document
$pdf->Output('scan_and_pay_qr.pdf', 'D');

I tried to include the data according to some ducomentation online (SEPA, EMVCo) but I did not managed to make it work. It shows invalid QR code data in my bank app.

4
  • 2
    Without the documentation and the code you tried, I don’t know if there’s much we can do to help
    – Chris Haas
    Commented May 4, 2024 at 13:18
  • Hi, thank you for your response! I added my code, the problem is that the string that QR code outputs is not readable by the bank app. Commented May 4, 2024 at 13:35
  • 1
    "include QR code that if user scans in the Bank app it will set the payment data for them" - does the bank come with documentation on how to generate the QR code? different financial institution tend to have their own format, we cant really advise given we dont even know the bank in question.
    – Bagus Tesa
    Commented May 4, 2024 at 13:40
  • How is the given code related to Wordpress or any kind of payment?
    – Nico Haase
    Commented Sep 3, 2024 at 14:19

2 Answers 2

1

I suggest you to read carefully the EPC guidelines : https://www.europeanpaymentscouncil.eu/sites/default/files/kb/file/2022-09/EPC069-12%20v3.0%20Quick%20Response%20Code%20-%20Guidelines%20to%20Enable%20the%20Data%20Capture%20for%20the%20Initiation%20of%20an%20SCT_0.pdf

Then here is a simple working example with TCPDF (read the EPC doc to understand the structure) :

<?php
require_once('tcpdf_include.php');
$pdf = new TCPDF();
$pdf->AddPage();

$amount = "10.00";
$iban = //*** your iban ***;
$bic = //*** your bic ***;
$name = //*** your name***;
$ref = "the veggie spaghetti 2015";

$qr_content = array();
$qr_content[] = "BCD";
$qr_content[] = "002";
$qr_content[] = "1";
$qr_content[] = "SCT";
$qr_content[] = $bic;
$qr_content[] = $name;
$qr_content[] = $iban;
$qr_content[] = "EUR".$amount;
$qr_content[] = "";
$qr_content[] = "";
$qr_content[] = $ref;
$qr_content[] = "";

$qr_string = implode(PHP_EOL, $qr_content);
$pdf->write2DBarcode($qr_string, 'QRCODE,H', 10, 10, 40, 40, null, 'N');

$pdf->Output('example_qrcode.pdf', 'I');

Please note that there is some checkings that should be made on the values length ie and you can also use structured refs if you want.

-2

Some times ago I developed QRCodeFormatter library to address the same problem so you may want to try it. Please note that while my solution works perfect for me I only tested it with apps of banks operating on Polish market. so your mileage may wary. The docs are in Polish but any automated translator should do the job if needed as there's not much to read anyway.

At last resort, if the lib I linked is not helping you much, please check if the app your bank provides is not able to generate the QR code for you. If that is supported then you are home -> just generate the code using own data, then decode the QRCode and see what is there.

PS: consider NOT using closing ?> tag, unless really required (usually it's not, unless you are spaghetti coder).

Not the answer you're looking for? Browse other questions tagged or ask your own question.