Completed
Push — master ( 79428d...367fd6 )
by Cesar
27s queued 11s
created

AdyenService::getClientKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Service;
4
5
use Adyen\AdyenException;
6
use Adyen\Client;
7
use Adyen\Environment;
8
use Adyen\Service\Checkout;
9
use Psr\Log\LoggerInterface;
10
11
/**
12
 * Class AdyenService
13
 * @package App\Service
14
 */
15
class AdyenService
16
{
17
    /**
18
     * @var SettingsService
19
     */
20
    protected $settingsService;
21
22
    /**
23
     * @var LoggerInterface
24
     */
25
    protected $logger;
26
27
    /**
28
     * @var $merchantAccount
29
     */
30
    private $merchantAccount;
31
32
    /**
33
     * @var $clientKey
34
     */
35
    private $clientKey;
36
37
    /**
38
     * @var $paypalId
39
     */
40
    private $paypalId;
41
42
    /**
43
     * @var Client
44
     */
45
    protected $checkout;
46
47
    /**
48
     * AdyenService constructor.
49
     *
50
     * @param string $apiKey
51
     * @param string $merchantAccount
52
     * @param string $clientKey
53
     * @param string $paypalId
54
     * @param SettingsService $settingsService
55
     * @throws AdyenException
56
     */
57
    public function __construct(
58
        string $apiKey,
59
        string $merchantAccount,
60
        string $clientKey,
61
        string $paypalId,
62
        SettingsService $settingsService
63
    ) {
64
        $client = new Client();
65
        $client->setXApiKey($apiKey);
66
        $client->setEnvironment(Environment::TEST);
67
68
        $this->checkout = new Checkout($client);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Adyen\Service\Checkout($client) of type object<Adyen\Service\Checkout> is incompatible with the declared type object<Adyen\Client> of property $checkout.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
69
        $this->merchantAccount = $merchantAccount;
70
        $this->clientKey = $clientKey;
71
        $this->settingsService = $settingsService;
72
        $this->paypalId = $paypalId;
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    public function getClientKey(): string
79
    {
80
        return $this->clientKey;
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function getPayPalId(): string
87
    {
88
        return $this->paypalId;
89
    }
90
91
    /**
92
     * @return mixed
93
     * @throws AdyenException
94
     */
95
    public function getPaymentMethods()
96
    {
97
        $params = [
98
            "allowedPaymentMethods" => ["paypal","card"],
99
            "merchantAccount" => $this->merchantAccount,
100
            "countryCode" => $this->settingsService->getSetting('settings-customer-country'),
101
            "shopperLocale" => $this->settingsService->getSetting('settings-customer-locale'),
102
            "amount" => [
103
                "currency" => $this->settingsService->getSetting('settings-customer-currency'),
104
                "value" => 100 * $this->settingsService->getSetting('settings-item-price'),
105
            ],
106
            "channel" => "Web"
107
        ];
108
109
        return $this->checkout->paymentMethods($params);
0 ignored issues
show
Bug introduced by
The method paymentMethods() does not seem to exist on object<Adyen\Client>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
110
    }
111
112
    /**
113
     * @param $data
114
     * @return mixed
115
     * @throws AdyenException
116
     */
117
    public function makePayment($data)
118
    {
119
        $params = [
120
            "amount" => $data['amount'],
121
            "reference" => rand(1, 1000000),
122
            "paymentMethod" => $data['paymentMethod'],
123
            "merchantAccount" => $this->merchantAccount,
124
        ];
125
126
        return $this->checkout->payments($params);
0 ignored issues
show
Bug introduced by
The method payments() does not exist on Adyen\Client. Did you maybe mean setAdyenPaymentSource()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
127
    }
128
129
    /**
130
     * @param $data
131
     * @return mixed
132
     * @throws AdyenException
133
     */
134
    public function paymentDetails($data)
135
    {
136
        return $this->checkout->paymentsDetails($data);
0 ignored issues
show
Bug introduced by
The method paymentsDetails() does not seem to exist on object<Adyen\Client>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
137
    }
138
}
139