Issues (38)

src/Service/AdyenService.php (8 issues)

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 Adyen\Service\Modification;
10
use Psr\Log\LoggerInterface;
11
12
/**
13
 * Class AdyenService
14
 * @package App\Service
15
 */
16
class AdyenService
17
{
18
    /**
19
     * @var SettingsService
20
     */
21
    protected $settingsService;
22
23
    /**
24
     * @var LoggerInterface
25
     */
26
    protected $logger;
27
28
    /**
29
     * @var $merchantAccount
0 ignored issues
show
Documentation Bug introduced by
The doc comment $merchantAccount at position 0 could not be parsed: Unknown type name '$merchantAccount' at position 0 in $merchantAccount.
Loading history...
30
     */
31
    private $merchantAccount;
32
33
    /**
34
     * @var $clientKey
0 ignored issues
show
Documentation Bug introduced by
The doc comment $clientKey at position 0 could not be parsed: Unknown type name '$clientKey' at position 0 in $clientKey.
Loading history...
35
     */
36
    private $clientKey;
37
38
    /**
39
     * @var $paypalId
0 ignored issues
show
Documentation Bug introduced by
The doc comment $paypalId at position 0 could not be parsed: Unknown type name '$paypalId' at position 0 in $paypalId.
Loading history...
40
     */
41
    private $paypalId;
42
43
    /**
44
     * @var Client
45
     */
46
    protected $checkout;
47
48
    /**
49
     * AdyenService constructor.
50
     *
51
     * @param string $apiKey
52
     * @param string $merchantAccount
53
     * @param string $clientKey
54
     * @param string $paypalId
55
     * @param SettingsService $settingsService
56
     * @throws AdyenException
57
     */
58
    public function __construct(
59
        string $apiKey,
60
        string $merchantAccount,
61
        string $clientKey,
62
        string $paypalId,
63
        SettingsService $settingsService
64
    ) {
65
        $client = new Client();
66
        $client->setXApiKey($apiKey);
67
        $client->setEnvironment(Environment::TEST);
68
69
        $this->checkout = new Checkout($client);
0 ignored issues
show
Documentation Bug introduced by
It seems like new Adyen\Service\Checkout($client) of type Adyen\Service\Checkout is incompatible with the declared type 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...
70
        $this->merchantAccount = $merchantAccount;
71
        $this->clientKey = $clientKey;
72
        $this->settingsService = $settingsService;
73
        $this->paypalId = $paypalId;
74
    }
75
76
    /**
77
     * @return string
78
     */
79
    public function getClientKey(): string
80
    {
81
        return $this->clientKey;
82
    }
83
84
    /**
85
     * @return string
86
     */
87
    public function getPayPalId(): string
88
    {
89
        return $this->paypalId;
90
    }
91
92
    /**
93
     * @return mixed
94
     * @throws AdyenException
95
     */
96
    public function getPaymentMethods()
97
    {
98
        $params = [
99
            "allowedPaymentMethods" => ["paypal","card"],
100
            "merchantAccount" => $this->merchantAccount,
101
            "countryCode" => $this->settingsService->getSetting('settings-customer-country'),
102
            "shopperLocale" => $this->settingsService->getSetting('settings-customer-locale'),
103
            "amount" => [
104
                "currency" => $this->settingsService->getSetting('settings-customer-currency'),
105
                "value" => 100 * $this->settingsService->getSetting('settings-item-price'),
106
            ],
107
            "channel" => "Web"
108
        ];
109
110
        return $this->checkout->paymentMethods($params);
0 ignored issues
show
The method paymentMethods() does not exist on Adyen\Client. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

110
        return $this->checkout->/** @scrutinizer ignore-call */ paymentMethods($params);

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...
111
    }
112
113
    /**
114
     * @param $data
115
     * @return mixed
116
     * @throws AdyenException
117
     */
118
    public function makePayment($data)
119
    {
120
        $params = [
121
            "amount" => $data['amount'],
122
            "reference" => rand(1, 1000000),
123
            "paymentMethod" => $data['paymentMethod'],
124
            "merchantAccount" => $this->merchantAccount,
125
        ];
126
127
        return $this->checkout->payments($params);
0 ignored issues
show
The method payments() does not exist on Adyen\Client. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

127
        return $this->checkout->/** @scrutinizer ignore-call */ payments($params);

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...
128
    }
129
130
    /**
131
     * @param $data
132
     * @return mixed
133
     * @throws AdyenException
134
     */
135
    public function paymentDetails($data)
136
    {
137
        return $this->checkout->paymentsDetails($data);
0 ignored issues
show
The method paymentsDetails() does not exist on Adyen\Client. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

137
        return $this->checkout->/** @scrutinizer ignore-call */ paymentsDetails($data);

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...
138
    }
139
140
    /**
141
     * @param $data
142
     * @return mixed
143
     * @throws AdyenException
144
     */
145
    public function paymentCapture($data)
146
    {
147
        $data['merchantAccount'] = $this->merchantAccount;
148
        $modification = new Modification($this->checkout->getClient());
0 ignored issues
show
The method getClient() does not exist on Adyen\Client. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

148
        $modification = new Modification($this->checkout->/** @scrutinizer ignore-call */ getClient());

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...
149
        return $modification->capture($data);
150
    }
151
}
152