Completed
Pull Request — master (#3)
by Dmitry
30:18 queued 26:17
created

PurchaseRequest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 48
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setForm() 0 4 1
A getFormInputs() 0 8 2
A getFormAction() 0 8 3
A getFormMethod() 0 8 2
1
<?php
2
/**
3
 * Yii2 extension for payment processing with Omnipay, Payum and more later.
4
 *
5
 * @link      https://github.com/hiqdev/yii2-merchant
6
 * @package   yii2-merchant
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\yii2\merchant\models;
12
13
use hiqdev\php\merchant\response\RedirectPurchaseResponse;
14
use yii\base\InvalidConfigException;
15
16
/**
17
 * Class PurchaseRequest
18
 *
19
 * @author Dmytro Naumenko <[email protected]>
20
 */
21
class PurchaseRequest
22
{
23
    public $id;
24
25
    public $merchant_name;
26
    public $system;
27
    public $label;
28
29
    public $amount;
30
    public $fee;
31
    public $commission_fee;
32
    public $currency;
33
34
    /** @var RedirectPurchaseResponse */
35
    public $form;
36
37
    public function setForm(RedirectPurchaseResponse $response)
38
    {
39
        $this->form = $response;
40
    }
41
42
    public function getFormInputs()
43
    {
44
        if (!isset($this->form)) {
45
            return [];
46
        }
47
48
        return $this->form->getRedirectData();
49
    }
50
51
    public function getFormAction()
52
    {
53
        if (!isset($this->form) || empty($this->form->getRedirectUrl())) {
54
            throw new InvalidConfigException('Form action for purchase request is missing');
55
        }
56
57
        return $this->form->getRedirectUrl();
58
    }
59
60
    public function getFormMethod()
61
    {
62
        if (!isset($this->form)) {
63
            return 'POST';
64
        }
65
66
        return $this->form->getMethod();
67
    }
68
}
69