Passed
Pull Request — master (#20)
by
unknown
03:50
created

Index   A

Complexity

Total Complexity 30

Size/Duplication

Total Lines 423
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 238
dl 0
loc 423
rs 10
c 2
b 0
f 0
wmc 30

9 Methods

Rating   Name   Duplication   Size   Complexity  
A checkDbTable() 0 14 2
A insertRow() 0 9 1
A insertLog() 0 15 2
A getOrders() 0 13 2
A checkDbLogTable() 0 15 2
A getMetadata() 0 10 1
F execute() 0 202 16
A getTaxId() 0 8 3
A __construct() 0 23 1
1
<?php
2
3
namespace Pagantis\Pagantis\Controller\Payment;
4
5
use Magento\Framework\App\Action\Action;
6
use Magento\Framework\App\Action\Context;
7
use Magento\Quote\Model\QuoteRepository;
8
use Magento\Sales\Model\ResourceModel\Order\Collection as OrderCollection;
9
use Magento\Checkout\Model\Session;
10
use Pagantis\OrdersApiClient\Model\Order;
11
use Pagantis\Pagantis\Helper\Config;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Pagantis\Pagantis\Controller\Payment\Config. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
12
use Pagantis\Pagantis\Helper\ExtraConfig;
13
use Magento\Framework\App\ResourceConnection;
14
use Magento\Framework\App\ProductMetadataInterface;
15
use Magento\Framework\Module\ModuleList;
16
use Magento\Store\Api\Data\StoreInterface;
17
use Pagantis\OrdersApiClient\Model\Order\User\Address;
18
use Magento\Framework\DB\Ddl\Table;
19
use Pagantis\OrdersApiClient\Model\Order\User;
20
use Pagantis\OrdersApiClient\Model\Order\User\OrderHistory;
21
use Pagantis\OrdersApiClient\Model\Order\ShoppingCart\Details;
22
use Pagantis\OrdersApiClient\Model\Order\ShoppingCart;
23
use Pagantis\OrdersApiClient\Model\Order\ShoppingCart\Details\Product;
24
use Pagantis\OrdersApiClient\Model\Order\Metadata;
25
use Pagantis\OrdersApiClient\Model\Order\Configuration\Urls;
26
use Pagantis\OrdersApiClient\Model\Order\Configuration\Channel;
27
use Pagantis\OrdersApiClient\Model\Order\Configuration;
28
use Pagantis\OrdersApiClient\Client;
29
30
/**
31
 * Class Index
32
 * @package Pagantis\Pagantis\Controller\Payment
33
 */
34
class Index extends Action
35
{
36
    /** Orders tablename */
37
    const ORDERS_TABLE = 'cart_process';
38
39
    /** Concurrency tablename */
40
    const LOGS_TABLE = 'Pagantis_logs';
41
42
    /** @var Context $context */
43
    protected $context;
44
45
    /** @var QuoteRepository  $quoteRepository */
46
    protected $quoteRepository;
47
48
    /** @var OrderCollection $orderCollection */
49
    protected $orderCollection;
50
51
    /** @var Session $session */
52
    protected $session;
53
54
    /** @var mixed $config */
55
    protected $config;
56
57
    /** @var ResourceConnection $dbObject */
58
    protected $dbObject;
59
60
    /** @var ProductMetadataInterface $productMetadataInterface */
61
    protected $productMetadataInterface;
62
63
    /** @var ModuleList $moduleList */
64
    protected $moduleList;
65
66
    /** @var ExtraConfig $extraConfig */
67
    protected $extraConfig;
68
    
69
    /** @var StoreInterface $store */
70
    protected $store;
71
72
    /**
73
     * Index constructor.
74
     *
75
     * @param Context                  $context
76
     * @param QuoteRepository          $quoteRepository
77
     * @param OrderCollection          $orderCollection
78
     * @param Session                  $session
79
     * @param Config                   $config
80
     * @param ResourceConnection       $dbObject
81
     * @param ProductMetadataInterface $productMetadataInterface
82
     * @param ModuleList               $moduleList
83
     * @param ExtraConfig              $extraConfig
84
     * @param StoreInterface           $storeInterface
85
     */
86
    public function __construct(
87
        Context $context,
88
        QuoteRepository $quoteRepository,
89
        OrderCollection $orderCollection,
90
        Session $session,
91
        Config $config,
92
        ResourceConnection $dbObject,
93
        ProductMetadataInterface $productMetadataInterface,
94
        ModuleList $moduleList,
95
        ExtraConfig $extraConfig,
96
        StoreInterface $storeInterface
97
    ) {
98
        parent::__construct($context);
99
        $this->session = $session;
100
        $this->context = $context;
101
        $this->config = $config->getConfig();
102
        $this->quoteRepository = $quoteRepository;
103
        $this->orderCollection = $orderCollection;
104
        $this->dbObject = $dbObject;
105
        $this->moduleList = $moduleList;
106
        $this->productMetadataInterface = $productMetadataInterface;
107
        $this->extraConfig = $extraConfig->getExtraConfig();
0 ignored issues
show
Documentation Bug introduced by
It seems like $extraConfig->getExtraConfig() of type array or array is incompatible with the declared type Pagantis\Pagantis\Helper\ExtraConfig of property $extraConfig.

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...
108
        $this->store = $storeInterface;
109
    }
110
111
    /**
112
     * Main function
113
     *
114
     * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void
115
     * @throws \Zend_Db_Exception
116
     */
117
    public function execute()
118
    {
119
        try {
120
            $cancelUrl = $this->_url->getUrl('checkout', ['_fragment' => 'payment']);
121
            $quote = $this->session->getQuote();
122
            /** @var Order $order */
123
            $lastOrder = $this->session->getLastRealOrder();
0 ignored issues
show
Unused Code introduced by
The assignment to $lastOrder is dead and can be removed.
Loading history...
124
            $params = $this->getRequest()->getParams();
125
            $customer = $quote->getCustomer();
126
            $shippingAddress = $quote->getShippingAddress();
127
128
            if (isset($params['email']) && $params['email']!='') {
129
                $this->session->setEmail($params['email']); //Get guest email after refresh page
130
                $customer->setEmail($params['email']);
0 ignored issues
show
Bug introduced by
The method setEmail() does not exist on Magento\Framework\Api\ExtensibleDataInterface. It seems like you code against a sub-type of Magento\Framework\Api\ExtensibleDataInterface such as Magento\Sales\Api\Data\OrderAddressInterface or Magento\Sales\Model\Order\Shipment\Track or Magento\Store\Model\Website or Magento\CatalogInventory\Model\Stock\Status or Magento\Sales\Model\Order\Creditmemo\Item or Magento\Tax\Model\Sales\Quote\QuoteDetails or Magento\Catalog\Model\ProductLink\Link or Magento\Framework\Model\AbstractExtensibleModel or Magento\Quote\Api\Data\AddressInterface or Magento\Customer\Api\Data\CustomerInterface or Magento\CatalogRule\Model\Rule or Magento\Catalog\Model\Product or Magento\Quote\Model\AddressAdditionalData or Magento\Quote\Model\Cart\TotalsAdditionalData or Magento\Framework\View\E...t\DataProvider\Document or Magento\Checkout\Model\TotalsInformation or Magento\CatalogRule\Model\Data\Condition or Magento\Customer\Model\Data\Customer or Magento\Quote\Model\EstimateAddress or Magento\Catalog\Model\Category or Magento\Eav\Model\Entity...ibute\AbstractAttribute or Magento\Catalog\Model\ResourceModel\Eav\Attribute or Magento\Catalog\Model\Category\Attribute or Magento\Checkout\Model\ShippingInformation or Magento\Tax\Model\Calculation\Rule or Magento\Sales\Model\Order\Status\History or Magento\Store\Model\Group or Magento\Catalog\Model\Product\Option or Magento\Catalog\Model\Product\Gallery\Entry or Magento\Quote\Model\Quote\ProductOption or Magento\Tax\Model\Sales\Quote\ItemDetails or Magento\Tax\Model\TaxDetails\AppliedTax or Magento\Sales\Model\Order\Tax\Item or Magento\Bundle\Model\Option or Magento\Eav\Model\Entity\Attribute\Set or Magento\Quote\Model\Cart\Currency or Magento\Sales\Model\Order\Shipment\Comment or Magento\Catalog\Model\Product\Price\Cost or Magento\Quote\Model\Cart\Totals or Magento\Sales\Model\Order\Invoice\Item or Magento\Downloadable\Model\File\Content or Magento\Catalog\Model\ProductRender\PriceInfo or Magento\CatalogInventory\Model\Stock or Magento\Quote\Model\ShippingAssignment or Magento\Quote\Model\Quote\Payment or Magento\Checkout\Model\PaymentDetails or Magento\Catalog\Model\ProductRender\Image or Magento\Tax\Model\TaxClass\Key or Magento\Sales\Model\Order\Creditmemo\Comment or Magento\Sales\Model\Order\Payment or Magento\Sales\Model\Order\Payment\Transaction or Magento\GiftMessage\Model\Message or Magento\Sales\Model\Order\Shipment\Item or Magento\Catalog\Model\Product\Price\TierPrice or Magento\Catalog\Model\Product\Attribute\Type or Magento\Tax\Model\TaxDetails\ItemDetails or Magento\Store\Model\Store or Magento\Catalog\Model\CustomOptions\CustomOption or Magento\Catalog\Model\Pr...nder\FormattedPriceInfo or Magento\Catalog\Model\ProductRender or Magento\Sales\Model\Order or Magento\Catalog\Model\Product\Option\Type or Magento\Quote\Model\Quote or Magento\Tax\Model\Calculation\Rate or Magento\Catalog\Model\Product\TierPrice or Magento\Tax\Model\Sales\Order\Details or Magento\Framework\Api\Te...erator\ExtensibleSample or Magento\Sales\Model\Order\Invoice\Comment or Magento\Sales\Model\Order\ShippingAssignment or Magento\Msrp\Model\ProductRender\MsrpPriceInfo or Magento\Sales\Model\Order\Item or Magento\Sales\Model\Order\Creditmemo or Magento\Sales\Model\Order\Invoice or Magento\Quote\Model\Shipping or Magento\Catalog\Model\Product\Price\BasePrice or Magento\Downloadable\Model\Sample or Magento\Eav\Model\Entity\Attribute\Group or Magento\Tax\Model\Sales\Order\Tax or Magento\Quote\Model\Cart\TotalSegment or Magento\Downloadable\Model\Link or Magento\CatalogInventory\Model\Stock\Item or Magento\Catalog\Model\Pr...Price\PriceUpdateResult or Magento\Tax\Model\Calculation\Rate\Title or Magento\Sales\Model\Order\Shipment or Magento\Catalog\Model\Product\Price\SpecialPrice or Magento\Tax\Model\ClassModel or Magento\Bundle\Model\Link or Magento\Bundle\Model\BundleOption or Magento\Tax\Model\TaxDetails\AppliedTaxRate or Magento\Bundle\Model\Source\Option\Type or Magento\Sales\Model\Order\Shipping or Magento\Quote\Model\Quote\Item or Magento\SalesRule\Model\Coupon or Magento\Tax\Model\TaxDetails\TaxDetails or Magento\Sales\Model\Order\ShippingTotal or Magento\Catalog\Model\ProductOption or Magento\Catalog\Model\ProductRender\Button. ( Ignorable by Annotation )

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

130
                $customer->/** @scrutinizer ignore-call */ 
131
                           setEmail($params['email']);
Loading history...
131
                $quote->setCheckoutMethod('guest');
132
                $quote->getBillingAddress()->setEmail($params['email']);
133
            } elseif ($customer->getEmail()=='') {
0 ignored issues
show
Bug introduced by
The method getEmail() does not exist on Magento\Framework\Api\ExtensibleDataInterface. It seems like you code against a sub-type of Magento\Framework\Api\ExtensibleDataInterface such as Magento\Sales\Api\Data\OrderAddressInterface or Magento\Sales\Model\Order\Shipment\Track or Magento\Store\Model\Website or Magento\CatalogInventory\Model\Stock\Status or Magento\Sales\Model\Order\Creditmemo\Item or Magento\Tax\Model\Sales\Quote\QuoteDetails or Magento\Catalog\Model\ProductLink\Link or Magento\Framework\Model\AbstractExtensibleModel or Magento\Quote\Api\Data\AddressInterface or Magento\Customer\Api\Data\CustomerInterface or Magento\CatalogRule\Model\Rule or Magento\Catalog\Model\Product or Magento\Quote\Model\AddressAdditionalData or Magento\Quote\Model\Cart\TotalsAdditionalData or Magento\Framework\View\E...t\DataProvider\Document or Magento\Checkout\Model\TotalsInformation or Magento\CatalogRule\Model\Data\Condition or Magento\Customer\Model\Data\Customer or Magento\Quote\Model\EstimateAddress or Magento\Catalog\Model\Category or Magento\Eav\Model\Entity...ibute\AbstractAttribute or Magento\Catalog\Model\ResourceModel\Eav\Attribute or Magento\Catalog\Model\Category\Attribute or Magento\Checkout\Model\ShippingInformation or Magento\Tax\Model\Calculation\Rule or Magento\Sales\Model\Order\Status\History or Magento\Store\Model\Group or Magento\Catalog\Model\Product\Option or Magento\Catalog\Model\Product\Gallery\Entry or Magento\Quote\Model\Quote\ProductOption or Magento\Tax\Model\Sales\Quote\ItemDetails or Magento\Tax\Model\TaxDetails\AppliedTax or Magento\Sales\Model\Order\Tax\Item or Magento\Bundle\Model\Option or Magento\Eav\Model\Entity\Attribute\Set or Magento\Quote\Model\Cart\Currency or Magento\Sales\Model\Order\Shipment\Comment or Magento\Catalog\Model\Product\Price\Cost or Magento\Quote\Model\Cart\Totals or Magento\Sales\Model\Order\Invoice\Item or Magento\Downloadable\Model\File\Content or Magento\Catalog\Model\ProductRender\PriceInfo or Magento\CatalogInventory\Model\Stock or Magento\Quote\Model\ShippingAssignment or Magento\Quote\Model\Quote\Payment or Magento\Checkout\Model\PaymentDetails or Magento\Catalog\Model\ProductRender\Image or Magento\Tax\Model\TaxClass\Key or Magento\Sales\Model\Order\Creditmemo\Comment or Magento\Sales\Model\Order\Payment or Magento\Sales\Model\Order\Payment\Transaction or Magento\GiftMessage\Model\Message or Magento\Sales\Model\Order\Shipment\Item or Magento\Catalog\Model\Product\Price\TierPrice or Magento\Catalog\Model\Product\Attribute\Type or Magento\Tax\Model\TaxDetails\ItemDetails or Magento\Store\Model\Store or Magento\Catalog\Model\CustomOptions\CustomOption or Magento\Catalog\Model\Pr...nder\FormattedPriceInfo or Magento\Catalog\Model\ProductRender or Magento\Sales\Model\Order or Magento\Catalog\Model\Product\Option\Type or Magento\Quote\Model\Quote or Magento\Tax\Model\Calculation\Rate or Magento\Catalog\Model\Product\TierPrice or Magento\Tax\Model\Sales\Order\Details or Magento\Framework\Api\Te...erator\ExtensibleSample or Magento\Sales\Model\Order\Invoice\Comment or Magento\Sales\Model\Order\ShippingAssignment or Magento\Msrp\Model\ProductRender\MsrpPriceInfo or Magento\Sales\Model\Order\Item or Magento\Sales\Model\Order\Creditmemo or Magento\Sales\Model\Order\Invoice or Magento\Quote\Model\Shipping or Magento\Catalog\Model\Product\Price\BasePrice or Magento\Downloadable\Model\Sample or Magento\Eav\Model\Entity\Attribute\Group or Magento\Tax\Model\Sales\Order\Tax or Magento\Quote\Model\Cart\TotalSegment or Magento\Downloadable\Model\Link or Magento\CatalogInventory\Model\Stock\Item or Magento\Catalog\Model\Pr...Price\PriceUpdateResult or Magento\Tax\Model\Calculation\Rate\Title or Magento\Sales\Model\Order\Shipment or Magento\Catalog\Model\Product\Price\SpecialPrice or Magento\Tax\Model\ClassModel or Magento\Bundle\Model\Link or Magento\Bundle\Model\BundleOption or Magento\Tax\Model\TaxDetails\AppliedTaxRate or Magento\Bundle\Model\Source\Option\Type or Magento\Sales\Model\Order\Shipping or Magento\Quote\Model\Quote\Item or Magento\SalesRule\Model\Coupon or Magento\Tax\Model\TaxDetails\TaxDetails or Magento\Sales\Model\Order\ShippingTotal or Magento\Catalog\Model\ProductOption or Magento\Catalog\Model\ProductRender\Button. ( Ignorable by Annotation )

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

133
            } elseif ($customer->/** @scrutinizer ignore-call */ getEmail()=='') {
Loading history...
134
                $customer->setEmail($this->session->getEmail());
0 ignored issues
show
Bug introduced by
It seems like $this->session->getEmail() can also be of type Magento\Checkout\Model\Session; however, parameter $email of Magento\Customer\Api\Dat...erInterface::setEmail() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

134
                $customer->setEmail(/** @scrutinizer ignore-type */ $this->session->getEmail());
Loading history...
135
                $quote->setCheckoutMethod('guest');
136
                $quote->getBillingAddress()->setEmail($this->session->getEmail());
137
            }
138
139
            /** @var Quote $currentQuote */
140
            $currentQuote = $this->quoteRepository->get($quote->getId());
141
            $currentQuote->setCustomerEmail($customer->getEmail());
142
            $this->quoteRepository->save($currentQuote);
143
144
            $userAddress =  new Address();
145
            $userAddress
146
                ->setZipCode($shippingAddress->getPostcode())
147
                ->setFullName($shippingAddress->getFirstname()." ".$shippingAddress->getLastname())
148
                ->setCountryCode('ES')
149
                ->setCity($shippingAddress->getCity())
150
                ->setAddress($shippingAddress->getStreetFull())
151
            ;
152
153
            $tax_id = $this->getTaxId($quote->getBillingAddress());
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $tax_id is correct as $this->getTaxId($quote->getBillingAddress()) targeting Pagantis\Pagantis\Contro...yment\Index::getTaxId() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
154
            $orderShippingAddress = new Address();
155
            $orderShippingAddress
156
                ->setZipCode($shippingAddress->getPostcode())
157
                ->setFullName($shippingAddress->getFirstname()." ".$shippingAddress->getLastname())
158
                ->setCountryCode('ES')
159
                ->setCity($shippingAddress->getCity())
160
                ->setAddress($shippingAddress->getStreetFull())
161
                ->setFixPhone($shippingAddress->getTelephone())
162
                ->setMobilePhone($shippingAddress->getTelephone())
163
                ->setTaxId($tax_id)
164
            ;
165
166
            $orderBillingAddress =  new Address();
167
            $billingAddress = $quote->getBillingAddress();
168
            $orderBillingAddress
169
                ->setZipCode($billingAddress->getPostcode())
170
                ->setFullName($billingAddress->getFirstname()." ".$shippingAddress->getLastname())
171
                ->setCountryCode('ES')
172
                ->setCity($billingAddress->getCity())
173
                ->setAddress($billingAddress->getStreetFull())
174
                ->setFixPhone($billingAddress->getTelephone())
175
                ->setMobilePhone($billingAddress->getTelephone())
176
                ->setTaxId($tax_id)
177
            ;
178
179
            $orderUser = new User();
180
            $billingAddress->setEmail($customer->getEmail());
181
            $orderUser
182
                ->setAddress($userAddress)
183
                ->setFullName($shippingAddress->getFirstname()." ".$shippingAddress->getLastname())
184
                ->setBillingAddress($orderBillingAddress)
185
                ->setEmail($customer->getEmail())
186
                ->setFixPhone($shippingAddress->getTelephone())
187
                ->setMobilePhone($shippingAddress->getTelephone())
188
                ->setShippingAddress($orderShippingAddress)
189
                ->setTaxId($tax_id)
190
            ;
191
192
            if ($customer->getDob()) {
0 ignored issues
show
Bug introduced by
The method getDob() does not exist on Magento\Framework\Api\ExtensibleDataInterface. It seems like you code against a sub-type of Magento\Framework\Api\ExtensibleDataInterface such as Magento\Sales\Model\Order\Shipment\Track or Magento\Store\Model\Website or Magento\CatalogInventory\Model\Stock\Status or Magento\Sales\Model\Order\Creditmemo\Item or Magento\Tax\Model\Sales\Quote\QuoteDetails or Magento\Catalog\Model\ProductLink\Link or Magento\Framework\Model\AbstractExtensibleModel or Magento\Customer\Api\Data\CustomerInterface or Magento\CatalogRule\Model\Rule or Magento\Catalog\Model\Product or Magento\Quote\Model\AddressAdditionalData or Magento\Quote\Model\Quote\Address or Magento\Quote\Model\Cart\TotalsAdditionalData or Magento\Framework\View\E...t\DataProvider\Document or Magento\Checkout\Model\TotalsInformation or Magento\CatalogRule\Model\Data\Condition or Magento\Customer\Model\Data\Customer or Magento\Quote\Model\EstimateAddress or Magento\Catalog\Model\Category or Magento\Eav\Model\Entity...ibute\AbstractAttribute or Magento\Catalog\Model\ResourceModel\Eav\Attribute or Magento\Catalog\Model\Category\Attribute or Magento\Checkout\Model\ShippingInformation or Magento\Tax\Model\Calculation\Rule or Magento\Sales\Model\Order\Status\History or Magento\Store\Model\Group or Magento\Catalog\Model\Product\Option or Magento\Catalog\Model\Product\Gallery\Entry or Magento\Quote\Model\Quote\ProductOption or Magento\Tax\Model\Sales\Quote\ItemDetails or Magento\Tax\Model\TaxDetails\AppliedTax or Magento\Sales\Model\Order\Tax\Item or Magento\Bundle\Model\Option or Magento\Eav\Model\Entity\Attribute\Set or Magento\Quote\Model\Cart\Currency or Magento\Sales\Model\Order\Shipment\Comment or Magento\Catalog\Model\Product\Price\Cost or Magento\Quote\Model\Cart\Totals or Magento\Sales\Model\Order\Invoice\Item or Magento\Downloadable\Model\File\Content or Magento\Catalog\Model\ProductRender\PriceInfo or Magento\CatalogInventory\Model\Stock or Magento\Quote\Model\ShippingAssignment or Magento\Quote\Model\Quote\Payment or Magento\Checkout\Model\PaymentDetails or Magento\Catalog\Model\ProductRender\Image or Magento\Sales\Model\Order\Address or Magento\Tax\Model\TaxClass\Key or Magento\Sales\Model\Order\Creditmemo\Comment or Magento\Sales\Model\Order\Payment or Magento\Sales\Model\Order\Payment\Transaction or Magento\GiftMessage\Model\Message or Magento\Sales\Model\Order\Shipment\Item or Magento\Catalog\Model\Product\Price\TierPrice or Magento\Catalog\Model\Product\Attribute\Type or Magento\Tax\Model\TaxDetails\ItemDetails or Magento\Store\Model\Store or Magento\Catalog\Model\CustomOptions\CustomOption or Magento\Catalog\Model\Pr...nder\FormattedPriceInfo or Magento\Catalog\Model\ProductRender or Magento\Sales\Model\Order or Magento\Catalog\Model\Product\Option\Type or Magento\Quote\Model\Quote or Magento\Tax\Model\Calculation\Rate or Magento\Catalog\Model\Product\TierPrice or Magento\Tax\Model\Sales\Order\Details or Magento\Framework\Api\Te...erator\ExtensibleSample or Magento\Sales\Model\Order\Invoice\Comment or Magento\Sales\Model\Order\ShippingAssignment or Magento\Msrp\Model\ProductRender\MsrpPriceInfo or Magento\Sales\Model\Order\Item or Magento\Sales\Model\Order\Creditmemo or Magento\Sales\Model\Order\Invoice or Magento\Quote\Model\Shipping or Magento\Catalog\Model\Product\Price\BasePrice or Magento\Downloadable\Model\Sample or Magento\Eav\Model\Entity\Attribute\Group or Magento\Tax\Model\Sales\Order\Tax or Magento\Quote\Model\Cart\TotalSegment or Magento\Downloadable\Model\Link or Magento\CatalogInventory\Model\Stock\Item or Magento\Catalog\Model\Pr...Price\PriceUpdateResult or Magento\Tax\Model\Calculation\Rate\Title or Magento\Sales\Model\Order\Shipment or Magento\Catalog\Model\Product\Price\SpecialPrice or Magento\Tax\Model\ClassModel or Magento\Bundle\Model\Link or Magento\Bundle\Model\BundleOption or Magento\Tax\Model\TaxDetails\AppliedTaxRate or Magento\Bundle\Model\Source\Option\Type or Magento\Sales\Model\Order\Shipping or Magento\Quote\Model\Quote\Item or Magento\SalesRule\Model\Coupon or Magento\Tax\Model\TaxDetails\TaxDetails or Magento\Sales\Model\Order\ShippingTotal or Magento\Catalog\Model\ProductOption or Magento\Catalog\Model\ProductRender\Button. ( Ignorable by Annotation )

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

192
            if ($customer->/** @scrutinizer ignore-call */ getDob()) {
Loading history...
193
                $orderUser->setDateOfBirth($customer->getDob());
194
            }
195
            if ($customer->getTaxvat()!='') {
0 ignored issues
show
Bug introduced by
The method getTaxvat() does not exist on Magento\Framework\Api\ExtensibleDataInterface. It seems like you code against a sub-type of Magento\Framework\Api\ExtensibleDataInterface such as Magento\Sales\Model\Order\Shipment\Track or Magento\Store\Model\Website or Magento\CatalogInventory\Model\Stock\Status or Magento\Sales\Model\Order\Creditmemo\Item or Magento\Tax\Model\Sales\Quote\QuoteDetails or Magento\Catalog\Model\ProductLink\Link or Magento\Framework\Model\AbstractExtensibleModel or Magento\Customer\Api\Data\CustomerInterface or Magento\CatalogRule\Model\Rule or Magento\Catalog\Model\Product or Magento\Quote\Model\AddressAdditionalData or Magento\Quote\Model\Quote\Address or Magento\Quote\Model\Cart\TotalsAdditionalData or Magento\Framework\View\E...t\DataProvider\Document or Magento\Checkout\Model\TotalsInformation or Magento\CatalogRule\Model\Data\Condition or Magento\Customer\Model\Data\Customer or Magento\Quote\Model\EstimateAddress or Magento\Catalog\Model\Category or Magento\Eav\Model\Entity...ibute\AbstractAttribute or Magento\Catalog\Model\ResourceModel\Eav\Attribute or Magento\Catalog\Model\Category\Attribute or Magento\Checkout\Model\ShippingInformation or Magento\Tax\Model\Calculation\Rule or Magento\Sales\Model\Order\Status\History or Magento\Store\Model\Group or Magento\Catalog\Model\Product\Option or Magento\Catalog\Model\Product\Gallery\Entry or Magento\Quote\Model\Quote\ProductOption or Magento\Tax\Model\Sales\Quote\ItemDetails or Magento\Tax\Model\TaxDetails\AppliedTax or Magento\Sales\Model\Order\Tax\Item or Magento\Bundle\Model\Option or Magento\Eav\Model\Entity\Attribute\Set or Magento\Quote\Model\Cart\Currency or Magento\Sales\Model\Order\Shipment\Comment or Magento\Catalog\Model\Product\Price\Cost or Magento\Quote\Model\Cart\Totals or Magento\Sales\Model\Order\Invoice\Item or Magento\Downloadable\Model\File\Content or Magento\Catalog\Model\ProductRender\PriceInfo or Magento\CatalogInventory\Model\Stock or Magento\Quote\Model\ShippingAssignment or Magento\Quote\Model\Quote\Payment or Magento\Checkout\Model\PaymentDetails or Magento\Catalog\Model\ProductRender\Image or Magento\Sales\Model\Order\Address or Magento\Tax\Model\TaxClass\Key or Magento\Sales\Model\Order\Creditmemo\Comment or Magento\Sales\Model\Order\Payment or Magento\Sales\Model\Order\Payment\Transaction or Magento\GiftMessage\Model\Message or Magento\Sales\Model\Order\Shipment\Item or Magento\Catalog\Model\Product\Price\TierPrice or Magento\Catalog\Model\Product\Attribute\Type or Magento\Tax\Model\TaxDetails\ItemDetails or Magento\Store\Model\Store or Magento\Catalog\Model\CustomOptions\CustomOption or Magento\Catalog\Model\Pr...nder\FormattedPriceInfo or Magento\Catalog\Model\ProductRender or Magento\Sales\Model\Order or Magento\Catalog\Model\Product\Option\Type or Magento\Quote\Model\Quote or Magento\Tax\Model\Calculation\Rate or Magento\Catalog\Model\Product\TierPrice or Magento\Tax\Model\Sales\Order\Details or Magento\Framework\Api\Te...erator\ExtensibleSample or Magento\Sales\Model\Order\Invoice\Comment or Magento\Sales\Model\Order\ShippingAssignment or Magento\Msrp\Model\ProductRender\MsrpPriceInfo or Magento\Sales\Model\Order\Item or Magento\Sales\Model\Order\Creditmemo or Magento\Sales\Model\Order\Invoice or Magento\Quote\Model\Shipping or Magento\Catalog\Model\Product\Price\BasePrice or Magento\Downloadable\Model\Sample or Magento\Eav\Model\Entity\Attribute\Group or Magento\Tax\Model\Sales\Order\Tax or Magento\Quote\Model\Cart\TotalSegment or Magento\Downloadable\Model\Link or Magento\CatalogInventory\Model\Stock\Item or Magento\Catalog\Model\Pr...Price\PriceUpdateResult or Magento\Tax\Model\Calculation\Rate\Title or Magento\Sales\Model\Order\Shipment or Magento\Catalog\Model\Product\Price\SpecialPrice or Magento\Tax\Model\ClassModel or Magento\Bundle\Model\Link or Magento\Bundle\Model\BundleOption or Magento\Tax\Model\TaxDetails\AppliedTaxRate or Magento\Bundle\Model\Source\Option\Type or Magento\Sales\Model\Order\Shipping or Magento\Quote\Model\Quote\Item or Magento\SalesRule\Model\Coupon or Magento\Tax\Model\TaxDetails\TaxDetails or Magento\Sales\Model\Order\ShippingTotal or Magento\Catalog\Model\ProductOption or Magento\Catalog\Model\ProductRender\Button. ( Ignorable by Annotation )

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

195
            if ($customer->/** @scrutinizer ignore-call */ getTaxvat()!='') {
Loading history...
196
                $orderUser->setDni($customer->getTaxvat());
197
                $orderBillingAddress->setDni($customer->getTaxvat());
198
                $orderShippingAddress->setDni($customer->getTaxvat());
199
                $orderUser->setNationalId($customer->getTaxvat());
200
                $orderBillingAddress->setNationalId($customer->getTaxvat());
201
                $orderShippingAddress->setNationalId($customer->getTaxvat());
202
            }
203
204
            $previousOrders = $this->getOrders($customer->getId());
0 ignored issues
show
Bug introduced by
The method getId() does not exist on Magento\Framework\Api\ExtensibleDataInterface. It seems like you code against a sub-type of Magento\Framework\Api\ExtensibleDataInterface such as Magento\Store\Api\Data\WebsiteInterface or Magento\Tax\Api\Data\TaxRuleInterface or Magento\Store\Api\Data\GroupInterface or Magento\Customer\Api\Data\GroupInterface or Magento\Catalog\Api\Data...iaGalleryEntryInterface or Magento\Directory\Api\Da...tryInformationInterface or Magento\Store\Api\Data\StoreInterface or Magento\Catalog\Api\Data\ProductRenderInterface or Magento\Quote\Api\Data\CartInterface or Magento\Store\Api\Data\StoreConfigInterface or Magento\Tax\Api\Data\TaxRateInterface or Magento\Downloadable\Api\Data\SampleInterface or Magento\Directory\Api\Da...ionInformationInterface or Magento\Downloadable\Api\Data\LinkInterface or Magento\Bundle\Api\Data\LinkInterface or Magento\Sales\Model\Order\Shipment\Track or Magento\CatalogInventory\Model\Stock\Status or Magento\Sales\Model\Order\Creditmemo\Item or Magento\Tax\Model\Sales\Quote\QuoteDetails or Magento\Catalog\Model\ProductLink\Link or Magento\Framework\Model\AbstractExtensibleModel or Magento\Catalog\Api\Data\ProductInterface or Magento\Quote\Api\Data\AddressInterface or Magento\Customer\Api\Data\CustomerInterface or Magento\Framework\Api\Search\DocumentInterface or Magento\Catalog\Api\Data\CategoryInterface or Magento\Customer\Api\Data\AddressInterface or Magento\CatalogRule\Model\Rule or Magento\Quote\Model\AddressAdditionalData or Magento\Quote\Model\Cart\TotalsAdditionalData or Magento\Checkout\Model\TotalsInformation or Magento\CatalogRule\Model\Data\Condition or Magento\Store\Model\Data\StoreConfig or Magento\Customer\Model\Data\Customer or Magento\Directory\Model\Data\RegionInformation or Magento\Customer\Model\Data\Group or Magento\Directory\Model\Data\CountryInformation or Magento\Customer\Model\Data\Address or Magento\Quote\Model\EstimateAddress or Magento\Eav\Model\Entity...ibute\AbstractAttribute or Magento\Catalog\Model\ResourceModel\Eav\Attribute or Magento\Catalog\Model\Category\Attribute or Magento\Checkout\Model\ShippingInformation or Magento\Sales\Model\Order\Status\History or Magento\Catalog\Model\Product\Option or Magento\Quote\Model\Quote\ProductOption or Magento\Tax\Model\Sales\Quote\ItemDetails or Magento\Tax\Model\TaxDetails\AppliedTax or Magento\Sales\Model\Order\Tax\Item or Magento\Bundle\Model\Option or Magento\Eav\Model\Entity\Attribute\Set or Magento\Quote\Model\Cart\Currency or Magento\Sales\Model\Order\Shipment\Comment or Magento\Catalog\Model\Product\Price\Cost or Magento\Quote\Model\Cart\Totals or Magento\Sales\Model\Order\Invoice\Item or Magento\Downloadable\Model\File\Content or Magento\Catalog\Model\ProductRender\PriceInfo or Magento\CatalogInventory\Model\Stock or Magento\Quote\Model\ShippingAssignment or Magento\Quote\Model\Quote\Payment or Magento\Checkout\Model\PaymentDetails or Magento\Catalog\Model\ProductRender\Image or Magento\Sales\Model\Order\Address or Magento\Tax\Model\TaxClass\Key or Magento\Sales\Model\Order\Creditmemo\Comment or Magento\Sales\Model\Order\Payment or Magento\Sales\Model\Order\Payment\Transaction or Magento\GiftMessage\Model\Message or Magento\Sales\Model\Order\Shipment\Item or Magento\Catalog\Model\Product\Price\TierPrice or Magento\Catalog\Model\Product\Attribute\Type or Magento\Tax\Model\TaxDetails\ItemDetails or Magento\Catalog\Model\CustomOptions\CustomOption or Magento\Catalog\Model\Pr...nder\FormattedPriceInfo or Magento\Sales\Model\Order or Magento\Catalog\Model\Product\Option\Type or Magento\Catalog\Model\Product\TierPrice or Magento\Tax\Model\Sales\Order\Details or Magento\Framework\Api\Te...erator\ExtensibleSample or Magento\Sales\Model\Order\Invoice\Comment or Magento\Sales\Model\Order\ShippingAssignment or Magento\Msrp\Model\ProductRender\MsrpPriceInfo or Magento\Sales\Model\Order\Item or Magento\Sales\Model\Order\Creditmemo or Magento\Sales\Model\Order\Invoice or Magento\Quote\Model\Shipping or Magento\Catalog\Model\Product\Price\BasePrice or Magento\Eav\Model\Entity\Attribute\Group or Magento\Tax\Model\Sales\Order\Tax or Magento\Quote\Model\Cart\TotalSegment or Magento\CatalogInventory\Model\Stock\Item or Magento\Catalog\Model\Pr...Price\PriceUpdateResult or Magento\Tax\Model\Calculation\Rate\Title or Magento\Sales\Model\Order\Shipment or Magento\Catalog\Model\Product\Price\SpecialPrice or Magento\Tax\Model\ClassModel or Magento\Bundle\Model\BundleOption or Magento\Tax\Model\TaxDetails\AppliedTaxRate or Magento\Bundle\Model\Source\Option\Type or Magento\Sales\Model\Order\Shipping or Magento\Quote\Model\Quote\Item or Magento\SalesRule\Model\Coupon or Magento\Tax\Model\TaxDetails\TaxDetails or Magento\Sales\Model\Order\ShippingTotal or Magento\Catalog\Model\ProductOption or Magento\Catalog\Model\ProductRender\Button. ( Ignorable by Annotation )

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

204
            $previousOrders = $this->getOrders($customer->/** @scrutinizer ignore-call */ getId());
Loading history...
205
            foreach ($previousOrders as $orderElement) {
206
                $orderHistory = new OrderHistory();
207
                $orderHistory
208
                    ->setAmount(intval(100 * $orderElement['grand_total']))
209
                    ->setDate(new \DateTime($orderElement['created_at']))
0 ignored issues
show
Bug introduced by
new DateTime($orderElement['created_at']) of type DateTime is incompatible with the type string expected by parameter $date of Pagantis\OrdersApiClient...OrderHistory::setDate(). ( Ignorable by Annotation )

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

209
                    ->setDate(/** @scrutinizer ignore-type */ new \DateTime($orderElement['created_at']))
Loading history...
210
                ;
211
                $orderUser->addOrderHistory($orderHistory);
212
            }
213
214
            $details = new Details();
215
            $shippingCost = $quote->collectTotals()->getTotals()['shipping']->getData('value');
216
            $details->setShippingCost(intval(strval(100 * $shippingCost)));
217
            $items = $quote->getAllVisibleItems();
218
            foreach ($items as $key => $item) {
219
                $product = new Product();
220
                $product
221
                    ->setAmount(intval(100 * $item->getPrice()))
222
                    ->setQuantity($item->getQty())
223
                    ->setDescription($item->getName());
224
                $details->addProduct($product);
225
            }
226
227
            $orderShoppingCart = new ShoppingCart();
228
            $orderShoppingCart
229
                ->setDetails($details)
230
                ->setOrderReference($quote->getId())
231
                ->setPromotedAmount(0)
232
                ->setTotalAmount(intval(strval(100 * $quote->getGrandTotal())))
233
            ;
234
235
            $metadataOrder = new Metadata();
236
            $metadata = $this->getMetadata();
237
            foreach ($metadata as $key => $metadatum) {
238
                $metadataOrder->addMetadata($key, $metadatum);
239
            }
240
241
            $orderConfigurationUrls = new Urls();
242
            $quoteId = $quote->getId();
243
            $okUrl = $this->_url->getUrl(
244
                'pagantis/notify/index',
245
                ['_query' => ['quoteId'=>$quoteId]]
246
            );
247
            if (version_compare($metadata['magento'], '2.3.0') >= 0) {
248
                $okUrl = $this->_url->getUrl('pagantis/notify/indexV2', ['_query' => ['quoteId'=>$quoteId]]);
249
            }
250
251
            $orderConfigurationUrls
252
                ->setCancel($cancelUrl)
253
                ->setKo($okUrl)
254
                ->setAuthorizedNotificationCallback($okUrl)
255
                ->setRejectedNotificationCallback($okUrl)
256
                ->setOk($okUrl)
257
            ;
258
259
            $orderChannel = new Channel();
260
            $orderChannel
261
                ->setAssistedSale(false)
262
                ->setType(Channel::ONLINE)
263
            ;
264
            
265
            $haystack  = $this->store->getLocale();
266
            $language = strstr($haystack, '_', true);
267
            $orderConfiguration = new Configuration();
268
            $orderConfiguration
269
                ->setChannel($orderChannel)
270
                ->setUrls($orderConfigurationUrls)
271
                ->setPurchaseCountry($language)
0 ignored issues
show
Bug introduced by
The method setPurchaseCountry() does not exist on Pagantis\OrdersApiClient\Model\Order\Configuration. ( Ignorable by Annotation )

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

271
                ->/** @scrutinizer ignore-call */ setPurchaseCountry($language)

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...
272
            ;
273
274
275
            $order = new Order();
276
            $order
277
                ->setConfiguration($orderConfiguration)
278
                ->setMetadata($metadataOrder)
279
                ->setShoppingCart($orderShoppingCart)
280
                ->setUser($orderUser)
281
            ;
282
283
            if ($this->config['pagantis_public_key']=='' || $this->config['pagantis_private_key']=='') {
284
                throw new \Exception('Public and Secret Key not found');
285
            }
286
287
            $orderClient = new Client(
288
                $this->config['pagantis_public_key'],
289
                $this->config['pagantis_private_key']
290
            );
291
292
            $order = $orderClient->createOrder($order);
293
            if ($order instanceof Order) {
0 ignored issues
show
introduced by
$order is always a sub-type of Pagantis\OrdersApiClient\Model\Order.
Loading history...
294
                $url = $order->getActionUrls()->getForm();
295
                $result = $this->insertRow($quote->getId(), $order->getId());
296
                if (!$result) {
297
                    throw new \Exception('Unable to save pagantis-order-id');
298
                }
299
            } else {
300
                throw new \Exception('Order not created');
301
            }
302
        } catch (\Exception $exception) {
303
            $this->insertLog($exception);
304
            echo $cancelUrl;
305
            exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
306
        }
307
308
        $displayMode = $this->extraConfig['PAGANTIS_FORM_DISPLAY_TYPE'];
309
        if ($displayMode==='0') {
310
            echo $url;
311
            exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
312
        } else {
313
            $iframeUrl = $this->_url->getUrl(
314
                "pagantis/Payment/iframe",
315
                ['_query' => ["orderId"=>$order->getId()]]
316
            );
317
            echo $iframeUrl;
318
            exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
319
        }
320
    }
321
322
    /**
323
     * Get the orders of a customer
324
     * @param $customerId
325
     *
326
     * @return array
327
     */
328
    private function getOrders($customerId)
329
    {
330
        $orderCollection = array();
331
        if ($customerId!='') {
332
            $this->orderCollection->addAttributeToFilter('customer_id', $customerId)
333
                            ->addAttributeToFilter(
334
                                'status',
335
                                ['in' => ['processing','pending','complete']]
336
                            )
337
                            ->load();
338
            $orderCollection = $this->orderCollection->getData();
339
        }
340
        return $orderCollection;
341
    }
342
343
    /**
344
     * @return void|\Zend_Db_Statement_Interface
345
     * @throws \Zend_Db_Exception
346
     */
347
    private function checkDbTable()
348
    {
349
        $dbConnection = $this->dbObject->getConnection();
350
        $tableName = $this->dbObject->getTableName(self::ORDERS_TABLE);
351
        if (!$dbConnection->isTableExists($tableName)) {
352
            $table = $dbConnection
353
                ->newTable($tableName)
354
                ->addColumn('id', Table::TYPE_SMALLINT, null, array('primary'=>true, 'nullable' => false))
355
                ->addColumn('order_id', Table::TYPE_TEXT, 50)
356
                ->addColumn('mg_order_id', Table::TYPE_TEXT, 50);
357
            return $dbConnection->createTable($table);
358
        }
359
360
        return;
361
    }
362
363
    /**
364
     * Create relationship between quote_id & Pagantis_order_id
365
     * @param $quoteId
366
     * @param $pagantisOrderId
367
     *
368
     * @return int
369
     * @throws \Zend_Db_Exception
370
     */
371
    private function insertRow($quoteId, $pagantisOrderId)
372
    {
373
        $this->checkDbTable();
374
        $dbConnection = $this->dbObject->getConnection();
375
        $tableName = $this->dbObject->getTableName(self::ORDERS_TABLE);
376
        return $dbConnection->insertOnDuplicate(
377
            $tableName,
378
            array('id'=>$quoteId,'order_id'=>$pagantisOrderId),
379
            array('order_id')
380
        );
381
    }
382
383
    /**
384
     * @return array
385
     */
386
    private function getMetadata()
387
    {
388
        $curlInfo = curl_version();
389
        $curlVersion = $curlInfo['version'];
390
        $magentoVersion = $this->productMetadataInterface->getVersion();
391
        $moduleInfo = $this->moduleList->getOne('Pagantis_Pagantis');
392
        return array(  'magento' => $magentoVersion,
393
                       'pagantis' => $moduleInfo['setup_version'],
394
                       'php' => phpversion(),
395
                       'curl' => $curlVersion);
396
    }
397
398
    /**
399
     * Check if log table exists, otherwise create it
400
     *
401
     * @return void|\Zend_Db_Statement_Interface
402
     * @throws \Zend_Db_Exception
403
     */
404
    private function checkDbLogTable()
405
    {
406
        /** @var \Magento\Framework\DB\Adapter\AdapterInterface $dbConnection */
407
        $dbConnection = $this->dbObject->getConnection();
408
        $tableName = $this->dbObject->getTableName(self::LOGS_TABLE);
409
        if (!$dbConnection->isTableExists($tableName)) {
410
            $table = $dbConnection
411
                ->newTable($tableName)
412
                ->addColumn('id', Table::TYPE_SMALLINT, null, array('nullable'=>false, 'auto_increment'=>true, 'primary'=>true))
413
                ->addColumn('log', Table::TYPE_TEXT, null, array('nullable'=>false))
414
                ->addColumn('createdAt', Table::TYPE_TIMESTAMP, null, array('nullable'=>false, 'default'=>Table::TIMESTAMP_INIT));
415
            return $dbConnection->createTable($table);
416
        }
417
418
        return;
419
    }
420
421
    /**
422
     * @param $exceptionMessage
423
     *
424
     * @throws \Zend_Db_Exception
425
     */
426
    private function insertLog($exceptionMessage)
427
    {
428
        if ($exceptionMessage instanceof \Exception) {
429
            $this->checkDbLogTable();
430
            $logObject          = new \stdClass();
431
            $logObject->message = $exceptionMessage->getMessage();
432
            $logObject->code    = $exceptionMessage->getCode();
433
            $logObject->line    = $exceptionMessage->getLine();
434
            $logObject->file    = $exceptionMessage->getFile();
435
            $logObject->trace   = $exceptionMessage->getTraceAsString();
436
437
            /** @var \Magento\Framework\DB\Adapter\AdapterInterface $dbConnection */
438
            $dbConnection = $this->dbObject->getConnection();
439
            $tableName    = $this->dbObject->getTableName(self::LOGS_TABLE);
440
            $dbConnection->insert($tableName, array('log' => json_encode($logObject)));
441
        }
442
    }
443
444
    /**
445
     * @param $billingAdd
446
     *
447
     * @return null
448
     */
449
    private function getTaxId($billingAdd)
450
    {
451
        if (isset($billingAdd['vat_id'])) {
452
            return $billingAdd['vat_id'];
453
        } elseif (isset($billingAdd['cod_fisc'])) {
454
            return $billingAdd['cod_fisc'];
455
        } else {
456
            return null;
457
        }
458
    }
459
}
460