Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from Sevenlive/master
Browse files Browse the repository at this point in the history
Update API-URLs and change endpoint Logic with special thanks to @Sevenlive
  • Loading branch information
bluewalk authored Sep 9, 2021
2 parents a4758f9 + c597274 commit 7966d5e
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions src/LidlPlus/LidlPlus.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@

class LidlPlus
{
private $language;
private $country;
private $account_url = 'https://accounts.lidl.com/';
private $appgateway_url = 'https://appgateway.lidlplus.com/app/v19/';
private $appgateway_url = 'https://appgateway.lidlplus.com/';
private $token;
private $refresh_token;
private $token_file;

private static $ENDPOINT_TOKEN = 'connect/token';
private static $ENDPOINT_RECEIPTS = 'tickets/list/%s';
private static $ENDPOINT_RECEIPT = 'tickets/%s';
private static $ENDPOINT_STORE = 'stores/%s';

public function __construct(string $refresh_token, string $countryShort = "NL", string $language = "nl_NL", string $pathToTokenFile = null)
{
// Set country and language
$this->_setCountry($countryShort, $language);
public function __construct(string $refresh_token, string $countryShort = "NL", string $pathToTokenFile = null)
{
$this->country = strtoupper($countryShort);

// Get TokenFile if existent
$this->refresh_token = $refresh_token;
Expand Down Expand Up @@ -52,7 +47,7 @@ private function _request(string $endpoint, string $method = 'GET', $data = null
'App-Version: 999.99.9',
'Operating-System: iOS',
'App: com.lidl.eci.lidl.plus',
'Accept-Language: ' . $this->language
'Accept-Language: ' . $this->country
];
$query_params = '';

Expand All @@ -72,7 +67,7 @@ private function _request(string $endpoint, string $method = 'GET', $data = null
if ($data)
$query_params = '?' . http_build_query($data);

curl_setopt($ch, CURLOPT_URL, $this->_getAppGatewayUrl() . $endpoint . $query_params);
curl_setopt($ch, CURLOPT_URL, $endpoint . $query_params);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
Expand All @@ -94,19 +89,22 @@ private function _request(string $endpoint, string $method = 'GET', $data = null
return json_decode($result);
}

private function _setCountry(string $countryShort, string $language = null)
private function _getAppGatewayUrl(string $Type)
{
$this->country = strtoupper($countryShort);

if ($language == null)
$this->language = strtolower($this->country) . "_" . $this->country;
else
$this->language = $language;
}

private function _getAppGatewayUrl()
{
return $this->appgateway_url . "/" . $this->country . "/";
switch ($Type) {
case 'Receipts':
$Endpoint = 'tickets/api/v1/' . $this->country . '/list/%s';
break;

case 'Receipt':
$Endpoint = 'app/v24/' . $this->country . '/tickets/%s';
break;

default:
$Endpoint = 'stores/v2/' . $this->country . '/%s';
break;
}
return $this->appgateway_url . $Endpoint;
}

private function _request_auth()
Expand Down Expand Up @@ -157,19 +155,19 @@ public function GetReceipts(int $page = 1)
{
$this->_checkAuth();

return $this->_request(sprintf($this::$ENDPOINT_RECEIPTS, $page));
return $this->_request(sprintf($this->_getAppGatewayUrl("Receipts"), $page));
}

public function GetReceipt(string $id = '')
{
$this->_checkAuth();

return $this->_request(sprintf($this::$ENDPOINT_RECEIPT, $id));
return $this->_request(sprintf($this->_getAppGatewayUrl("Receipt"), $id));
}

public function GetStore(string $store)
{
return $this->_request(sprintf($this::$ENDPOINT_STORE, $store));
return $this->_request(sprintf($this->_getAppGatewayUrl("Store"), $store));
}

public function GetReceiptJpeg(string $id = '')
Expand Down

0 comments on commit 7966d5e

Please sign in to comment.