update cara upload gambar
This commit is contained in:
@@ -11,84 +11,195 @@ date_default_timezone_set('Asia/Jakarta');
|
||||
require "/www/wwwroot/bilspro/config/connect.php";
|
||||
require "/www/wwwroot/bilspro/payment/flip/Flip/Transaction.php";
|
||||
|
||||
// try {
|
||||
// // Ambil maksimum 5 data agar ringan
|
||||
// $sql = "
|
||||
// SELECT
|
||||
// a.id,
|
||||
// a.transaction_id,
|
||||
// b.apikey_payment_gateway,
|
||||
// b.url_payment_gateway
|
||||
// FROM
|
||||
// tagihan a
|
||||
// LEFT JOIN
|
||||
// data_server b ON a.id_data_server = b.id
|
||||
// WHERE
|
||||
// a.status = 'lewat'
|
||||
// AND a.transaction_id != ''
|
||||
// AND a.transaction_status = 'ACTIVE'
|
||||
// AND b.payment_gateway = 'flip'
|
||||
// AND b.status_payment_gateway = 'ACTIVE'
|
||||
// AND (
|
||||
// YEAR(a.limit_pembayaran) < YEAR(NOW())
|
||||
// OR (
|
||||
// YEAR(a.limit_pembayaran) = YEAR(NOW())
|
||||
// AND MONTH(a.limit_pembayaran) < MONTH(NOW())
|
||||
// )
|
||||
// )
|
||||
// ORDER BY a.limit_pembayaran ASC
|
||||
// LIMIT 5
|
||||
// ";
|
||||
|
||||
// $stmt = $pdo->prepare($sql);
|
||||
// $stmt->execute();
|
||||
// $data = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// if (empty($data)) {
|
||||
// exit; // tidak ada data, langsung keluar biar hemat resource
|
||||
// }
|
||||
|
||||
// $logFile = "/www/wwwroot/bilspro/load/cronjob/flip_auto_inactive.log";
|
||||
// if (!file_exists(dirname($logFile))) {
|
||||
// mkdir(dirname($logFile), 0777, true);
|
||||
// }
|
||||
|
||||
// $results = [];
|
||||
|
||||
// foreach ($data as $row) {
|
||||
// try {
|
||||
// $flip = new FlipPaymentGateway($row['apikey_payment_gateway'], $row['url_payment_gateway']);
|
||||
// $response = $flip->getBillStatus($row['transaction_id']);
|
||||
|
||||
// if (!is_array($response) || empty($response['link_id'])) {
|
||||
// $results[] = [
|
||||
// 'id' => $row['id'],
|
||||
// 'transaction_id' => $row['transaction_id'],
|
||||
// 'status' => 'error',
|
||||
// 'message' => 'Invalid or missing response from Flip API'
|
||||
// ];
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// $delete = $flip->editBill(
|
||||
// $response['link_id'],
|
||||
// 'INACTIVE',
|
||||
// $response['title'] ?? '',
|
||||
// $response['amount'] ?? 0
|
||||
// );
|
||||
|
||||
// $results[] = [
|
||||
// 'id' => $row['id'],
|
||||
// 'transaction_id' => $row['transaction_id'],
|
||||
// 'flip_response' => $delete
|
||||
// ];
|
||||
|
||||
// if ($delete) {
|
||||
// $update = $pdo->prepare("UPDATE tagihan SET transaction_status = 'INACTIVE' WHERE id = :id");
|
||||
// $update->execute([':id' => $row['id']]);
|
||||
// }
|
||||
|
||||
// // Delay 1 detik antar request agar tidak membanjiri Flip API
|
||||
// sleep(1);
|
||||
// } catch (Exception $e) {
|
||||
// $results[] = [
|
||||
// 'id' => $row['id'],
|
||||
// 'transaction_id' => $row['transaction_id'],
|
||||
// 'status' => 'error',
|
||||
// 'message' => $e->getMessage()
|
||||
// ];
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Simpan hasil ke log file, bukan echo ke output
|
||||
// file_put_contents(
|
||||
// $logFile,
|
||||
// "[" . date('Y-m-d H:i:s') . "] " . json_encode($results, JSON_UNESCAPED_SLASHES) . PHP_EOL,
|
||||
// FILE_APPEND
|
||||
// );
|
||||
|
||||
// } catch (Throwable $e) {
|
||||
// // Tangkap semua error (PDO/Exception)
|
||||
// file_put_contents(
|
||||
// "/www/wwwroot/bilspro/load/cronjob/flip_auto_inactive_error.log",
|
||||
// "[" . date('Y-m-d H:i:s') . "] ERROR: " . $e->getMessage() . PHP_EOL,
|
||||
// FILE_APPEND
|
||||
// );
|
||||
// }
|
||||
|
||||
try {
|
||||
// Ambil maksimum 5 data agar ringan
|
||||
$sql = "
|
||||
SELECT
|
||||
a.id,
|
||||
a.transaction_id,
|
||||
a.transaction_data,
|
||||
b.apikey_payment_gateway,
|
||||
b.url_payment_gateway
|
||||
FROM
|
||||
tagihan a
|
||||
LEFT JOIN
|
||||
data_server b ON a.id_data_server = b.id
|
||||
data_server b
|
||||
ON a.id_data_server = b.id
|
||||
WHERE
|
||||
a.status = 'lewat'
|
||||
a.status = 'lunas'
|
||||
AND a.transaction_id != ''
|
||||
AND a.transaction_status = 'ACTIVE'
|
||||
AND a.transaction_data != ''
|
||||
AND b.payment_gateway = 'flip'
|
||||
AND b.status_payment_gateway = 'ACTIVE'
|
||||
AND (
|
||||
YEAR(a.limit_pembayaran) < YEAR(NOW())
|
||||
OR (
|
||||
YEAR(a.limit_pembayaran) = YEAR(NOW())
|
||||
AND MONTH(a.limit_pembayaran) < MONTH(NOW())
|
||||
)
|
||||
)
|
||||
ORDER BY a.limit_pembayaran ASC
|
||||
LIMIT 5
|
||||
AND YEAR(a.limit_pembayaran) = YEAR(NOW())
|
||||
AND MONTH(a.limit_pembayaran) = MONTH(NOW())
|
||||
ORDER BY a.id ASC
|
||||
LIMIT 15
|
||||
";
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute();
|
||||
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
if (empty($data)) {
|
||||
exit; // tidak ada data, langsung keluar biar hemat resource
|
||||
}
|
||||
if (empty($data)) exit;
|
||||
|
||||
$logFile = "/www/wwwroot/bilspro/load/cronjob/flip_auto_inactive.log";
|
||||
if (!file_exists(dirname($logFile))) {
|
||||
mkdir(dirname($logFile), 0777, true);
|
||||
}
|
||||
if (!file_exists(dirname($logFile))) mkdir(dirname($logFile), 0777, true);
|
||||
|
||||
$results = [];
|
||||
$no = 1;
|
||||
|
||||
foreach ($data as $row) {
|
||||
try {
|
||||
$flip = new FlipPaymentGateway($row['apikey_payment_gateway'], $row['url_payment_gateway']);
|
||||
$response = $flip->getBillStatus($row['transaction_id']);
|
||||
$data2 = json_decode($row['transaction_data'], true);
|
||||
|
||||
if (!is_array($response) || empty($response['link_id'])) {
|
||||
if (json_last_error() !== JSON_ERROR_NONE || empty($data2)) {
|
||||
$results[] = [
|
||||
'nomor' => $no++,
|
||||
'id' => $row['id'],
|
||||
'transaction_id' => $row['transaction_id'],
|
||||
'status' => 'error',
|
||||
'message' => 'Invalid or missing response from Flip API'
|
||||
'title' => '(invalid JSON)',
|
||||
'error' => 'transaction_data tidak valid'
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
$delete = $flip->editBill(
|
||||
$response['link_id'],
|
||||
'INACTIVE',
|
||||
$response['title'] ?? '',
|
||||
$response['amount'] ?? 0
|
||||
);
|
||||
if (empty($data2['link_id'])) {
|
||||
$results[] = [
|
||||
'nomor' => $no++,
|
||||
'id' => $row['id'],
|
||||
'transaction_id' => $row['transaction_id'],
|
||||
'status' => 'error',
|
||||
'message' => 'link_id kosong di transaction_data'
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
$results[] = [
|
||||
'id' => $row['id'],
|
||||
'transaction_id' => $row['transaction_id'],
|
||||
'flip_response' => $delete
|
||||
];
|
||||
$flip = new FlipPaymentGateway($row['apikey_payment_gateway'], $row['url_payment_gateway']);
|
||||
$delete = $flip->editBill(
|
||||
$data2['link_id'],
|
||||
'INACTIVE',
|
||||
$data2['title'] ?? '',
|
||||
$data2['amount'] ?? 0
|
||||
);
|
||||
|
||||
if ($delete) {
|
||||
$update = $pdo->prepare("UPDATE tagihan SET transaction_status = 'INACTIVE' WHERE id = :id");
|
||||
$update->execute([':id' => $row['id']]);
|
||||
}
|
||||
|
||||
// Delay 1 detik antar request agar tidak membanjiri Flip API
|
||||
$results[] = [
|
||||
'nomor' => $no++,
|
||||
'id' => $row['id'],
|
||||
'transaction_id' => $row['transaction_id'],
|
||||
'title' => is_array($delete) ? ($delete['title'] ?? '(tidak ada title)') : '(tidak ada title)'
|
||||
];
|
||||
|
||||
sleep(1);
|
||||
} catch (Exception $e) {
|
||||
$results[] = [
|
||||
@@ -100,18 +211,16 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
// Simpan hasil ke log file, bukan echo ke output
|
||||
file_put_contents(
|
||||
$logFile,
|
||||
"[" . date('Y-m-d H:i:s') . "] " . json_encode($results, JSON_UNESCAPED_SLASHES) . PHP_EOL,
|
||||
"[" . date('Y-m-d H:i:s') . "] " . json_encode($results, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . PHP_EOL,
|
||||
FILE_APPEND
|
||||
);
|
||||
|
||||
} catch (Throwable $e) {
|
||||
// Tangkap semua error (PDO/Exception)
|
||||
file_put_contents(
|
||||
"/www/wwwroot/bilspro/load/cronjob/flip_auto_inactive_error.log",
|
||||
"[" . date('Y-m-d H:i:s') . "] ERROR: " . $e->getMessage() . PHP_EOL,
|
||||
FILE_APPEND
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user