Completed
Push — master ( cddd98...c8ab6f )
by Oleksandr
14s queued 10s
created

TokenGenerator::generateToken()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Service\Braintree\Model\TokenGenerator;
9
10
use Braintree\ClientToken;
11
use Braintree\Configuration;
12
use SprykerEco\Service\Braintree\BraintreeConfig;
13
14
class TokenGenerator implements TokenGeneratorInterface
15
{
16
    /**
17
     * @var \SprykerEco\Service\Braintree\BraintreeConfig
18
     */
19
    protected $config;
20
21
    /**
22
     * @var string
23
     */
24
    protected static $clientToken;
25
26
    /**
27
     * @param \SprykerEco\Service\Braintree\BraintreeConfig $config
28
     */
29
    public function __construct(BraintreeConfig $config)
30
    {
31
        $this->config = $config;
32
    }
33
34
    /**
35
     * @return string
36
     */
37
    public function generateToken(): string
38
    {
39
        if (static::$clientToken) {
40
            return static::$clientToken;
41
        }
42
43
        $this->configure();
44
45
        static::$clientToken = ClientToken::generate();
46
47
        return static::$clientToken;
48
    }
49
50
    /**
51
     * @return void
52
     */
53
    protected function configure(): void
54
    {
55
        Configuration::environment($this->config->getEnvironment());
56
        Configuration::merchantId($this->config->getMerchantId());
57
        Configuration::publicKey($this->config->getPublicKey());
58
        Configuration::privateKey($this->config->getPrivateKey());
59
    }
60
}
61