<?php
header('Content-Type: application/json');
date_default_timezone_set('Asia/Jakarta');
require_once('includes/load.php');
$refreshToken = $_GET['refresh_token'];
$shopId = $_GET['shop_id'];
$data = TiktokRefreshToken($refreshToken);
$refresh_token = $data['data']['refresh_token'];
$access_token = $data['data']['access_token'];
$expire_in = $data['data']['access_token_expire_in'];
$sql = "UPDATE shop SET refresh_token = ?, access_token = ?, expire_in = ? WHERE shop_id = ?";
$stmt = $db->prepare($sql);

// Bind parameters
$stmt->bind_param("ssis", $refresh_token, $access_token, $expire_in, $shopId);

if (!$stmt->execute()) {
  return [$access_token, $refresh_token, true];
}
