Passed
Pull Request — master (#23)
by Volodymyr
05:28
created

SecurityInvoice::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
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\Authorization\AbstractAuthorizationContainer;
18
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PaymentMethod\SecurityInvoiceContainer;
19
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PersonalContainer;
20
use SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainer;
21
use SprykerEco\Zed\Payone\Business\Api\Request\Container\CaptureContainer;
22
use SprykerEco\Zed\Payone\Business\Api\Request\Container\DebitContainer;
23
use SprykerEco\Zed\Payone\Business\Api\Request\Container\GetSecurityInvoiceContainer;
24
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Invoicing\ItemContainer;
25
use SprykerEco\Zed\Payone\Business\Api\Request\Container\PreAuthorizationContainer;
26
use SprykerEco\Zed\Payone\Business\Api\Request\Container\RefundContainer;
27
use SprykerEco\Zed\Payone\PayoneConfig;
28
29
class SecurityInvoice extends AbstractMapper
30
{
31
    /**
32
     * @var PayoneConfig
33
     */
34
    protected $payoneConfig;
35
    /**
36
     * @param \Spryker\Shared\Kernel\Store $storeConfig
37
     */
38
    public function __construct(Store $storeConfig, PayoneConfig $payoneConfig)
39
    {
40
        parent::__construct($storeConfig);
41
        $this->payoneConfig = $payoneConfig;
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function getName()
48
    {
49
        return PayoneApiConstants::PAYMENT_METHOD_SECURITY_INVOICE;
50
    }
51
52
    /**
53
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
54
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
55
     *
56
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainerInterface
57
     */
58 View Code Duplication
    public function mapPaymentToAuthorization(SpyPaymentPayone $paymentEntity, OrderTransfer $orderTransfer)
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...
59
    {
60
        $authorizationContainer = new AuthorizationContainer();
61
        $authorizationContainer = $this->mapPaymentToAbstractAuthorization($paymentEntity, $authorizationContainer);
62
        $authorizationContainer = $this->mapOrderItems($orderTransfer, $authorizationContainer);
63
        $authorizationContainer = $this->mapEmail($paymentEntity, $authorizationContainer);
64
        $authorizationContainer = $this->mapBusinessRelation($authorizationContainer);
65
66
        return $authorizationContainer;
67
    }
68
69
    /**
70
     * @param OrderTransfer $orderTransfer
71
     * @param AbstractAuthorizationContainer $authorizationContainer
72
     *
73
     * @return AbstractAuthorizationContainer
74
     */
75
    public function mapOrderItems(OrderTransfer $orderTransfer, AbstractAuthorizationContainer $authorizationContainer): AbstractAuthorizationContainer
76
    {
77
        $arrayIt = [];
78
        $arrayId = [];
79
        $arrayPr = [];
80
        $arrayNo = [];
81
        $arrayDe = [];
82
        $arrayVa = [];
83
84
        $key = 1;
85
86
        foreach ($orderTransfer->getItems() as $itemTransfer) {
87
            $arrayIt[$key] = PayoneApiConstants::INVOICING_ITEM_TYPE_GOODS;
88
            $arrayId[$key] = $itemTransfer->getSku();
89
            $arrayPr[$key] = $itemTransfer->getSumPrice();
90
            $arrayNo[$key] = $itemTransfer->getQuantity();
91
            $arrayDe[$key] = $itemTransfer->getName();
92
            $arrayVa[$key] = $itemTransfer->getTaxRate();
93
            $key++;
94
        }
95
96
        $authorizationContainer->setIt($arrayIt);
97
        $authorizationContainer->setId($arrayId);
98
        $authorizationContainer->setPr($arrayPr);
99
        $authorizationContainer->setNo($arrayNo);
100
        $authorizationContainer->setDe($arrayDe);
101
        $authorizationContainer->setVa($arrayVa);
102
        $authorizationContainer->setAmount($orderTransfer->getTotals()->getSubtotal());
103
104
        return $authorizationContainer;
105
    }
106
107
    /**
108
     * @param SpyPaymentPayone $paymentEntity
109
     * @param AbstractAuthorizationContainer $container
110
     * @return AbstractAuthorizationContainer
111
     */
112
    public function mapEmail(SpyPaymentPayone $paymentEntity, AbstractAuthorizationContainer $container): AbstractAuthorizationContainer
113
    {
114
        $container->setEmail($paymentEntity->getSpySalesOrder()->getEmail());
115
116
        return $container;
117
    }
118
119
    /**
120
     * @param SpyPaymentPayone $paymentEntity
121
     * @param AbstractAuthorizationContainer $container
122
     * @return AbstractAuthorizationContainer
123
     * @throws \Propel\Runtime\Exception\PropelException
124
     */
125
    public function mapAmount(SpyPaymentPayone $paymentEntity, AbstractAuthorizationContainer $container): AbstractAuthorizationContainer
126
    {
127
        $container->setAmount($paymentEntity->getSpySalesOrder()->getOrderTotals()->get(0)->getSubTotal());
128
129
        return $container;
130
    }
131
132
    /**
133
     * @param AbstractAuthorizationContainer $container
134
     * @return AbstractAuthorizationContainer
135
     */
136
    public function mapBusinessRelation(AbstractAuthorizationContainer $container): AbstractAuthorizationContainer
137
    {
138
        $container->setBusinessrelation($this->payoneConfig->getBusinessRelation());
139
140
        return $container;
141
    }
142
143
    /**
144
     * @param \Generated\Shared\Transfer\ExpenseTransfer $expense
145
     *
146
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Invoicing\ItemContainer
147
     */
148 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...
149
    {
150
        $itemContainer = new ItemContainer();
151
        $itemContainer->setIt(PayoneApiConstants::INVOICING_ITEM_TYPE_SHIPMENT);
152
        $itemContainer->setId('-');
153
        $itemContainer->setPr($expense->getUnitGrossPrice());
154
        $itemContainer->setNo($expense->getQuantity());
155
        $itemContainer->setDe($expense->getName());
156
        $itemContainer->setVa($expense->getTaxRate());
157
158
        return $itemContainer;
159
    }
160
161
    /**
162
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
163
     *
164
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\CaptureContainer
165
     */
166 View Code Duplication
    public function mapPaymentToCapture(SpyPaymentPayone $paymentEntity)
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...
167
    {
168
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
169
170
        $captureContainer = new CaptureContainer();
171
        $captureContainer->setAmount($paymentDetailEntity->getAmount());
172
        $captureContainer->setCurrency($this->getStandardParameter()->getCurrency());
173
        $captureContainer->setTxid($paymentEntity->getTransactionId());
174
175
        return $captureContainer;
176
    }
177
178
    /**
179
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
180
     *
181
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainerInterface
182
     */
183 View Code Duplication
    public function mapPaymentToPreAuthorization(SpyPaymentPayone $paymentEntity)
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...
184
    {
185
        $preAuthorizationContainer = new PreAuthorizationContainer();
186
        $preAuthorizationContainer = $this->mapPaymentToAbstractAuthorization($paymentEntity, $preAuthorizationContainer);
187
        $preAuthorizationContainer = $this->mapEmail($paymentEntity, $preAuthorizationContainer);
188
        $preAuthorizationContainer = $this->mapAmount($paymentEntity, $preAuthorizationContainer);
189
        $preAuthorizationContainer = $this->mapBusinessRelation($preAuthorizationContainer);
190
191
        return $preAuthorizationContainer;
192
    }
193
194
    /**
195
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
196
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer $authorizationContainer
197
     *
198
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer
199
     */
200 View Code Duplication
    protected function mapPaymentToAbstractAuthorization(SpyPaymentPayone $paymentEntity, AbstractAuthorizationContainer $authorizationContainer)
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...
201
    {
202
        $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...
203
204
        $authorizationContainer->setAid($this->getStandardParameter()->getAid());
205
        $authorizationContainer->setClearingType(PayoneApiConstants::CLEARING_TYPE_SECURITY_INVOICE);
206
        $authorizationContainer->setClearingsubtype(PayoneApiConstants::CLEARING_SUBTYPE_SECURITY_INVOICE);
207
        $authorizationContainer->setReference($paymentEntity->getReference());
208
        $authorizationContainer->setCurrency($this->getStandardParameter()->getCurrency());
209
        $authorizationContainer->setPaymentMethod($this->createPaymentMethodContainerFromPayment($paymentEntity));
210
211
        $personalContainer = new PersonalContainer();
212
        $this->mapBillingAddressToPersonalContainer($personalContainer, $paymentEntity);
213
214
        $authorizationContainer->setPersonalData($personalContainer);
215
216
        return $authorizationContainer;
217
    }
218
219
    /**
220
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
221
     *
222
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\DebitContainer
223
     */
224 View Code Duplication
    public function mapPaymentToDebit(SpyPaymentPayone $paymentEntity)
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...
225
    {
226
        $debitContainer = new DebitContainer();
227
228
        $debitContainer->setTxid($paymentEntity->getTransactionId());
229
        $debitContainer->setSequenceNumber($this->getNextSequenceNumber($paymentEntity->getTransactionId()));
230
        $debitContainer->setCurrency($this->getStandardParameter()->getCurrency());
231
        $debitContainer->setAmount($paymentEntity->getSpyPaymentPayoneDetail()->getAmount());
232
233
        return $debitContainer;
234
    }
235
236
    /**
237
     * @param \Generated\Shared\Transfer\PayoneGetSecurityInvoiceTransfer $getSecurityInvoiceTransfer
238
     *
239
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\GetSecurityInvoiceContainer
240
     */
241
    public function mapGetSecurityInvoice(PayoneGetSecurityInvoiceTransfer $getSecurityInvoiceTransfer)
242
    {
243
        $getInvoiceContainer = new GetSecurityInvoiceContainer();
244
        $getInvoiceContainer->setInvoiceTitle($getSecurityInvoiceTransfer->getReference());
245
246
        return $getInvoiceContainer;
247
    }
248
249
    /**
250
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
251
     *
252
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\RefundContainer
253
     */
254 View Code Duplication
    public function mapPaymentToRefund(SpyPaymentPayone $paymentEntity)
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...
255
    {
256
        $refundContainer = new RefundContainer();
257
258
        $refundContainer->setTxid($paymentEntity->getTransactionId());
259
        $refundContainer->setSequenceNumber($this->getNextSequenceNumber($paymentEntity->getTransactionId()));
260
        $refundContainer->setCurrency($this->getStandardParameter()->getCurrency());
261
262
        $refundContainer->setBankcountry($paymentEntity->getSpyPaymentPayoneDetail()->getBankCountry());
263
        $refundContainer->setBankaccount($paymentEntity->getSpyPaymentPayoneDetail()->getBankAccount());
264
        $refundContainer->setBankcode($paymentEntity->getSpyPaymentPayoneDetail()->getBankCode());
265
        $refundContainer->setBankbranchcode($paymentEntity->getSpyPaymentPayoneDetail()->getBankBranchCode());
266
        $refundContainer->setBankcheckdigit($paymentEntity->getSpyPaymentPayoneDetail()->getBankCheckDigit());
267
        $refundContainer->setIban($paymentEntity->getSpyPaymentPayoneDetail()->getIban());
268
        $refundContainer->setBic($paymentEntity->getSpyPaymentPayoneDetail()->getBic());
269
270
        return $refundContainer;
271
    }
272
273
    /**
274
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
275
     *
276
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PaymentMethod\SecurityInvoiceContainer
277
     */
278
    protected function createPaymentMethodContainerFromPayment(SpyPaymentPayone $paymentEntity)
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...
279
    {
280
        $paymentMethodContainer = new SecurityInvoiceContainer();
281
282
        return $paymentMethodContainer;
283
    }
284
285
    /**
286
     * @param \Generated\Shared\Transfer\PayoneAuthorizationTransfer $payoneAuthorizationTransfer
287
     *
288
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PersonalContainer
289
     */
290 View Code Duplication
    protected function createAuthorizationPersonalData(PayoneAuthorizationTransfer $payoneAuthorizationTransfer)
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...
291
    {
292
        $personalContainer = new PersonalContainer();
293
294
        $personalContainer->setFirstName($payoneAuthorizationTransfer->getOrder()->getFirstName());
295
        $personalContainer->setLastName($payoneAuthorizationTransfer->getOrder()->getLastName());
296
        $personalContainer->setCountry($this->storeConfig->getCurrentCountry());
297
298
        return $personalContainer;
299
    }
300
}
301