update cara upload gambar

This commit is contained in:
WD - Dev
2025-11-11 12:57:39 +07:00
parent 4a7c248fff
commit 15fba86cbd
24 changed files with 129884 additions and 19764 deletions
+36 -34
View File
@@ -3,10 +3,12 @@ include '../config/connect.php';
require '../payment/flip/Flip/Transaction.php';
try {
// Query ambil data tagihan yang lunas & masih ACTIVE di bulan berjalan
$sql = "
SELECT
a.id,
a.transaction_id,
a.transaction_data,
b.apikey_payment_gateway,
b.url_payment_gateway
FROM
@@ -15,14 +17,15 @@ try {
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())
AND MONTH(a.limit_pembayaran) = MONTH(NOW())
ORDER BY a.limit_pembayaran ASC
ORDER BY a.id ASC
LIMIT 5
";
@@ -31,64 +34,63 @@ try {
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
$results = [];
$no = 1;
foreach ($data as $row) {
// Pastikan class FlipPaymentGateway ada di Transaction.php
$flip = new FlipPaymentGateway($row['apikey_payment_gateway'], $row['url_payment_gateway']);
// Decode JSON transaction_data
$data2 = json_decode($row['transaction_data'], true);
// Ambil status bill
$response = $flip->getBillStatus($row['transaction_id']);
// Cek apakah respon valid dan mengandung link_id
if (!is_array($response) || empty($response['link_id'])) {
// Cek jika JSON tidak valid atau kosong
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'
];
$no++;
continue;
}
$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']]);
}
// Tampilkan respon dari Flip (opsional)
// print_r($response);
// Edit bill menjadi INACTIVE
// $delete = $flip->editBill(
// $response['link_id'],
// 'INACTIVE',
// $response['title'] ?? '',
// $response['amount'] ?? 0
// );
// Tambahkan ke hasil
$results[] = [
'nomor' => $no,
'id' => $row['id'],
'transaction_id' => $row['transaction_id'],
'flip_response' => $response
'title' => $delete['title'] ?? '(tidak ada title)',
// 'flip_response' => $response // bisa diaktifkan nanti jika perlu request ke Flip API
];
// // Jika berhasil, update status di database
// if ($delete) {
// $update = $pdo->prepare("UPDATE tagihan SET transaction_status = :status WHERE id = :id");
// $update->execute([
// ':status' => 'INACTIVE',
// ':id' => $row['id']
// ]);
// }
$no++;
}
// Tampilkan hasil dari Flip (bukan data dari DB)
// Output hasil
header('Content-Type: application/json');
echo json_encode($results, JSON_PRETTY_PRINT);
} catch (PDOException $e) {
echo json_encode([
'status' => 'error',
'message' => $e->getMessage()
'message' => 'Database Error: ' . $e->getMessage()
]);
} catch (Exception $e) {
echo json_encode([
'status' => 'error',
'message' => $e->getMessage()
'message' => 'General Error: ' . $e->getMessage()
]);
}