Skip to content

Commit 3f35535

Browse files
authored
Merge pull request #1394 from PrestaShopCorp/fix/PAYSHIP-3576
Release v5.0.5
2 parents fc6c491 + 2b00b64 commit 3f35535

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+767
-345
lines changed

core/src/Customer/Action/ExpressCheckoutAction.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
namespace PsCheckout\Core\Customer\Action;
2222

23+
use Exception;
2324
use PsCheckout\Core\Customer\Request\ValueObject\ExpressCheckoutRequest;
25+
use PsCheckout\Core\Exception\PsCheckoutException;
2426
use PsCheckout\Infrastructure\Action\CreateOrUpdateAddressActionInterface;
2527
use PsCheckout\Infrastructure\Action\CustomerAuthenticationActionInterface;
2628
use PsCheckout\Infrastructure\Adapter\ContextInterface;
@@ -54,10 +56,26 @@ public function __construct(
5456

5557
public function execute(ExpressCheckoutRequest $expressCheckoutRequest)
5658
{
57-
if ($this->context->getCustomer() && !$this->context->getCustomer()->isLogged()) {
58-
$this->customerAuthenticationAction->execute($expressCheckoutRequest);
59+
$customer = $this->context->getCustomer();
60+
61+
if (!$customer->isLogged()) {
62+
$customer->is_guest = true;
63+
$customer->email = $expressCheckoutRequest->getPayerEmail();
64+
$customer->firstname = $expressCheckoutRequest->getPayerFirstName();
65+
$customer->lastname = $expressCheckoutRequest->getPayerLastName();
66+
$customer->passwd = md5(time() . _COOKIE_KEY_);
67+
68+
try {
69+
$customer->save();
70+
} catch (Exception $exception) {
71+
throw new PsCheckoutException($exception->getMessage(), PsCheckoutException::PSCHECKOUT_EXPRESS_CHECKOUT_CANNOT_SAVE_CUSTOMER, $exception);
72+
}
73+
74+
$this->context->updateCustomer($customer);
5975
}
6076

77+
$this->context->setPayPalEmail($expressCheckoutRequest->getPayerEmail());
78+
6179
$this->context->resetContextCartAddresses();
6280

6381
$this->createOrUpdateAddressAction->execute($expressCheckoutRequest);

core/src/Order/Builder/Node/AmountBreakdownNode.php

100755100644
File mode changed.

core/src/Settings/Configuration/PayPalExpressCheckoutConfiguration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ class PayPalExpressCheckoutConfiguration
2727
const PS_CHECKOUT_EC_CHECKOUT_PAGE = 'PS_CHECKOUT_EC_CHECKOUT_PAGE';
2828

2929
const PS_CHECKOUT_EC_PRODUCT_PAGE = 'PS_CHECKOUT_EC_PRODUCT_PAGE';
30+
31+
const PS_GUEST_CHECKOUT_ENABLED = 'PS_GUEST_CHECKOUT_ENABLED';
3032
}

core/tests/Unit/Order/Builder/Node/AmountBreakdownNodeTest.php

100755100644
File mode changed.

infrastructure/src/Action/CreateOrUpdateAddressAction.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ public function __construct(
7070
*/
7171
public function execute(ExpressCheckoutRequest $expressCheckoutRequest)
7272
{
73+
if (!$expressCheckoutRequest->getShippingAddress()) {
74+
return false;
75+
}
76+
7377
// check if country is available for delivery
7478
$shopIsoCode = PaypalCountryCodeUtility::getShopIsoCode($expressCheckoutRequest->getShippingCountryCode());
7579

infrastructure/src/Action/CustomerAuthenticationAction.php

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
namespace PsCheckout\Infrastructure\Action;
2222

23-
use Customer;
2423
use PsCheckout\Core\Customer\Request\ValueObject\ExpressCheckoutRequest;
2524
use PsCheckout\Core\Exception\PsCheckoutException;
2625
use PsCheckout\Infrastructure\Adapter\ConfigurationInterface;
@@ -63,45 +62,6 @@ public function __construct(
6362
*/
6463
public function execute(ExpressCheckoutRequest $expressCheckoutRequest)
6564
{
66-
/** @var int $idCustomerExists */
67-
$customerId = $this->customer->customerExists($expressCheckoutRequest->getPayerEmail());
68-
69-
if ($customerId === 0) {
70-
$customer = $this->createCustomer($expressCheckoutRequest);
71-
} else {
72-
$customer = new Customer($customerId);
73-
}
74-
75-
$this->context->updateCustomer($customer);
76-
}
77-
78-
/**
79-
* @param ExpressCheckoutRequest $expressCheckoutRequest
80-
*
81-
* @return Customer
82-
*
83-
* @throws PsCheckoutException
84-
*/
85-
private function createCustomer(ExpressCheckoutRequest $expressCheckoutRequest): Customer
86-
{
87-
$customer = new Customer();
88-
$customer->email = $expressCheckoutRequest->getPayerEmail();
89-
$customer->firstname = $expressCheckoutRequest->getPayerFirstName();
90-
$customer->lastname = $expressCheckoutRequest->getPayerLastName();
91-
92-
if ($this->configuration->get('PS_CHECKOUT_EXPRESS_USE_GUEST')) {
93-
$customer->is_guest = true;
94-
$customer->id_default_group = $this->configuration->getInteger('PS_GUEST_GROUP');
95-
}
96-
97-
$customer->passwd = md5(time() . _COOKIE_KEY_);
98-
99-
try {
100-
$customer->save();
101-
} catch (\Exception $exception) {
102-
throw new PsCheckoutException($exception->getMessage(), PsCheckoutException::PSCHECKOUT_EXPRESS_CHECKOUT_CANNOT_SAVE_CUSTOMER, $exception);
103-
}
104-
105-
return $customer;
65+
throw new PsCheckoutException('CustomerAuthenticationAction is deprecated and should not be used anymore.');
10666
}
10767
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
/**
4+
* Copyright since 2007 PrestaShop SA and Contributors
5+
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
6+
*
7+
* NOTICE OF LICENSE
8+
*
9+
* This source file is subject to the Academic Free License version 3.0
10+
* that is bundled with this package in the file LICENSE.md.
11+
* It is also available through the world-wide-web at this URL:
12+
* https://opensource.org/licenses/AFL-3.0
13+
* If you did not receive a copy of the license and are unable to
14+
* obtain it through the world-wide-web, please send an email
15+
* to license@prestashop.com so we can send you a copy immediately.
16+
*
17+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
18+
* @copyright Since 2007 PrestaShop SA and Contributors
19+
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
20+
*/
21+
22+
namespace PsCheckout\Infrastructure\Action;
23+
24+
use Exception;
25+
use InvalidArgumentException;
26+
use PsCheckout\Core\Settings\Configuration\PayPalConfiguration;
27+
use PsCheckout\Infrastructure\Adapter\ConfigurationInterface;
28+
use RuntimeException;
29+
30+
class SaveBatchConfigurationAction implements SaveBatchConfigurationActionInterface
31+
{
32+
/**
33+
* @var ConfigurationInterface
34+
*/
35+
private $configuration;
36+
37+
public function __construct(ConfigurationInterface $configuration)
38+
{
39+
$this->configuration = $configuration;
40+
}
41+
42+
/**
43+
* {@inheritDoc}
44+
*/
45+
public function execute(array $configuration)
46+
{
47+
$this->validateBatchConfiguration($configuration);
48+
49+
try {
50+
foreach ($configuration as $configurationItem) {
51+
$this->configuration->set($configurationItem['name'], $configurationItem['value']);
52+
}
53+
} catch (Exception $exception) {
54+
throw new RuntimeException('Could not save configuration: ' . $exception->getMessage(), 0, $exception);
55+
}
56+
}
57+
58+
/**
59+
* @param array $configuration an associative array where keys are configuration names and values are the corresponding settings to be saved
60+
*
61+
* @return void
62+
*/
63+
private function validateBatchConfiguration(array $configuration)
64+
{
65+
$blacklistedConfigurationKeys = [
66+
PayPalConfiguration::PS_CHECKOUT_PAYPAL_ID_MERCHANT,
67+
PayPalConfiguration::PS_CHECKOUT_PAYPAL_EMAIL_STATUS,
68+
PayPalConfiguration::PS_CHECKOUT_PAYPAL_PAYMENT_STATUS,
69+
];
70+
71+
if (empty($configuration)) {
72+
throw new InvalidArgumentException("Config can't be empty");
73+
}
74+
75+
foreach ($configuration as $configurationItem) {
76+
if (!is_array($configurationItem)
77+
|| !array_key_exists('name', $configurationItem)
78+
|| !array_key_exists('value', $configurationItem)
79+
|| empty($configurationItem['name'])
80+
|| 0 !== strpos($configurationItem['name'], 'PS_CHECKOUT_')
81+
) {
82+
throw new InvalidArgumentException('Received invalid configuration key');
83+
}
84+
85+
if (in_array($configurationItem['name'], $blacklistedConfigurationKeys, true)) {
86+
throw new InvalidArgumentException('Received blacklisted configuration key');
87+
}
88+
}
89+
}
90+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/**
4+
* Copyright since 2007 PrestaShop SA and Contributors
5+
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
6+
*
7+
* NOTICE OF LICENSE
8+
*
9+
* This source file is subject to the Academic Free License version 3.0
10+
* that is bundled with this package in the file LICENSE.md.
11+
* It is also available through the world-wide-web at this URL:
12+
* https://opensource.org/licenses/AFL-3.0
13+
* If you did not receive a copy of the license and are unable to
14+
* obtain it through the world-wide-web, please send an email
15+
* to license@prestashop.com so we can send you a copy immediately.
16+
*
17+
* @author PrestaShop SA and Contributors <contact@prestashop.com>
18+
* @copyright Since 2007 PrestaShop SA and Contributors
19+
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
20+
*/
21+
22+
namespace PsCheckout\Infrastructure\Action;
23+
24+
interface SaveBatchConfigurationActionInterface
25+
{
26+
/**
27+
* Saves multiple configuration settings at once.
28+
*
29+
* @param array $configuration an associative array where keys are configuration names and values are the corresponding settings to be saved
30+
*
31+
* @return void
32+
*
33+
* @throw InvalidArgumentException if configuration is not valid
34+
* @throw RuntimeException if configuration could not be saved
35+
*/
36+
public function execute(array $configuration);
37+
}

infrastructure/src/Adapter/Context.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ public function setCurrentCart(\Cart $cart)
140140
public function updateCustomer(\Customer $customer)
141141
{
142142
$this->context->updateCustomer($customer);
143-
144-
$this->context->cookie->__set('paypalEmail', $customer->email);
145-
$this->context->cookie->write();
146143
}
147144

148145
/**
@@ -154,4 +151,15 @@ public function resetContextCartAddresses()
154151
$this->context->cart->id_address_invoice = 0;
155152
$this->context->cart->save();
156153
}
154+
155+
/**
156+
* {@inheritDoc}
157+
*/
158+
public function setPayPalEmail(string $email): void
159+
{
160+
if (\Validate::isEmail($email)) {
161+
$this->context->cookie->__set('paypalEmail', $email);
162+
$this->context->cookie->write();
163+
}
164+
}
157165
}

infrastructure/src/Adapter/ContextInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,6 @@ public function updateCustomer(\Customer $customer);
9595
* @return void
9696
*/
9797
public function resetContextCartAddresses();
98+
99+
public function setPayPalEmail(string $email): void;
98100
}

0 commit comments

Comments
 (0)