Issues (55)

Gateway/Command/AuthorizationCommand.php (6 issues)

Labels
Severity
1
<?php
2
3
namespace B2Binpay\Payment\Gateway\Command;
4
5
use Magento\Framework\UrlInterface;
0 ignored issues
show
The type Magento\Framework\UrlInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Magento\Payment\Gateway\CommandInterface;
0 ignored issues
show
The type Magento\Payment\Gateway\CommandInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Magento\Payment\Gateway\Command\CommandException;
0 ignored issues
show
The type Magento\Payment\Gateway\Command\CommandException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use B2Binpay\Payment\Gateway\Config\Config;
9
use B2Binpay\Payment\Model\Adapter\B2BinpayAdapterFactory;
10
use B2Binpay\Exception\B2BinpayException;
0 ignored issues
show
The type B2Binpay\Exception\B2BinpayException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Psr\Log\LoggerInterface;
0 ignored issues
show
The type Psr\Log\LoggerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
class AuthorizationCommand implements CommandInterface
14
{
15
    /**
16
     * @var Config
17
     */
18
    private $config;
19
20
    /**
21
     * @var UrlInterface
22
     */
23
    private $urlBuilder;
24
25
    /**
26
     * @var B2BinpayAdapterFactory
27
     */
28
    private $adapterFactory;
29
30
    /**
31
     * @var LoggerInterface
32
     */
33
    private $logger;
34
35
    /**
36
     * @param Config $config
37
     * @param UrlInterface $urlBuilder
38
     * @param B2BinpayAdapterFactory $adapterFactory
39
     * @param LoggerInterface $logger
40
     */
41
    public function __construct(
42
        Config $config,
43
        UrlInterface $urlBuilder,
44
        B2BinpayAdapterFactory $adapterFactory,
45
        LoggerInterface $logger
46
    ) {
47
        $this->config = $config;
48
        $this->urlBuilder = $urlBuilder;
49
        $this->adapterFactory = $adapterFactory;
50
        $this->logger = $logger;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function execute(array $commandSubject)
57
    {
58
        $storeAmount = $commandSubject['amount'];
59
        $paymentDO = $commandSubject['payment'];
60
61
        $payment = $paymentDO->getPayment();
62
        $order = $payment->getOrder();
63
        $storeId = $order->getStoreId();
64
        $walletId = $payment->getAdditionalInformation('wallet');
65
66
        if (empty($walletId)) {
67
            $this->logger->critical('Payment Error: empty Wallet id.');
68
69
            throw new CommandException(
70
                __('No currency provided.')
0 ignored issues
show
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

70
                /** @scrutinizer ignore-call */ 
71
                __('No currency provided.')
Loading history...
71
            );
72
        }
73
74
        $b2binpay = $this->adapterFactory->create($storeId);
75
76
        try {
77
            $wallet = $b2binpay->getWallet($walletId);
78
        } catch (B2BinpayException $e) {
79
            $this->logger->critical('Payment Error: ' . $e);
80
            throw new CommandException(__('Payment method error.'));
81
        }
82
83
        $amount = $b2binpay->convertCurrency(
84
            $storeAmount,
85
            $order->getBaseCurrencyCode(),
86
            $wallet->currency->alpha
87
        );
88
89
        $markup = $this->config->getValue('markup', $storeId);
90
91
        if (!empty($markup)) {
92
            $amount = $b2binpay->addMarkup(
93
                $amount,
94
                $wallet->currency->alpha,
95
                $markup
96
            );
97
        }
98
99
        try {
100
            $bill = $b2binpay->createBill(
101
                $wallet->id,
102
                $amount,
103
                $wallet->currency->alpha,
104
                $this->config->getValue('lifetime', $storeId),
105
                $order->getIncrementId(),
106
                $this->urlBuilder->getUrl($this->config::CALLBACK_URI)
107
            );
108
        } catch (B2BinpayException $e) {
109
            $this->logger->critical('Payment Error: ' . $e);
110
            throw new CommandException(__('Payment method error.'));
111
        }
112
113
        $payment->setAdditionalInformation('redirect_url', $bill->url)
114
            ->setTransactionId($bill->id)
115
            ->setIsTransactionClosed(false)
116
            ->setIsTransactionPending(true);
117
118
        $order->addStatusToHistory(
119
            $order->getStatus(),
120
            __('B2BinPay created new invoice for ') . $amount . $wallet->currency->alpha
121
        )->save();
122
    }
123
}
124