Passed
Pull Request — master (#305)
by
unknown
02:24
created

CancelOrderReference::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 2
b 0
f 0
nc 1
nop 7
dl 0
loc 12
rs 10
1
<?php
2
3
/**
4
 * PAYONE Magento 2 Connector is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * PAYONE Magento 2 Connector is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with PAYONE Magento 2 Connector. If not, see <http://www.gnu.org/licenses/>.
16
 *
17
 * PHP version 5
18
 *
19
 * @category  Payone
20
 * @package   Payone_Magento2_Plugin
21
 * @author    FATCHIP GmbH <[email protected]>
22
 * @copyright 2003 - 2020 Payone GmbH
23
 * @license   <http://www.gnu.org/licenses/> GNU Lesser General Public License
24
 * @link      http://www.payone.de
25
 */
26
27
namespace Payone\Core\Model\Api\Request\Genericpayment;
28
29
use Magento\Quote\Model\Quote;
0 ignored issues
show
Bug introduced by
The type Magento\Quote\Model\Quote 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...
30
use Payone\Core\Model\Methods\PayoneMethod;
31
32
/**
33
 * Class for the PAYONE Server API request genericpayment - "cancelorderreference"
34
 */
35
class CancelOrderReference extends Base
36
{
37
    /**
38
     * Logger object
39
     *
40
     * @var \Psr\Log\LoggerInterface
0 ignored issues
show
Bug introduced by
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...
41
     */
42
    protected $logger = null;
43
44
    /**
45
     * URL helper
46
     *
47
     * @var \Magento\Framework\Url
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Url 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...
48
     */
49
    protected $url;
50
51
    /**
52
     * Constructor
53
     *
54
     * @param \Payone\Core\Helper\Shop                $shopHelper
55
     * @param \Payone\Core\Helper\Environment         $environmentHelper
56
     * @param \Payone\Core\Helper\Api                 $apiHelper
57
     * @param \Payone\Core\Model\ResourceModel\ApiLog $apiLog
58
     * @param \Payone\Core\Helper\Customer            $customerHelper
59
     * @param \Psr\Log\LoggerInterface                $logger
60
     * @param \Magento\Framework\Url                  $url
61
     */
62
    public function __construct(
63
        \Payone\Core\Helper\Shop $shopHelper,
64
        \Payone\Core\Helper\Environment $environmentHelper,
65
        \Payone\Core\Helper\Api $apiHelper,
66
        \Payone\Core\Model\ResourceModel\ApiLog $apiLog,
67
        \Payone\Core\Helper\Customer $customerHelper,
68
        \Psr\Log\LoggerInterface $logger,
69
        \Magento\Framework\Url $url
70
    ) {
71
        parent::__construct($shopHelper, $environmentHelper, $apiHelper, $apiLog, $customerHelper);
72
        $this->logger = $logger;
73
        $this->url = $url;
74
    }
75
76
    /**
77
     * Reserves order id if not set yet
78
     * Returns reserved order id
79
     *
80
     * @param  Quote        $oQuote
81
     * @param  PayoneMethod $oPayment
82
     * @return string
83
     */
84
    protected function getReservedOrderId(Quote $oQuote, PayoneMethod $oPayment)
85
    {
86
        if (!$oQuote->getReservedOrderId()) {
87
            try {
88
                $oQuote->reserveOrderId()->save();
89
            } catch (\Exception $e) {
90
                $this->logger->debug($e->getMessage());
91
            }
92
        }
93
        $sRefNr = $this->shopHelper->getConfigParam('ref_prefix').$oQuote->getReservedOrderId();
94
        $sRefNr = $oPayment->formatReferenceNumber($sRefNr);
95
        return $sRefNr;
96
    }
97
98
    /**
99
     * Send request to PAYONE Server-API with request-type "genericpayment" and action "confirmorderreference"
100
     *
101
     * @param  PayoneMethod $oPayment payment object
102
     * @param  Quote        $oQuote
103
     * @param  string       $sWorkorderId
104
     * @param  string       $sAmazonReferenceId
105
     * @return array
106
     */
107
    public function sendRequest(PayoneMethod $oPayment, Quote $oQuote, $sWorkorderId, $sAmazonReferenceId)
108
    {
109
        $this->addParameter('request', 'genericpayment');
110
        $this->addParameter('add_paydata[action]', 'cancelorderreference');
111
112
        $this->addParameter('add_paydata[amazon_reference_id]', $sAmazonReferenceId);
113
        $this->addParameter('add_paydata[reference]', $this->getReservedOrderId($oQuote, $oPayment));
114
        $this->addParameter('workorderid', $sWorkorderId);
115
116
        $this->addParameter('mode', $oPayment->getOperationMode());
117
        $this->addParameter('aid', $this->shopHelper->getConfigParam('aid'));
118
        $this->addParameter('api_version', '3.10');
119
120
        $this->addParameter('clearingtype', $oPayment->getClearingtype());
121
        $this->addParameter('wallettype', 'AMZ');
122
123
        $this->addParameter('currency', $this->apiHelper->getCurrencyFromQuote($oQuote));
124
125
        $this->addParameter('successurl', $this->url->getUrl('payone/amazon/loadReview?action=placeOrder'));
126
        $this->addParameter('errorurl', $this->url->getUrl('payone/amazon/confirmOrderError'));
127
128
        return $this->send($oPayment);
129
    }
130
}
131