Download the PHP package fidele007/bakong-khqr-php without Composer
On this page you can find all versions of the php package fidele007/bakong-khqr-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package bakong-khqr-php
Bakong KHQR PHP
This is a complete implementation of the bakong-khqr
npm module, including all the available API calls documented here: https://api-bakong.nbc.gov.kh/document.
Installation
Usage
All available methods are exposed through the BakongKHQR
class:
Static methods (no token is required):
generateIndividual(IndividualInfo $individualInfo)
generateMerchant(MerchantInfo $merchantInfo)
decode(string $khqrString)
decodeNonKhqr(string $qr)
verify(string $KHQRString)
generateDeepLink(string $qr, ?SourceInfo $sourceInfo, bool $isTest = false)
generateDeepLinkWithUrl(string $url, string $qr, ?SourceInfo $sourceInfo)
isExpiredToken(string $token)
renewToken(string $email, bool $isTest = false)
checkBakongAccount(string $bakongID, bool $isTest = false)
checkBakongAccountWithUrl(string $url, string $bakongID)
Non-static methods (token is required):
checkTransactionByMD5(string $md5, bool $isTest = false)
checkTransactionByMD5List(array $md5Array, bool $isTest = false)
checkTransactionByFullHash(string $fullHash, bool $isTest = false)
checkTransactionByFullHashList(array $fullHashArrray, bool $isTest = false)
checkTransactionByShortHash(string $shortHash, float $amount, string $currency, bool $isTest = false)
checkTransactionByInstructionReference(string $ref, bool $isTest = false)
checkTransactionByExternalReference(string $ref, bool $isTest = false)
Generate KHQR for an individual
[!IMPORTANT] Starting from v1.1.0 (the v1.0.18 equivalent of the npm package) The
expirationTimestamp
parameter is required for dynamic KHQR, i.e. KHQR with a transaction amount. The expected format is a timestamp string in milliseconds.
Output:
Generate KHQR for a merchant
Output:
Decode KHQR
Output:
Decode Non-KHQR
Output:
Verify KHQR
Output:
API - Generate KHQR with Deep Link
Output:
API - Generate KHQR with Deep Link by Providing URL
Bakong API has two available URLs:
- Production URL: https://api-bakong.nbc.gov.kh
- SIT URL (for testing): https://sit-api-bakong.nbc.gov.kh
So the deep link API URLs can be different according to the environment you want to use:
- Production URL: https://api-bakong.nbc.gov.kh/v1/generate_deeplink_by_qr
- SIT URL (for testing): https://sit-api-bakong.nbc.gov.kh/v1/generate_deeplink_by_qr
This method can be used with any of the above URLs. For example:
Output:
API - Check Bakong Account Existence
Output:
API - Check Bakong Account Existence by Providing URL
Just like the Deep Link API, you can use any of the available Bakong API URLs to check for a Bakong account existence:
Output:
API - Checking if a Bakong API Token is Expired
Output:
API - Renewing an expired Bakong API Token
If your token has expired, you will get a KHQRException
when calling authorized Bakong API requests:
You can renew your token with the renewToken
method:
Output:
In case your email is not registered:
API - Check Transaction Status
A valid token is required to check transaction status. You can get one by registering on the Bakong website: https://api-bakong.nbc.gov.kh/register. At the moment of writing this README the token has to be renewed every 90 days. Then you can create a BakongKHQR
instance with the token:
Check Transaction by MD5
Check Transaction by MD5 List
Check Transaction by Full Hash
Check Transaction by Full Hash List
Check Transaction by Short Hash
Check Transaction by Instruction Reference
Check Transaction by External Reference
Testing
To run the tests:
Static Code Analysis
To run static code analysis:
Code Style
To run the code style fixer:
Code Refactoring
Troubleshooting
PHP curl does not work correctly on Windows
It may be due to the fact that your PHP configuration does not include a valid certificate file. This can be confirmed by disabling the SSL verification:
or by checking with phpinfo()
:
If that's true, the certificate file can be downloaded from https://curl.se/ca/cacert.pem, and include in php.ini
file:
After that, restart your services or your terminal and retest.