1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FLAIRUK\GoodTillSystem; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Http; |
6
|
|
|
use Illuminate\Support\Facades\Config; |
7
|
|
|
use FLAIRUK\GoodTillSystem\RESTInterface; |
8
|
|
|
|
9
|
|
|
class Authorize extends API { |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Good Till Authentication |
13
|
|
|
* |
14
|
|
|
* @source https://apidoc.thegoodtill.com/#api-Authentication |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
const LOGIN = 'login'; |
18
|
|
|
const LOGOUT = 'logout'; |
19
|
|
|
const REFRESH = 'refresh_token'; |
20
|
|
|
|
21
|
|
|
const SUBDOMAIN = 'subdomain'; |
22
|
|
|
const USERNAME = 'username'; |
23
|
|
|
const PASSWORD = 'password'; |
24
|
|
|
|
25
|
|
|
const CONFIG_ROUTE = 'goodtill.routes.api'; |
26
|
|
|
const CONFIG_SUBDOMAIN = 'goodtill.authorize.subdomain'; |
27
|
|
|
const CONFIG_USERNAME = 'goodtill.authorize.username'; |
28
|
|
|
const CONFIG_PASSWORD = 'goodtill.authorize.password'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Good Till System: Authorize |
32
|
|
|
* |
33
|
|
|
* @return array |
34
|
|
|
* @source https://apidoc.thegoodtill.com/#api-Authentication-CreateToken |
35
|
|
|
*/ |
36
|
|
|
public static function authorize(): array { |
37
|
|
|
return self::authorizer(Config::get(self::CONFIG_ROUTE) . self::LOGIN); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Good Till System: Revoke |
42
|
|
|
* |
43
|
|
|
* @return array |
44
|
|
|
* @source https://apidoc.thegoodtill.com/#api-Authentication-InvalidateToken |
45
|
|
|
*/ |
46
|
|
|
public static function revoke(): array { |
47
|
|
|
return self::authorizer(Config::get(self::CONFIG_ROUTE) . self::LOGOUT); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Good Till System: Refresh |
52
|
|
|
* |
53
|
|
|
* @return array |
54
|
|
|
* @source https://apidoc.thegoodtill.com/#api-Authentication-RefreshToken |
55
|
|
|
*/ |
56
|
|
|
public static function refresh(): array { |
57
|
|
|
return self::authorizer(Config::get(self::CONFIG_ROUTE) . self::REFRESH); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Good Till System: Authorizer |
62
|
|
|
* |
63
|
|
|
* @param string $route |
64
|
|
|
* @return array |
65
|
|
|
*/ |
66
|
|
|
public static function authorizer(string $route): array { |
67
|
|
|
return Http::post($route, [ |
68
|
|
|
self::SUBDOMAIN => Config::get(self::CONFIG_SUBDOMAIN), |
69
|
|
|
self::USERNAME => Config::get(self::CONFIG_USERNAME), |
70
|
|
|
self::PASSWORD => Config::get(self::CONFIG_PASSWORD) |
71
|
|
|
])->json(); |
72
|
|
|
} |
73
|
|
|
} |