From 8b7ed8faff0d8e1910e0fc447d13a80829169707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Gust?= Date: Thu, 19 Dec 2024 18:27:33 +0100 Subject: [PATCH 1/2] PSPAYPAL-870 remove bug in paypal express and shipping --- src/Controller/ProxyController.php | 21 ++++++++++++--------- src/Service/ModuleSettings.php | 5 +++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Controller/ProxyController.php b/src/Controller/ProxyController.php index 09dd7a17e..bdd942b07 100644 --- a/src/Controller/ProxyController.php +++ b/src/Controller/ProxyController.php @@ -401,17 +401,20 @@ public function setPayPalPaymentMethod($defaultPayPalPaymentId = PayPalDefinitio $requestedPayPalPaymentId = $this->getRequestedPayPalPaymentId($defaultPayPalPaymentId); if ($session->getVariable('paymentid') !== $requestedPayPalPaymentId) { $basket->setPayment($requestedPayPalPaymentId); + $session->setVariable('paymentid', $requestedPayPalPaymentId); + } + $this->getActiveShippingSetId($session, $user, $basket); + } - // get the active shippingSetId - /** @psalm-suppress InvalidArgument */ - [, $shippingSetId,] = - Registry::get(DeliverySetList::class)->getDeliverySetData('', $user, $basket); + private function getActiveShippingSetId($session, $user, $basket): void + { + /** @psalm-suppress InvalidArgument */ + [, $shippingSetId,] = + Registry::get(DeliverySetList::class)->getDeliverySetData('', $user, $basket); - if ($shippingSetId) { - $basket->setShipping($shippingSetId); - $session->setVariable('sShipSet', $shippingSetId); - } - $session->setVariable('paymentid', $requestedPayPalPaymentId); + if ($shippingSetId) { + $basket->setShipping($shippingSetId); + $session->setVariable('sShipSet', $shippingSetId); } } diff --git a/src/Service/ModuleSettings.php b/src/Service/ModuleSettings.php index 1ca002d36..bcd6ba26c 100755 --- a/src/Service/ModuleSettings.php +++ b/src/Service/ModuleSettings.php @@ -631,7 +631,7 @@ public function isVaultingAllowedForPayment(string $paymentId): bool $payment = oxNew(Payment::class); $payment->load($paymentId); $paymentEnabled = (bool)$payment->oxpayments__oxactive->value; - $paymentType = PayPalDefinitions::getPayPalDefinitions()[$paymentId]["vaultingtype"]; + $vaultingType = PayPalDefinitions::getPayPalDefinitions()[$paymentId]["vaultingtype"]; $session = Registry::getSession(); $actShipSet = $session->getVariable('sShipSet'); @@ -650,7 +650,8 @@ public function isVaultingAllowedForPayment(string $paymentId): bool return $paymentEnabled && $this->getIsVaultingActive() && - PayPalDefinitions::isPayPalVaultingPossible($paymentId, $paymentType) && + $vaultingType && + PayPalDefinitions::isPayPalVaultingPossible($paymentId, $vaultingType) && array_key_exists($paymentId, $paymentList) && ( empty($payPalDefinitions[$paymentId]['currencies']) || From ff78e0926438490015af5d29308e16b59eeb7096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Gust?= Date: Thu, 19 Dec 2024 18:28:54 +0100 Subject: [PATCH 2/2] PSPAYPAL-870 phpcs issues --- src/Core/Api/VaultingService.php | 8 ++-- src/Core/PayPalDefinitions.php | 2 +- src/Service/ModuleSettings.php | 8 ++-- src/Service/Payment.php | 4 +- src/Service/StaticContent.php | 3 +- src/Traits/AccountControllerTrait.php | 60 +++++++++++++-------------- 6 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/Core/Api/VaultingService.php b/src/Core/Api/VaultingService.php index 25c6bd30f..ff506e750 100644 --- a/src/Core/Api/VaultingService.php +++ b/src/Core/Api/VaultingService.php @@ -45,7 +45,7 @@ public function generateUserIdToken($payPalCustomerId = false): array $body = $response->getBody(); } $result = json_decode((string)$body, true, 512, JSON_THROW_ON_ERROR); - } catch (ApiException|JsonException $e) { + } catch (ApiException | JsonException $e) { $result = []; } @@ -98,7 +98,7 @@ public function createVaultSetupToken(bool $card = false): array $body = $response->getBody(); } $result = json_decode((string)$body, true, 512, JSON_THROW_ON_ERROR); - } catch (ApiException|JsonException $e) { + } catch (ApiException | JsonException $e) { $result = []; } @@ -215,7 +215,7 @@ public function createVaultPaymentToken(string $setupToken): array $body = $response->getBody(); } $result = json_decode((string)$body, true, 512, JSON_THROW_ON_ERROR); - } catch (ApiException|JsonException $e) { + } catch (ApiException | JsonException $e) { $result = []; } @@ -242,7 +242,7 @@ public function getVaultPaymentTokens(string $paypalCustomerId): array $body = $response->getBody(); } $result = json_decode((string)$body, true, 512, JSON_THROW_ON_ERROR); - } catch (ApiException|JsonException $e) { + } catch (ApiException | JsonException $e) { $this->getServiceFromContainer(Logger::class) ->log('error', __CLASS__ . ' ' . __FUNCTION__ . ' : ' . $e->getMessage()); $result = []; diff --git a/src/Core/PayPalDefinitions.php b/src/Core/PayPalDefinitions.php index cadffc370..e880f1b3c 100644 --- a/src/Core/PayPalDefinitions.php +++ b/src/Core/PayPalDefinitions.php @@ -519,7 +519,7 @@ public static function isPayPalVaultingPossible(string $paymentId, string $paypa */ public static function isDeprecatedPayment(string $paymentId): bool { - if ( isset(self::PAYPAL_DEFINTIONS[$paymentId]['deprecated']) && self::PAYPAL_DEFINTIONS[$paymentId]['deprecated'] === true ) { + if (isset(self::PAYPAL_DEFINTIONS[$paymentId]['deprecated']) && self::PAYPAL_DEFINTIONS[$paymentId]['deprecated'] === true) { return true; } return false; diff --git a/src/Service/ModuleSettings.php b/src/Service/ModuleSettings.php index bcd6ba26c..5ed7b25cb 100755 --- a/src/Service/ModuleSettings.php +++ b/src/Service/ModuleSettings.php @@ -417,8 +417,7 @@ public function getShopName(): string $shop = Registry::getConfig()->getActiveShop(); if (isset($shop->oxshops__oxname->rawValue)) { $value = $shop->oxshops__oxname->rawValue; - } - elseif(isset($shop->oxshops__oxname->value)) { + } elseif (isset($shop->oxshops__oxname->value)) { $value = $shop->oxshops__oxname->value; } return $value; @@ -434,8 +433,7 @@ public function getInfoEMail(): string $shop = Registry::getConfig()->getActiveShop(); if (isset($shop->oxshops__oxinfoemail->rawValue)) { $value = $shop->oxshops__oxinfoemail->rawValue; - } - elseif(isset($shop->oxshops__oxinfoemail->value)) { + } elseif (isset($shop->oxshops__oxinfoemail->value)) { $value = $shop->oxshops__oxinfoemail->value; } return $value; @@ -633,7 +631,7 @@ public function isVaultingAllowedForPayment(string $paymentId): bool $paymentEnabled = (bool)$payment->oxpayments__oxactive->value; $vaultingType = PayPalDefinitions::getPayPalDefinitions()[$paymentId]["vaultingtype"]; - $session = Registry::getSession(); + $session = Registry::getSession(); $actShipSet = $session->getVariable('sShipSet'); $basket = $session->getBasket(); $user = $session->getUser(); diff --git a/src/Service/Payment.php b/src/Service/Payment.php index 36aab5013..754c9ff16 100644 --- a/src/Service/Payment.php +++ b/src/Service/Payment.php @@ -305,7 +305,7 @@ public function doCapturePayPalOrder( } elseif ($payPalOrder->status !== Constants::PAYPAL_STATUS_COMPLETED) { $request = new OrderCaptureRequest(); //order number must be resolved before order patching - if (!$order->hasOrderNumber()){ + if (!$order->hasOrderNumber()) { $order->setOrderNumber(); } @@ -808,7 +808,7 @@ public function getCustomIdParameter(?EshopModelOrder $order): string $module->load(Module::MODULE_ID); $orderNumber = $order instanceof EshopModelOrder ? $order->getFieldData('oxordernr') : null; - if($moduleSettings->isCustomIdSchemaStructural()){ + if ($moduleSettings->isCustomIdSchemaStructural()) { $customID = [ 'oxordernr' => $orderNumber, 'moduleVersion' => $module->getInfo('version'), diff --git a/src/Service/StaticContent.php b/src/Service/StaticContent.php index 41f49d21c..6e70634f4 100644 --- a/src/Service/StaticContent.php +++ b/src/Service/StaticContent.php @@ -115,7 +115,8 @@ protected function createPaymentMethod(string $paymentId, array $definitions): v * @return void * @throws \Exception */ - protected function deactivatePaymentMethod(string $paymentId) : void { + protected function deactivatePaymentMethod(string $paymentId): void + { $paymentModel = oxNew(EshopModelPayment::class); if ($paymentModel->load($paymentId)) { $paymentModel->oxpayments__oxactive = new Field(false); diff --git a/src/Traits/AccountControllerTrait.php b/src/Traits/AccountControllerTrait.php index 51dfea570..e3782bfc8 100644 --- a/src/Traits/AccountControllerTrait.php +++ b/src/Traits/AccountControllerTrait.php @@ -1,30 +1,30 @@ -getRequestEscapedParameter("paymentTokenId"); - $vaultingService = Registry::get(ServiceFactory::class)->getVaultingService(); - - if (!$vaultingService->deleteVaultedPayment($paymentTokenId)) { - Registry::getUtilsView()->addErrorToDisplay( - Registry::getLang()->translateString('OSC_PAYPAL_DELETE_FAILED'), - false, - true - ); - } - } -} +getRequestEscapedParameter("paymentTokenId"); + $vaultingService = Registry::get(ServiceFactory::class)->getVaultingService(); + + if (!$vaultingService->deleteVaultedPayment($paymentTokenId)) { + Registry::getUtilsView()->addErrorToDisplay( + Registry::getLang()->translateString('OSC_PAYPAL_DELETE_FAILED'), + false, + true + ); + } + } +}