PurchaseResponse::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 8
ccs 4
cts 5
cp 0.8
crap 3.072
rs 10
1
<?php
2
3
namespace ByTIC\Payments\Stripe\Message;
4
5
use ByTIC\Omnipay\Common\Message\Traits\HasViewTrait;
6
use ByTIC\Payments\Stripe\Utility\Paths;
7
use Omnipay\Common\Message\AbstractResponse;
8
use Omnipay\Common\Message\RedirectResponseInterface;
9
use Omnipay\Common\Message\RequestInterface;
10
use Stripe\Checkout\Session;
11
12
/**
13
 * Class PurchaseResponse
14
 * @package ByTIC\Payments\Stripe\Message
15
 */
16
class PurchaseResponse extends AbstractResponse implements RedirectResponseInterface
17
{
18
    use HasViewTrait;
19
20
    /**
21
     * @var Session|null $session
22
     */
23
    private $session = null;
24
25
    /**
26
     * @inheritDoc
27
     */
28 1
    public function __construct(RequestInterface $request, $data)
29
    {
30 1
        parent::__construct($request, $data);
31
32 1
        if (isset($data['session']) && $data['session'] instanceof Session) {
33 1
            $this->setSession($data['session']);
34
        } else {
35
            throw new \InvalidArgumentException('A valid Session must be supplied');
36
        }
37 1
    }
38
39
    /**
40
     * @param Session $session
41
     */
42 1
    public function setSession(Session $session)
43
    {
44 1
        $this->session = $session;
45 1
    }
46
47 1
    public function getSessionID()
48
    {
49 1
        return $this->session ? $this->session->id : null;
50
    }
51
52
53 1
    protected function initViewVars()
54
    {
55 1
        $data = $this->getData();
56 1
        $data['session_id'] = $this->getSessionID();
57 1
        $data['session_id'] = $this->getSessionID();
58 1
        $this->getView()->with($data);
59 1
    }
60
61
    /**
62
     * @inheritDoc
63
     */
64 1
    protected function generateViewPath()
65
    {
66 1
        return Paths::viewsPath();
67
    }
68
69
    /**
70
     * @return string
71
     */
72 1
    protected function getViewFile()
73
    {
74 1
        return 'purchase';
75
    }
76
77
    public function isSuccessful()
78
    {
79
        return true;
80
    }
81
}
82