Completed
Push — v2 ( 1a5c3b...ed0a80 )
by Raza
05:30
created

PayPal   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 49
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A setOptions() 0 20 2
1
<?php
2
3
namespace Srmklive\PayPal\Services;
4
5
use Exception;
6
use Illuminate\Support\Collection;
7
use Psr\Http\Message\StreamInterface;
8
use Srmklive\PayPal\Traits\PayPalRequest as PayPalAPIRequest;
9
10
class PayPal
11
{
12
    use PayPalAPIRequest;
13
14
    /**
15
     * ExpressCheckout constructor.
16
     *
17
     * @param array $config
18
     *
19
     * @throws Exception
20
     */
21
    public function __construct(array $config = [])
22
    {
23
        // Setting PayPal API Credentials
24
        $this->setConfig($config);
25
26
        $this->httpBodyParam = 'form_params';
27
28
        $this->options = [];
29
    }
30
31
    /**
32
     * Set ExpressCheckout API endpoints & options.
33
     *
34
     * @param array $credentials
35
     *
36
     * @return void
37
     */
38
    public function setOptions($credentials)
39
    {
40
        // Setting API Endpoints
41
        if ($this->mode === 'sandbox') {
42
            $this->config['api_url'] = 'https://api.sandbox.paypal.com';
43
44
            $this->config['gateway_url'] = 'https://www.sandbox.paypal.com';
45
            $this->config['ipn_url'] = 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr';
46
        } else {
47
            $this->config['api_url'] = 'https://api.paypal.com/';
48
49
            $this->config['gateway_url'] = 'https://www.paypal.com';
50
            $this->config['ipn_url'] = 'https://ipnpb.paypal.com/cgi-bin/webscr';
51
        }
52
53
        // Adding params outside sandbox / live array
54
        $this->config['payment_action'] = $credentials['payment_action'];
55
        $this->config['notify_url'] = $credentials['notify_url'];
56
        $this->config['locale'] = $credentials['locale'];
57
    }
58
}
59