Completed
Push — master ( 60539d...725f3a )
by Dmitry
07:23
created

PurchaseRequest::getFormAction()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 2
nop 0
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
    public $disableReason;
34
35
    /** @var RedirectPurchaseResponse */
36
    public $form;
37
38
    public function setForm(RedirectPurchaseResponse $response)
39
    {
40
        $this->form = $response;
41
    }
42
43
    public function getFormInputs()
44
    {
45
        if (!isset($this->form)) {
46
            return [];
47
        }
48
49
        return $this->form->getRedirectData();
50
    }
51
52
    public function getFormAction()
53
    {
54
        if (!isset($this->form) || empty($this->form->getRedirectUrl())) {
55
            throw new InvalidConfigException('Form action for purchase request is missing');
56
        }
57
58
        return $this->form->getRedirectUrl();
59
    }
60
61
    public function getFormMethod()
62
    {
63
        if (!isset($this->form)) {
64
            return 'POST';
65
        }
66
67
        return $this->form->getMethod();
68
    }
69
}
70