Completed
Pull Request — master (#4)
by Cesar
02:11 queued 45s
created

AbstractPaypalService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 4
1
<?php
2
3
namespace App\Service\Paypal;
4
5
use App\Service\SessionService;
6
use PayPal\Auth\OAuthTokenCredential;
7
use PayPal\Rest\ApiContext;
8
use Psr\Log\LoggerInterface;
9
10
/**
11
 * Class AbstractPaypalService
12
 * @package App\Service\Paypal
13
 */
14
abstract class AbstractPaypalService
15
{
16
    /**
17
     * @var string
18
     */
19
    protected $clientId;
20
21
    /**
22
     * @var string
23
     */
24
    protected $clientSecret;
25
26
    /**
27
     * @var ApiContext
28
     */
29
    protected $apiContext;
30
31
    /**
32
     * @var LoggerInterface
33
     */
34
    protected $logger;
35
36
    /**
37
     * PaypalService constructor.
38
     * @param string $clientId
39
     * @param string $clientSecret
40
     * @param LoggerInterface $logger
41
     * @param SessionService $sessionService
42
     */
43
    public function __construct(
44
        string $clientId,
45
        string $clientSecret,
46
        LoggerInterface $logger,
47
        SessionService $sessionService
48
    ) {
49
        $sessionClientId = $sessionService->session->get('PAYPAL_SDK_CLIENT_ID');
50
        $sessionClientSecret = $sessionService->session->get('PAYPAL_SDK_CLIENT_SECRET');
51
        $this->clientId = $sessionClientId ?? $clientId;
52
        $this->clientSecret = $sessionClientSecret ?? $clientSecret;
53
        $this->logger = $logger;
54
        $apiContext = new ApiContext(new OAuthTokenCredential($this->clientId, $this->clientSecret));
55
        $apiContext->setConfig(['mode' => 'sandbox']);
56
        $this->apiContext = $apiContext;
57
    }
58
}
59