|
19 | 19 |
|
20 | 20 | use Magento\Checkout\Model\ConfigProviderInterface;
|
21 | 21 | use Magento\Checkout\Model\Session;
|
22 |
| -use Magento\Framework\App\Config\ScopeConfigInterface; |
23 | 22 | use Magento\Framework\App\Config\Storage\WriterInterface;
|
24 | 23 | use Magento\Framework\Exception\LocalizedException;
|
25 | 24 | use Magento\Framework\Exception\NoSuchEntityException;
|
|
33 | 32 | use MultiSafepay\ConnectCore\Util\JsonHandler;
|
34 | 33 | use MultiSafepay\Exception\ApiException;
|
35 | 34 | use MultiSafepay\Exception\InvalidApiKeyException;
|
| 35 | +use MultiSafepay\Exception\InvalidArgumentException; |
36 | 36 | use MultiSafepay\Sdk;
|
37 | 37 | use Psr\Http\Client\ClientExceptionInterface;
|
38 | 38 |
|
@@ -181,15 +181,18 @@ public function isPreselected(): bool
|
181 | 181 | */
|
182 | 182 | public function getSdk(?int $storeId = null): ?Sdk
|
183 | 183 | {
|
| 184 | + if ($storeId === null) { |
| 185 | + $storeId = $this->getStoreIdFromCheckoutSession(); |
| 186 | + } |
| 187 | + |
184 | 188 | try {
|
185 | 189 | return $this->sdkFactory->create($storeId);
|
186 | 190 | } catch (InvalidApiKeyException $invalidApiKeyException) {
|
187 | 191 | $this->logger->logInvalidApiKeyException($invalidApiKeyException);
|
188 | 192 |
|
189 | 193 | return null;
|
190 | 194 | } catch (ApiException $apiException) {
|
191 |
| - $orderId = $this->checkoutSession->getLastRealOrder()->getIncrementId(); |
192 |
| - $this->logger->logGetIssuersApiException($orderId, $apiException); |
| 195 | + $this->logger->logException($apiException); |
193 | 196 |
|
194 | 197 | return null;
|
195 | 198 | }
|
@@ -231,7 +234,7 @@ public function getTransactionType(): string
|
231 | 234 |
|
232 | 235 | return (string)$this->paymentConfig->getValue(
|
233 | 236 | 'transaction_type',
|
234 |
| - $this->checkoutSession->getQuote()->getStoreId() |
| 237 | + $this->getStoreIdFromCheckoutSession() |
235 | 238 | );
|
236 | 239 | }
|
237 | 240 |
|
@@ -292,4 +295,47 @@ public function getAccountData(int $storeId = null): array
|
292 | 295 |
|
293 | 296 | return $accountData;
|
294 | 297 | }
|
| 298 | + |
| 299 | + /** |
| 300 | + * @return array |
| 301 | + * @throws ClientExceptionInterface |
| 302 | + */ |
| 303 | + public function getIssuers(): array |
| 304 | + { |
| 305 | + $issuers = []; |
| 306 | + |
| 307 | + if ($multiSafepaySdk = $this->getSdk()) { |
| 308 | + try { |
| 309 | + $issuerListing = $multiSafepaySdk->getIssuerManager()->getIssuersByGatewayCode($this->getGatewayCode()); |
| 310 | + foreach ($issuerListing as $issuer) { |
| 311 | + $issuers[] = [ |
| 312 | + 'code' => $issuer->getCode(), |
| 313 | + 'description' => $issuer->getDescription(), |
| 314 | + ]; |
| 315 | + } |
| 316 | + } catch (InvalidArgumentException $invalidArgumentException) { |
| 317 | + $this->logger->logException($invalidArgumentException); |
| 318 | + return $issuers; |
| 319 | + } |
| 320 | + } |
| 321 | + |
| 322 | + return $issuers; |
| 323 | + } |
| 324 | + |
| 325 | + /** |
| 326 | + * Return the store ID from the Checkout Session |
| 327 | + * |
| 328 | + * @return int|null |
| 329 | + */ |
| 330 | + private function getStoreIdFromCheckoutSession(): ?int |
| 331 | + { |
| 332 | + try { |
| 333 | + $storeId = $this->checkoutSession->getQuote()->getStoreId(); |
| 334 | + } catch (LocalizedException $localizedException) { |
| 335 | + $this->logger->logException($localizedException); |
| 336 | + return null; |
| 337 | + } |
| 338 | + |
| 339 | + return $storeId; |
| 340 | + } |
295 | 341 | }
|
0 commit comments