Info::getPaymentStatus()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 4
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
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
        if ((float) $payment->getAmountRefunded() > 0) {
39
            return __('Refunded');
40
        } else if ((float) $payment->getAmountCanceled() > 0) {
41
            return __('Cancelled');
42
        } else if ((float) $payment->getAmountPaid() === (float) $payment->getAmountOrdered()) {
43
            return __('Fully paid');
44
        } else {
45
            return __('Unpaid');
46
        }
47
    }
48
49
    /**
50
     * Prepare Getloy-specific payment information
51
     *
52
     * @param  \Magento\Framework\DataObject|array|null $transport
53
     * @return \Magento\Framework\DataObject
54
     */
55
    protected function _prepareSpecificInformation($transport = null)
56
    {
57
        $transport = parent::_prepareSpecificInformation($transport);
58
        $payment = $this->getInfo();
59
        $info = [
60
            (string) __('Status') => $this->getPaymentStatus($payment),
61
        ];
62
63
        $additionalInfo = $payment->getAdditionalInformation();
64
        if (array_key_exists('getloy_transaction_id', $additionalInfo)) {
65
            $info[ (string) __('Transaction ID') ] = $additionalInfo[
66
                'getloy_transaction_id'
67
            ];
68
        }
69
70
        return $transport->addData($info);
71
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function getTitle()
77
    {
78
        $additionalInfo = $this->getInfo()->getAdditionalInformation();
79
80
        if (array_key_exists('getloy_payment_method', $additionalInfo)) {
81
            return __('Paid with %1', $additionalInfo[ 'getloy_payment_method' ]);
82
        }
83
    }
84
}
85