Completed
Pull Request — master (#21)
by Cesar
01:55
created

AdyenService::paymentCapture()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
30
     */
31
    private $merchantAccount;
32
33
    /**
34
     * @var $clientKey
35
     */
36
    private $clientKey;
37
38
    /**
39
     * @var $paypalId
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 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...
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
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...
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
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...
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
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...
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
Bug introduced by
The method getClient() 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...
149
        return $modification->capture($data);
150
    }
151
}
152