Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
676 lars 1
<?php
2
 
3
namespace Srmklive\PayPal\Services;
4
 
5
use Exception;
6
use Srmklive\PayPal\Traits\PayPalRequest as PayPalAPIRequest;
7
use Srmklive\PayPal\Traits\PayPalVerifyIPN;
8
 
9
class PayPal
10
{
11
    use PayPalAPIRequest;
12
    use PayPalVerifyIPN;
13
 
14
    /**
15
     * PayPal 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
        $this->options['headers'] = [
30
            'Accept'            => 'application/json',
31
            'Accept-Language'   => $this->locale,
32
        ];
33
    }
34
 
35
    /**
36
     * Set ExpressCheckout API endpoints & options.
37
     *
38
     * @param array $credentials
39
     */
40
    protected function setOptions(array $credentials): void
41
    {
42
        // Setting API Endpoints
43
        $this->config['api_url'] = 'https://api-m.paypal.com';
44
 
45
        $this->config['gateway_url'] = 'https://www.paypal.com';
46
        $this->config['ipn_url'] = 'https://ipnpb.paypal.com/cgi-bin/webscr';
47
 
48
        if ($this->mode === 'sandbox') {
49
            $this->config['api_url'] = 'https://api-m.sandbox.paypal.com';
50
 
51
            $this->config['gateway_url'] = 'https://www.sandbox.paypal.com';
52
            $this->config['ipn_url'] = 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr';
53
        }
54
 
55
        // Adding params outside sandbox / live array
56
        $this->config['payment_action'] = $credentials['payment_action'];
57
        $this->config['notify_url'] = $credentials['notify_url'];
58
        $this->config['locale'] = $credentials['locale'];
59
    }
60
}