|
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
|
|
|
use Yii; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class PurchaseRequest |
|
19
|
|
|
* |
|
20
|
|
|
* @author Dmytro Naumenko <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class PurchaseRequest |
|
23
|
|
|
{ |
|
24
|
|
|
public $id; |
|
25
|
|
|
|
|
26
|
|
|
public $merchant_name; |
|
27
|
|
|
public $system; |
|
28
|
|
|
public $label; |
|
29
|
|
|
|
|
30
|
|
|
public $amount; |
|
31
|
|
|
public $fee; |
|
32
|
|
|
public $commission_fee; |
|
33
|
|
|
|
|
34
|
|
|
public $vat_rate; |
|
35
|
|
|
public $vat_sum; |
|
36
|
|
|
|
|
37
|
|
|
public $currency; |
|
38
|
|
|
public $disableReason; |
|
39
|
|
|
|
|
40
|
|
|
public $paymentMethod; |
|
41
|
|
|
|
|
42
|
|
|
/** @var RedirectPurchaseResponse */ |
|
43
|
|
|
public $form; |
|
44
|
|
|
|
|
45
|
|
|
public function setForm(RedirectPurchaseResponse $response) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->form = $response; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getFormInputs() |
|
51
|
|
|
{ |
|
52
|
|
|
if (!isset($this->form)) { |
|
53
|
|
|
return []; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
return $this->form->getRedirectData(); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function getFormAction() |
|
60
|
|
|
{ |
|
61
|
|
|
if (!isset($this->form) || empty($this->form->getRedirectUrl())) { |
|
62
|
|
|
throw new InvalidConfigException('Form action for purchase request is missing'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $this->form->getRedirectUrl(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function getFormMethod() |
|
69
|
|
|
{ |
|
70
|
|
|
if (!isset($this->form)) { |
|
71
|
|
|
return 'POST'; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $this->form->getMethod(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getPaymentMethodLabel(): ?string |
|
78
|
|
|
{ |
|
79
|
|
|
if ($this->system !== 'yandexmoney') { |
|
80
|
|
|
return null; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
if ($this->paymentMethod === null) { |
|
84
|
|
|
return null; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
if ($this->paymentMethod === 'AC') { |
|
88
|
|
|
return Yii::t('merchant', 'via bank card'); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
if ($this->paymentMethod === 'PC') { |
|
92
|
|
|
return Yii::t('merchant', 'via account balance'); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
return Yii::t('merchant', 'via phone'); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|