Passed
Pull Request — master (#84)
by Olha
12:53
created

Invoice::createAuthorizationPersonalData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 9
rs 10
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;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ExpenseTransfer 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...
11
use Generated\Shared\Transfer\ItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ItemTransfer 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...
12
use Generated\Shared\Transfer\OrderTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\OrderTransfer 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...
13
use Generated\Shared\Transfer\PayoneGetInvoiceTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PayoneGetInvoiceTransfer 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...
14
use Orm\Zed\Payone\Persistence\SpyPaymentPayone;
0 ignored issues
show
Bug introduced by
The type Orm\Zed\Payone\Persistence\SpyPaymentPayone 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...
15
use SprykerEco\Shared\Payone\PayoneApiConstants;
16
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer;
17
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PaymentMethod\InvoiceContainer;
18
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PersonalContainer;
19
use SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainer;
20
use SprykerEco\Zed\Payone\Business\Api\Request\Container\CaptureContainer;
21
use SprykerEco\Zed\Payone\Business\Api\Request\Container\CaptureContainerInterface;
22
use SprykerEco\Zed\Payone\Business\Api\Request\Container\DebitContainer;
23
use SprykerEco\Zed\Payone\Business\Api\Request\Container\DebitContainerInterface;
24
use SprykerEco\Zed\Payone\Business\Api\Request\Container\GetInvoiceContainer;
25
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Invoicing\ItemContainer;
26
use SprykerEco\Zed\Payone\Business\Api\Request\Container\PreAuthorizationContainer;
27
use SprykerEco\Zed\Payone\Business\Api\Request\Container\PreAuthorizationContainerInterface;
28
use SprykerEco\Zed\Payone\Business\Api\Request\Container\RefundContainer;
29
use SprykerEco\Zed\Payone\Business\Api\Request\Container\RefundContainerInterface;
30
31
class Invoice extends AbstractMapper implements InvoiceInterface
32
{
33
    /**
34
     * @return string
35
     */
36
    public function getName(): string
37
    {
38
        return PayoneApiConstants::PAYMENT_METHOD_INVOICE;
39
    }
40
41
    /**
42
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
43
     * @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer
44
     *
45
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainer
46
     */
47
    public function mapPaymentToAuthorization(SpyPaymentPayone $paymentEntity, OrderTransfer $orderTransfer): AbstractAuthorizationContainer
48
    {
49
        $authorizationContainer = new AuthorizationContainer();
50
        $authorizationContainer = $this->mapPaymentToAbstractAuthorization($paymentEntity, $authorizationContainer);
51
52
        return $authorizationContainer;
53
    }
54
55
    /**
56
     * @param \Generated\Shared\Transfer\ItemTransfer $orderItem
57
     *
58
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Invoicing\ItemContainer
59
     */
60
    public function mapOrderItemToItemContainer(ItemTransfer $orderItem)
61
    {
62
        $itemContainer = new ItemContainer();
63
        $itemContainer->setIt(PayoneApiConstants::INVOICING_ITEM_TYPE_GOODS);
64
        $itemContainer->setId($orderItem->getSku());
65
        $itemContainer->setPr($orderItem->getUnitGrossPrice());
66
        $itemContainer->setNo($orderItem->getQuantity());
67
        $itemContainer->setDe($orderItem->getName());
68
        $itemContainer->setVa($orderItem->getTaxRate());
69
70
        return $itemContainer;
71
    }
72
73
    /**
74
     * @param \Generated\Shared\Transfer\ExpenseTransfer $expense
75
     *
76
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Invoicing\ItemContainer
77
     */
78
    public function mapExpenseToItemContainer(ExpenseTransfer $expense)
79
    {
80
        $itemContainer = new ItemContainer();
81
        $itemContainer->setIt(PayoneApiConstants::INVOICING_ITEM_TYPE_SHIPMENT);
82
        $itemContainer->setId('-');
83
        $itemContainer->setPr($expense->getUnitGrossPrice());
84
        $itemContainer->setNo($expense->getQuantity());
85
        $itemContainer->setDe($expense->getName());
86
        $itemContainer->setVa($expense->getTaxRate());
87
88
        return $itemContainer;
89
    }
90
91
    /**
92
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
93
     *
94
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\CaptureContainerInterface
95
     */
96
    public function mapPaymentToCapture(SpyPaymentPayone $paymentEntity): CaptureContainerInterface
97
    {
98
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
99
100
        $captureContainer = new CaptureContainer();
101
        $captureContainer->setAmount($paymentDetailEntity->getAmount());
102
        $captureContainer->setCurrency($this->getStandardParameter()->getCurrency());
103
        $captureContainer->setTxid($paymentEntity->getTransactionId());
104
105
        return $captureContainer;
106
    }
107
108
    /**
109
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
110
     *
111
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\PreAuthorizationContainerInterface
112
     */
113
    public function mapPaymentToPreAuthorization(SpyPaymentPayone $paymentEntity): PreAuthorizationContainerInterface
114
    {
115
        $preAuthorizationContainer = new PreAuthorizationContainer();
116
        $preAuthorizationContainer = $this->mapPaymentToAbstractAuthorization($paymentEntity, $preAuthorizationContainer);
117
118
        return $preAuthorizationContainer;
119
    }
120
121
    /**
122
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
123
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer $authorizationContainer
124
     *
125
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer
126
     */
127
    protected function mapPaymentToAbstractAuthorization(SpyPaymentPayone $paymentEntity, AbstractAuthorizationContainer $authorizationContainer)
128
    {
129
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
130
131
        $authorizationContainer->setAid($this->getStandardParameter()->getAid());
132
        $authorizationContainer->setClearingType(PayoneApiConstants::CLEARING_TYPE_INVOICE);
133
        $authorizationContainer->setReference($paymentEntity->getReference());
134
        $authorizationContainer->setAmount($paymentDetailEntity->getAmount());
135
        $authorizationContainer->setCurrency($this->getStandardParameter()->getCurrency());
136
        $authorizationContainer->setPaymentMethod($this->createPaymentMethodContainerFromPayment());
137
138
        $personalContainer = new PersonalContainer();
139
        $this->mapBillingAddressToPersonalContainer($personalContainer, $paymentEntity);
140
141
        $authorizationContainer->setPersonalData($personalContainer);
142
143
        return $authorizationContainer;
144
    }
145
146
    /**
147
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
148
     *
149
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\DebitContainerInterface
150
     */
151
    public function mapPaymentToDebit(SpyPaymentPayone $paymentEntity): DebitContainerInterface
152
    {
153
        $debitContainer = new DebitContainer();
154
155
        $debitContainer->setTxid($paymentEntity->getTransactionId());
156
        $debitContainer->setSequenceNumber($this->getNextSequenceNumber($paymentEntity->getTransactionId()));
157
        $debitContainer->setCurrency($this->getStandardParameter()->getCurrency());
158
        $debitContainer->setAmount($paymentEntity->getSpyPaymentPayoneDetail()->getAmount());
159
160
        return $debitContainer;
161
    }
162
163
    /**
164
     * @param \Generated\Shared\Transfer\PayoneGetInvoiceTransfer $getInvoiceTransfer
165
     *
166
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\GetInvoiceContainer
167
     */
168
    public function mapGetInvoice(PayoneGetInvoiceTransfer $getInvoiceTransfer): GetInvoiceContainer
169
    {
170
        $getInvoiceContainer = new GetInvoiceContainer();
171
        $getInvoiceContainer->setInvoiceTitle($getInvoiceTransfer->getReference());
172
173
        return $getInvoiceContainer;
174
    }
175
176
    /**
177
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
178
     *
179
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\RefundContainerInterface
180
     */
181
    public function mapPaymentToRefund(SpyPaymentPayone $paymentEntity): RefundContainerInterface
182
    {
183
        $refundContainer = new RefundContainer();
184
185
        $refundContainer->setTxid($paymentEntity->getTransactionId());
186
        $refundContainer->setSequenceNumber($this->getNextSequenceNumber($paymentEntity->getTransactionId()));
187
        $refundContainer->setCurrency($this->getStandardParameter()->getCurrency());
188
189
        $refundContainer->setBankcountry($paymentEntity->getSpyPaymentPayoneDetail()->getBankCountry());
190
        $refundContainer->setBankaccount($paymentEntity->getSpyPaymentPayoneDetail()->getBankAccount());
191
        $refundContainer->setBankcode($paymentEntity->getSpyPaymentPayoneDetail()->getBankCode());
192
        $refundContainer->setBankbranchcode($paymentEntity->getSpyPaymentPayoneDetail()->getBankBranchCode());
193
        $refundContainer->setBankcheckdigit($paymentEntity->getSpyPaymentPayoneDetail()->getBankCheckDigit());
194
        $refundContainer->setIban($paymentEntity->getSpyPaymentPayoneDetail()->getIban());
195
        $refundContainer->setBic($paymentEntity->getSpyPaymentPayoneDetail()->getBic());
196
197
        return $refundContainer;
198
    }
199
200
    /**
201
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PaymentMethod\InvoiceContainer
202
     */
203
    protected function createPaymentMethodContainerFromPayment(): InvoiceContainer
204
    {
205
        return new InvoiceContainer();
206
    }
207
}
208