From 6ead436f23979384eba60cf2331bcf7b2fccf021 Mon Sep 17 00:00:00 2001 From: Matt75 <5262628+Matt75@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:25:03 +0200 Subject: [PATCH] Fix rebase --- config/common.yml | 2 +- .../AdminAjaxPrestashopCheckoutController.php | 8 +- src/Adapter/LinkAdapter.php | 7 +- src/Cart/CartInterface.php | 45 --------- src/Cart/CartRepositoryInterface.php | 36 ------- .../CheckoutEventSubscriber.php | 1 - src/Dispatcher/OrderDispatcher.php | 3 - src/Environment/Env.php | 16 +++- src/Http/MaaslandHttpClient.php | 3 +- ...eatePayPalOrderPayloadBuilderInterface.php | 38 -------- src/Presenter/Order/OrderPresenter.php | 2 +- src/Provider/PaymentMethodLogoProvider.php | 2 - src/Repository/PsAccountRepository.php | 1 - src/ShopContext.php | 16 ++-- .../DTO/CreatePayPalOrderRequestTest.php | 96 ------------------- 15 files changed, 28 insertions(+), 248 deletions(-) delete mode 100644 src/Cart/CartInterface.php delete mode 100644 src/Cart/CartRepositoryInterface.php delete mode 100644 src/PayPal/Order/CreatePayPalOrderPayloadBuilderInterface.php delete mode 100644 tests/Unit/PayPal/Order/DTO/CreatePayPalOrderRequestTest.php diff --git a/config/common.yml b/config/common.yml index 36f037929..67f064daf 100644 --- a/config/common.yml +++ b/config/common.yml @@ -136,7 +136,7 @@ services: class: 'PrestaShop\Module\PrestashopCheckout\ShopContext' public: true arguments: - - '@PrestaShop\Module\PrestashopCheckout\Environment\PaymentEnv' + - '@PrestaShop\Module\PrestashopCheckout\Environment\Env' PrestaShop\Module\PrestashopCheckout\Shop\ShopProvider: class: 'PrestaShop\Module\PrestashopCheckout\Shop\ShopProvider' diff --git a/controllers/admin/AdminAjaxPrestashopCheckoutController.php b/controllers/admin/AdminAjaxPrestashopCheckoutController.php index 78f76a34e..5e12b256f 100755 --- a/controllers/admin/AdminAjaxPrestashopCheckoutController.php +++ b/controllers/admin/AdminAjaxPrestashopCheckoutController.php @@ -267,10 +267,10 @@ private function updateExpressCheckoutSettings() $maaslandHttpClient->updateSettings([ 'settings' => [ - 'cb' => (bool)$configuration->get('PS_CHECKOUT_CARD_PAYMENT_ENABLED'), - 'express_in_product' => (bool)$ecConfiguration->isProductPageEnabled(), - 'express_in_cart' => (bool)$ecConfiguration->isOrderPageEnabled(), - 'express_in_checkout' => (bool)$ecConfiguration->isCheckoutPageEnabled(), + 'cb' => (bool) $configuration->get('PS_CHECKOUT_CARD_PAYMENT_ENABLED'), + 'express_in_product' => (bool) $ecConfiguration->isProductPageEnabled(), + 'express_in_cart' => (bool) $ecConfiguration->isOrderPageEnabled(), + 'express_in_checkout' => (bool) $ecConfiguration->isCheckoutPageEnabled(), ], ]); } diff --git a/src/Adapter/LinkAdapter.php b/src/Adapter/LinkAdapter.php index 41f03a312..8a678f7d5 100644 --- a/src/Adapter/LinkAdapter.php +++ b/src/Adapter/LinkAdapter.php @@ -20,9 +20,6 @@ namespace PrestaShop\Module\PrestashopCheckout\Adapter; -use PrestaShop\Module\PrestashopCheckout\Environment\PaymentEnv; -use PrestaShop\Module\PrestashopCheckout\ShopContext; - /** * Link adapter */ @@ -53,14 +50,12 @@ public function __construct(\Link $link = null) * @param array $params * * @return string - * - * @throws \PrestaShopException */ public function getAdminLink($controller, $withToken = true, $sfRouteParams = [], $params = []) { $shop = \Context::getContext()->shop; - if ((new ShopContext(new PaymentEnv()))->isShop17()) { + if (version_compare(_PS_VERSION_, '1.7.0.0', '>=')) { $adminLink = $this->link->getAdminLink($controller, $withToken, $sfRouteParams, $params); if ($shop->virtual_uri !== '') { diff --git a/src/Cart/CartInterface.php b/src/Cart/CartInterface.php deleted file mode 100644 index 1c635a8b0..000000000 --- a/src/Cart/CartInterface.php +++ /dev/null @@ -1,45 +0,0 @@ - - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 - */ - -namespace PrestaShop\Module\PrestashopCheckout\Cart; - -use PrestaShop\Module\PrestashopCheckout\PayPal\Order\DTO\PurchaseUnitRequest; - -interface CartInterface -{ - /** - * @return int - */ - public function getId(); - - /** - * @return string - */ - public function getCurrencyCode(); - - public function getCustomer(); - - public function getBillingAddress(); - - /** - * @return PurchaseUnitRequest[] - */ - public function getPurchaseUnits(); -} diff --git a/src/Cart/CartRepositoryInterface.php b/src/Cart/CartRepositoryInterface.php deleted file mode 100644 index f38d7e206..000000000 --- a/src/Cart/CartRepositoryInterface.php +++ /dev/null @@ -1,36 +0,0 @@ - - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 - */ - -namespace PrestaShop\Module\PrestashopCheckout\Cart; - -use PrestaShop\Module\PrestashopCheckout\Cart\Exception\CartNotFoundException; -use PrestaShop\Module\PrestashopCheckout\Cart\ValueObject\CartId; - -interface CartRepositoryInterface -{ - /** - * @param CartId $cartId - * - * @return CartInterface - * - * @throws CartNotFoundException - */ - public function getCartById(CartId $cartId); -} diff --git a/src/Checkout/EventSubscriber/CheckoutEventSubscriber.php b/src/Checkout/EventSubscriber/CheckoutEventSubscriber.php index 9f869a390..5443ec59a 100644 --- a/src/Checkout/EventSubscriber/CheckoutEventSubscriber.php +++ b/src/Checkout/EventSubscriber/CheckoutEventSubscriber.php @@ -43,7 +43,6 @@ class CheckoutEventSubscriber implements EventSubscriberInterface { - /** * @var CommandBusInterface */ diff --git a/src/Dispatcher/OrderDispatcher.php b/src/Dispatcher/OrderDispatcher.php index 6c7b3009c..f88d4e50c 100644 --- a/src/Dispatcher/OrderDispatcher.php +++ b/src/Dispatcher/OrderDispatcher.php @@ -20,9 +20,7 @@ namespace PrestaShop\Module\PrestashopCheckout\Dispatcher; -use Module; use PrestaShop\Module\PrestashopCheckout\Event\EventDispatcherInterface; -use PrestaShop\Module\PrestashopCheckout\Event\SymfonyEventDispatcherAdapter; use PrestaShop\Module\PrestashopCheckout\Exception\PsCheckoutException; use PrestaShop\Module\PrestashopCheckout\PayPal\Order\Event\PayPalOrderApprovalReversedEvent; use PrestaShop\Module\PrestashopCheckout\PayPal\Order\Event\PayPalOrderApprovedEvent; @@ -38,7 +36,6 @@ use PrestaShop\Module\PrestashopCheckout\PayPal\PaymentToken\Event\PaymentTokenDeletedEvent; use PrestaShop\Module\PrestashopCheckout\PayPal\PaymentToken\Event\PaymentTokenDeletionInitiatedEvent; use PrestaShop\Module\PrestashopCheckout\PayPal\PayPalConfiguration; -use Ps_checkout; use Psr\Log\LoggerInterface; class OrderDispatcher implements DispatcherInterface diff --git a/src/Environment/Env.php b/src/Environment/Env.php index 2e113c5db..20264dd5c 100644 --- a/src/Environment/Env.php +++ b/src/Environment/Env.php @@ -22,7 +22,6 @@ use PrestaShop\Module\PrestashopCheckout\PayPal\Mode; use PrestaShop\Module\PrestashopCheckout\PayPal\PayPalConfiguration; -use Ps_checkout; /** * Get the current environment used: prod or test // sandbox or live @@ -140,7 +139,6 @@ public function getPaymentApiUrl() return $this->getEnv('PAYMENT_API_URL_LIVE'); } - /** * @return string */ @@ -164,4 +162,18 @@ public function getPaypalClientId() return $this->getEnv('PAYPAL_CLIENT_ID_LIVE'); } + + /** + * @return string + */ + public function getBnCode() + { + $bnCode = $this->getEnv('PAYPAL_BN_CODE'); + + if (empty($bnCode)) { + $bnCode = 'PrestaShop_Cart_PSXO_PSDownload'; + } + + return $bnCode; + } } diff --git a/src/Http/MaaslandHttpClient.php b/src/Http/MaaslandHttpClient.php index 9efe83e93..f37f93278 100644 --- a/src/Http/MaaslandHttpClient.php +++ b/src/Http/MaaslandHttpClient.php @@ -25,9 +25,7 @@ use Http\Client\Exception\NetworkException; use Http\Client\Exception\RequestException; use Http\Client\Exception\TransferException; -use PrestaShop\Module\PrestashopCheckout\Configuration\PrestaShopConfiguration; use PrestaShop\Module\PrestashopCheckout\Exception\PayPalException; -use PrestaShop\Module\PrestashopCheckout\ExpressCheckout\ExpressCheckoutConfiguration; use PrestaShop\Module\PrestashopCheckout\PayPalError; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; @@ -147,6 +145,7 @@ public function getShopSignature(array $payload, array $options = []) * Used to notify PSL on settings update * * @return array + * * @throws PayPalException */ public function updateSettings(array $payload) diff --git a/src/PayPal/Order/CreatePayPalOrderPayloadBuilderInterface.php b/src/PayPal/Order/CreatePayPalOrderPayloadBuilderInterface.php deleted file mode 100644 index 6c8dc8cb5..000000000 --- a/src/PayPal/Order/CreatePayPalOrderPayloadBuilderInterface.php +++ /dev/null @@ -1,38 +0,0 @@ - - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 - */ - -namespace PrestaShop\Module\PrestashopCheckout\PayPal\Order; - -use PrestaShop\Module\PrestashopCheckout\Cart\CartInterface; -use PrestaShop\Module\PrestashopCheckout\PayPal\Order\DTO\CreatePayPalOrderRequest; -use PrestaShop\Module\PrestashopCheckout\PayPal\PaymentToken\ValueObject\PaymentTokenId; - -interface CreatePayPalOrderPayloadBuilderInterface -{ - /** - * @param CartInterface $cart - * @param string $fundingSource - * @param bool $vault - * @param PaymentTokenId|null $vaultId - * - * @return CreatePayPalOrderRequest - */ - public function build(CartInterface $cart, $fundingSource, $vault = false, $vaultId = null); -} diff --git a/src/Presenter/Order/OrderPresenter.php b/src/Presenter/Order/OrderPresenter.php index 02995528c..31d80ad29 100644 --- a/src/Presenter/Order/OrderPresenter.php +++ b/src/Presenter/Order/OrderPresenter.php @@ -280,7 +280,7 @@ private function getTotal() continue; } - $total += (float)$purchase['amount']['value']; + $total += (float) $purchase['amount']['value']; $currency = $purchase['amount']['currency_code']; } diff --git a/src/Provider/PaymentMethodLogoProvider.php b/src/Provider/PaymentMethodLogoProvider.php index d5e1adb58..8df95a5a3 100644 --- a/src/Provider/PaymentMethodLogoProvider.php +++ b/src/Provider/PaymentMethodLogoProvider.php @@ -20,8 +20,6 @@ namespace PrestaShop\Module\PrestashopCheckout\Provider; -use Ps_checkout; - class PaymentMethodLogoProvider { /** diff --git a/src/Repository/PsAccountRepository.php b/src/Repository/PsAccountRepository.php index e5e605220..e288b4bc1 100644 --- a/src/Repository/PsAccountRepository.php +++ b/src/Repository/PsAccountRepository.php @@ -21,7 +21,6 @@ namespace PrestaShop\Module\PrestashopCheckout\Repository; use Exception; -use PrestaShop\Module\PrestashopCheckout\Configuration\PrestaShopConfiguration; use PrestaShop\Module\PrestashopCheckout\Entity\PsAccount; use PrestaShop\PsAccountsInstaller\Installer\Facade\PsAccounts; diff --git a/src/ShopContext.php b/src/ShopContext.php index 15ee8f9e3..20e992c4f 100644 --- a/src/ShopContext.php +++ b/src/ShopContext.php @@ -20,7 +20,7 @@ namespace PrestaShop\Module\PrestashopCheckout; -use PrestaShop\Module\PrestashopCheckout\Environment\PaymentEnv; +use PrestaShop\Module\PrestashopCheckout\Environment\Env; /** * Get the shop context @@ -28,13 +28,13 @@ class ShopContext { /** - * @var PaymentEnv + * @var Env */ - private $paymentEnv; + private $env; - public function __construct(PaymentEnv $paymentEnv) + public function __construct(Env $env) { - $this->paymentEnv = $paymentEnv; + $this->env = $env; } /** @@ -55,11 +55,7 @@ public function isReady() */ public function getBnCode() { - if ($this->isReady()) { // if on ready send an empty bn-code - return ''; - } - - return $this->paymentEnv->getBnCode(); + return $this->env->getBnCode(); } public function isShop17() diff --git a/tests/Unit/PayPal/Order/DTO/CreatePayPalOrderRequestTest.php b/tests/Unit/PayPal/Order/DTO/CreatePayPalOrderRequestTest.php deleted file mode 100644 index ba00a0906..000000000 --- a/tests/Unit/PayPal/Order/DTO/CreatePayPalOrderRequestTest.php +++ /dev/null @@ -1,96 +0,0 @@ - - * @copyright Since 2007 PrestaShop SA and Contributors - * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 - */ - -namespace Tests\Unit\PayPal\Order\DTO; - -use PHPUnit\Framework\TestCase; -use PrestaShop\Module\PrestashopCheckout\PayPal\Order\DTO\AmountWithBreakdown; -use PrestaShop\Module\PrestashopCheckout\PayPal\Order\DTO\CreatePayPalOrderRequest; -use PrestaShop\Module\PrestashopCheckout\PayPal\Order\DTO\PaymentSourceRequest; -use PrestaShop\Module\PrestashopCheckout\PayPal\Order\DTO\PayPalRequest; -use PrestaShop\Module\PrestashopCheckout\PayPal\Order\DTO\PayPalWalletExperienceContext; -use PrestaShop\Module\PrestashopCheckout\PayPal\Order\DTO\PurchaseUnitRequest; - -class CreatePayPalOrderRequestTest extends TestCase -{ - /** - * @var CreatePayPalOrderRequest - */ - private $createPayPalOrderRequest; - - public function setUp(): void - { - $this->createPayPalOrderRequest = new CreatePayPalOrderRequest(); - $this->createPayPalOrderRequest->setIntent('CAPTURE'); - $this->createPayPalOrderRequest->setPurchaseUnits($this->createPurchaseUnits()); - $this->createPayPalOrderRequest->setPaymentSource($this->createPaymentSource()); - } - - public function testGetIntent() - { - $this->assertEquals('CAPTURE', $this->createPayPalOrderRequest->getIntent()); - } - - public function testGetPurchaseUnits() - { - $purchaseUnits = $this->createPayPalOrderRequest->getPurchaseUnits(); - $this->assertEquals(1, count($purchaseUnits)); - $this->assertInstanceOf(PurchaseUnitRequest::class, $purchaseUnits[0]); - } - - public function testGetPaymentSource() - { - $this->assertInstanceOf(PaymentSourceRequest::class, $this->createPayPalOrderRequest->getPaymentSource()); - } - - /** - * @return PurchaseUnitRequest[] - */ - private function createPurchaseUnits() - { - $purchaseUnits = []; - $amountWithBreakdown = new AmountWithBreakdown(); - $amountWithBreakdown->setValue('100.00'); - $amountWithBreakdown->setCurrencyCode('EUR'); - $purchaseUnitRequest = new PurchaseUnitRequest(); - $purchaseUnitRequest->setAmount($amountWithBreakdown); - $purchaseUnits[] = $purchaseUnitRequest; - - return $purchaseUnits; - } - - /** - * @return PaymentSourceRequest - */ - private function createPaymentSource() - { - $paymentSource = new PaymentSourceRequest(); - $paypal = new PayPalRequest(); - $experienceContext = new PayPalWalletExperienceContext(); - $experienceContext->setBrandName('PrestaShop'); - $experienceContext->setLandingPage('LOGIN'); - $experienceContext->setReturnUrl('https://www.prestashop.com/return'); - $experienceContext->setCancelUrl('https://www.prestashop.com/cancel'); - $paypal->setExperienceContext($experienceContext); - $paymentSource->setPaypal($paypal); - - return $paymentSource; - } -}