<?php
function update_token(){
require("../mainconfig.php");
 
$check_token = mysqli_query($db, "SELECT * FROM akun_qris");
$cek_data = mysqli_fetch_assoc($check_token);
$nomor_hp = $cek_data['phone_number'];
$paswet = $cek_data['password'];

$url = "https://pos.indibizpay.id/api/v1/auth/login";

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
   "Content-Type: application/json",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$data = <<<DATA
{
  "phone_number": "$nomor_hp",
  "password": "$paswet",
  "fcm_token": null
}
DATA;
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$resp = curl_exec($curl);
curl_close($curl);

$tokennya = json_decode($resp, true)['data']['token'];
$updatedbnya = mysqli_query($db,"UPDATE akun_qris SET token = '$tokennya', waktu = '$date $time' WHERE password = '$paswet'");
$update_monitor = mysqli_query($db,"UPDATE monitor_cron SET status = 'Success', response = '$tokennya', tanggal = '$date $time' WHERE judul = 'update_token_qris'");
return $tokennya;
}

echo update_token();