Welcome to the KBank API SDK for PHP! This SDK simplifies the process of integrating with KBank APIs by providing a set of pre-built functions that handle authentication, requests, and responses. With this SDK, developers can easily build applications that leverage KBank services, such as payment processing, account management, and more. The KBank API SDK for PHP is designed to be easy to use, with clear documentation and examples to get you started quickly.
See full documentation at https://farzai.gitbook.io/kbank-kapi-php
{
"php": "^8.0",
"ext-json": "*",
"ext-curl": "*"
}
Done | Products |
---|---|
- | QR Payment |
- | Bill Payment |
- | Slip Verification |
- | Inward Remittance |
- | KGP Merchant Payment Platform |
- | Corporate Fund Transfer |
This project is still under development.
- OAuth2 Authentication
- Setup environment and test suite
- Documentation
- Implement products
- Webhook callback capture
- Code coverage must >= 80%
- Add support two-way SSL authentication
- Release v1.0.0
You can install the package via composer:
composer require farzai/kapi-sdk
This is a simple example of qr payment.
use Farzai\KApi\ClientBuilder;
use Farzai\KApi\OAuth2\Requests as OAuth2Requests;
use Farzai\KApi\QrPayment\Requests as QrPaymentRequests;
// Create client instance
$client = ClientBuilder::make()
->setConsumer("<YOUR_CONSUMER_ID>", "<YOUR_CONSUMER_SECRET>")
->asSandbox()
->build();
// This SDK will automatically generate oauth2 access token for you.
// You can ignore this step !!
// $accessToken = $client->oauth2
// ->sendRequest(new OAuth2Requests\RequestAccessToken())
// ->throw()
// ->json('access_token');
Next, Build qr code payment request
$yourTransactionId = 'TS'.time();
$request = new QrPaymentRequests\RequestThaiQRCode();
$request
// Required
->setMerchant(id: '<YOUR_MERCHANT_ID>')
->setPartner(
partnerTransactionID: $yourTransactionId,
partnerID: '<YOUR_PARTNER_ID>',
partnerSecret: '<YOUR_PARTNER_SECRET>',
requestDateTime: new \DateTime('now'),
)
->setAmount(100)
->setReferences('<YOUR_ORDER_ID>')
// or ->setReferences('<reference1>', '<reference2>', '<reference3>', '<reference4>')
// Optional
->setTerminal('<YOUR_TERMINAL_ID>')
->setCurrency('THB') // Default is THB
->setMetadata([
'แก้วเบียร์ 40บ.',
'เหล้าขาว 60บ.',
]);
// Send request
$response = $client->qrPayment->sendRequest($request);
// Print response data
print_r($response->json());
// Or, you can get response data with specific key
echo $response->json('partnerTxnUid'); // Output: xxxxxxx
Sometime, you may want to handle webhook from payment notification service
use Farzai\KApi\QrPayment;
// This SDK will automatically validate your request.
$result = $client->processWebhook(new QrPayment\PaymentNotificationCallback);
$result->json() // returns: array
$result->json('partnerTxnUid') // returns: string
$result->isSuccessful() // returns: bool
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.