skip to Main Content

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.

2

Answers


  1. yes this is very well possible

    Login or Signup to reply.
  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).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search