1. Go to this page and download the library: Download unicloudvn/klbpay-php-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/ */
use src\transaction\model\CustomerInfo;
use src\transaction\request\CreateTransactionRequest;
amount'];
$desc = $_POST['description'];
$timeout = $_POST['timeout'];
$title = $_POST['title'];
$language = $_POST['language'];
$full_name = $_POST['full_name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$address = $_POST['address'];
$success_url = 'https://success.example.com.vn';
$fail_url = 'https://fail.example.com.vn';
$redirect_after = 5;
$bank_account_no = "";
$customer_info = new CustomerInfo($full_name, $email, $phone, $address);
$request = new CreateTransactionRequest(
$tnx_ref,
$amount,
$desc,
$timeout,
$title,
$language,
$customer_info,
$success_url,
$fail_url,
$redirect_after,
$bank_account_no // hệ thống chọn tài khoản mặc định trong trường hợp null
);
try {
if (!empty($pay_client)) {
$response = $pay_client->createTransaction($request);
header('Location: ' . $response->getUrl());
}
} catch (Exception $e) {
error_log($e->getMessage());
}
$order_id = $_POST["order-id"];
$checkRequest = new QueryTransactionRequest($order_id);
$response = $pay_client->checkTransaction($checkRequest);
$order_id = $_POST["order-id"];
$cancelRequest = new CancelTransactionRequest($order_id);
$response = $pay_client->cancelTransaction($cancelRequest);
use src\security\SecurityUtil;
Payment Notify
* IPN URL: Ghi nhận kết quả thanh toán từ KLBPay
* $response_data -> Giá trị 'data' từ Request body
* $encrypt_key -> ENCRYPT_KEY
* $decrypt_data -> Giá trị data sau khi decryptAES (JSON String)
*/
$decrypt_data = SecurityUtil::decryptAES($response_data, $encrypt_key)
// Kiểm tra giao dịch và trả về giá trị bool $status (true or false)
echo json_encode(['status' => $status]);
$accountNo = $_POST['account_no'];
$checkRequest = new CheckAccountNoRequest($accountNo);
$response = $client->checkAccountNo($checkRequest);