From dee05a1ff8b213f09dd3d6ce69ea07b725f35d20 Mon Sep 17 00:00:00 2001 From: Vitalij Mik Date: Wed, 9 Oct 2024 14:34:15 +0200 Subject: [PATCH] NTR: CS Fix --- src/Components/ApplePayDirect/ApplePayDirect.php | 5 ++--- src/Components/PaypalExpress/PayPalExpress.php | 6 +++--- .../PaypalExpressControllerBase.php | 5 +---- .../PaymentMethod/PaymentMethodRepository.php | 2 -- src/Service/CustomFieldService.php | 2 +- src/Service/CustomerService.php | 4 ++-- src/Service/CustomerServiceInterface.php | 2 +- .../Remover/PayPalExpressPaymentRemover.php | 1 - src/Service/PaymentMethodService.php | 2 +- src/Struct/Address/AddressStruct.php | 16 ++++++++++++++-- src/Subscriber/PaypalExpressSubscriber.php | 1 - tests/PHPUnit/Fakes/FakeCustomerService.php | 2 +- 12 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/Components/ApplePayDirect/ApplePayDirect.php b/src/Components/ApplePayDirect/ApplePayDirect.php index 0194f3170..1084ba7d0 100644 --- a/src/Components/ApplePayDirect/ApplePayDirect.php +++ b/src/Components/ApplePayDirect/ApplePayDirect.php @@ -13,11 +13,9 @@ use Kiener\MolliePayments\Facade\MolliePaymentDoPay; use Kiener\MolliePayments\Factory\MollieApiFactory; use Kiener\MolliePayments\Handler\Method\ApplePayPayment; -use Kiener\MolliePayments\Repository\Order\OrderAddressRepository; use Kiener\MolliePayments\Repository\Order\OrderAddressRepositoryInterface; use Kiener\MolliePayments\Repository\PaymentMethod\PaymentMethodRepository; use Kiener\MolliePayments\Service\Cart\CartBackupService; -use Kiener\MolliePayments\Service\CartService; use Kiener\MolliePayments\Service\CartServiceInterface; use Kiener\MolliePayments\Service\CustomerService; use Kiener\MolliePayments\Service\DomainExtractor; @@ -363,11 +361,12 @@ public function prepareCustomer(string $firstname, string $lastname, string $ema # if we are not logged in, # then we have to create a new guest customer for our express order if (! $this->customerService->isCustomerLoggedIn($context)) { - $address = new AddressStruct($firstname, $lastname, $email, $street, '', $zipcode, $city, $countryCode); + $address = new AddressStruct($firstname, $lastname, $email, $street, '', $zipcode, $city, $countryCode, $phone); $customer = $this->customerService->createGuestAccount( $address, $applePayID, + $acceptedDataProtection, $context ); diff --git a/src/Components/PaypalExpress/PayPalExpress.php b/src/Components/PaypalExpress/PayPalExpress.php index d246847c6..369e3d00b 100644 --- a/src/Components/PaypalExpress/PayPalExpress.php +++ b/src/Components/PaypalExpress/PayPalExpress.php @@ -10,7 +10,6 @@ use Kiener\MolliePayments\Service\Router\RoutingBuilder; use Kiener\MolliePayments\Struct\Address\AddressStruct; use Mollie\Api\Resources\Session; -use Ramsey\Uuid\Uuid; use Shopware\Core\Checkout\Cart\Cart; use Shopware\Core\Checkout\Customer\CustomerEntity; use Shopware\Core\System\SalesChannel\SalesChannelContext; @@ -157,7 +156,7 @@ public function loadSession(string $sessionId, SalesChannelContext $context): Se * @throws \Exception * @return SalesChannelContext */ - public function prepareCustomer(AddressStruct $shippingAddress, SalesChannelContext $context, ?AddressStruct $billingAddress = null): SalesChannelContext + public function prepareCustomer(AddressStruct $shippingAddress, int $acceptedDataProtection, SalesChannelContext $context, ?AddressStruct $billingAddress = null): SalesChannelContext { $updateShippingAddress = true; $paypalExpressId = $this->getActivePaypalExpressID($context); @@ -170,7 +169,7 @@ public function prepareCustomer(AddressStruct $shippingAddress, SalesChannelCont if ($customer === null) { # find existing customer by email - $customer = $this->customerService->findCustomerByEmail($shippingAddress->getEmail(), $context->getContext()); + $customer = $this->customerService->findCustomerByEmail($shippingAddress->getEmail(), $context); if ($customer === null) { @@ -178,6 +177,7 @@ public function prepareCustomer(AddressStruct $shippingAddress, SalesChannelCont $customer = $this->customerService->createGuestAccount( $shippingAddress, $paypalExpressId, + $acceptedDataProtection, $context, $billingAddress ); diff --git a/src/Controller/Storefront/PaypalExpress/PaypalExpressControllerBase.php b/src/Controller/Storefront/PaypalExpress/PaypalExpressControllerBase.php index ebcda05e9..8554182ff 100644 --- a/src/Controller/Storefront/PaypalExpress/PaypalExpressControllerBase.php +++ b/src/Controller/Storefront/PaypalExpress/PaypalExpressControllerBase.php @@ -15,7 +15,6 @@ use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\RouterInterface; class PaypalExpressControllerBase extends StorefrontController @@ -155,9 +154,7 @@ public function finishCheckout(SalesChannelContext $context): Response # create new account or find existing and login - $this->paypalExpress->prepareCustomer($shippingAddress, $context, $billingAddress); - - + $this->paypalExpress->prepareCustomer($shippingAddress, 1, $context, $billingAddress); $returnUrl = $this->getCheckoutConfirmPage($this->router); diff --git a/src/Repository/PaymentMethod/PaymentMethodRepository.php b/src/Repository/PaymentMethod/PaymentMethodRepository.php index b79b7c3de..a6a313dea 100644 --- a/src/Repository/PaymentMethod/PaymentMethodRepository.php +++ b/src/Repository/PaymentMethod/PaymentMethodRepository.php @@ -2,10 +2,8 @@ namespace Kiener\MolliePayments\Repository\PaymentMethod; -use Kiener\MolliePayments\Components\PaypalExpress\PayPalExpress; use Kiener\MolliePayments\Handler\Method\ApplePayPayment; use Kiener\MolliePayments\Handler\Method\PayPalExpressPayment; -use Kiener\MolliePayments\Handler\Method\PayPalPayment; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\DataAbstractionLayer\Event\EntityWrittenContainerEvent; diff --git a/src/Service/CustomFieldService.php b/src/Service/CustomFieldService.php index e145972aa..59af32a68 100644 --- a/src/Service/CustomFieldService.php +++ b/src/Service/CustomFieldService.php @@ -5,4 +5,4 @@ class CustomFieldService { public const CUSTOM_FIELDS_KEY_MOLLIE_PAYMENTS = 'mollie_payments'; -} \ No newline at end of file +} diff --git a/src/Service/CustomerService.php b/src/Service/CustomerService.php index 636658691..bdb2091d3 100644 --- a/src/Service/CustomerService.php +++ b/src/Service/CustomerService.php @@ -604,7 +604,7 @@ public function createMollieCustomer(string $customerId, string $salesChannelId, } - public function findCustomerByEmail(string $email, Context $context): ?CustomerEntity + public function findCustomerByEmail(string $email, SalesChannelContext $context): ?CustomerEntity { $criteria = new Criteria(); $criteria->addFilter(new EqualsFilter('email', $email)); @@ -734,7 +734,7 @@ public function reuseOrCreateAddresses(CustomerEntity $customer, AddressStruct $ return $this->customerRepository->upsert([$customer], $context); } - public function createGuestAccount(AddressStruct $shippingAddress, string $paymentMethodId, SalesChannelContext $context, ?AddressStruct $billingAddress = null): ?CustomerEntity + public function createGuestAccount(AddressStruct $shippingAddress, string $paymentMethodId, int $acceptedDataProtection, SalesChannelContext $context, ?AddressStruct $billingAddress = null): ?CustomerEntity { $countryId = $this->getCountryId($shippingAddress->getCountryCode(), $context->getContext()); $salutationId = $this->getSalutationId($context->getContext()); diff --git a/src/Service/CustomerServiceInterface.php b/src/Service/CustomerServiceInterface.php index 296dc186e..8ab308cf2 100644 --- a/src/Service/CustomerServiceInterface.php +++ b/src/Service/CustomerServiceInterface.php @@ -44,7 +44,7 @@ public function getCustomerStruct(string $customerId, Context $context): Custome */ public function getAddressArray($address, CustomerEntity $customer): array; - public function createGuestAccount(AddressStruct $shippingAddress, string $paymentMethodId, SalesChannelContext $context, ?AddressStruct $billingAddress = null): ?CustomerEntity; + public function createGuestAccount(AddressStruct $shippingAddress, string $paymentMethodId, int $acceptedDataProtection, SalesChannelContext $context, ?AddressStruct $billingAddress = null): ?CustomerEntity; public function getCountryId(string $countryCode, Context $context): ?string; diff --git a/src/Service/Payment/Remover/PayPalExpressPaymentRemover.php b/src/Service/Payment/Remover/PayPalExpressPaymentRemover.php index 3cb04a0e2..c6f0f8988 100644 --- a/src/Service/Payment/Remover/PayPalExpressPaymentRemover.php +++ b/src/Service/Payment/Remover/PayPalExpressPaymentRemover.php @@ -3,7 +3,6 @@ namespace Kiener\MolliePayments\Service\Payment\Remover; -use Kiener\MolliePayments\Controller\Storefront\PaypalExpress\PaypalExpressControllerBase; use Kiener\MolliePayments\Handler\Method\PayPalExpressPayment; use Kiener\MolliePayments\Service\CustomFieldsInterface; use Kiener\MolliePayments\Struct\PaymentMethod\PaymentMethodAttributes; diff --git a/src/Service/PaymentMethodService.php b/src/Service/PaymentMethodService.php index 997b52256..caa877425 100644 --- a/src/Service/PaymentMethodService.php +++ b/src/Service/PaymentMethodService.php @@ -23,8 +23,8 @@ use Kiener\MolliePayments\Handler\Method\KlarnaPayNowPayment; use Kiener\MolliePayments\Handler\Method\KlarnaSliceItPayment; use Kiener\MolliePayments\Handler\Method\MyBankPayment; -use Kiener\MolliePayments\Handler\Method\PayPalExpressPayment; use Kiener\MolliePayments\Handler\Method\PayconiqPayment; +use Kiener\MolliePayments\Handler\Method\PayPalExpressPayment; use Kiener\MolliePayments\Handler\Method\PayPalPayment; use Kiener\MolliePayments\Handler\Method\PaySafeCardPayment; use Kiener\MolliePayments\Handler\Method\PosPayment; diff --git a/src/Struct/Address/AddressStruct.php b/src/Struct/Address/AddressStruct.php index 276f673ac..84bec380f 100644 --- a/src/Struct/Address/AddressStruct.php +++ b/src/Struct/Address/AddressStruct.php @@ -45,6 +45,11 @@ final class AddressStruct */ private $countryCode; + /** + * @var string + */ + private $phone; + /** * @param string $firstName * @param string $lastName @@ -55,7 +60,7 @@ final class AddressStruct * @param string $city * @param string $countryCode */ - public function __construct(string $firstName, string $lastName, string $email, string $street, string $streetAdditional, string $zipCode, string $city, string $countryCode) + public function __construct(string $firstName, string $lastName, string $email, string $street, string $streetAdditional, string $zipCode, string $city, string $countryCode, string $phone) { $this->firstName = $firstName; $this->lastName = $lastName; @@ -65,6 +70,7 @@ public function __construct(string $firstName, string $lastName, string $email, $this->city = $city; $this->countryCode = $countryCode; $this->email = $email; + $this->phone = $phone; } /** @@ -78,7 +84,7 @@ public static function createFromApiResponse(\stdClass $address) $streetAdditional = $address->streetAdditional; } - return new AddressStruct($address->givenName, $address->familyName, $address->email, $address->streetAndNumber, $streetAdditional, $address->postalCode, $address->city, $address->country); + return new AddressStruct($address->givenName, $address->familyName, $address->email, $address->streetAndNumber, $streetAdditional, $address->postalCode, $address->city, $address->country, $address->phone); } public function getFirstName(): string @@ -121,6 +127,12 @@ public function getCountryCode(): string return $this->countryCode; } + public function getPhone(): string + { + return $this->phone; + } + + public function getMollieAddressId(): string { return md5(implode('-', [$this->firstName, $this->lastName, $this->email, $this->street, $this->streetAdditional, $this->zipCode, $this->city, $this->countryCode])); diff --git a/src/Subscriber/PaypalExpressSubscriber.php b/src/Subscriber/PaypalExpressSubscriber.php index 93f61008d..07177f53c 100644 --- a/src/Subscriber/PaypalExpressSubscriber.php +++ b/src/Subscriber/PaypalExpressSubscriber.php @@ -3,7 +3,6 @@ namespace Kiener\MolliePayments\Subscriber; use Kiener\MolliePayments\Components\PaypalExpress\PayPalExpress; -use Kiener\MolliePayments\Service\CustomerServiceInterface; use Kiener\MolliePayments\Service\SettingsService; use Shopware\Storefront\Event\StorefrontRenderEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; diff --git a/tests/PHPUnit/Fakes/FakeCustomerService.php b/tests/PHPUnit/Fakes/FakeCustomerService.php index a022875f5..ecc8e0373 100644 --- a/tests/PHPUnit/Fakes/FakeCustomerService.php +++ b/tests/PHPUnit/Fakes/FakeCustomerService.php @@ -84,7 +84,7 @@ public function getAddressArray($address, CustomerEntity $customer): array return []; } - public function createGuestAccount(AddressStruct $shippingAddress, string $paymentMethodId, SalesChannelContext $context, ?AddressStruct $billingAddress = null): ?CustomerEntity{ + public function createGuestAccount(AddressStruct $shippingAddress, string $paymentMethodId, int $acceptedDataProtection, SalesChannelContext $context, ?AddressStruct $billingAddress = null): ?CustomerEntity{ return null; }