1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Yii2 extension for payment processing with Omnipay, Payum and more later |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/hiqdev/yii2-merchant |
7
|
|
|
* @package yii2-merchant |
8
|
|
|
* @license BSD-3-Clause |
9
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace hiqdev\yii2\merchant\widgets; |
13
|
|
|
|
14
|
|
|
use hiqdev\paymenticons\yii2\PaymentIconsAsset; |
15
|
|
|
use hiqdev\php\merchant\AbstractRequest; |
16
|
|
|
use Yii; |
17
|
|
|
use yii\base\Event; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class PayButton. |
21
|
|
|
*/ |
22
|
|
|
class PayButton extends \yii\base\Widget |
23
|
|
|
{ |
24
|
|
|
const EVENT_RENDER_COMMENT = 'renderComment'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var AbstractRequest |
28
|
|
|
*/ |
29
|
|
|
public $request; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var array|string the URL for action |
33
|
|
|
*/ |
34
|
|
|
public $action = ['/merchant/pay/request']; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
|
|
public function init() |
40
|
|
|
{ |
41
|
|
|
parent::init(); |
42
|
|
|
PaymentIconsAsset::register(Yii::$app->getView()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
public function run() |
49
|
|
|
{ |
50
|
|
|
parent::run(); |
51
|
|
|
echo $this->renderButton(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Renders the payment button. |
56
|
|
|
* |
57
|
|
|
* @return string |
58
|
|
|
*/ |
59
|
|
|
public function renderButton() |
60
|
|
|
{ |
61
|
|
|
return $this->render('pay-button', [ |
62
|
|
|
'widget' => $this, |
63
|
|
|
'request' => $this->request, |
64
|
|
|
]); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Extracts merchant name from the [[request]] |
69
|
|
|
* @return string |
70
|
|
|
*/ |
71
|
|
|
public function getMerchantName() |
72
|
|
|
{ |
73
|
|
|
return $this->request->merchant->id; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Renders the button comment. Normally triggers [[EVENT_RENDER_COMMENT]] event |
78
|
|
|
*/ |
79
|
|
|
public function renderButtonComment() |
80
|
|
|
{ |
81
|
|
|
$event = new Event(); |
82
|
|
|
$event->sender = $this; |
83
|
|
|
$event->name = self::EVENT_RENDER_COMMENT; |
84
|
|
|
|
85
|
|
|
Event::trigger(self::class, self::EVENT_RENDER_COMMENT, $event); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function formatMoney($sum) |
89
|
|
|
{ |
90
|
|
|
return Yii::$app->formatter->format($sum, ['currency', $this->request->getCurrency()]); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|