Passed
Push — v2.0 ( ec0aca...350fec )
by Raza
02:16
created

PayPal::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0078

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 13
ccs 7
cts 8
cp 0.875
crap 2.0078
rs 10
1
<?php
2
3
namespace Srmklive\PayPal\Services;
4
5
use Exception;
6
use Srmklive\PayPal\Traits\PayPalRequest as PayPalAPIRequest;
7
8
class PayPal
9
{
10 1
    use PayPalAPIRequest;
11
12
    /**
13
     * PayPal constructor.
14
     *
15
     * @param string|array $config
16
     *
17
     * @throws Exception
18
     */
19 5
    public function __construct($config = '')
20
    {
21
        // Setting PayPal API Credentials
22 5
        if (is_array($config)) {
23
            $this->setConfig();
24
        }
25
26 5
        $this->httpBodyParam = 'form_params';
27
28 5
        $this->options = [];
29 5
        $this->options['headers'] = [
30 5
            'Accept'            => 'application/json',
31 5
            'Accept-Language'   => $this->locale,
32
        ];
33 5
    }
34
35
    /**
36
     * Set ExpressCheckout API endpoints & options.
37
     *
38
     * @param array $credentials
39
     *
40
     * @return void
41
     */
42
    protected function setOptions($credentials)
43
    {
44
        // Setting API Endpoints
45
        if ($this->mode === 'sandbox') {
46
            $this->config['api_url'] = 'https://api.sandbox.paypal.com';
47
48
            $this->config['gateway_url'] = 'https://www.sandbox.paypal.com';
49
            $this->config['ipn_url'] = 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr';
50
        } else {
51
            $this->config['api_url'] = 'https://api.paypal.com/';
52
53
            $this->config['gateway_url'] = 'https://www.paypal.com';
54
            $this->config['ipn_url'] = 'https://ipnpb.paypal.com/cgi-bin/webscr';
55
        }
56
57
        // Adding params outside sandbox / live array
58
        $this->config['payment_action'] = $credentials['payment_action'];
59
        $this->config['notify_url'] = $credentials['notify_url'];
60
        $this->config['locale'] = $credentials['locale'];
61
    }
62
}
63