Passed
Pull Request — master (#23)
by Volodymyr
08:09
created

SecurityInvoice::mapRefundOrderItems()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 34

Duplication

Lines 34
Ratio 100 %

Importance

Changes 0
Metric Value
dl 34
loc 34
rs 9.376
c 0
b 0
f 0
cc 2
nc 2
nop 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A SecurityInvoice::mapPaymentToCapture() 11 11 1
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\Payone\Business\Payment\MethodMapper;
9
10
use Generated\Shared\Transfer\ExpenseTransfer;
11
use Generated\Shared\Transfer\OrderTransfer;
12
use Generated\Shared\Transfer\PayoneAuthorizationTransfer;
13
use Generated\Shared\Transfer\PayoneGetSecurityInvoiceTransfer;
14
use Orm\Zed\Payone\Persistence\SpyPaymentPayone;
15
use Spryker\Shared\Kernel\Store;
16
use SprykerEco\Shared\Payone\PayoneApiConstants;
17
use SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer;
18
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer;
19
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PaymentMethod\SecurityInvoiceContainer;
20
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PersonalContainer;
21
use SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainer;
22
use SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainerInterface;
23
use SprykerEco\Zed\Payone\Business\Api\Request\Container\CaptureContainer;
24
use SprykerEco\Zed\Payone\Business\Api\Request\Container\ContainerInterface;
25
use SprykerEco\Zed\Payone\Business\Api\Request\Container\DebitContainer;
26
use SprykerEco\Zed\Payone\Business\Api\Request\Container\GetSecurityInvoiceContainer;
27
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Invoicing\ItemContainer;
28
use SprykerEco\Zed\Payone\Business\Api\Request\Container\PreAuthorizationContainer;
29
use SprykerEco\Zed\Payone\Business\Api\Request\Container\RefundContainer;
30
use SprykerEco\Zed\Payone\PayoneConfig;
31
32
class SecurityInvoice extends AbstractMapper
33
{
34
    /**
35
     * @var \SprykerEco\Zed\Payone\PayoneConfig
36
     */
37
    protected $payoneConfig;
38
39
    /**
40
     * @param \Spryker\Shared\Kernel\Store $storeConfig
41
     * @param \SprykerEco\Zed\Payone\PayoneConfig $payoneConfig
42
     */
43
    public function __construct(Store $storeConfig, PayoneConfig $payoneConfig)
44
    {
45
        parent::__construct($storeConfig);
46
        $this->payoneConfig = $payoneConfig;
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    public function getName(): string
53
    {
54
        return PayoneApiConstants::PAYMENT_METHOD_SECURITY_INVOICE;
55
    }
56
57
    /**
58
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
59
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
60
     *
61
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainerInterface
62
     */
63 View Code Duplication
    public function mapPaymentToAuthorization(SpyPaymentPayone $paymentEntity, OrderTransfer $orderTransfer): AuthorizationContainerInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        $authorizationContainer = new AuthorizationContainer();
66
        $authorizationContainer = $this->mapPaymentToAbstractAuthorization($paymentEntity, $authorizationContainer);
67
        $authorizationContainer = $this->mapEmail($paymentEntity, $authorizationContainer);
68
        $authorizationContainer = $this->mapBusinessRelation($authorizationContainer);
69
        $authorizationContainer->setAmount($orderTransfer->getTotals()->getGrandTotal());
70
71
        return $authorizationContainer;
72
    }
73
74
    /**
75
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
76
     *
77
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainerInterface
78
     */
79 View Code Duplication
    public function mapPaymentToPreAuthorization(SpyPaymentPayone $paymentEntity): AuthorizationContainerInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
    {
81
        $preAuthorizationContainer = new PreAuthorizationContainer();
82
        $preAuthorizationContainer = $this->mapPaymentToAbstractAuthorization($paymentEntity, $preAuthorizationContainer);
83
        $preAuthorizationContainer = $this->mapEmail($paymentEntity, $preAuthorizationContainer);
84
        $preAuthorizationContainer = $this->mapAmount($paymentEntity, $preAuthorizationContainer);
85
        $preAuthorizationContainer = $this->mapBusinessRelation($preAuthorizationContainer);
86
87
        return $preAuthorizationContainer;
88
    }
89
90
    /**
91
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
92
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer $container
93
     *
94
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer
95
     */
96
    public function mapEmail(SpyPaymentPayone $paymentEntity, AbstractAuthorizationContainer $container): AbstractAuthorizationContainer
97
    {
98
        $container->setEmail($paymentEntity->getSpySalesOrder()->getEmail());
99
100
        return $container;
101
    }
102
103
    /**
104
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
105
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer $container
106
     *
107
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer
108
     */
109
    public function mapAmount(SpyPaymentPayone $paymentEntity, AbstractAuthorizationContainer $container): AbstractAuthorizationContainer
110
    {
111
        $container->setAmount($paymentEntity->getSpySalesOrder()->getOrderTotals()->get(0)->getSubTotal());
112
113
        return $container;
114
    }
115
116
    /**
117
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer $container
118
     *
119
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer
120
     */
121
    public function mapBusinessRelation(AbstractAuthorizationContainer $container): AbstractAuthorizationContainer
122
    {
123
        $container->setBusinessrelation($this->payoneConfig->getBusinessRelation());
124
125
        return $container;
126
    }
127
128
    /**
129
     * @param \Generated\Shared\Transfer\ExpenseTransfer $expense
130
     *
131
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Invoicing\ItemContainer
132
     */
133 View Code Duplication
    public function mapExpenseToItemContainer(ExpenseTransfer $expense)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
134
    {
135
        $itemContainer = new ItemContainer();
136
        $itemContainer->setIt(PayoneApiConstants::INVOICING_ITEM_TYPE_SHIPMENT);
137
        $itemContainer->setId('-');
138
        $itemContainer->setPr($expense->getUnitGrossPrice());
139
        $itemContainer->setNo($expense->getQuantity());
140
        $itemContainer->setDe($expense->getName());
141
        $itemContainer->setVa($expense->getTaxRate());
142
143
        return $itemContainer;
144
    }
145
146
    /**
147
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
148
     *
149
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
150
     */
151 View Code Duplication
    public function mapPaymentToCapture(SpyPaymentPayone $paymentEntity): AbstractRequestContainer
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
152
    {
153
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
154
155
        $captureContainer = new CaptureContainer();
156
        $captureContainer->setAmount($paymentDetailEntity->getAmount());
157
        $captureContainer->setCurrency($this->getStandardParameter()->getCurrency());
158
        $captureContainer->setTxid($paymentEntity->getTransactionId());
159
160
        return $captureContainer;
161
    }
162
163
    /**
164
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
165
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer $authorizationContainer
166
     *
167
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer
168
     */
169 View Code Duplication
    protected function mapPaymentToAbstractAuthorization(SpyPaymentPayone $paymentEntity, AbstractAuthorizationContainer $authorizationContainer): AbstractAuthorizationContainer
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
170
    {
171
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
0 ignored issues
show
Unused Code introduced by
$paymentDetailEntity is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
172
173
        $authorizationContainer->setAid($this->getStandardParameter()->getAid());
174
        $authorizationContainer->setClearingType(PayoneApiConstants::CLEARING_TYPE_SECURITY_INVOICE);
175
        $authorizationContainer->setClearingsubtype(PayoneApiConstants::CLEARING_SUBTYPE_SECURITY_INVOICE);
176
        $authorizationContainer->setReference($paymentEntity->getReference());
177
        $authorizationContainer->setCurrency($this->getStandardParameter()->getCurrency());
178
        $authorizationContainer->setPaymentMethod($this->createPaymentMethodContainerFromPayment($paymentEntity));
0 ignored issues
show
Compatibility introduced by
$this->createPaymentMeth...Payment($paymentEntity) of type object<SprykerEco\Zed\Pa...ner\ContainerInterface> is not a sub-type of object<SprykerEco\Zed\Pa...PaymentMethodContainer>. It seems like you assume a concrete implementation of the interface SprykerEco\Zed\Payone\Bu...iner\ContainerInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
179
180
        $personalContainer = new PersonalContainer();
181
        $this->mapBillingAddressToPersonalContainer($personalContainer, $paymentEntity);
182
183
        $authorizationContainer->setPersonalData($personalContainer);
184
185
        return $authorizationContainer;
186
    }
187
188
    /**
189
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
190
     *
191
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\ContainerInterface
192
     */
193 View Code Duplication
    public function mapPaymentToDebit(SpyPaymentPayone $paymentEntity): ContainerInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
194
    {
195
        $debitContainer = new DebitContainer();
196
197
        $debitContainer->setTxid($paymentEntity->getTransactionId());
198
        $debitContainer->setSequenceNumber($this->getNextSequenceNumber($paymentEntity->getTransactionId()));
199
        $debitContainer->setCurrency($this->getStandardParameter()->getCurrency());
200
        $debitContainer->setAmount($paymentEntity->getSpyPaymentPayoneDetail()->getAmount());
201
202
        return $debitContainer;
203
    }
204
205
    /**
206
     * @param \Generated\Shared\Transfer\PayoneGetSecurityInvoiceTransfer $getSecurityInvoiceTransfer
207
     *
208
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\ContainerInterface
209
     */
210
    public function mapGetSecurityInvoice(PayoneGetSecurityInvoiceTransfer $getSecurityInvoiceTransfer): ContainerInterface
211
    {
212
        $getInvoiceContainer = new GetSecurityInvoiceContainer();
213
        $getInvoiceContainer->setInvoiceTitle($getSecurityInvoiceTransfer->getReference());
214
215
        return $getInvoiceContainer;
216
    }
217
218
    /**
219
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
220
     *
221
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AbstractRequestContainer
222
     */
223 View Code Duplication
    public function mapPaymentToRefund(SpyPaymentPayone $paymentEntity): AbstractRequestContainer
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
224
    {
225
        $refundContainer = new RefundContainer();
226
227
        $refundContainer->setTxid($paymentEntity->getTransactionId());
228
        $refundContainer->setSequenceNumber($this->getNextSequenceNumber($paymentEntity->getTransactionId()));
229
        $refundContainer->setCurrency($this->getStandardParameter()->getCurrency());
230
        $refundContainer->setBankcountry($paymentEntity->getSpyPaymentPayoneDetail()->getBankCountry());
231
        $refundContainer->setBankaccount($paymentEntity->getSpyPaymentPayoneDetail()->getBankAccount());
232
        $refundContainer->setBankcode($paymentEntity->getSpyPaymentPayoneDetail()->getBankCode());
233
        $refundContainer->setBankbranchcode($paymentEntity->getSpyPaymentPayoneDetail()->getBankBranchCode());
234
        $refundContainer->setBankcheckdigit($paymentEntity->getSpyPaymentPayoneDetail()->getBankCheckDigit());
235
        $refundContainer->setIban($paymentEntity->getSpyPaymentPayoneDetail()->getIban());
236
        $refundContainer->setBic($paymentEntity->getSpyPaymentPayoneDetail()->getBic());
237
238
        return $refundContainer;
239
    }
240
241
    /**
242
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
243
     *
244
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\ContainerInterface
245
     */
246
    protected function createPaymentMethodContainerFromPayment(SpyPaymentPayone $paymentEntity): ContainerInterface
0 ignored issues
show
Unused Code introduced by
The parameter $paymentEntity is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
247
    {
248
        $paymentMethodContainer = new SecurityInvoiceContainer();
249
250
        return $paymentMethodContainer;
251
    }
252
253
    /**
254
     * @param \Generated\Shared\Transfer\PayoneAuthorizationTransfer $payoneAuthorizationTransfer
255
     *
256
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\ContainerInterface
257
     */
258 View Code Duplication
    protected function createAuthorizationPersonalData(PayoneAuthorizationTransfer $payoneAuthorizationTransfer): ContainerInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
259
    {
260
        $personalContainer = new PersonalContainer();
261
262
        $personalContainer->setFirstName($payoneAuthorizationTransfer->getOrder()->getFirstName());
263
        $personalContainer->setLastName($payoneAuthorizationTransfer->getOrder()->getLastName());
264
        $personalContainer->setCountry($this->storeConfig->getCurrentCountry());
265
266
        return $personalContainer;
267
    }
268
}
269