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->payPalExpressToQuoteMapper->mapAddressTransfer($quoteTransfer, $payPalInitResponseTransfer); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
132
|
|
|
* |
133
|
|
|
* @return \Generated\Shared\Transfer\QuoteTransfer |
134
|
|
|
*/ |
135
|
|
|
protected function addBillingAddressToQuote(QuoteTransfer $quoteTransfer): QuoteTransfer |
136
|
|
|
{ |
137
|
|
|
$payPalInitResponseTransfer = $quoteTransfer->getPayment()->getComputopPayPalExpress()->getPayPalExpressInitResponse(); |
138
|
|
|
if ($payPalInitResponseTransfer->getBillingAddressStreet() === null) { |
139
|
|
|
return $quoteTransfer; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
return $this->payPalExpressToQuoteMapper->mapBillingTransfer($quoteTransfer, $payPalInitResponseTransfer); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
147
|
|
|
* |
148
|
|
|
* @return \Generated\Shared\Transfer\QuoteTransfer |
149
|
|
|
*/ |
150
|
|
|
protected function addCustomerToQuote(QuoteTransfer $quoteTransfer): QuoteTransfer |
151
|
|
|
{ |
152
|
|
|
if (!$quoteTransfer->getCustomer()->getIsGuest()) { |
153
|
|
|
return $quoteTransfer; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
$payPalInitResponseTransfer = $quoteTransfer |
157
|
|
|
->getPayment() |
158
|
|
|
->getComputopPayPalExpress() |
159
|
|
|
->getPayPalExpressInitResponse(); |
160
|
|
|
|
161
|
|
|
return $this->payPalExpressToQuoteMapper->mapCustomerTransfer($quoteTransfer, $payPalInitResponseTransfer); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer |
166
|
|
|
* |
167
|
|
|
* @return \Generated\Shared\Transfer\QuoteTransfer |
168
|
|
|
*/ |
169
|
|
|
protected function addPaymentSelectionToQuote(QuoteTransfer $quoteTransfer): QuoteTransfer |
170
|
|
|
{ |
171
|
|
|
$quoteTransfer->getPayment()->setPaymentSelection(ComputopConfig::PAYMENT_METHOD_PAY_PAL_EXPRESS); |
172
|
|
|
$handler = (new ComputopFactory())->createComputopPaymentHandler(); |
173
|
|
|
|
174
|
|
|
return $handler->addPaymentToQuote($quoteTransfer); |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
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