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\Computop\Handler\ExpressCheckout; |
9
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\ComputopPayPalExpressPaymentTransfer; |
|
|
|
|
11
|
|
|
use Generated\Shared\Transfer\QuoteTransfer; |
|
|
|
|
12
|
|
|
use Spryker\Shared\Kernel\Transfer\TransferInterface; |
13
|
|
|
use SprykerEco\Client\Computop\ComputopClientInterface; |
14
|
|
|
use SprykerEco\Shared\Computop\ComputopConfig; |
15
|
|
|
use SprykerEco\Yves\Computop\ComputopFactory; |
16
|
|
|
use SprykerEco\Yves\Computop\Converter\ConverterInterface; |
17
|
|
|
use SprykerEco\Yves\Computop\Dependency\Client\ComputopToQuoteClientInterface; |
18
|
|
|
use SprykerEco\Yves\Computop\Dependency\Client\ComputopToShipmentClientInterface; |
19
|
|
|
use SprykerEco\Yves\Computop\Mapper\Init\PrePlace\PayPalExpressToQuoteMapperInterface; |
20
|
|
|
|
21
|
|
|
class ComputopPayPalExpressInitHandler implements ComputopPayPalExpressInitHandlerInterface |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var \SprykerEco\Yves\Computop\Converter\ConverterInterface |
25
|
|
|
*/ |
26
|
|
|
protected $converter; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var \SprykerEco\Yves\Computop\Dependency\Client\ComputopToQuoteClientInterface |
30
|
|
|
*/ |
31
|
|
|
protected $quoteClient; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var \SprykerEco\Client\Computop\ComputopClientInterface |
35
|
|
|
*/ |
36
|
|
|
protected $computopClient; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var \SprykerEco\Yves\Computop\Dependency\Client\ComputopToShipmentClientInterface |
40
|
|
|
*/ |
41
|
|
|
protected $shipmentClient; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var \SprykerEco\Yves\Computop\Mapper\Init\PrePlace\PayPalExpressToQuoteMapperInterface |
45
|
|
|
*/ |
46
|
|
|
protected $payPalExpressToQuoteMapper; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param \SprykerEco\Yves\Computop\Converter\ConverterInterface $converter |
50
|
|
|
* @param \SprykerEco\Yves\Computop\Dependency\Client\ComputopToQuoteClientInterface $quoteClient |
51
|
|
|
* @param \SprykerEco\Client\Computop\ComputopClientInterface $computopClient |
52
|
|
|
* @param \SprykerEco\Yves\Computop\Dependency\Client\ComputopToShipmentClientInterface $shipmentClient |
53
|
|
|
* @param \SprykerEco\Yves\Computop\Mapper\Init\PrePlace\PayPalExpressToQuoteMapperInterface $payPalExpressToQuoteMapper |
54
|
|
|
*/ |
55
|
|
|
public function __construct( |
56
|
|
|
ConverterInterface $converter, |
57
|
|
|
ComputopToQuoteClientInterface $quoteClient, |
58
|
|
|
ComputopClientInterface $computopClient, |
59
|
|
|
ComputopToShipmentClientInterface $shipmentClient, |
60
|
|
|
PayPalExpressToQuoteMapperInterface $payPalExpressToQuoteMapper |
61
|
|
|
) { |
62
|
|
|
$this->converter = $converter; |
63
|
|
|
$this->quoteClient = $quoteClient; |
64
|
|
|
$this->computopClient = $computopClient; |
65
|
|
|
$this->shipmentClient = $shipmentClient; |
66
|
|
|
$this->payPalExpressToQuoteMapper = $payPalExpressToQuoteMapper; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
71
|
|
|
* @param array $responseArray |
72
|
|
|
* |
73
|
|
|
* @return \Generated\Shared\Transfer\QuoteTransfer |
74
|
|
|
*/ |
75
|
|
|
public function handle(QuoteTransfer $quoteTransfer, array $responseArray): QuoteTransfer |
76
|
|
|
{ |
77
|
|
|
$responseTransfer = $this->converter->getResponseTransfer($responseArray); |
78
|
|
|
|
79
|
|
|
$quoteTransfer = $this->addPaymentToQuote($quoteTransfer, $responseTransfer); |
80
|
|
|
$quoteTransfer = $this->addPaymentSelectionToQuote($quoteTransfer); |
81
|
|
|
$quoteTransfer = $this->addShippingAddressToQuote($quoteTransfer); |
82
|
|
|
$quoteTransfer = $this->addBillingAddressToQuote($quoteTransfer); |
83
|
|
|
$quoteTransfer = $this->addCustomerToQuote($quoteTransfer); |
84
|
|
|
|
85
|
|
|
$quoteTransfer->setCheckoutConfirmed(true); |
86
|
|
|
|
87
|
|
|
$this->quoteClient->setQuote($quoteTransfer); |
88
|
|
|
|
89
|
|
|
return $quoteTransfer; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
94
|
|
|
* @param \Spryker\Shared\Kernel\Transfer\TransferInterface $responseTransfer |
95
|
|
|
* |
96
|
|
|
* @return \Generated\Shared\Transfer\QuoteTransfer |
97
|
|
|
*/ |
98
|
|
|
protected function addPaymentToQuote(QuoteTransfer $quoteTransfer, TransferInterface $responseTransfer): QuoteTransfer |
99
|
|
|
{ |
100
|
|
|
if ($quoteTransfer->getPayment()->getComputopPayPalExpress() === null) { |
101
|
|
|
$computopTransfer = new ComputopPayPalExpressPaymentTransfer(); |
102
|
|
|
$quoteTransfer->getPayment()->setComputopPayPalExpress($computopTransfer); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** @var \Generated\Shared\Transfer\ComputopPayPalExpressInitResponseTransfer $responseTransfer */ |
106
|
|
|
$quoteTransfer->getPayment()->getComputopPayPalExpress()->setPayPalExpressInitResponse( |
107
|
|
|
$responseTransfer |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
return $quoteTransfer; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
115
|
|
|
* |
116
|
|
|
* @return \Generated\Shared\Transfer\QuoteTransfer |
117
|
|
|
*/ |
118
|
|
|
protected function addShippingAddressToQuote(QuoteTransfer $quoteTransfer): QuoteTransfer |
119
|
|
|
{ |
120
|
|
|
$payPalInitResponseTransfer = $quoteTransfer->getPayment()->getComputopPayPalExpress()->getPayPalExpressInitResponse(); |
121
|
|
|
if ($payPalInitResponseTransfer->getAddressStreet() === null) { |
122
|
|
|
return $quoteTransfer; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
$quoteTransfer = $this->shipmentClient->expandQuoteWithShipmentGroups($quoteTransfer); |
126
|
|
|
|
127
|
|
|
return $this |
128
|
|
|
->payPalExpressToQuoteMapper |
129
|
|
|
->mapAddressFromComputopPayPalExpressInitResponseToQuote($payPalInitResponseTransfer, $quoteTransfer); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
134
|
|
|
* |
135
|
|
|
* @return \Generated\Shared\Transfer\QuoteTransfer |
136
|
|
|
*/ |
137
|
|
|
protected function addBillingAddressToQuote(QuoteTransfer $quoteTransfer): QuoteTransfer |
138
|
|
|
{ |
139
|
|
|
$payPalInitResponseTransfer = $quoteTransfer |
140
|
|
|
->getPaymentOrFail() |
141
|
|
|
->getComputopPayPalExpressOrFail()->getPayPalExpressInitResponseOrFail(); |
142
|
|
|
|
143
|
|
|
if ($payPalInitResponseTransfer->getBillingAddressStreet() === null) { |
144
|
|
|
$quoteTransfer->setBillingAddress($quoteTransfer->getShippingAddress()); |
145
|
|
|
|
146
|
|
|
return $quoteTransfer->setBillingSameAsShipping(true); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
return $this->payPalExpressToQuoteMapper->mapBillingAddressFromComputopPayPalExpressInitResponseToQuote($payPalInitResponseTransfer, $quoteTransfer); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
154
|
|
|
* |
155
|
|
|
* @return \Generated\Shared\Transfer\QuoteTransfer |
156
|
|
|
*/ |
157
|
|
|
protected function addCustomerToQuote(QuoteTransfer $quoteTransfer): QuoteTransfer |
158
|
|
|
{ |
159
|
|
|
if ($quoteTransfer->getCustomer()->getIsGuest() !== null && !$quoteTransfer->getCustomer()->getIsGuest()) { |
160
|
|
|
return $quoteTransfer; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
$payPalInitResponseTransfer = $quoteTransfer->getPayment() |
164
|
|
|
->getComputopPayPalExpress() |
165
|
|
|
->getPayPalExpressInitResponse(); |
166
|
|
|
|
167
|
|
|
return $this->payPalExpressToQuoteMapper->mapCustomerFromComputopPayPalExpressInitResponseToQuote($payPalInitResponseTransfer, $quoteTransfer); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
172
|
|
|
* |
173
|
|
|
* @return \Generated\Shared\Transfer\QuoteTransfer |
174
|
|
|
*/ |
175
|
|
|
protected function addPaymentSelectionToQuote(QuoteTransfer $quoteTransfer): QuoteTransfer |
176
|
|
|
{ |
177
|
|
|
$quoteTransfer->getPayment()->setPaymentSelection(ComputopConfig::PAYMENT_METHOD_PAY_PAL_EXPRESS); |
178
|
|
|
$handler = (new ComputopFactory())->createComputopPaymentHandler(); |
179
|
|
|
|
180
|
|
|
return $handler->addPaymentToQuote($quoteTransfer); |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|
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