|
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; |
|
|
|
|
|
|
11
|
|
|
use Generated\Shared\Transfer\PayoneKlarnaStartSessionRequestTransfer; |
|
|
|
|
|
|
12
|
|
|
use Generated\Shared\Transfer\QuoteTransfer; |
|
|
|
|
|
|
13
|
|
|
use Orm\Zed\Payone\Persistence\SpyPaymentPayone; |
|
|
|
|
|
|
14
|
|
|
use SprykerEco\Shared\Payone\PayoneApiConstants; |
|
15
|
|
|
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\AbstractAuthorizationContainer; |
|
16
|
|
|
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PersonalContainer; |
|
17
|
|
|
use SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\ShippingContainer; |
|
18
|
|
|
use SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainer; |
|
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\ContainerInterface; |
|
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\GenericPayment\PaydataContainer; |
|
25
|
|
|
use SprykerEco\Zed\Payone\Business\Api\Request\Container\KlarnaGenericPaymentContainer; |
|
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
|
|
|
use SprykerEco\Zed\Payone\Business\Model\StoreReaderInterface; |
|
31
|
|
|
use SprykerEco\Zed\Payone\Dependency\Facade\PayoneToStoreFacadeInterface; |
|
32
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
33
|
|
|
|
|
34
|
|
|
class KlarnaPaymentMapper extends AbstractMapper implements KlarnaPaymentMapperInterface |
|
35
|
|
|
{ |
|
36
|
|
|
protected const STREET_ADDRESS_SEPARATOR = ' '; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var \Symfony\Component\HttpFoundation\RequestStack |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $requestStack; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var \SprykerEco\Zed\Payone\Dependency\Facade\PayoneToStoreFacadeInterface |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $storeFacade; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var \SprykerEco\Zed\Payone\Business\Model\StoreReaderInterface |
|
50
|
|
|
*/ |
|
51
|
|
|
protected StoreReaderInterface $storeReader; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack |
|
55
|
|
|
* @param \SprykerEco\Zed\Payone\Dependency\Facade\PayoneToStoreFacadeInterface $storeFacade |
|
56
|
|
|
* @param \SprykerEco\Zed\Payone\Business\Model\StoreReaderInterface $storeReader |
|
57
|
|
|
*/ |
|
58
|
|
|
public function __construct( |
|
59
|
|
|
PayoneToStoreFacadeInterface $storeFacade, |
|
60
|
|
|
RequestStack $requestStack, |
|
61
|
|
|
StoreReaderInterface $storeReader |
|
62
|
|
|
) { |
|
63
|
|
|
$this->storeFacade = $storeFacade; |
|
64
|
|
|
$this->requestStack = $requestStack; |
|
65
|
|
|
$this->storeReader = $storeReader; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return string |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getName(): string |
|
72
|
|
|
{ |
|
73
|
|
|
return PayoneApiConstants::PAYMENT_METHOD_KLARNA; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity |
|
78
|
|
|
* |
|
79
|
|
|
* @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\PreAuthorizationContainerInterface |
|
80
|
|
|
*/ |
|
81
|
|
|
public function mapPaymentToPreAuthorization(SpyPaymentPayone $paymentEntity): PreAuthorizationContainerInterface |
|
82
|
|
|
{ |
|
83
|
|
|
$preAuthorizationContainer = new PreAuthorizationContainer(); |
|
84
|
|
|
|
|
85
|
|
|
return $this->mapPaymentToAbstractAuthorization($paymentEntity, $preAuthorizationContainer); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity |
|
90
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
|
91
|
|
|
* |
|
92
|
|
|
* @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\PreAuthorizationContainerInterface |
|
93
|
|
|
*/ |
|
94
|
|
|
public function mapKlarnaPaymentToPreAuthorization(SpyPaymentPayone $paymentEntity, QuoteTransfer $quoteTransfer): PreAuthorizationContainerInterface |
|
95
|
|
|
{ |
|
96
|
|
|
$preAuthorizationContainer = new PreAuthorizationContainer(); |
|
97
|
|
|
$this->mapKlarnaPaymentToAbstractAuthorization($paymentEntity, $quoteTransfer, $preAuthorizationContainer); |
|
98
|
|
|
|
|
99
|
|
|
return $preAuthorizationContainer; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity |
|
104
|
|
|
* @param \Generated\Shared\Transfer\OrderTransfer $orderTransfer |
|
105
|
|
|
* |
|
106
|
|
|
* @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\AuthorizationContainer |
|
107
|
|
|
*/ |
|
108
|
|
|
public function mapPaymentToAuthorization(SpyPaymentPayone $paymentEntity, OrderTransfer $orderTransfer): AbstractAuthorizationContainer |
|
109
|
|
|
{ |
|
110
|
|
|
return new AuthorizationContainer(); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity |
|
115
|
|
|
* |
|
116
|
|
|
* @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\CaptureContainerInterface |
|
117
|
|
|
*/ |
|
118
|
|
|
public function mapPaymentToCapture(SpyPaymentPayone $paymentEntity): CaptureContainerInterface |
|
119
|
|
|
{ |
|
120
|
|
|
$paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail(); |
|
121
|
|
|
$captureContainer = new CaptureContainer(); |
|
122
|
|
|
|
|
123
|
|
|
$captureContainer->setAmount($paymentDetailEntity->getAmount()); |
|
124
|
|
|
$captureContainer->setCurrency($this->getStandardParameter()->getCurrency()); |
|
125
|
|
|
$captureContainer->setTxid($paymentEntity->getTransactionId()); |
|
126
|
|
|
$captureContainer->setCaptureMode(PayoneApiConstants::CAPTURE_MODE_NOTCOMPLETED); |
|
127
|
|
|
$sequenceNumber = $this->getNextSequenceNumber($paymentEntity->getTransactionId()); |
|
128
|
|
|
$captureContainer->setSequenceNumber($sequenceNumber); |
|
129
|
|
|
|
|
130
|
|
|
return $captureContainer; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity |
|
135
|
|
|
* |
|
136
|
|
|
* @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\DebitContainerInterface |
|
137
|
|
|
*/ |
|
138
|
|
|
public function mapPaymentToDebit(SpyPaymentPayone $paymentEntity): DebitContainerInterface |
|
139
|
|
|
{ |
|
140
|
|
|
$debitContainer = new DebitContainer(); |
|
141
|
|
|
|
|
142
|
|
|
$debitContainer->setTxid($paymentEntity->getTransactionId()); |
|
143
|
|
|
$debitContainer->setSequenceNumber($this->getNextSequenceNumber($paymentEntity->getTransactionId())); |
|
144
|
|
|
$debitContainer->setCurrency($this->getStandardParameter()->getCurrency()); |
|
145
|
|
|
$debitContainer->setAmount($paymentEntity->getSpyPaymentPayoneDetail()->getAmount()); |
|
146
|
|
|
|
|
147
|
|
|
return $debitContainer; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity |
|
152
|
|
|
* |
|
153
|
|
|
* @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\RefundContainerInterface |
|
154
|
|
|
*/ |
|
155
|
|
|
public function mapPaymentToRefund(SpyPaymentPayone $paymentEntity): RefundContainerInterface |
|
156
|
|
|
{ |
|
157
|
|
|
$refundContainer = new RefundContainer(); |
|
158
|
|
|
|
|
159
|
|
|
$refundContainer->setTxid($paymentEntity->getTransactionId()); |
|
160
|
|
|
$refundContainer->setSequenceNumber($this->getNextSequenceNumber($paymentEntity->getTransactionId())); |
|
161
|
|
|
$refundContainer->setCurrency($this->getStandardParameter()->getCurrency()); |
|
162
|
|
|
|
|
163
|
|
|
return $refundContainer; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* @param \Generated\Shared\Transfer\PayoneKlarnaStartSessionRequestTransfer $payoneKlarnaStartSessionRequestTransfer |
|
168
|
|
|
* |
|
169
|
|
|
* @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\KlarnaGenericPaymentContainer |
|
170
|
|
|
*/ |
|
171
|
|
|
public function mapPaymentToKlarnaGenericPaymentContainer( |
|
172
|
|
|
PayoneKlarnaStartSessionRequestTransfer $payoneKlarnaStartSessionRequestTransfer |
|
173
|
|
|
): ContainerInterface { |
|
174
|
|
|
$quoteTransfer = $payoneKlarnaStartSessionRequestTransfer->getQuote(); |
|
175
|
|
|
|
|
176
|
|
|
$klarnaGenericPaymentContainer = new KlarnaGenericPaymentContainer(); |
|
177
|
|
|
|
|
178
|
|
|
$klarnaGenericPaymentContainer->setAid($this->getStandardParameter()->getAid()); |
|
179
|
|
|
$klarnaGenericPaymentContainer->setAmount($quoteTransfer->getTotals()->getGrandTotal()); |
|
180
|
|
|
$klarnaGenericPaymentContainer->setCurrency($quoteTransfer->getCurrency()->getCode()); |
|
181
|
|
|
$klarnaGenericPaymentContainer->setClearingType(PayoneApiConstants::CLEARING_TYPE_FINANCING); |
|
182
|
|
|
$klarnaGenericPaymentContainer->setFinancingType($payoneKlarnaStartSessionRequestTransfer->getPayMethod()); |
|
183
|
|
|
|
|
184
|
|
|
$paydataContainer = new PaydataContainer(); |
|
185
|
|
|
$paydataContainer->setAction(PayoneApiConstants::PAYMENT_KLARNA_START_SESSION_ACTION); |
|
186
|
|
|
$klarnaGenericPaymentContainer->setPaydata($paydataContainer); |
|
187
|
|
|
|
|
188
|
|
|
$personalContainer = $this->createPersonalContainerFromQuoteTransfer($quoteTransfer); |
|
189
|
|
|
$klarnaGenericPaymentContainer->setPersonalData($personalContainer); |
|
190
|
|
|
|
|
191
|
|
|
return $klarnaGenericPaymentContainer; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
|
196
|
|
|
* |
|
197
|
|
|
* @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PersonalContainer |
|
198
|
|
|
*/ |
|
199
|
|
|
protected function createPersonalContainerFromQuoteTransfer(QuoteTransfer $quoteTransfer): ContainerInterface |
|
200
|
|
|
{ |
|
201
|
|
|
$personalContainer = new PersonalContainer(); |
|
202
|
|
|
$billingAddress = $quoteTransfer->getBillingAddress(); |
|
203
|
|
|
$personalContainer->setEmail($billingAddress->getEmail()); |
|
204
|
|
|
$personalContainer->setCity($billingAddress->getCity()); |
|
205
|
|
|
|
|
206
|
|
|
$personalContainer->setCountry($this->getCurrentCountry()); |
|
207
|
|
|
$personalContainer->setFirstName($billingAddress->getFirstName()); |
|
208
|
|
|
$personalContainer->setLastName($billingAddress->getLastName()); |
|
209
|
|
|
$personalContainer->setSalutation($billingAddress->getSalutation()); |
|
210
|
|
|
|
|
211
|
|
|
$personalContainer->setTelephoneNumber($billingAddress->getPhone()); |
|
212
|
|
|
$personalContainer->setLanguage($this->getStandardParameter()->getLanguage()); |
|
213
|
|
|
|
|
214
|
|
|
return $personalContainer; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity |
|
219
|
|
|
* @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\PreAuthorizationContainer $authorizationContainer |
|
220
|
|
|
* |
|
221
|
|
|
* @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\PreAuthorizationContainer |
|
222
|
|
|
*/ |
|
223
|
|
|
protected function mapPaymentToAbstractAuthorization( |
|
224
|
|
|
SpyPaymentPayone $paymentEntity, |
|
225
|
|
|
AbstractAuthorizationContainer $authorizationContainer |
|
226
|
|
|
): AbstractAuthorizationContainer { |
|
227
|
|
|
$authorizationContainer->setAid($this->getStandardParameter()->getAid()); |
|
228
|
|
|
|
|
229
|
|
|
$paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail(); |
|
230
|
|
|
|
|
231
|
|
|
$authorizationContainer->setAmount($paymentDetailEntity->getAmount()); |
|
232
|
|
|
$authorizationContainer->setCurrency($this->getStandardParameter()->getCurrency()); |
|
233
|
|
|
$authorizationContainer->setClearingType(PayoneApiConstants::CLEARING_TYPE_FINANCING); |
|
234
|
|
|
|
|
235
|
|
|
$authorizationContainer->setReference($paymentEntity->getReference()); |
|
236
|
|
|
|
|
237
|
|
|
$paydataContainer = new PaydataContainer(); |
|
238
|
|
|
$authorizationContainer->setPaydata($paydataContainer); |
|
|
|
|
|
|
239
|
|
|
|
|
240
|
|
|
$personalContainer = $this->buildPersonalContainer($paymentEntity); |
|
241
|
|
|
$authorizationContainer->setPersonalData($personalContainer); |
|
242
|
|
|
$orderReference = $paymentEntity->getSpySalesOrder()->getOrderReference(); |
|
243
|
|
|
$authorizationContainer->setRedirect($this->createRedirectContainer($orderReference)); |
|
|
|
|
|
|
244
|
|
|
|
|
245
|
|
|
$shippingAddressEntity = $paymentEntity->getSpySalesOrder()->getShippingAddress(); |
|
246
|
|
|
|
|
247
|
|
|
if ($shippingAddressEntity) { |
|
248
|
|
|
$shippingContainer = new ShippingContainer(); |
|
249
|
|
|
$this->mapShippingAddressToShippingContainer($shippingContainer, $shippingAddressEntity); |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
return $authorizationContainer; |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity |
|
257
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
|
258
|
|
|
* @param \SprykerEco\Zed\Payone\Business\Api\Request\Container\PreAuthorizationContainerInterface $authorizationContainer |
|
259
|
|
|
* |
|
260
|
|
|
* @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\PreAuthorizationContainerInterface |
|
261
|
|
|
*/ |
|
262
|
|
|
protected function mapKlarnaPaymentToAbstractAuthorization( |
|
263
|
|
|
SpyPaymentPayone $paymentEntity, |
|
264
|
|
|
QuoteTransfer $quoteTransfer, |
|
265
|
|
|
PreAuthorizationContainerInterface $authorizationContainer |
|
266
|
|
|
): PreAuthorizationContainerInterface { |
|
267
|
|
|
$authorizationContainer->setAid($this->getStandardParameter()->getAid()); |
|
268
|
|
|
|
|
269
|
|
|
$paymentDetailEntity = $paymentEntity->getSpyPaymentPayoneDetail(); |
|
270
|
|
|
$payoneKlarnaTransfer = $quoteTransfer->getPayment()->getPayoneKlarna(); |
|
271
|
|
|
|
|
272
|
|
|
$authorizationContainer->setAmount($paymentDetailEntity->getAmount()); |
|
273
|
|
|
$authorizationContainer->setCurrency($this->getStandardParameter()->getCurrency()); |
|
274
|
|
|
$authorizationContainer->setClearingType(PayoneApiConstants::CLEARING_TYPE_FINANCING); |
|
275
|
|
|
$authorizationContainer->setFinancingType($payoneKlarnaTransfer->getPayMethod()); |
|
276
|
|
|
|
|
277
|
|
|
$authorizationContainer->setReference($paymentEntity->getReference()); |
|
278
|
|
|
|
|
279
|
|
|
$paydataContainer = new PaydataContainer(); |
|
280
|
|
|
$paydataContainer->setAuthorizationToken($payoneKlarnaTransfer->getPayMethodToken()); |
|
281
|
|
|
$authorizationContainer->setPaydata($paydataContainer); |
|
282
|
|
|
|
|
283
|
|
|
$personalContainer = $this->buildPersonalContainer($paymentEntity); |
|
284
|
|
|
$authorizationContainer->setPersonalData($personalContainer); |
|
285
|
|
|
$orderReference = $paymentEntity->getSpySalesOrder()->getOrderReference(); |
|
286
|
|
|
$authorizationContainer->setRedirect($this->createRedirectContainer($orderReference)); |
|
287
|
|
|
|
|
288
|
|
|
$shippingAddressEntity = $paymentEntity->getSpySalesOrder()->getShippingAddress(); |
|
289
|
|
|
|
|
290
|
|
|
if ($shippingAddressEntity) { |
|
291
|
|
|
$shippingContainer = new ShippingContainer(); |
|
292
|
|
|
$this->mapShippingAddressToShippingContainer($shippingContainer, $shippingAddressEntity); |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
return $authorizationContainer; |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* @param \Orm\Zed\Payone\Persistence\SpyPaymentPayone $paymentEntity |
|
300
|
|
|
* |
|
301
|
|
|
* @return \SprykerEco\Zed\Payone\Business\Api\Request\Container\Authorization\PersonalContainer |
|
302
|
|
|
*/ |
|
303
|
|
|
protected function buildPersonalContainer(SpyPaymentPayone $paymentEntity): ContainerInterface |
|
304
|
|
|
{ |
|
305
|
|
|
$personalContainer = new PersonalContainer(); |
|
306
|
|
|
|
|
307
|
|
|
$this->mapBillingAddressToPersonalContainer($personalContainer, $paymentEntity); |
|
308
|
|
|
$personalContainer->setCompany(null); |
|
309
|
|
|
$personalContainer->setEmail($paymentEntity->getSpySalesOrder()->getEmail()); |
|
310
|
|
|
|
|
311
|
|
|
$currentRequest = $this->requestStack->getCurrentRequest(); |
|
312
|
|
|
$personalContainer->setIp($currentRequest->getClientIp()); |
|
313
|
|
|
|
|
314
|
|
|
return $personalContainer; |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
/** |
|
318
|
|
|
* @return string |
|
319
|
|
|
*/ |
|
320
|
|
|
protected function getCurrentCountry(): string |
|
321
|
|
|
{ |
|
322
|
|
|
return $this->storeReader->getDefaultStoreCountry(); |
|
323
|
|
|
} |
|
324
|
|
|
} |
|
325
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths