addBodyParsingMiddleware(); // Add CORS middleware $app->add(function (Request $request, $handler) { // Handle preflight OPTIONS request if ($request->getMethod() === 'OPTIONS') { $response = new \Slim\Psr7\Response(); return $response ->withHeader('Access-Control-Allow-Origin', '*') ->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization') ->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS') ->withStatus(200); } $response = $handler->handle($request); return $response ->withHeader('Access-Control-Allow-Origin', '*') ->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization') ->withHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS'); }); // Handle OPTIONS request $app->options('/{routes:.+}', function (Request $request, Response $response) { return $response; }); // Add error middleware $app->addErrorMiddleware(true, true, true); // Initialize controllers $authController = new AuthController(); $slController = new SLController(); $tagihanController = new TagihanController(); $pembayaranController = new \App\Controllers\PembayaranController(); $laporanController = new \App\Controllers\LaporanController(); $wipayController = new \App\Controllers\WipayController(); $otherController = new \App\Controllers\OtherController(); $uploadController = new \App\Controllers\UploadController(); $resetPasswordController = new \App\Controllers\ResetPasswordController(); // Health check $app->get('/health', function (Request $request, Response $response) { $response->getBody()->write(json_encode([ 'status' => 'ok', 'timestamp' => date('Y-m-d H:i:s') ])); return $response->withHeader('Content-Type', 'application/json'); }); // Root endpoint $app->get('/', function (Request $request, Response $response) { $response->getBody()->write(json_encode([ 'message' => 'Welcome to Timo Wipay API', 'version' => '1.0.0', 'endpoints' => [ 'auth' => [ 'POST /timo/daftar', 'POST /timo/login', 'POST /timo/login_token', 'POST /timo/update_akun', 'POST /timo/update_password' ], 'sl' => [ 'POST /timo/cek_sl', 'POST /timo/confirm_sl', 'POST /timo/hapus_sl' ], 'tagihan' => [ 'GET /timo/history/{sl}/{periode}', 'GET /timo/tagihan/{sl}' ], 'pembayaran' => [ 'POST /timo/request_pembayaran', 'POST /timo/cek_pembayaran', 'POST /timo/cek_transfer', 'POST /timo/batal_pembayaran', 'POST /timo/confirm_pembayaran', 'POST /timo/history_bayar' ], 'laporan' => [ 'POST /timo/jenis_laporan', 'POST /timo/history_gangguan' ], 'wipay' => [ 'POST /timo/cek_wipay', 'POST /timo/buat_kode', 'POST /timo/cek_kode', 'POST /timo/reset_kode' ], 'other' => [ 'POST /timo/promo', 'POST /timo/riwayat_pasang', 'POST /timo/jadwal_catat_meter', 'POST /timo/request_order_baca_mandiri' ] ] ])); return $response->withHeader('Content-Type', 'application/json'); }); // Authentication routes $app->post('/timo/daftar', [$authController, 'daftar']); $app->post('/timo/login', [$authController, 'login']); $app->post('/timo/login_token', [$authController, 'loginToken']); $app->post('/timo/update_akun', [$authController, 'updateAkun']); $app->post('/timo/update_password', [$authController, 'updatePassword']); // SL Management routes $app->post('/timo/cek_sl', [$slController, 'cekSL']); $app->post('/timo/confirm_sl', [$slController, 'confirmSL']); $app->post('/timo/hapus_sl', [$slController, 'hapusSL']); // Tagihan routes $app->get('/timo/history/{sl}/{periode}', [$tagihanController, 'history']); $app->get('/timo/tagihan/{sl}', [$tagihanController, 'tagihan']); // Pembayaran routes $app->post('/timo/request_pembayaran', [$pembayaranController, 'requestPembayaran']); $app->post('/timo/cek_pembayaran', [$pembayaranController, 'cekPembayaran']); $app->post('/timo/cek_transfer', [$pembayaranController, 'cekTransfer']); $app->post('/timo/batal_pembayaran', [$pembayaranController, 'batalPembayaran']); $app->post('/timo/confirm_pembayaran', [$pembayaranController, 'confirmPembayaran']); $app->post('/timo/history_bayar', [$pembayaranController, 'historyBayar']); $app->post('/timo/cek_status_qris', [$pembayaranController, 'cekStatusQris']); // New: QRIS status check // Laporan routes $app->post('/timo/jenis_laporan', [$laporanController, 'jenisLaporan']); $app->post('/timo/history_gangguan', [$laporanController, 'historyGangguan']); // WIPAY routes $app->post('/timo/cek_wipay', [$wipayController, 'cekWipay']); $app->post('/timo/aktifkan_wipay', [$wipayController, 'aktifkanWipay']); // Other routes $app->post('/timo/promo', [$otherController, 'promo']); $app->post('/timo/riwayat_pasang', [$otherController, 'riwayatPasang']); $app->post('/timo/jadwal_catat_meter', [$otherController, 'jadwalCatatMeter']); $app->post('/timo/request_order_baca_mandiri', [$otherController, 'requestOrderBacaMandiri']); // Upload routes $app->post('/timo/upload_catat_meter', [$uploadController, 'uploadCatatMeter']); $app->post('/timo/upload_pp', [$uploadController, 'uploadPp']); $app->post('/timo/hapus_pp', [$uploadController, 'hapusPp']); $app->post('/timo/upload_gangguan', [$uploadController, 'uploadGangguan']); $app->post('/timo/upload_pasang_baru', [$uploadController, 'uploadPasangBaru']); $app->post('/timo/upload_bukti_transfer', [$uploadController, 'uploadBuktiTransfer']); $app->post('/timo/upload_baca_mandiri', [$uploadController, 'uploadBacaMandiri']); // Reset Password routes (menggunakan nama endpoint yang sama dengan API lama) // Note: buat_kode, cek_kode, reset_kode di API lama adalah untuk reset password // Untuk kode unik pembayaran, sudah otomatis di-generate saat request_pembayaran $app->post('/timo/buat_kode', [$resetPasswordController, 'buatKode']); $app->post('/timo/cek_kode', [$resetPasswordController, 'cekKode']); $app->post('/timo/reset_kode', [$resetPasswordController, 'resetKode']); // ============================================ // EXTERNAL API ROUTES // ============================================ // Initialize external API controllers $apiController = new \App\Controllers\ApiController(); $fastController = new \App\Controllers\FastController(); $siteController = new \App\Controllers\SiteController(); $apiKeyMiddleware = new \App\Middleware\ApiKeyMiddleware(); // API Routes (Public - no auth) $app->get('/api/mandiri/{tanggal}', [$apiController, 'mandiri']); // Fast Routes (with API Key auth) $app->get('/fast/test', [$fastController, 'test']); // No auth $app->post('/fast/check_bill', [$fastController, 'checkBill'])->add($apiKeyMiddleware); $app->post('/fast/process_payment', [$fastController, 'processPayment'])->add($apiKeyMiddleware); $app->get('/fast/process_payment_get', [$fastController, 'processPaymentGet'])->add($apiKeyMiddleware); $app->get('/fast/payment_status', [$fastController, 'paymentStatus'])->add($apiKeyMiddleware); $app->post('/fast/payment_status', [$fastController, 'paymentStatus'])->add($apiKeyMiddleware); $app->get('/fast/check_wipay_saldo', [$fastController, 'checkWipaySaldo'])->add($apiKeyMiddleware); $app->post('/fast/check_wipay_saldo', [$fastController, 'checkWipaySaldo'])->add($apiKeyMiddleware); $app->get('/fast/check_wipay_saldo_get', [$fastController, 'checkWipaySaldoGet'])->add($apiKeyMiddleware); $app->get('/fast/mandiri/{tanggal}', [$fastController, 'mandiri']); // Site Routes (Admin - no auth for now, bisa ditambahkan session auth jika diperlukan) $app->post('/site/verify_bri', [$siteController, 'verifyBri']); $app->post('/site/approve/{id_trx}', [$siteController, 'approve']); // Run app $app->run();