Completed
Push — master ( 4f1c26...2e5cbd )
by Dmitry
28:06
created

PayButton::renderButtonComment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
crap 2
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