ConfigBoleto::getExpiration()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 10
rs 10
1
<?php
2
/**
3
 * Copyright © Getnet. All rights reserved.
4
 *
5
 * @author    Bruno Elisei <[email protected]>
6
 * See LICENSE for license details.
7
 */
8
declare(strict_types=1);
9
10
namespace Getnet\PaymentMagento\Gateway\Config;
11
12
use Magento\Framework\App\Config\ScopeConfigInterface;
13
use Magento\Framework\Stdlib\DateTime\DateTime;
14
use Magento\Payment\Gateway\Config\Config as PaymentConfig;
15
use Magento\Store\Model\ScopeInterface;
16
17
/**
18
 * Class ConfigBoleto - Returns form of payment configuration properties.
19
 */
20
class ConfigBoleto extends PaymentConfig
21
{
22
    /**
23
     * @const string
24
     */
25
    public const METHOD = 'getnet_paymentmagento_boleto';
26
27
    /**
28
     * @const string
29
     */
30
    public const ACTIVE = 'active';
31
32
    /**
33
     * @const string
34
     */
35
    public const TITLE = 'title';
36
37
    /**
38
     * @const string
39
     */
40
    public const INSTRUCTION_CHECKOUT = 'instruction_checkout';
41
42
    /**
43
     * @const string
44
     */
45
    public const EXPIRATION = 'expiration';
46
47
    /**
48
     * @const string
49
     */
50
    public const INSTRUCTION_LINE = 'instruction_line';
51
52
    /**
53
     * @const string
54
     */
55
    public const USE_GET_TAX_DOCUMENT = 'get_tax_document';
56
57
    /**
58
     * @const string
59
     */
60
    public const USE_GET_NAME = 'get_name';
61
62
    /**
63
     * @var ScopeConfigInterface
64
     */
65
    protected $scopeConfig;
66
67
    /**
68
     * @var DateTime
69
     */
70
    protected $date;
71
72
    /**
73
     * @var Config
74
     */
75
    protected $config;
76
77
    /**
78
     * @param ScopeConfigInterface $scopeConfig
79
     * @param DateTime             $date
80
     * @param Config               $config
81
     * @param string|null          $methodCode
82
     */
83
    public function __construct(
84
        ScopeConfigInterface $scopeConfig,
85
        DateTime $date,
86
        Config $config,
87
        $methodCode = null
88
    ) {
89
        parent::__construct($scopeConfig, $methodCode);
90
        $this->scopeConfig = $scopeConfig;
91
        $this->date = $date;
92
        $this->config = $config;
93
    }
94
95
    /**
96
     * Get Payment configuration status.
97
     *
98
     * @param int|null $storeId
99
     *
100
     * @return bool
101
     */
102
    public function isActive($storeId = null): bool
103
    {
104
        $pathPattern = 'payment/%s/%s';
105
106
        return (bool) $this->scopeConfig->getValue(
107
            sprintf($pathPattern, self::METHOD, self::ACTIVE),
108
            ScopeInterface::SCOPE_STORE,
109
            $storeId
110
        );
111
    }
112
113
    /**
114
     * Get title of payment.
115
     *
116
     * @param int|null $storeId
117
     *
118
     * @return string|null
119
     */
120
    public function getTitle($storeId = null): ?string
121
    {
122
        $pathPattern = 'payment/%s/%s';
123
124
        return $this->scopeConfig->getValue(
125
            sprintf($pathPattern, self::METHOD, self::TITLE),
126
            ScopeInterface::SCOPE_STORE,
127
            $storeId
128
        );
129
    }
130
131
    /**
132
     * Get Instruction - Checkoout.
133
     *
134
     * @param int|null $storeId
135
     *
136
     * @return string|null
137
     */
138
    public function getInstructionCheckout($storeId = null): ?string
139
    {
140
        $pathPattern = 'payment/%s/%s';
141
142
        return $this->scopeConfig->getValue(
143
            sprintf($pathPattern, self::METHOD, self::INSTRUCTION_CHECKOUT),
144
            ScopeInterface::SCOPE_STORE,
145
            $storeId
146
        );
147
    }
148
149
    /**
150
     * Get Expiration.
151
     *
152
     * @param int|null $storeId
153
     *
154
     * @return string
155
     */
156
    public function getExpiration($storeId = null): ?string
157
    {
158
        $pathPattern = 'payment/%s/%s';
159
        $due = $this->scopeConfig->getValue(
160
            sprintf($pathPattern, self::METHOD, self::EXPIRATION),
161
            ScopeInterface::SCOPE_STORE,
162
            $storeId
163
        );
164
165
        return $this->date->gmtDate('d/m/Y', strtotime("+{$due} days"));
166
    }
167
168
    /**
169
     * Get Expiration Formart.
170
     *
171
     * @param int|null $storeId
172
     *
173
     * @return string
174
     */
175
    public function getExpirationFormat($storeId = null): ?string
176
    {
177
        $pathPattern = 'payment/%s/%s';
178
        $due = $this->scopeConfig->getValue(
179
            sprintf($pathPattern, self::METHOD, self::EXPIRATION),
180
            ScopeInterface::SCOPE_STORE,
181
            $storeId
182
        );
183
184
        return $this->date->gmtDate('d/m/Y', strtotime("+{$due} days"));
185
    }
186
187
    /**
188
     * Get Instruction Line.
189
     *
190
     * @param int|null $storeId
191
     *
192
     * @return string|null
193
     */
194
    public function getInstructionLine($storeId = null): ?string
195
    {
196
        $pathPattern = 'payment/%s/%s';
197
198
        return $this->scopeConfig->getValue(
199
            sprintf($pathPattern, self::METHOD, self::INSTRUCTION_LINE),
200
            ScopeInterface::SCOPE_STORE,
201
            $storeId
202
        );
203
    }
204
205
    /**
206
     * Get if you use document capture on the form.
207
     *
208
     * @param int|null $storeId
209
     *
210
     * @return bool
211
     */
212
    public function hasUseTaxDocumentCapture($storeId = null): ?bool
213
    {
214
        $pathPattern = 'payment/%s/%s';
215
216
        return (bool) $this->scopeConfig->getValue(
217
            sprintf($pathPattern, self::METHOD, self::USE_GET_TAX_DOCUMENT),
218
            ScopeInterface::SCOPE_STORE,
219
            $storeId
220
        );
221
    }
222
223
    /**
224
     * Get if you use name capture on the form.
225
     *
226
     * @param int|null $storeId
227
     *
228
     * @return bool
229
     */
230
    public function hasUseNameCapture($storeId = null): ?bool
231
    {
232
        $pathPattern = 'payment/%s/%s';
233
234
        return (bool) $this->scopeConfig->getValue(
235
            sprintf($pathPattern, self::METHOD, self::USE_GET_NAME),
236
            ScopeInterface::SCOPE_STORE,
237
            $storeId
238
        );
239
    }
240
241
    /**
242
     * Get Formatted Link Boleto.
243
     *
244
     * @param string $linkRelative
245
     *
246
     * @return string
247
     */
248
    public function getFormattedLinkBoleto(string $linkRelative): string
249
    {
250
        $environmentMode = $this->config->getApiUrl();
251
252
        return $environmentMode.$linkRelative;
253
    }
254
}
255