WebHookController   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 15
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 13 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: igor
5
 * Date: 10/06/18
6
 * Time: 10:06
7
 */
8
9
namespace AdminWeb\PayerPagSeguro\Http;
10
11
12
use AdminWeb\Payer\EnvInterface;
13
use AdminWeb\Payer\Subscription;
14
use AdminWeb\PayerPagSeguro\Payment\Transaction;
15
use Illuminate\Http\Request;
16
use Illuminate\Routing\Controller;
17
18
class WebHookController extends Controller
19
{
20
    public function handle(Request $request)
21
    {
22
        $env = app()->make(EnvInterface::class);
23
        $t = new Transaction($env);
24
        $response = $t->getTransaction($request->notificationCode);
25
        $reference = $response->getElementsByTagName('reference');
26
        $status = $response->getElementsByTagName('status');
27
        $referenceValue = $reference[0]->nodeValue;
28
        $statusValue = $status[0]->nodeValue;
29
        $sub = Subscription::where('reference_id', $referenceValue)->get()->first();
30
        $sub->status = makeState($statusValue);
31
        event(makeEvent($statusValue));
32
        $sub->save();
33
    }
34
}