Passed
Pull Request — master (#2330)
by
unknown
09:59
created

Webhook::__invoke()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 14
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 19
rs 9.4888
1
<?php
2
3
namespace App\Http\Controllers\Stripe;
4
use App\Models\Role;
0 ignored issues
show
Bug introduced by
The type App\Models\Role was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
5
use App\Http\Controllers\Controller;
6
use App\Models\User;
7
use Illuminate\Http\Request;
8
use Stripe;
9
10
class Webhook extends Controller
11
{
12
    /**
13
     * Handle the incoming request.
14
     *
15
     * @return \Illuminate\Http\Response
16
     */
17
    public function __invoke(Request $request)
18
    {
19
        Stripe\Stripe::setApiKey(\Config::get('services.stripe.secret'));
20
        $plans = Stripe\Plan::all();
21
        $data = request()->all();
22
        $user = User::where('stripe_id', $data['data']['object']['customer'])->first();
23
        if ($user) {
24
            $plan_nickname = $data['data']['object']['items']['data'][0]['plan']['nickname'];
25
            foreach ($plans as $plan) {
26
                if ($plan->nickname === $plan_nickname) {
27
                    $roles= Role::where('name', strtolower($plan->nickname))->first();
28
                    if ($roles) {
29
                        $user->role_id = $roles->id;
30
                        $user->save();
31
                    }
32
                }
33
            }
34
        } else {
35
            echo 'User not found!';
36
        }
37
    }
38
}
39