Completed
Push — master ( b65164...009680 )
by Albert
08:03
created

LicenseChecker   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 11 2
A validLicense() 0 10 3
1
<?php
2
namespace Elimuswift\Core\Middleware;
3
4
use Closure;
5
6
class LicenseChecker
7
{
8
    /**
9
     * Handle an incoming request.
10
     *
11
     * @param  \Illuminate\Http\Request  $request
12
     * @param  \Closure  $next
13
     * @return mixed
14
     */
15
    public function handle($request, Closure $next, $licenseKey = null)
16
    {
17
        
18
    	if($this->validLicense($licenseKey)){
19
        	return $next($request);
20
    	}
21
    	else{
22
    		return response()->json(['UnAuthorized' => 'Invalid Purchase Key'],403);
23
    	}
24
25
    }
26
27
    /** 
28
     * Check if license key is valid
29
     *
30
     * @return boolean
31
     **/
32
    private function validLicense($licenseKey)
33
    {
34
35
        $purchase = app()->envatoapi->verifyPurchase($licenseKey );
36
        if ( is_array($purchase) and $purchase['status'] == 'success') {
37
            return true;
38
        }
39
        return false;
40
41
    }
42
}
43