Passed
Push — dev ( 6076ca...bd4ba6 )
by Jan
05:12
created

Info::getPaymentStatus()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 9
c 0
b 0
f 0
nc 4
nop 1
dl 0
loc 13
rs 9.9666
1
<?php
2
/**
3
 * Copyright © 2016 Magento. All rights reserved.
4
 * See COPYING.txt for license details.
5
 */
6
namespace Getloy\GetloyMagentoGateway\Block;
7
8
use Magento\Framework\Phrase;
9
use Magento\Payment\Block\ConfigurableInfo;
10
11
class Info extends ConfigurableInfo
12
{
13
14
    /**
15
     * @var string
16
     */
17
    protected $_template = 'Getloy_GetloyMagentoGateway::info.phtml';
18
19
    /**
20
     * Returns label
21
     *
22
     * @param string $field
23
     *
24
     * @return Phrase
25
     */
26
    protected function getLabel($field)
27
    {
28
        return __($field);
29
    }
30
31
    /**
32
     * @param \Magento\Sales\Model\Order\Payment $payment
33
     * @return string
34
     */
35
    protected function getPaymentStatus(
36
        \Magento\Sales\Model\Order\Payment $payment
37
    ) {
38
        $info = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $info is dead and can be removed.
Loading history...
39
40
        if ((float) $payment->getAmountRefunded() > 0) {
41
            return __('Refunded');
42
        } else if ((float) $this->getAmountCanceled() > 0) {
0 ignored issues
show
Bug introduced by
The method getAmountCanceled() does not exist on Getloy\GetloyMagentoGateway\Block\Info. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
        } else if ((float) $this->/** @scrutinizer ignore-call */ getAmountCanceled() > 0) {
Loading history...
43
            return __('Cancelled');
44
        } else if ((float) $payment->getAmountPaid() === (float) $payment->getAmountOrdered()) {
45
            return __('Fully paid');
46
        } else {
47
            return __('Unpaid');
48
        }
49
    }
50
51
    /**
52
     * Prepare Getloy-specific payment information
53
     *
54
     * @param \Magento\Framework\DataObject|array|null $transport
55
     * @return \Magento\Framework\DataObject
56
     */
57
    protected function _prepareSpecificInformation($transport = null)
58
    {
59
        $transport = parent::_prepareSpecificInformation($transport);
60
        $payment = $this->getInfo();
61
        $info = [
62
            (string)__('Status') => $this->getPaymentStatus($payment),
63
        ];
64
65
        $additionalInfo = $payment->getAdditionalInformation();
66
        if (array_key_exists('getloy_transaction_id', $additionalInfo)) {
67
            $info[(string)__('Transaction ID')] = $additionalInfo[
68
                'getloy_transaction_id'
69
            ];
70
        }
71
72
        $this->getPaymentInfo($payment);
0 ignored issues
show
Bug introduced by
The method getPaymentInfo() does not exist on Getloy\GetloyMagentoGateway\Block\Info. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

72
        $this->/** @scrutinizer ignore-call */ 
73
               getPaymentInfo($payment);
Loading history...
73
74
        return $transport->addData($info);
75
    }
76
77
    /**
78
     * @return string
79
     */
80
    public function getTitle()
81
    {
82
        $additionalInfo = $this->getInfo()->getAdditionalInformation();
83
84
        if (array_key_exists('getloy_payment_method', $additionalInfo)) {
85
            return __('Paid with %1', $additionalInfo['getloy_payment_method']);
86
        }
87
    }
88
}
89