Transaction::getTransaction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 2
dl 0
loc 14
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: igor
5
 * Date: 10/06/18
6
 * Time: 10:58
7
 */
8
9
namespace AdminWeb\PayerPagSeguro\Payment;
10
11
12
use AdminWeb\Payer\EnvInterface;
13
use GuzzleHttp\Client;
14
15
class Transaction
16
{
17
    /**
18
     * @var EnvInterface
19
     */
20
    private $env;
21
22
    /**
23
     * Notification constructor.
24
     * @param $env
25
     */
26
    public function __construct(EnvInterface $env)
27
    {
28
        $this->setEnv($env);
29
    }
30
31
    public function getTransaction($transactionCode, $isSimple = false)
32
    {
33
        $client = new Client([
34
            'base_uri' => $this->env->getUri(),
35
            //'http_errors' => false
36
        ]);
37
38
        $xml = $client->get("/v3/transactions/{$transactionCode}", ['query' => [
39
            'email' => $this->env->getCredential(),
40
            'token' => $this->env->getToken()
41
        ]])->getBody()->getContents();
42
        $doc = new \DOMDocument();
43
        $doc->loadXML($xml);
44
        return !$isSimple ? $doc : $xml;
45
    }
46
47
    /**
48
     * @return EnvInterface
49
     */
50
    public function getEnv()
51
    {
52
        return $this->env;
53
    }
54
55
    /**
56
     * @param EnvInterface $env
57
     * @return Transaction
58
     */
59
    public function setEnv(EnvInterface $env)
60
    {
61
        $this->env = $env;
62
        return $this;
63
    }
64
65
66
}