PHPackages                             farzai/promptpay - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. farzai/promptpay

ActiveLibrary[Payment Processing](/categories/payments)

farzai/promptpay
================

PromptPay QR Code Generator

3.0.0(6mo ago)92186[3 PRs](https://github.com/farzai/promptpay-qr-php/pulls)MITPHPPHP ^8.1CI passing

Since May 25Pushed 1mo agoCompare

[ Source](https://github.com/farzai/promptpay-qr-php)[ Packagist](https://packagist.org/packages/farzai/promptpay)[ Docs](https://github.com/farzai/promptpay-qr-php)[ GitHub Sponsors](https://github.com/parsilver)[ RSS](/packages/farzai-promptpay/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (11)Versions (10)Used By (0)

PromptPay QR Code Generator - PHP
=================================

[](#promptpay-qr-code-generator---php)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b5d4d7c63df3f778f5b8f48e47be5ea5a4d5847ec55c37bcf2b9539c7663c2f1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6661727a61692f70726f6d70747061792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/farzai/promptpay)[![Tests](https://camo.githubusercontent.com/163bcff0181d16372a37dc014c9174860a653c9ce6afd9f3907c8d84c56e7571/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6661727a61692f70726f6d70747061792d71722d7068702f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/farzai/promptpay-qr-php/actions/workflows/run-tests.yml)[![codecov](https://camo.githubusercontent.com/d21f36f590d9f3941d7f93a50fe4374cb1444f7d9b5149d359bb5c2be8cc03e7/68747470733a2f2f636f6465636f762e696f2f67682f6661727a61692f70726f6d70747061792d71722d7068702f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/farzai/promptpay-qr-php)[![Total Downloads](https://camo.githubusercontent.com/0c4a3f622e613e1f11386f9c3650919b4760c5da029a202277790a952f8eb633/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6661727a61692f70726f6d70747061792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/farzai/promptpay)

A modern, type-safe PHP library for generating PromptPay QR codes.

Features
--------

[](#features)

- **Zero Config** - Works out of the box with sensible defaults
- **Multiple Formats** - PNG, SVG, GIF support
- **Amount Support** - Static or dynamic QR codes
- **CLI Tool** - Command-line interface included

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Composer

Installation
------------

[](#installation)

### For PHP Applications

[](#for-php-applications)

```
composer require farzai/promptpay
```

### For CLI Usage (Global)

[](#for-cli-usage-global)

```
composer global require farzai/promptpay
```

Make sure Composer's global bin directory is in your `$PATH`:

- **macOS/Linux**: `~/.composer/vendor/bin` or `~/.config/composer/vendor/bin`
- **Windows**: `%USERPROFILE%\AppData\Roaming\Composer\vendor\bin`

Quick Start
-----------

[](#quick-start)

### Simple Example

[](#simple-example)

```
use Farzai\PromptPay\PromptPay;

// Generate QR code (backward compatible)
$qrCode = PromptPay::create('0899999999', 100);
echo $qrCode; // Raw payload string
```

### Modern Builder API (Recommended)

[](#modern-builder-api-recommended)

```
use Farzai\PromptPay\PromptPay;

// Immutable builder pattern
$result = PromptPay::generate('0899999999')
    ->withAmount(100.50)
    ->toDataUri('png');

echo '';
```

Usage Guide
-----------

[](#usage-guide)

### Creating QR Codes

[](#creating-qr-codes)

#### Static QR Code (No Amount)

[](#static-qr-code-no-amount)

```
// Customer scans and enters amount themselves
$qrCode = PromptPay::generate('0899999999')->build();
```

#### Dynamic QR Code (With Amount)

[](#dynamic-qr-code-with-amount)

```
// Amount is pre-filled in payment app
$result = PromptPay::qrCode('0899999999', 150.75)
    ->toDataUri('png');
```

### Recipient Types

[](#recipient-types)

The library automatically detects recipient type based on length:

```
// Phone Number (10 digits)
PromptPay::generate('0899999999');

// Tax ID / Citizen ID (13 digits)
PromptPay::generate('1234567890123');

// E-Wallet ID (15 digits)
PromptPay::generate('123456789012345');

// Special characters are automatically removed
PromptPay::generate('089-999-9999'); // Works!
```

### Output Formats

[](#output-formats)

#### 1. Data URI (for `` tags)

[](#1-data-uri-for-img-tags)

```
$result = PromptPay::generate('0899999999')
    ->withAmount(100)
    ->toDataUri('png');

echo '';

// Available formats: png, svg, pdf, gif
```

#### 2. Save to File

[](#2-save-to-file)

```
$result = PromptPay::qrCode('0899999999', 100)
    ->toFile('qrcode.png');

echo 'Saved to: ' . $result->getPath();
echo 'File size: ' . $result->getSize() . ' bytes';
```

#### 3. PSR-7 HTTP Response

[](#3-psr-7-http-response)

First, install any PSR-17/PSR-7 implementation:

```
# Choose one:
composer require nyholm/psr7
# or
composer require guzzlehttp/psr7
```

Then create the response:

```
use Nyholm\Psr7\Factory\Psr17Factory;

// Create PSR-17 factory (implements both ResponseFactory and StreamFactory)
$factory = new Psr17Factory();

$response = PromptPay::generate('0899999999')
    ->withAmount(100)
    ->toResponse($factory, $factory);

// Returns PSR-7 ResponseInterface
// Perfect for Laravel, Symfony, Slim, etc.
return $response;
```

**With Guzzle PSR-7:**

```
use GuzzleHttp\Psr7\HttpFactory;

$factory = new HttpFactory();
$response = PromptPay::generate('0899999999')
    ->withAmount(100)
    ->toResponse($factory, $factory);
```

**Why PSR-17?** No hard dependencies! Works with ANY PSR-7 library - choose the one your project already uses.

#### 4. Console Output (CLI)

[](#4-console-output-cli)

```
use Symfony\Component\Console\Output\ConsoleOutput;

$output = new ConsoleOutput();
PromptPay::generate('0899999999')
    ->withAmount(100)
    ->toConsole($output);
```

#### 5. Raw Payload String

[](#5-raw-payload-string)

```
$payload = PromptPay::generate('0899999999')
    ->withAmount(100)
    ->toPayload();

echo $payload;
// 00020101021229370016A000000677010111011300668999999995802TH53037645406100.006304CB89
```

### Advanced Configuration

[](#advanced-configuration)

```
use Farzai\PromptPay\PromptPay;
use Farzai\PromptPay\ValueObjects\QrCodeConfig;

// Custom QR code size and margin
$config = QrCodeConfig::create(
    size: 400,      // 400x400 pixels
    margin: 20,     // 20px margin
    encoding: 'UTF-8'
);

$result = PromptPay::generate('0899999999')
    ->withAmount(100)
    ->withConfig($config)
    ->toDataUri('svg');
```

### Immutable Builder Pattern

[](#immutable-builder-pattern)

The builder is fully immutable - each method returns a new instance:

```
$builder1 = PromptPay::generate('0899999999')->withAmount(100);
$builder2 = $builder1->withAmount(200); // New instance!

echo $builder1->getAmount(); // 100
echo $builder2->getAmount(); // 200
```

Validation &amp; Error Handling
-------------------------------

[](#validation--error-handling)

The library provides comprehensive validation with helpful error messages:

### Recipient Validation

[](#recipient-validation)

```
use Farzai\PromptPay\Exceptions\InvalidRecipientException;

try {
    PromptPay::generate('12345')->build(); // Too short
} catch (InvalidRecipientException $e) {
    echo $e->getMessage();
    // "Invalid recipient length: 5 digits. Expected formats:
    // Too short! • Phone Number: 10 digits (e.g., 0899999999)
    // • Tax ID: 13 digits (e.g., 1234567890123)
    // • E-Wallet ID: 15 digits (e.g., 123456789012345)"

    echo $e->getCode(); // 1003
}
```

### Amount Validation

[](#amount-validation)

```
use Farzai\PromptPay\Exceptions\InvalidAmountException;

try {
    PromptPay::qrCode('0899999999', -50)->build();
} catch (InvalidAmountException $e) {
    echo $e->getMessage();
    // "Invalid amount: -50.00 THB cannot be negative.
    // Please provide a positive amount."

    echo $e->getCode(); // 2002
}
```

### Error Codes Reference

[](#error-codes-reference)

**Recipient Errors (1xxx)**

- `1001` - Empty recipient
- `1002` - Not numeric
- `1003` - Invalid length
- `1004` - Empty after normalization

**Amount Errors (2xxx)**

- `2001` - Not numeric
- `2002` - Negative amount
- `2003` - Too large (&gt; 999,999,999.99)
- `2004` - Zero (when positive required)
- `2005` - Too small (&lt; 0.01)

**Configuration Errors (3xxx)**

- `3001` - Size too small
- `3002` - Size too large
- `3003` - Margin too small
- `3004` - Margin too large
- `3005` - Invalid encoding
- `3006` - Invalid path
- `3007` - Missing dependency

CLI Usage
---------

[](#cli-usage)

```
# Basic usage
promptpay 0899999999 100

# Interactive mode (no arguments)
promptpay

# Output shows QR code in terminal
```

Testing
-------

[](#testing)

```
# Run tests
composer test

# Run tests with coverage
composer test-coverage

# Run static analysis
composer analyse

# Run code formatting
composer format
```

Examples
--------

[](#examples)

Check the `examples/` directory for real-world usage scenarios:

- **01-basic-usage.php** - Basic QR code generation and builder patterns
- **02-file-generation.php** - Saving to files with custom configurations
- **03-error-handling.php** - Comprehensive error handling patterns
- **04-web-integration.php** - Web form integration with HTML
- **05-laravel-integration.php** - Laravel framework integration
- **06-symfony-integration.php** - Symfony framework integration
- **07-custom-validation.php** - Custom validation patterns and business rules
- **08-batch-generation.php** - Batch processing and bulk generation

Contributing
------------

[](#contributing)

Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security vulnerabilities, please review [our security policy](../../security/policy) on how to report them.

Changelog
---------

[](#changelog)

Please see [CHANGELOG.md](CHANGELOG.md) for recent changes.

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE.md](LICENSE.md) for more information.

Credits
-------

[](#credits)

- [parsilver](https://github.com/parsilver)
- [All Contributors](../../contributors)

Acknowledgments
---------------

[](#acknowledgments)

- Built with [endroid/qr-code](https://github.com/endroid/qr-code)
- Follows PromptPay EMV QR Code Specification
- Inspired by Thailand's National e-Payment Master Plan

---

**Made with ❤️ for the Thai developer community**

###  Health Score

46

—

FairBetter than 93% of packages

Maintenance79

Regular maintenance activity

Popularity22

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 63.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~221 days

Total

5

Last Release

203d ago

Major Versions

1.0.1 → 2.0.02024-07-01

2.1.0 → 3.0.02025-10-27

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4928451?v=4)[parsilver](/maintainers/parsilver)[@parsilver](https://github.com/parsilver)

---

Top Contributors

[![parsilver](https://avatars.githubusercontent.com/u/4928451?v=4)](https://github.com/parsilver "parsilver (55 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (21 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (9 commits)")[![ImgBotApp](https://avatars.githubusercontent.com/u/31427850?v=4)](https://github.com/ImgBotApp "ImgBotApp (1 commits)")[![zenepay](https://avatars.githubusercontent.com/u/1179823?v=4)](https://github.com/zenepay "zenepay (1 commits)")

---

Tags

paymentpromptpaypromptpay-qrqrcodeqr codeqrPromptpaypromptpay-qrfarzai

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/farzai-promptpay/health.svg)

```
[![Health](https://phpackages.com/badges/farzai-promptpay/health.svg)](https://phpackages.com/packages/farzai-promptpay)
```

###  Alternatives

[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[dfridrich/qr-platba

Generování QR Plateb a QR Faktur v PHP.

47270.8k1](/packages/dfridrich-qr-platba)[sevaske/php-zatca-xml

An unofficial PHP library for generating ZATCA Fatoora e-invoices. This library facilitates the creation of compliant e-invoices, QR Codes, and certificates, as well as the submission of e-invoices to ZATCA's servers. It provides developers with an easy-to-use, customizable, and robust toolkit to integrate and automate ZATCA e-invoicing processes in PHP applications.

193.3k1](/packages/sevaske-php-zatca-xml)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
