Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 15
Notification
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 15
 __construct
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 8
 register
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 7
1<?php namespace Framework\PagSeguro;
2
3use PagSeguro\Configuration\Configure;
4use PagSeguro\Helpers\Xhr;
5use PagSeguro\Library;
6use PagSeguro\Services\Transactions\Notification as PagSeguroNotification;
7
8class Notification
9{
10    protected bool $logActive;
11    protected string $logNotificationPath;
12
13    public function __construct(Config $config)
14    {
15        Library::initialize();
16        Configure::setEnvironment($config->environment);
17        Configure::setAccountCredentials($config->email, $config->token);
18        Configure::setCharset($config->charset);
19        Configure::setLog($config->logActive, $config->logPath);
20        $this->logActive = $config->logActive;
21        $this->logNotificationPath = $config->logNotificationPath;
22    }
23
24    public function register()
25    {
26        if ( ! Xhr::hasPost()) {
27            throw new \InvalidArgumentException($_POST);
28        }
29        $response = PagSeguroNotification::check(
30            Configure::getAccountCredentials()
31        );
32        if ($this->logActive) {
33            \file_put_contents($this->logNotificationPath, \print_r($response, true));
34        }
35        return $response;
36    }
37}