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

CashOnDelivery::createAuthorizationPersonalData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 5
c 2
b 0
f 1
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\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...
11
use Generated\Shared\Transfer\PayoneBankAccountCheckTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ankAccountCheckTransfer 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 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...
13
use SprykerEco\Shared\Payone\PayoneApiConstants;
14
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer;
15
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PaymentMethod\CashOnDeliveryContainer;
16
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PersonalContainer;
17
use SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainer;
18
use SprykerEco\Zed\Payone\Business\Api\Request\Container\BankAccountCheckContainer;
19
use SprykerEco\Zed\Payone\Business\Api\Request\Container\CaptureContainer;
20
use SprykerEco\Zed\Payone\Business\Api\Request\Container\CaptureContainerInterface;
21
use SprykerEco\Zed\Payone\Business\Api\Request\Container\DebitContainer;
22
use SprykerEco\Zed\Payone\Business\Api\Request\Container\DebitContainerInterface;
23
use SprykerEco\Zed\Payone\Business\Api\Request\Container\PreAuthorizationContainer;
24
use SprykerEco\Zed\Payone\Business\Api\Request\Container\PreAuthorizationContainerInterface;
25
use SprykerEco\Zed\Payone\Business\Api\Request\Container\RefundContainer;
26
use SprykerEco\Zed\Payone\Business\Api\Request\Container\RefundContainerInterface;
27
use SprykerEco\Zed\Payone\Dependency\Facade\PayoneToGlossaryFacadeInterface;
28
29
class CashOnDelivery extends AbstractMapper
30
{
31
    /**
32
     * @var \SprykerEco\Zed\Payone\Dependency\Facade\PayoneToGlossaryFacadeInterface
33
     */
34
    protected $glossaryFacade;
35
36
    /**
37
     * @param \SprykerEco\Zed\Payone\Dependency\Facade\PayoneToGlossaryFacadeInterface $glossaryFacade
38
     */
39
    public function __construct(PayoneToGlossaryFacadeInterface $glossaryFacade)
40
    {
41
        $this->glossaryFacade = $glossaryFacade;
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function getName(): string
48
    {
49
        return PayoneApiConstants::PAYMENT_METHOD_CASH_ON_DELIVERY;
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\Authorization\AbstractAuthorizationContainer|\SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainer
57
     */
58
    public function mapPaymentToAuthorization(SpyPaymentPayone $paymentEntity, OrderTransfer $orderTransfer): AbstractAuthorizationContainer
59
    {
60
        $authorizationContainer = new AuthorizationContainer();
61
        $authorizationContainer = $this->mapPaymentToAbstractAuthorization($paymentEntity, $authorizationContainer);
62
63
        return $authorizationContainer;
64
    }
65
66
    /**
67
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
68
     *
69
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\CaptureContainerInterface
70
     */
71
    public function mapPaymentToCapture(SpyPaymentPayone $paymentEntity): CaptureContainerInterface
72
    {
73
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
74
75
        $captureContainer = new CaptureContainer();
76
        $captureContainer->setAmount($paymentDetailEntity->getAmount());
77
        $captureContainer->setCurrency($this->getStandardParameter()->getCurrency());
78
        $captureContainer->setTxid($paymentEntity->getTransactionId());
79
        $captureContainer->setSequenceNumber($this->getNextSequenceNumber($paymentEntity->getTransactionId()));
80
81
        return $captureContainer;
82
    }
83
84
    /**
85
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
86
     *
87
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\PreAuthorizationContainerInterface
88
     */
89
    public function mapPaymentToPreAuthorization(SpyPaymentPayone $paymentEntity): PreAuthorizationContainerInterface
90
    {
91
        $preAuthorizationContainer = new PreAuthorizationContainer();
92
        $preAuthorizationContainer = $this->mapPaymentToAbstractAuthorization($paymentEntity, $preAuthorizationContainer);
93
94
        return $preAuthorizationContainer;
95
    }
96
97
    /**
98
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
99
     *
100
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\DebitContainerInterface
101
     */
102
    public function mapPaymentToDebit(SpyPaymentPayone $paymentEntity): DebitContainerInterface
103
    {
104
        $debitContainer = new DebitContainer();
105
106
        $debitContainer->setTxid($paymentEntity->getTransactionId());
107
        $debitContainer->setSequenceNumber($this->getNextSequenceNumber($paymentEntity->getTransactionId()));
108
        $debitContainer->setCurrency($this->getStandardParameter()->getCurrency());
109
        $debitContainer->setAmount($paymentEntity->getSpyPaymentPayoneDetail()->getAmount());
110
111
        return $debitContainer;
112
    }
113
114
    /**
115
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
116
     *
117
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\RefundContainerInterface
118
     */
119
    public function mapPaymentToRefund(SpyPaymentPayone $paymentEntity): RefundContainerInterface
120
    {
121
        $refundContainer = new RefundContainer();
122
123
        $refundContainer->setTxid($paymentEntity->getTransactionId());
124
        $refundContainer->setSequenceNumber($this->getNextSequenceNumber($paymentEntity->getTransactionId()));
125
        $refundContainer->setCurrency($this->getStandardParameter()->getCurrency());
126
127
        $refundContainer->setBankcountry($paymentEntity->getSpyPaymentPayoneDetail()->getBankCountry());
128
        $refundContainer->setBankaccount($paymentEntity->getSpyPaymentPayoneDetail()->getBankAccount());
129
        $refundContainer->setBankcode($paymentEntity->getSpyPaymentPayoneDetail()->getBankCode());
130
        $refundContainer->setBankbranchcode($paymentEntity->getSpyPaymentPayoneDetail()->getBankBranchCode());
131
        $refundContainer->setBankcheckdigit($paymentEntity->getSpyPaymentPayoneDetail()->getBankCheckDigit());
132
        $refundContainer->setIban($paymentEntity->getSpyPaymentPayoneDetail()->getIban());
133
        $refundContainer->setBic($paymentEntity->getSpyPaymentPayoneDetail()->getBic());
134
135
        return $refundContainer;
136
    }
137
138
    /**
139
     * @param \Generated\Shared\Transfer\PayoneBankAccountCheckTransfer $bankAccountCheckTransfer
140
     *
141
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\BankAccountCheckContainer
142
     */
143
    public function mapBankAccountCheck(PayoneBankAccountCheckTransfer $bankAccountCheckTransfer): BankAccountCheckContainer
144
    {
145
        $bankAccountCheckContainer = new BankAccountCheckContainer();
146
147
        $bankAccountCheckContainer->setAid($this->getStandardParameter()->getAid());
148
        $bankAccountCheckContainer->setBankCountry($bankAccountCheckTransfer->getBankCountry());
149
        $bankAccountCheckContainer->setBankAccount($bankAccountCheckTransfer->getBankAccount());
150
        $bankAccountCheckContainer->setBankCode($bankAccountCheckTransfer->getBankCode());
151
        $bankAccountCheckContainer->setIban($bankAccountCheckTransfer->getIban());
152
        $bankAccountCheckContainer->setBic($bankAccountCheckTransfer->getBic());
153
        $bankAccountCheckContainer->setLanguage($this->getStandardParameter()->getLanguage());
154
155
        return $bankAccountCheckContainer;
156
    }
157
158
    /**
159
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
160
     * @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer $authorizationContainer
161
     *
162
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer
163
     */
164
    protected function mapPaymentToAbstractAuthorization(
165
        SpyPaymentPayone $paymentEntity,
166
        AbstractAuthorizationContainer $authorizationContainer
167
    ): AbstractAuthorizationContainer {
168
        $paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail();
169
170
        $authorizationContainer->setAid($this->getStandardParameter()->getAid());
171
        $authorizationContainer->setClearingType(PayoneApiConstants::CLEARING_TYPE_CASH_ON_DELIVERY);
172
        $authorizationContainer->setReference($paymentEntity->getReference());
173
        $authorizationContainer->setAmount($paymentDetailEntity->getAmount());
174
        $authorizationContainer->setCurrency($this->getStandardParameter()->getCurrency());
175
        $authorizationContainer->setPaymentMethod($this->createPaymentMethodContainerFromPayment($paymentEntity));
176
177
        $personalContainer = $this->buildPersonalContainer($paymentEntity);
178
        $authorizationContainer->setPersonalData($personalContainer);
179
180
        return $authorizationContainer;
181
    }
182
183
    /**
184
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
185
     *
186
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PersonalContainer
187
     */
188
    protected function buildPersonalContainer(SpyPaymentPayone $paymentEntity): PersonalContainer
189
    {
190
        $personalContainer = new PersonalContainer();
191
192
        $this->mapBillingAddressToPersonalContainer($personalContainer, $paymentEntity);
193
194
        $personalContainer->setLanguage($this->getStandardParameter()->getLanguage());
195
196
        return $personalContainer;
197
    }
198
199
    /**
200
     * @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity
201
     *
202
     * @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PaymentMethod\CashOnDeliveryContainer
203
     */
204
    protected function createPaymentMethodContainerFromPayment(SpyPaymentPayone $paymentEntity): CashOnDeliveryContainer
205
    {
206
        $shippingProviderName = $paymentEntity->getSpyPaymentPayoneDetail()->getShippingProvider();
207
208
        $translatedShippingProviderName = $shippingProviderName ? $this->translate($shippingProviderName) : $shippingProviderName;
209
210
        $paymentMethodContainer = new CashOnDeliveryContainer();
211
        $paymentMethodContainer->setShippingProvider($translatedShippingProviderName);
212
213
        return $paymentMethodContainer;
214
    }
215
216
    /**
217
     * @param string $glossaryKey
218
     *
219
     * @return string
220
     */
221
    protected function translate(string $glossaryKey): string
222
    {
223
        return $this->glossaryFacade->translate($glossaryKey, []);
224
    }
225
}
226