|
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\Yves\Payone\Form\DataProvider; |
|
9
|
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\PaymentTransfer; |
|
|
|
|
|
|
11
|
|
|
use Generated\Shared\Transfer\PayonePaymentTransfer; |
|
|
|
|
|
|
12
|
|
|
use Spryker\Shared\Kernel\Transfer\AbstractTransfer; |
|
13
|
|
|
use Spryker\Yves\StepEngine\Dependency\Form\StepEngineFormDataProviderInterface; |
|
14
|
|
|
use SprykerEco\Yves\Payone\Dependency\Client\PayoneToStoreClientInterface; |
|
15
|
|
|
use SprykerEco\Yves\Payone\Form\KlarnaSubForm; |
|
16
|
|
|
|
|
17
|
|
|
class KlarnaDataProvider implements StepEngineFormDataProviderInterface |
|
18
|
|
|
{ |
|
19
|
|
|
protected const ADDRESS_SEPARATOR = ' '; |
|
20
|
|
|
|
|
21
|
|
|
protected const GIVEN_NAME = 'given_name'; |
|
22
|
|
|
protected const FAMILY_NAME = 'family_name'; |
|
23
|
|
|
protected const EMAIL = 'email'; |
|
24
|
|
|
protected const STREET_ADDRESS = 'street_address'; |
|
25
|
|
|
protected const POSTAL_CODE = 'postal_code'; |
|
26
|
|
|
protected const CITY = 'city'; |
|
27
|
|
|
protected const COUNTRY = 'country'; |
|
28
|
|
|
protected const PHONE = 'phone'; |
|
29
|
|
|
|
|
30
|
|
|
protected const DATE_OF_BIRTH = 'date_of_birth'; |
|
31
|
|
|
|
|
32
|
|
|
protected const SLICE_IT_PAY_METHOD = 'Slice it'; |
|
33
|
|
|
protected const PAY_LATER_PAY_METHOD = 'Pay later'; |
|
34
|
|
|
protected const PAY_NOW_PAY_METHOD = 'Pay now'; |
|
35
|
|
|
|
|
36
|
|
|
protected const SLICE_IT_PAY_METHOD_CODE = 'KIS'; |
|
37
|
|
|
protected const PAY_LATER_PAY_METHOD_CODE = 'KIV'; |
|
38
|
|
|
protected const PAY_NOW_PAY_METHOD_CODE = 'KDD'; |
|
39
|
|
|
|
|
40
|
|
|
protected const SLICE_IT_WIDGET_PAY_METHOD_CODE = 'pay_over_time'; |
|
41
|
|
|
protected const PAY_LATER_WIDGET_PAY_METHOD_CODE = 'pay_later'; |
|
42
|
|
|
protected const PAY_NOW_WIDGET_PAY_METHOD_CODE = 'pay_now'; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @var \SprykerEco\Yves\Payone\Dependency\Client\PayoneToStoreClientInterface |
|
46
|
|
|
*/ |
|
47
|
|
|
protected $storeClient; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param \SprykerEco\Yves\Payone\Dependency\Client\PayoneToStoreClientInterface $storeClient |
|
51
|
|
|
*/ |
|
52
|
|
|
public function __construct(PayoneToStoreClientInterface $storeClient) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->storeClient = $storeClient; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
|
|
|
|
|
|
59
|
|
|
* |
|
60
|
|
|
* @return \Generated\Shared\Transfer\QuoteTransfer |
|
61
|
|
|
*/ |
|
62
|
|
|
public function getData(AbstractTransfer $quoteTransfer): AbstractTransfer |
|
63
|
|
|
{ |
|
64
|
|
|
if ($quoteTransfer->getPayment() !== null) { |
|
|
|
|
|
|
65
|
|
|
return $quoteTransfer; |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$paymentTransfer = new PaymentTransfer(); |
|
69
|
|
|
$paymentTransfer->setPayone(new PayonePaymentTransfer()); |
|
70
|
|
|
$quoteTransfer->setPayment($paymentTransfer); |
|
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
return $quoteTransfer; |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
|
77
|
|
|
* |
|
78
|
|
|
* @return array |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getOptions(AbstractTransfer $quoteTransfer): array |
|
81
|
|
|
{ |
|
82
|
|
|
$billingAddress = $quoteTransfer->getBillingAddress(); |
|
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
$currentStoreCountryList = $this->storeClient->getCurrentStore()->getCountries(); |
|
85
|
|
|
$firstCurrentStoreCountry = reset($currentStoreCountryList); |
|
86
|
|
|
|
|
87
|
|
|
return [ |
|
88
|
|
|
KlarnaSubForm::PAY_METHOD_CHOICES => $this->getPayMethods(), |
|
89
|
|
|
KlarnaSubForm::BILLING_ADDRESS_DATA => [ |
|
90
|
|
|
static::GIVEN_NAME => $billingAddress->getFirstName(), |
|
91
|
|
|
static::FAMILY_NAME => $billingAddress->getLastName(), |
|
92
|
|
|
static::EMAIL => $quoteTransfer->getCustomer()->getEmail(), |
|
|
|
|
|
|
93
|
|
|
static::STREET_ADDRESS => implode(self::ADDRESS_SEPARATOR, [$billingAddress->getAddress1(), $billingAddress->getAddress2()]), |
|
94
|
|
|
static::POSTAL_CODE => $billingAddress->getZipCode(), |
|
95
|
|
|
static::CITY => $billingAddress->getCity(), |
|
96
|
|
|
static::COUNTRY => $firstCurrentStoreCountry, |
|
97
|
|
|
static::PHONE => $billingAddress->getPhone(), |
|
98
|
|
|
], |
|
99
|
|
|
KlarnaSubForm::CUSTOMER_DATA => [ |
|
100
|
|
|
static::DATE_OF_BIRTH => $quoteTransfer->getCustomer() ? $quoteTransfer->getCustomer()->getDateOfBirth() : null, |
|
101
|
|
|
], |
|
102
|
|
|
KlarnaSubForm::WIDGET_PAY_METHODS => $this->getKlarnaPayMethods(), |
|
103
|
|
|
]; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* @return string[] |
|
108
|
|
|
*/ |
|
109
|
|
|
protected function getPayMethods(): array |
|
110
|
|
|
{ |
|
111
|
|
|
return [ |
|
112
|
|
|
static::PAY_LATER_PAY_METHOD => static::PAY_LATER_PAY_METHOD_CODE, |
|
113
|
|
|
]; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @return string[] |
|
118
|
|
|
*/ |
|
119
|
|
|
protected function getKlarnaPayMethods(): array |
|
120
|
|
|
{ |
|
121
|
|
|
return [ |
|
122
|
|
|
static::SLICE_IT_PAY_METHOD_CODE => static::SLICE_IT_WIDGET_PAY_METHOD_CODE, |
|
123
|
|
|
static::PAY_LATER_PAY_METHOD_CODE => static::PAY_LATER_WIDGET_PAY_METHOD_CODE, |
|
124
|
|
|
static::PAY_NOW_PAY_METHOD_CODE => static::PAY_NOW_WIDGET_PAY_METHOD_CODE, |
|
125
|
|
|
]; |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
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