File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Codelayer \LaravelShopifyIntegration \Lib ;
4
4
5
+ use DateTime ;
5
6
use Exception ;
7
+ use Shopify \Auth \OAuth ;
6
8
use Shopify \Auth \Session ;
7
- use Shopify \Utils ;
9
+ use Shopify \Context ;
8
10
9
11
class ShopifySessionHandler
10
12
{
11
13
public function getSessionForShopOrThrow (string $ shop ): Session
12
14
{
13
- $ session = Utils:: loadOfflineSession ($ shop );
15
+ $ session = $ this -> loadOfflineSession ($ shop );
14
16
15
17
if ($ session === null ) {
16
18
throw new Exception (
@@ -20,4 +22,24 @@ public function getSessionForShopOrThrow(string $shop): Session
20
22
21
23
return $ session ;
22
24
}
25
+
26
+ public function sessionIsValid (Session $ session ): bool
27
+ {
28
+ return $ session ->getAccessToken () &&
29
+ (! $ session ->getExpires () || ($ session ->getExpires () > new DateTime ()));
30
+ }
31
+
32
+ private function loadOfflineSession (string $ shop , bool $ includeExpired = false ): ?Session
33
+ {
34
+ Context::throwIfUninitialized ();
35
+
36
+ $ sessionId = OAuth::getOfflineSessionId ($ shop );
37
+ $ session = Context::$ SESSION_STORAGE ->loadSession ($ sessionId );
38
+
39
+ if ($ session && ! $ includeExpired && ! $ this ->sessionIsValid ($ session )) {
40
+ return null ;
41
+ }
42
+
43
+ return $ session ;
44
+ }
23
45
}
You can’t perform that action at this time.
0 commit comments