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

PayPal   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 42.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 53
ccs 9
cts 21
cp 0.4286
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 2
A setOptions() 0 19 2
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