Passed
Pull Request — master (#23)
by Volodymyr
48:37
created

SecurityInvoice::mapPaymentToRefund()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
dl 18
loc 18
c 0
b 0
f 0
rs 9.6666
cc 1
nc 1
nop 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\ItemTransfer;
12
use Generated\Shared\Transfer\OrderTransfer;
13
use Generated\Shared\Transfer\PayoneAuthorizationTransfer;
14
use Generated\Shared\Transfer\PayoneGetSecurityInvoiceTransfer;
15
use Orm\Zed\Payone\Persistence\SpyPaymentPayone;
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
28
class SecurityInvoice extends AbstractMapper
29
{
30
    /**
31
     * @return string
32
     */
33
    public function getName()
34
    {
35
        return PayoneApiConstants::PAYMENT_METHOD_SECURITY_INVOICE;
36
    }
37
38
    /**
39
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
40
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
41
     *
42
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainerInterface
43
     */
44
    public function mapPaymentToAuthorization(SpyPaymentPayone $paymentEntity, OrderTransfer $orderTransfer)
45
    {
46
        $authorizationContainer = new AuthorizationContainer();
47
        $authorizationContainer = $this->mapPaymentToAbstractAuthorization($paymentEntity, $authorizationContainer);
48
49
        return $authorizationContainer;
50
    }
51
52
    /**
53
     * @param \Generated\Shared\Transfer\ItemTransfer $orderItem
54
     *
55
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Invoicing\ItemContainer
56
     */
57 View Code Duplication
    public function mapOrderItemToItemContainer(ItemTransfer $orderItem)
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...
58
    {
59
        $itemContainer = new ItemContainer();
60
        $itemContainer->setIt(PayoneApiConstants::INVOICING_ITEM_TYPE_GOODS);
61
        $itemContainer->setId($orderItem->getSku());
62
        $itemContainer->setPr($orderItem->getUnitGrossPrice());
63
        $itemContainer->setNo($orderItem->getQuantity());
64
        $itemContainer->setDe($orderItem->getName());
65
        $itemContainer->setVa($orderItem->getTaxRate());
66
67
        return $itemContainer;
68
    }
69
70
    /**
71
     * @param \Generated\Shared\Transfer\ExpenseTransfer $expense
72
     *
73
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Invoicing\ItemContainer
74
     */
75
    public function mapExpenseToItemContainer(ExpenseTransfer $expense)
76
    {
77
        $itemContainer = new ItemContainer();
78
        $itemContainer->setIt(PayoneApiConstants::INVOICING_ITEM_TYPE_SHIPMENT);
79
        $itemContainer->setId('-');
80
        $itemContainer->setPr($expense->getUnitGrossPrice());
81
        $itemContainer->setNo($expense->getQuantity());
82
        $itemContainer->setDe($expense->getName());
83
        $itemContainer->setVa($expense->getTaxRate());
84
85
        return $itemContainer;
86
    }
87
88
    /**
89
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
90
     *
91
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\CaptureContainer
92
     */
93 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...
94
    {
95
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
96
97
        $captureContainer = new CaptureContainer();
98
        $captureContainer->setAmount($paymentDetailEntity->getAmount());
99
        $captureContainer->setCurrency($this->getStandardParameter()->getCurrency());
100
        $captureContainer->setTxid($paymentEntity->getTransactionId());
101
102
        return $captureContainer;
103
    }
104
105
    /**
106
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
107
     *
108
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainerInterface
109
     */
110
    public function mapPaymentToPreAuthorization(SpyPaymentPayone $paymentEntity)
111
    {
112
        $preAuthorizationContainer = new PreAuthorizationContainer();
113
        $preAuthorizationContainer = $this->mapPaymentToAbstractAuthorization($paymentEntity, $preAuthorizationContainer);
114
115
        return $preAuthorizationContainer;
116
    }
117
118
    /**
119
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
120
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer $authorizationContainer
121
     *
122
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer
123
     */
124 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...
125
    {
126
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
127
128
        $authorizationContainer->setAid($this->getStandardParameter()->getAid());
129
        $authorizationContainer->setClearingType(PayoneApiConstants::CLEARING_TYPE_SECURITY_INVOICE);
130
//        $authorizationContainer->setClearingsubtype(PayoneApiConstants::CLEARING_SUBTYPE_SECURITY_INVOICE);
131
        $authorizationContainer->setReference($paymentEntity->getReference());
132
        $authorizationContainer->setAmount($paymentDetailEntity->getAmount());
133
        $authorizationContainer->setCurrency($this->getStandardParameter()->getCurrency());
134
        $authorizationContainer->setPaymentMethod($this->createPaymentMethodContainerFromPayment($paymentEntity));
135
136
        $personalContainer = new PersonalContainer();
137
        $this->mapBillingAddressToPersonalContainer($personalContainer, $paymentEntity);
138
139
        $authorizationContainer->setPersonalData($personalContainer);
140
141
        return $authorizationContainer;
142
    }
143
144
    /**
145
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
146
     *
147
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\DebitContainer
148
     */
149 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...
150
    {
151
        $debitContainer = new DebitContainer();
152
153
        $debitContainer->setTxid($paymentEntity->getTransactionId());
154
        $debitContainer->setSequenceNumber($this->getNextSequenceNumber($paymentEntity->getTransactionId()));
155
        $debitContainer->setCurrency($this->getStandardParameter()->getCurrency());
156
        $debitContainer->setAmount($paymentEntity->getSpyPaymentPayoneDetail()->getAmount());
157
158
        return $debitContainer;
159
    }
160
161
    /**
162
     * @param \Generated\Shared\Transfer\PayoneGetSecurityInvoiceTransfer $getSecurityInvoiceTransfer
163
     *
164
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\GetSecurityInvoiceContainer
165
     */
166
    public function mapGetInvoice(PayoneGetSecurityInvoiceTransfer $getSecurityInvoiceTransfer)
167
    {
168
        $getSecurityInvoiceContainer = new GetSecurityInvoiceContainer();
169
        $getSecurityInvoiceContainer->setInvoiceTitle($getSecurityInvoiceTransfer->getReference());
170
171
        return $getSecurityInvoiceContainer;
172
    }
173
174
    /**
175
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
176
     *
177
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\RefundContainer
178
     */
179 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...
180
    {
181
        $refundContainer = new RefundContainer();
182
183
        $refundContainer->setTxid($paymentEntity->getTransactionId());
184
        $refundContainer->setSequenceNumber($this->getNextSequenceNumber($paymentEntity->getTransactionId()));
185
        $refundContainer->setCurrency($this->getStandardParameter()->getCurrency());
186
187
        $refundContainer->setBankcountry($paymentEntity->getSpyPaymentPayoneDetail()->getBankCountry());
188
        $refundContainer->setBankaccount($paymentEntity->getSpyPaymentPayoneDetail()->getBankAccount());
189
        $refundContainer->setBankcode($paymentEntity->getSpyPaymentPayoneDetail()->getBankCode());
190
        $refundContainer->setBankbranchcode($paymentEntity->getSpyPaymentPayoneDetail()->getBankBranchCode());
191
        $refundContainer->setBankcheckdigit($paymentEntity->getSpyPaymentPayoneDetail()->getBankCheckDigit());
192
        $refundContainer->setIban($paymentEntity->getSpyPaymentPayoneDetail()->getIban());
193
        $refundContainer->setBic($paymentEntity->getSpyPaymentPayoneDetail()->getBic());
194
195
        return $refundContainer;
196
    }
197
198
    /**
199
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
200
     *
201
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PaymentMethod\SecurityInvoiceContainer
202
     */
203
    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...
204
    {
205
        $paymentMethodContainer = new SecurityInvoiceContainer();
206
207
        return $paymentMethodContainer;
208
    }
209
210
    /**
211
     * @param \Generated\Shared\Transfer\PayoneAuthorizationTransfer $payoneAuthorizationTransfer
212
     *
213
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PersonalContainer
214
     */
215 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...
216
    {
217
        $personalContainer = new PersonalContainer();
218
219
        $personalContainer->setFirstName($payoneAuthorizationTransfer->getOrder()->getFirstName());
220
        $personalContainer->setLastName($payoneAuthorizationTransfer->getOrder()->getLastName());
221
        $personalContainer->setCountry($this->storeConfig->getCurrentCountry());
222
223
        return $personalContainer;
224
    }
225
}
226