Pisah server penyimpanan dan update payment gateway
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
include '../config/connect.php';
|
||||
require '../payment/flip/Flip/Transaction.php';
|
||||
|
||||
try {
|
||||
$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())
|
||||
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);
|
||||
|
||||
$results = [];
|
||||
|
||||
foreach ($data as $row) {
|
||||
// Pastikan class FlipPaymentGateway ada di Transaction.php
|
||||
$flip = new FlipPaymentGateway($row['apikey_payment_gateway'], $row['url_payment_gateway']);
|
||||
|
||||
// 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'])) {
|
||||
$results[] = [
|
||||
'id' => $row['id'],
|
||||
'transaction_id' => $row['transaction_id'],
|
||||
'status' => 'error',
|
||||
'message' => 'Invalid or missing response from Flip API'
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
// Tampilkan respon dari Flip (opsional)
|
||||
// print_r($response);
|
||||
|
||||
// Edit bill menjadi INACTIVE
|
||||
// $delete = $flip->editBill(
|
||||
// $response['link_id'],
|
||||
// 'INACTIVE',
|
||||
// $response['title'] ?? '',
|
||||
// $response['amount'] ?? 0
|
||||
// );
|
||||
|
||||
$results[] = [
|
||||
'id' => $row['id'],
|
||||
'transaction_id' => $row['transaction_id'],
|
||||
'flip_response' => $response
|
||||
];
|
||||
|
||||
// // 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']
|
||||
// ]);
|
||||
// }
|
||||
}
|
||||
|
||||
// Tampilkan hasil dari Flip (bukan data dari DB)
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($results, JSON_PRETTY_PRINT);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => $e->getMessage()
|
||||
]);
|
||||
}
|
||||
Reference in New Issue
Block a user