WIP: ecommerce
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
// ?XDEBUG_SESSION_START=PHPSTORM
|
||||
//importApiloInvoices();
|
||||
//importInvoices();
|
||||
function importInvoices()
|
||||
{
|
||||
$apilo_config = loadApiloConfiguration();
|
||||
@@ -10,9 +10,8 @@ function importInvoices()
|
||||
$offset = intval($db->fetchByAssoc($dbRes)['last_id']);
|
||||
|
||||
$invoices = loadApiloInvoices($apilo_config['token'], $offset);
|
||||
|
||||
if (isset($invoices->error)) {
|
||||
if (refreshApiloToken($apilo_config['refresh_token'], $apilo_config['client_id'], $apilo_config['client_secret']) == true) {
|
||||
if (refreshApiloToken($apilo_config['refreshToken'], $apilo_config['clientId'], $apilo_config['clientSecret']) == true) {
|
||||
$apilo_config = loadApiloConfiguration();
|
||||
$invoices = loadApiloInvoices($apilo_config['token'], $offset);
|
||||
} else {
|
||||
@@ -72,41 +71,42 @@ function loadApiloInvoices($token, $offset)
|
||||
}
|
||||
function refreshApiloToken($refreshToken, $clientId, $clientSecret)
|
||||
{
|
||||
$url = "https://api.apilo.com/oauth/token";
|
||||
$url = "https://twinpol.apilo.com/rest/auth/token/";
|
||||
|
||||
$data = [
|
||||
'grant_type' => 'refresh_token',
|
||||
'refresh_token' => $refreshToken,
|
||||
'client_id' => $clientId,
|
||||
'client_secret' => $clientSecret
|
||||
'grantType' => 'refresh_token',
|
||||
'token' => $refreshToken,
|
||||
];
|
||||
|
||||
$headers = [
|
||||
'Content-Type: application/x-www-form-urlencoded',
|
||||
'Authorization: Basic ' . base64_encode($clientId . ':' . $clientSecret),
|
||||
'Content-Type: application/json',
|
||||
'Accept: application/json'
|
||||
];
|
||||
|
||||
$curl = curl_init($url);
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
$err = curl_error($curl);
|
||||
curl_close($curl);
|
||||
|
||||
brecho($response);
|
||||
brecho($httpCode);
|
||||
if ($httpCode !== 200) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$tokenData = json_decode($response, true);
|
||||
|
||||
if (isset($tokenData['access_token'])) {
|
||||
brecho($tokenData);
|
||||
if (isset($tokenData['accessToken'])) {
|
||||
global $db;
|
||||
$db->query("UPDATE config SET value='" . $tokenData['access_token'] . "' WHERE category='apilo' AND name='access_token'");
|
||||
|
||||
if (isset($tokenData['refresh_token'])) {
|
||||
$db->query("UPDATE config SET value='" . $tokenData['refresh_token'] . "' WHERE category='apilo' AND name='refresh_token'");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user