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

PurchaseRequest::setForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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