1. Go to this page and download the library: Download farzai/kapi-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
farzai / kapi-sdk example snippets
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');
$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
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