PHP code example of ndradev / okeconnect-php-client
1. Go to this page and download the library: Download ndradev/okeconnect-php-client 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/ */
ndradev / okeconnect-php-client example snippets
use OkeConnect\OkeConnect;
$oke = new OkeConnect(
memberId: 'OK00123',
pin: '123456',
password: 'secret'
);
OkeConnect::setInstance($oke);
oke_connect('OK00123', '123456', 'secret');
$response = oke_transaction('T1', '089660522887', 'REF123');
use OkeConnect\OkeConnectException;
try {
$response = $oke->transaction('T1', '089660522887', 'TRX123');
echo $response->transactionId;
echo $response->refId;
echo $response->provider;
echo $response->nominal;
echo $response->destination;
if ($response->isSuccessful()) {
echo "Berhasil";
echo $response->serialNumber;
}
if ($response->isFailed()) {
echo "Gagal: " . $response->failureReason;
}
} catch (OkeConnectException $e) {
echo "Error: " . $e->getUserMessage();
}
try {
$response = $oke->transactionOpenDenom('BBSDN', '085736044280', 50000, 'EW123');
echo $response->nominal;
echo $response->transactionId;
} catch (OkeConnectException $e) {
if ($e->getCode() === OkeConnectException::INVALID_PARAMETER) {
echo "Nominal harus antara 10.000 - 10.000.000";
}
}
try {
$status = $oke->checkStatus('T5', '08980204060', 'REF123');
echo $status->getStatusText();
if ($status->isSuccessful()) {
echo $status->serialNumber;
echo $status->price;
}
if ($status->isFailed()) {
echo $status->failureReason;
}
if ($status->isPending()) {
echo "Transaksi masih pending";
}
if ($status->isNoData()) {
echo "Data tidak ditemukan";
}
} catch (OkeConnectException $e) {
echo "Error: " . $e->getUserMessage();
}
try {
$callback = $oke->parseWebhook($_GET);
echo $callback->transactionId;
echo $callback->refId;
echo $callback->getStatusText();
if ($callback->isSuccessful()) {
echo $callback->serialNumber;
echo $callback->date;
echo $callback->time;
}
if ($callback->isFailed()) {
echo $callback->failureReason;
}
} catch (OkeConnectException $e) {
echo "Error: " . $e->getUserMessage();
}
try {
$products = $oke->getPriceList();
foreach ($products as $product) {
echo $product->code;
echo $product->description;
echo $product->getFormattedPrice();
if ($product->isAvailable()) {
echo "Tersedia";
}
}
} catch (OkeConnectException $e) {
echo "Error: " . $e->getUserMessage();
}
$produk = $oke->findProductByCode('SMDC150');
if ($produk) {
echo $produk->description;
echo $produk->getFormattedPrice();
}
$products = $oke->findProductByCategory('SMARTFREN');
foreach ($products as $product) {
echo $product->code . ": " . $product->description;
}
$products = $oke->findProductByKeterangan('30GB');
foreach ($products as $product) {
echo $product->code . ": " . $product->description;
}
$available = $oke->findProductByStatus('1');
$unavailable = $oke->findProductByStatus('0');
$harga = $oke->getPrice('SMDC150');
$response = oke_transaction('T1', '089660522887', 'REF123');
$response = oke_topup('BBSDN', '085736044280', 50000, 'REF123');
$status = oke_check_status('T5', '08980204060', 'REF123');
$callback = oke_webhook($_GET);
$products = oke_products();
$product = oke_product('SMDC150');
$price = oke_price('SMDC150');
$product = oke_find_product_by_code('SMDC150');
$products = oke_find_product_by_category('SMARTFREN');
$products = oke_find_product_by_keterangan('30GB');
$products = oke_find_product_by_status('1');
keConnect\OkeConnect;
use OkeConnect\OkeConnectException;
header('Content-Type: application/json');
if (empty($_GET['message'])) {
http_response_code(400);
echo json_encode(['error' => 'Missing message parameter']);
exit;
}
try {
$oke = new OkeConnect('OK00123', '123456', 'secret');
$callback = $oke->parseWebhook($_GET);
if ($callback->isSuccessful()) {
echo json_encode([
'success' => true,
'ref_id' => $callback->refId,
'transaction_id' => $callback->transactionId,
'serial_number' => $callback->serialNumber,
]);
}
if ($callback->isFailed()) {
echo json_encode([
'success' => false,
'ref_id' => $callback->refId,
'failure_reason' => $callback->failureReason,
]);
}
} catch (OkeConnectException $e) {
http_response_code(400);
echo json_encode([
'success' => false,
'error' => $e->getUserMessage(),
]);
}
try {
$response = $oke->transaction('T1', '089660522887', 'REF123');
} catch (OkeConnectException $e) {
echo $e->getCode();
echo $e->getUserMessage();
echo $e->getMessage();
print_r($e->getContext());
if ($e->isCredentialError()) {
echo "Periksa kredensial Anda";
}
if ($e->isTransactionError()) {
echo "Transaksi gagal";
}
}
bash
composer