From efb4e76140954398497e3278c68c488f335c4b7b Mon Sep 17 00:00:00 2001 From: Laurynas Date: Tue, 28 May 2024 16:14:20 +0300 Subject: [PATCH 01/20] Added google pay to payment option list --- .../FundingSourceCollectionBuilder.php | 5 +++ .../FundingSourceTranslationProvider.php | 1 + views/img/google_pay.svg | 37 +++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 views/img/google_pay.svg diff --git a/src/FundingSource/FundingSourceCollectionBuilder.php b/src/FundingSource/FundingSourceCollectionBuilder.php index 762d7afda..1a12bb331 100644 --- a/src/FundingSource/FundingSourceCollectionBuilder.php +++ b/src/FundingSource/FundingSourceCollectionBuilder.php @@ -107,6 +107,11 @@ public function create() $blik->setIsEnabled($this->configuration->isEnabled('blik')); $blik->setCountries($this->eligibilityConstraint->getCountries('blik')); + // Google pay + $blik = new FundingSourceEntity('google_pay'); + $blik->setPosition($this->configuration->getPosition('google_pay', 11)); + $blik->setIsEnabled($this->configuration->isEnabled('google_pay')); + return [$paypal, $paylater, $card, $bancontact, $eps, $giropay, $ideal, $mybank, $p24, $blik]; } } diff --git a/src/FundingSource/FundingSourceTranslationProvider.php b/src/FundingSource/FundingSourceTranslationProvider.php index e1deeafb9..9b85066f9 100644 --- a/src/FundingSource/FundingSourceTranslationProvider.php +++ b/src/FundingSource/FundingSourceTranslationProvider.php @@ -64,6 +64,7 @@ public function __construct(Module $module) 'maxima' => 'Maxima', 'mercadopago' => 'Mercado Pago', 'sepa' => 'SEPA', + 'google_pay' => 'Google Pay', 'token' => $module->l('Pay with %s', 'fundingsourcetranslationprovider'), ]; diff --git a/views/img/google_pay.svg b/views/img/google_pay.svg new file mode 100644 index 000000000..713044919 --- /dev/null +++ b/views/img/google_pay.svg @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + From b918fb28667f54e3f8e59116166cfb814d01d3b3 Mon Sep 17 00:00:00 2001 From: Laurynas Date: Wed, 29 May 2024 14:05:32 +0300 Subject: [PATCH 02/20] Fixed funding source collection builder --- src/FundingSource/FundingSourceCollectionBuilder.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/FundingSource/FundingSourceCollectionBuilder.php b/src/FundingSource/FundingSourceCollectionBuilder.php index 1a12bb331..a27b623e1 100644 --- a/src/FundingSource/FundingSourceCollectionBuilder.php +++ b/src/FundingSource/FundingSourceCollectionBuilder.php @@ -108,10 +108,10 @@ public function create() $blik->setCountries($this->eligibilityConstraint->getCountries('blik')); // Google pay - $blik = new FundingSourceEntity('google_pay'); - $blik->setPosition($this->configuration->getPosition('google_pay', 11)); - $blik->setIsEnabled($this->configuration->isEnabled('google_pay')); + $googlePay = new FundingSourceEntity('google_pay'); + $googlePay->setPosition($this->configuration->getPosition('google_pay', 11)); + $googlePay->setIsEnabled($this->configuration->isEnabled('google_pay')); - return [$paypal, $paylater, $card, $bancontact, $eps, $giropay, $ideal, $mybank, $p24, $blik]; + return [$paypal, $paylater, $card, $bancontact, $eps, $giropay, $ideal, $mybank, $p24, $blik, $googlePay]; } } From 98cf34a4be6a7216ec05e1374fdbf9d8b0c61485 Mon Sep 17 00:00:00 2001 From: Laurynas Date: Wed, 29 May 2024 14:10:56 +0300 Subject: [PATCH 03/20] Added country list for GPay --- src/FundingSource/FundingSourceCollectionBuilder.php | 1 + src/FundingSource/FundingSourceEligibilityConstraint.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/FundingSource/FundingSourceCollectionBuilder.php b/src/FundingSource/FundingSourceCollectionBuilder.php index a27b623e1..96dcbe195 100644 --- a/src/FundingSource/FundingSourceCollectionBuilder.php +++ b/src/FundingSource/FundingSourceCollectionBuilder.php @@ -111,6 +111,7 @@ public function create() $googlePay = new FundingSourceEntity('google_pay'); $googlePay->setPosition($this->configuration->getPosition('google_pay', 11)); $googlePay->setIsEnabled($this->configuration->isEnabled('google_pay')); + $googlePay->setCountries($this->eligibilityConstraint->getCountries('google_pay')); return [$paypal, $paylater, $card, $bancontact, $eps, $giropay, $ideal, $mybank, $p24, $blik, $googlePay]; } diff --git a/src/FundingSource/FundingSourceEligibilityConstraint.php b/src/FundingSource/FundingSourceEligibilityConstraint.php index f6284123e..18a94aff2 100644 --- a/src/FundingSource/FundingSourceEligibilityConstraint.php +++ b/src/FundingSource/FundingSourceEligibilityConstraint.php @@ -41,6 +41,7 @@ public function getCountries($fundingSourceName) 'mybank' => ['IT'], 'p24' => ['PL'], 'paylater' => ['FR', 'GB', 'US', 'ES', 'IT'], + 'google_pay' => ['AU', 'AT', 'BE', 'BG', 'CA', 'CN', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE', 'IT', 'LV', 'LI', 'LT', 'LU', 'MK', 'MT', 'NL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'GB', 'US'], ]; return $countries[$fundingSourceName]; From 62fa60db87ec328a1dfd632e6c4266d7726c740a Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Tue, 25 Jun 2024 15:28:03 +0300 Subject: [PATCH 04/20] Replaced gpay logo with borderless one --- views/img/google_pay.svg | 48 +++++++++------------------------------- 1 file changed, 11 insertions(+), 37 deletions(-) diff --git a/views/img/google_pay.svg b/views/img/google_pay.svg index 713044919..3ddf1e493 100644 --- a/views/img/google_pay.svg +++ b/views/img/google_pay.svg @@ -1,37 +1,11 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + From f5e80587c75767ac641d5bb07cbc0dd7ef3f6686 Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Thu, 27 Jun 2024 13:17:01 +0300 Subject: [PATCH 05/20] Added google pay component to PayPal sdk config --- config/common.yml | 1 + .../FundingSourceEligibilityConstraint.php | 16 +++++++ .../Sdk/PayPalSdkConfigurationBuilder.php | 42 +++++++++++++++---- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/config/common.yml b/config/common.yml index 1d1b8e545..b7a5304e0 100644 --- a/config/common.yml +++ b/config/common.yml @@ -237,6 +237,7 @@ services: - '@PrestaShop\Module\PrestashopCheckout\ShopContext' - '@PrestaShop\Module\PrestashopCheckout\Context\PrestaShopContext' - '@ps_checkout.logger' + - '@PrestaShop\Module\PrestashopCheckout\FundingSource\FundingSourceEligibilityConstraint' PrestaShop\Module\PrestashopCheckout\Presenter\Store\Modules\PaypalModule: class: 'PrestaShop\Module\PrestashopCheckout\Presenter\Store\Modules\PaypalModule' diff --git a/src/FundingSource/FundingSourceEligibilityConstraint.php b/src/FundingSource/FundingSourceEligibilityConstraint.php index 18a94aff2..e107f518f 100644 --- a/src/FundingSource/FundingSourceEligibilityConstraint.php +++ b/src/FundingSource/FundingSourceEligibilityConstraint.php @@ -46,4 +46,20 @@ public function getCountries($fundingSourceName) return $countries[$fundingSourceName]; } + + /** + * Get eligible currencies for PayPal funding sources + * + * @param string $fundingSourceName + * + * @return array + */ + public function getCurrencies($fundingSourceName) + { + $currencies = [ + 'google_pay' => ['AUD', 'BRL', 'CAD', 'CHF', 'CZK', 'DKK', 'EUR', 'GBP', 'HKD', 'HUF', 'ILS', 'JPY', 'MXN', 'NOK', 'NZD', 'PHP', 'PLN', 'SEK', 'SGD', 'THB', 'TWD', 'USD'], + ]; + + return $currencies[$fundingSourceName]; + } } diff --git a/src/PayPal/Sdk/PayPalSdkConfigurationBuilder.php b/src/PayPal/Sdk/PayPalSdkConfigurationBuilder.php index 87fcbdc25..8e2394147 100644 --- a/src/PayPal/Sdk/PayPalSdkConfigurationBuilder.php +++ b/src/PayPal/Sdk/PayPalSdkConfigurationBuilder.php @@ -27,11 +27,13 @@ use PrestaShop\Module\PrestashopCheckout\Environment\Env; use PrestaShop\Module\PrestashopCheckout\ExpressCheckout\ExpressCheckoutConfiguration; use PrestaShop\Module\PrestashopCheckout\FundingSource\FundingSourceConfigurationRepository; +use PrestaShop\Module\PrestashopCheckout\FundingSource\FundingSourceEligibilityConstraint; use PrestaShop\Module\PrestashopCheckout\PayPal\OAuth\Query\GetPayPalGetUserIdTokenQuery; use PrestaShop\Module\PrestashopCheckout\PayPal\OAuth\Query\GetPayPalGetUserIdTokenQueryResult; use PrestaShop\Module\PrestashopCheckout\PayPal\PayPalConfiguration; use PrestaShop\Module\PrestashopCheckout\PayPal\PayPalPayLaterConfiguration; use PrestaShop\Module\PrestashopCheckout\ShopContext; +use PrestaShop\PrestaShop\Adapter\Shop\Context; use Psr\Log\LoggerInterface; /** @@ -78,9 +80,14 @@ class PayPalSdkConfigurationBuilder * @var Env */ private $env; + /** + * @var FundingSourceEligibilityConstraint + */ + private $fundingSourceEligibilityConstraint; /** * @param \Ps_checkout $module + * @param Env $env * @param PayPalConfiguration $configuration * @param PayPalPayLaterConfiguration $payLaterConfiguration * @param FundingSourceConfigurationRepository $fundingSourceConfigurationRepository @@ -88,17 +95,19 @@ class PayPalSdkConfigurationBuilder * @param ShopContext $shopContext * @param PrestaShopContext $prestaShopContext * @param LoggerInterface $logger + * @param FundingSourceEligibilityConstraint $fundingSourceEligibilityConstraint */ public function __construct( - \Ps_checkout $module, - Env $env, - PayPalConfiguration $configuration, - PayPalPayLaterConfiguration $payLaterConfiguration, + \Ps_checkout $module, + Env $env, + PayPalConfiguration $configuration, + PayPalPayLaterConfiguration $payLaterConfiguration, FundingSourceConfigurationRepository $fundingSourceConfigurationRepository, - ExpressCheckoutConfiguration $expressCheckoutConfiguration, - ShopContext $shopContext, - PrestaShopContext $prestaShopContext, - LoggerInterface $logger + ExpressCheckoutConfiguration $expressCheckoutConfiguration, + ShopContext $shopContext, + PrestaShopContext $prestaShopContext, + LoggerInterface $logger, + FundingSourceEligibilityConstraint $fundingSourceEligibilityConstraint ) { $this->configuration = $configuration; $this->payLaterConfiguration = $payLaterConfiguration; @@ -109,6 +118,7 @@ public function __construct( $this->prestaShopContext = $prestaShopContext; $this->logger = $logger; $this->env = $env; + $this->fundingSourceEligibilityConstraint = $fundingSourceEligibilityConstraint; } /** @@ -133,6 +143,10 @@ public function buildConfiguration() $components[] = 'messages'; } + if ($this->shouldIncludeGooglePayComponent()) { + $components[] = 'googlepay'; + } + $params = [ 'clientId' => $this->env->getPaypalClientId(), 'merchantId' => $this->configuration->getMerchantId(), @@ -472,4 +486,16 @@ private function getEligibleAlternativePaymentMethods() return $fundingSourcesEnabled; } + + private function shouldIncludeGooglePayComponent() + { + $context = \Context::getContext(); + $country = $this->getCountry(); + $fundingSource = $this->fundingSourceConfigurationRepository->get('google_pay'); + + return $fundingSource && $fundingSource['active'] + && \Configuration::get('PS_CHECKOUT_GOOGLE_PAY', false) === '1' + && in_array($country, $this->fundingSourceEligibilityConstraint->getCountries('google_pay'), true) + && in_array($context->currency->iso_code, $this->fundingSourceEligibilityConstraint->getCurrencies('google_pay'), true); + } } From 8c9fdad99ffa832f3f77e30a904fe88960b24260 Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Fri, 28 Jun 2024 14:52:37 +0300 Subject: [PATCH 06/20] Added custom mark for Google Pay --- ps_checkout.php | 13 +++++++++---- src/FundingSource/FundingSourcePresenter.php | 12 +++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/ps_checkout.php b/ps_checkout.php index 0720d6294..06b754318 100755 --- a/ps_checkout.php +++ b/ps_checkout.php @@ -960,18 +960,22 @@ public function hookActionFrontControllerSetMedia() $fundingSourcesSorted = []; $payWithTranslations = []; $isCardAvailable = false; - $vaultedPaymentMarks = []; + $customMarks = []; foreach ($fundingSourceProvider->getSavedTokens($this->context->customer->id) as $fundingSource) { $fundingSourcesSorted[] = $fundingSource->name; $payWithTranslations[$fundingSource->name] = $fundingSource->label; - $vaultedPaymentMarks[$fundingSource->name] = $fundingSource->customMark; + $customMarks[$fundingSource->name] = $fundingSource->customMark; } foreach ($fundingSourceProvider->getAll() as $fundingSource) { $fundingSourcesSorted[] = $fundingSource->name; $payWithTranslations[$fundingSource->name] = $fundingSource->label; + if ($fundingSource->customMark !== null) { + $customMarks[$fundingSource->name] = $fundingSource->customMark; + } + if ('card' === $fundingSource->name) { $isCardAvailable = $fundingSource->isEnabled; } @@ -1005,7 +1009,7 @@ public function hookActionFrontControllerSetMedia() $this->name . 'LoaderImage' => $this->getPathUri() . 'views/img/loader.svg', $this->name . 'PayPalButtonConfiguration' => $payPalConfiguration->getButtonConfiguration(), $this->name . 'CardFundingSourceImg' => Media::getMediaPath(_PS_MODULE_DIR_ . $this->name . '/views/img/payment-cards.png'), - $this->name . 'VaultedPaymentMarks' => $vaultedPaymentMarks, + $this->name . 'CustomMarks' => $customMarks, $this->name . 'CardLogos' => [ 'AMEX' => Media::getMediaPath(_PS_MODULE_DIR_ . $this->name . '/views/img/amex.svg'), 'CB_NATIONALE' => Media::getMediaPath(_PS_MODULE_DIR_ . $this->name . '/views/img/cb.svg'), @@ -1102,7 +1106,8 @@ public function hookActionFrontControllerSetMedia() if (method_exists($this->context->controller, 'registerJavascript')) { $this->context->controller->registerJavascript( $this->name . 'Front', - $this->getPathUri() . 'views/js/front.js?version=' . $version->getSemVersion(), + 'https://fo-sdk.laurynas-sedys-ext-mytun.prestashop.name/ps_checkout-fo-sdk.js', +// $this->getPathUri() . 'views/js/front.js?version=' . $version->getSemVersion(), [ 'position' => 'bottom', 'priority' => 201, diff --git a/src/FundingSource/FundingSourcePresenter.php b/src/FundingSource/FundingSourcePresenter.php index addad1d1d..d6902b3ca 100644 --- a/src/FundingSource/FundingSourcePresenter.php +++ b/src/FundingSource/FundingSourcePresenter.php @@ -44,8 +44,11 @@ class FundingSourcePresenter * @param FundingSourceTranslationProvider $translation * @param CountryRepository $country */ - public function __construct(FundingSourceTranslationProvider $translation, CountryRepository $country, PaymentMethodLogoProvider $paymentMethodLogoProvider) - { + public function __construct( + FundingSourceTranslationProvider $translation, + CountryRepository $country, + PaymentMethodLogoProvider $paymentMethodLogoProvider + ) { $this->translation = $translation; $this->country = $country; $this->paymentMethodLogoProvider = $paymentMethodLogoProvider; @@ -67,7 +70,10 @@ public function present($entity, $isAdmin) $entity->getPosition(), $isAdmin ? $this->country->getCountryNames($entity->getCountries()) : $entity->getCountries(), $entity->getIsEnabled(), - $entity->getIsToggleable() + $entity->getIsToggleable(), + null, + null, + $name === 'google_pay' ? $this->paymentMethodLogoProvider->getLogoByPaymentSource([$name => []]) : null ); } From ba89939110f9c6f148e675dd4c8b38634ec3466b Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Fri, 5 Jul 2024 15:32:03 +0300 Subject: [PATCH 07/20] Added new controller for google pay and transaction info builder --- config/common.yml | 7 + config/query-handlers.yml | 6 + controllers/front/googlepay.php | 94 +++++++++ ps_checkout.php | 1 + .../Builder/GoogleTransactionInfoBuilder.php | 117 +++++++++++ .../GooglePay/DTO/GooglePayDisplayItem.php | 111 ++++++++++ .../DTO/GooglePayTransactionInfo.php | 191 ++++++++++++++++++ .../GetGooglePayTransactionInfoQuery.php | 26 +++ ...etGooglePayTransactionInfoQueryHandler.php | 30 +++ ...GetGooglePayTransactionInfoQueryResult.php | 25 +++ src/Translations/Translations.php | 8 + 11 files changed, 616 insertions(+) create mode 100644 controllers/front/googlepay.php create mode 100644 src/PayPal/GooglePay/Builder/GoogleTransactionInfoBuilder.php create mode 100644 src/PayPal/GooglePay/DTO/GooglePayDisplayItem.php create mode 100644 src/PayPal/GooglePay/DTO/GooglePayTransactionInfo.php create mode 100644 src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQuery.php create mode 100644 src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryHandler.php create mode 100644 src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryResult.php diff --git a/config/common.yml b/config/common.yml index b7a5304e0..54bc75f48 100644 --- a/config/common.yml +++ b/config/common.yml @@ -87,6 +87,7 @@ services: PrestaShop\Module\PrestashopCheckout\PayPal\Customer\Command\SavePayPalCustomerCommand: 'PrestaShop\Module\PrestashopCheckout\PayPal\Customer\CommandHandler\SavePayPalCustomerCommandHandler' PrestaShop\Module\PrestashopCheckout\PayPal\OAuth\Query\GetPayPalGetUserIdTokenQuery: 'PrestaShop\Module\PrestashopCheckout\PayPal\OAuth\Query\GetPayPalGetUserIdTokenQueryHandler' PrestaShop\Module\PrestashopCheckout\PayPal\Order\Command\SavePayPalOrderCommand: 'PrestaShop\Module\PrestashopCheckout\PayPal\Order\CommandHandler\SavePayPalOrderCommandHandler' + PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Query\GetGooglePayTransactionInfoQuery: 'PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Query\GetGooglePayTransactionInfoQueryHandler' PrestaShop\Module\PrestashopCheckout\Event\SymfonyEventDispatcherFactory: class: 'PrestaShop\Module\PrestashopCheckout\Event\SymfonyEventDispatcherFactory' @@ -474,3 +475,9 @@ services: public: true arguments: - '@ps_checkout.module' + + PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Builder\GoogleTransactionInfoBuilder: + class: 'PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Builder\GoogleTransactionInfoBuilder' + public: true + arguments: + - '@PrestaShop\Module\PrestashopCheckout\Translations\Translations' diff --git a/config/query-handlers.yml b/config/query-handlers.yml index 865d1df55..390c6f44a 100644 --- a/config/query-handlers.yml +++ b/config/query-handlers.yml @@ -80,3 +80,9 @@ services: - '@PrestaShop\Module\PrestashopCheckout\PayPal\OAuth\OAuthService' - '@PrestaShop\Module\PrestashopCheckout\Repository\PayPalCustomerRepository' - '@PrestaShop\Module\PrestashopCheckout\PayPal\PayPalConfiguration' + + PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Query\GetGooglePayTransactionInfoQueryHandler: + class: 'PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Query\GetGooglePayTransactionInfoQueryHandler' + public: true + arguments: + - '@PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Builder\GoogleTransactionInfoBuilder' diff --git a/controllers/front/googlepay.php b/controllers/front/googlepay.php new file mode 100644 index 000000000..f17d53de1 --- /dev/null +++ b/controllers/front/googlepay.php @@ -0,0 +1,94 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +use PrestaShop\Module\PrestashopCheckout\Cart\ValueObject\CartId; +use PrestaShop\Module\PrestashopCheckout\CommandBus\CommandBusInterface; +use PrestaShop\Module\PrestashopCheckout\Controller\AbstractFrontController; +use PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Query\GetGooglePayTransactionInfoQuery; + +/** + * This controller receive ajax call on customer click on a payment button + */ +class Ps_CheckoutGooglepayModuleFrontController extends AbstractFrontController { + + /** + * @var Ps_checkout + */ + public $module; + + /** + * @var CommandBusInterface + */ + private $commandBus; + + /** + * @see FrontController::postProcess() + */ + public function postProcess() { + try { + $bodyValues = []; + $bodyContent = file_get_contents('php://input'); + + if (!empty($bodyContent)) { + $bodyValues = json_decode($bodyContent, true); + } + + $action = $bodyValues['action']; + + $this->commandBus = $this->module->getService('ps_checkout.bus.command'); + + switch ($action) { + case 'create': + $this->create($bodyValues); + break; + case 'capture': + $this->capture($bodyValues); + break; + case 'getTransactionInfo': + $this->getTransactionInfo($bodyValues); + break; + default: + $this->exitWithExceptionMessage(new Exception('Invalid request', 400)); + } + } catch (Exception $exception) { + $this->exitWithExceptionMessage($exception); + } + } + + private function create($bodyValues) + { + + } + + private function capture($bodyValues) + { + + } + + private function getTransactionInfo($bodyValues) + { + $transactionInfo = $this->commandBus->handle(new GetGooglePayTransactionInfoQuery(new CartId($this->context->cart->id))); + + $this->exitWithResponse([ + 'httpCode' => 200, + 'body' => $transactionInfo->getPayload()->toArray(), + ]); + } +} diff --git a/ps_checkout.php b/ps_checkout.php index 06b754318..863512d6d 100755 --- a/ps_checkout.php +++ b/ps_checkout.php @@ -1031,6 +1031,7 @@ public function hookActionFrontControllerSetMedia() $this->name . 'ExpressCheckoutUrl' => $this->context->link->getModuleLink($this->name, 'ExpressCheckout', [], true), $this->name . 'VaultUrl' => $this->context->link->getModuleLink($this->name, 'vault', [], true), $this->name . 'PaymentUrl' => $this->context->link->getModuleLink($this->name, 'payment', [], true), + $this->name . 'GooglePayUrl' => $this->context->link->getModuleLink($this->name, 'googlepay', [], true), $this->name . 'CheckoutUrl' => $this->getCheckoutPageUrl(), $this->name . 'ConfirmUrl' => $this->context->link->getPageLink('order-confirmation', true, (int) $this->context->language->id), $this->name . 'PayPalSdkConfig' => $payPalSdkConfigurationBuilder->buildConfiguration(), diff --git a/src/PayPal/GooglePay/Builder/GoogleTransactionInfoBuilder.php b/src/PayPal/GooglePay/Builder/GoogleTransactionInfoBuilder.php new file mode 100644 index 000000000..434038bfb --- /dev/null +++ b/src/PayPal/GooglePay/Builder/GoogleTransactionInfoBuilder.php @@ -0,0 +1,117 @@ +language->iso_code; + $this->translations = $translations->getTranslations()[$isoCode]['google_pay']; + } + + /** + * @return GooglePayTransactionInfo + * + * @throws PsCheckoutException + */ + public function buildFromPayPalPayload($payload) + { + $transactionInfo = new GooglePayTransactionInfo(); + + $breakdown = $payload['amount']['breakdown']; + + $displayItems = []; + + if ($breakdown['shipping']['value'] > 0) { + $shipping = new GooglePayDisplayItem(); + $shipping->setPrice($breakdown['shipping']['value']) + ->setType(GooglePayDisplayItem::TYPE_LINE_ITEM) + ->setLabel($this->translations['shipping']); + $displayItems[] = $shipping; + } + + if ($breakdown['handling']['value'] > 0) { + $handling = new GooglePayDisplayItem(); + $handling->setPrice($breakdown['handling']['value']) + ->setType(GooglePayDisplayItem::TYPE_LINE_ITEM) + ->setLabel($this->translations['handling']); + $displayItems[] = $handling; + } + + if ($breakdown['discount']['value'] > 0) { + $discount = new GooglePayDisplayItem(); + $discount->setPrice('-' . $breakdown['discount']['value']) + ->setType(GooglePayDisplayItem::TYPE_LINE_ITEM) + ->setLabel($this->translations['discount']); + $displayItems[] = $discount; + } + + $subtotal = new GooglePayDisplayItem(); + $subtotal->setPrice($this->formatAmount($payload['amount']['value'] - $breakdown['tax_total']['value'], $payload['amount']['currency_code'])) + ->setType(GooglePayDisplayItem::TYPE_SUBTOTAL) + ->setLabel($this->translations['subtotal']); + $displayItems[] = $subtotal; + + $tax = new GooglePayDisplayItem(); + $tax->setPrice($breakdown['tax_total']['value']) + ->setType(GooglePayDisplayItem::TYPE_TAX) + ->setLabel($this->translations['tax']); + + $displayItems[] = $tax; + + $productItems = array_map(function ($item) { + $productItem = new GooglePayDisplayItem(); + $productItem->setPrice($item['unit_amount']['value']) + ->setType(GooglePayDisplayItem::TYPE_LINE_ITEM) + ->setLabel($item['name'] . ' ' . $item['description'] . ' x' . $item['quantity']); + + return $productItem; + }, $payload['items']); + + $displayItems = array_merge($productItems, $displayItems); + + $transactionInfo->setCurrencyCode($payload['amount']['currency_code']) + ->setTotalPrice($payload['amount']['value']) + ->setTotalPriceLabel($this->translations['total']) + ->setDisplayItems($displayItems); + + return $transactionInfo; + } + + /** + * Get decimal to round correspondent to the payment currency used + * Advise from PayPal: Always round to 2 decimals except for HUF, JPY and TWD + * currencies which require a round with 0 decimal + * + * @return int + */ + private function getNbDecimalToRound($currencyIsoCode) + { + if (in_array($currencyIsoCode, ['HUF', 'JPY', 'TWD'], true)) { + return 0; + } + + return 2; + } + + /** + * @param float|int|string $amount + * + * @return string + */ + private function formatAmount($amount, $currencyIsoCode) + { + return sprintf("%01.{$this->getNbDecimalToRound($currencyIsoCode)}F", $amount); + } +} diff --git a/src/PayPal/GooglePay/DTO/GooglePayDisplayItem.php b/src/PayPal/GooglePay/DTO/GooglePayDisplayItem.php new file mode 100644 index 000000000..b7d3ff680 --- /dev/null +++ b/src/PayPal/GooglePay/DTO/GooglePayDisplayItem.php @@ -0,0 +1,111 @@ +label = $label; + return $this; + } + + /** + * @return string + */ + public function getLabel() + { + return $this->label; + } + + /** + * @param string $type + * @return GooglePayDisplayItem + */ + public function setType($type) + { + $this->type = $type; + return $this; + } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $price + * @return GooglePayDisplayItem + */ + public function setPrice($price) + { + $this->price = $price; + return $this; + } + + /** + * @return string + */ + public function getPrice() + { + return $this->price; + } + + /** + * @param string $status + * @return GooglePayDisplayItem + */ + public function setStatus($status) + { + $this->status = $status; + return $this; + } + + /** + * @return string + */ + public function getStatus() + { + return $this->status; + } + + public function toArray() + { + return array_filter([ + 'label' => $this->label, + 'type' => $this->type, + 'price' => $this->price, + 'status' => $this->status, + ]); + } +} diff --git a/src/PayPal/GooglePay/DTO/GooglePayTransactionInfo.php b/src/PayPal/GooglePay/DTO/GooglePayTransactionInfo.php new file mode 100644 index 000000000..0a454e15e --- /dev/null +++ b/src/PayPal/GooglePay/DTO/GooglePayTransactionInfo.php @@ -0,0 +1,191 @@ +currencyCode; + } + + /** + * @param string $currencyCode + * @return GooglePayTransactionInfo + */ + public function setCurrencyCode($currencyCode) + { + $this->currencyCode = $currencyCode; + return $this; + } + + /** + * @return string + */ + public function getCountryCode() + { + return $this->countryCode; + } + /** + * @param string $countryCode + * @return GooglePayTransactionInfo + */ + public function setCountryCode($countryCode) + { + $this->countryCode = $countryCode; + return $this; + } + /** + * @return string + */ + public function getTransactionId() + { + return $this->transactionId; + } + /** + * @param string $transactionId + * @return GooglePayTransactionInfo + */ + public function setTransactionId($transactionId) + { + $this->transactionId = $transactionId; + return $this; + } + /** + * @return string + */ + public function getTotalPriceStatus() + { + return $this->totalPriceStatus; + } + /** + * @param string $totalPriceStatus + * @return GooglePayTransactionInfo + */ + public function setTotalPriceStatus($totalPriceStatus) + { + $this->totalPriceStatus = $totalPriceStatus; + return $this; + } + /** + * @return string + */ + public function getTotalPrice() + { + return $this->totalPrice; + } + /** + * @param string $totalPrice + * @return GooglePayTransactionInfo + */ + public function setTotalPrice($totalPrice) + { + $this->totalPrice = $totalPrice; + return $this; + } + /** + * @return GooglePayDisplayItem[] + */ + public function getDisplayItems() + { + return $this->displayItems; + } + /** + * @param GooglePayDisplayItem[] $displayItems + * @return GooglePayTransactionInfo + */ + public function setDisplayItems($displayItems) + { + $this->displayItems = $displayItems; + return $this; + } + /** + * @return string + */ + public function getTotalPriceLabel() + { + return $this->totalPriceLabel; + } + /** + * @param string $totalPriceLabel + * @return GooglePayTransactionInfo + */ + public function setTotalPriceLabel($totalPriceLabel) + { + $this->totalPriceLabel = $totalPriceLabel; + return $this; + } + /** + * @return string + */ + public function getCheckoutOption() + { + return $this->checkoutOption; + } + /** + * @param string $checkoutOption + * @return GooglePayTransactionInfo + */ + public function setCheckoutOption($checkoutOption) + { + $this->checkoutOption = $checkoutOption; + return $this; + } + + public function toArray() + { + return array_filter([ + 'currencyCode' => $this->currencyCode, + 'countryCode' => $this->countryCode, + 'transactionId' => $this->transactionId, + 'totalPriceStatus' => $this->totalPriceStatus, + 'totalPrice' => $this->totalPrice, + 'totalPriceLabel' => $this->totalPriceLabel, + 'checkoutOption' => $this->checkoutOption, + 'displayItems' => array_map(function (GooglePayDisplayItem $item) { + return $item->toArray(); + }, $this->displayItems), + ]); + } +} diff --git a/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQuery.php b/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQuery.php new file mode 100644 index 000000000..86bfa2c88 --- /dev/null +++ b/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQuery.php @@ -0,0 +1,26 @@ +cartId = $cartId; + } + + /** + * @return CartId + */ + public function getCartId() + { + return $this->cartId; + } +} diff --git a/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryHandler.php b/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryHandler.php new file mode 100644 index 000000000..c47921fa5 --- /dev/null +++ b/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryHandler.php @@ -0,0 +1,30 @@ +builder = $builder; + } + + public function handle(GetGooglePayTransactionInfoQuery $query) + { + $cartPresenter = (new CartPresenter())->present(); + $orderPayloadBuilder = new OrderPayloadBuilder($cartPresenter); + + $orderPayloadBuilder->buildFullPayload(); + $payload = $orderPayloadBuilder->presentPayload(); + + return new GetGooglePayTransactionInfoQueryResult($this->builder->buildFromPayPalPayload($payload->getArray())); + } +} diff --git a/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryResult.php b/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryResult.php new file mode 100644 index 000000000..1bf9649dc --- /dev/null +++ b/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryResult.php @@ -0,0 +1,25 @@ +payload = $payload; + } + + /** + * @return GooglePayTransactionInfo + */ + public function getPayload() + { + return $this->payload; + } +} diff --git a/src/Translations/Translations.php b/src/Translations/Translations.php index 9bb8e36ac..c2332bbe7 100644 --- a/src/Translations/Translations.php +++ b/src/Translations/Translations.php @@ -537,6 +537,14 @@ public function getTranslations() 'paymentTokenNotSaved' => $this->module->l('was not saved for future purchases', 'translations'), ], ], + 'google_pay' => [ + 'shipping' => $this->module->l('Shipping', 'translations'), + 'tax' => $this->module->l('Tax', 'translations'), + 'total' => $this->module->l('Total', 'translations'), + 'subtotal' => $this->module->l('Subtotal', 'translations'), + 'handling' => $this->module->l('Handling', 'translations'), + 'discount' => $this->module->l('Discount', 'translations'), + ] ]; return $translations; From 0192b8abb7181cc54d715565d282baf1edb71948 Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Fri, 5 Jul 2024 17:02:04 +0300 Subject: [PATCH 08/20] Added license headers --- .../Builder/GoogleTransactionInfoBuilder.php | 18 ++++++++++++++++++ .../GooglePay/DTO/GooglePayDisplayItem.php | 18 ++++++++++++++++++ .../DTO/GooglePayTransactionInfo.php | 18 ++++++++++++++++++ .../GetGooglePayTransactionInfoQuery.php | 18 ++++++++++++++++++ ...etGooglePayTransactionInfoQueryHandler.php | 19 +++++++++++++++++++ ...GetGooglePayTransactionInfoQueryResult.php | 19 +++++++++++++++++++ 6 files changed, 110 insertions(+) diff --git a/src/PayPal/GooglePay/Builder/GoogleTransactionInfoBuilder.php b/src/PayPal/GooglePay/Builder/GoogleTransactionInfoBuilder.php index 434038bfb..8b512bb31 100644 --- a/src/PayPal/GooglePay/Builder/GoogleTransactionInfoBuilder.php +++ b/src/PayPal/GooglePay/Builder/GoogleTransactionInfoBuilder.php @@ -1,4 +1,22 @@ + * @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\GooglePay\Builder; diff --git a/src/PayPal/GooglePay/DTO/GooglePayDisplayItem.php b/src/PayPal/GooglePay/DTO/GooglePayDisplayItem.php index b7d3ff680..bc471588b 100644 --- a/src/PayPal/GooglePay/DTO/GooglePayDisplayItem.php +++ b/src/PayPal/GooglePay/DTO/GooglePayDisplayItem.php @@ -1,4 +1,22 @@ + * @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\GooglePay\DTO; diff --git a/src/PayPal/GooglePay/DTO/GooglePayTransactionInfo.php b/src/PayPal/GooglePay/DTO/GooglePayTransactionInfo.php index 0a454e15e..e463f5a73 100644 --- a/src/PayPal/GooglePay/DTO/GooglePayTransactionInfo.php +++ b/src/PayPal/GooglePay/DTO/GooglePayTransactionInfo.php @@ -1,4 +1,22 @@ + * @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\GooglePay\DTO; diff --git a/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQuery.php b/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQuery.php index 86bfa2c88..e231252f9 100644 --- a/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQuery.php +++ b/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQuery.php @@ -1,4 +1,22 @@ + * @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\GooglePay\Query; diff --git a/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryHandler.php b/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryHandler.php index c47921fa5..7bd3badd8 100644 --- a/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryHandler.php +++ b/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryHandler.php @@ -1,4 +1,23 @@ + * @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\GooglePay\Query; use PrestaShop\Module\PrestashopCheckout\Builder\Payload\OrderPayloadBuilder; diff --git a/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryResult.php b/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryResult.php index 1bf9649dc..fa799c18a 100644 --- a/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryResult.php +++ b/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryResult.php @@ -1,4 +1,23 @@ + * @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\GooglePay\Query; use PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\DTO\GooglePayTransactionInfo; From c23fbe46e2c392e18a03680f5d1f74bd78dcc96d Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Fri, 5 Jul 2024 17:19:04 +0300 Subject: [PATCH 09/20] CS fix --- controllers/front/googlepay.php | 9 +++-- src/PayPal/GooglePay/Builder/index.php | 28 ++++++++++++++++ .../GooglePay/DTO/GooglePayDisplayItem.php | 14 ++++++-- .../DTO/GooglePayTransactionInfo.php | 33 +++++++++++++++++-- src/PayPal/GooglePay/DTO/index.php | 28 ++++++++++++++++ src/PayPal/GooglePay/Query/index.php | 28 ++++++++++++++++ .../Sdk/PayPalSdkConfigurationBuilder.php | 22 ++++++------- src/Translations/Translations.php | 2 +- 8 files changed, 142 insertions(+), 22 deletions(-) create mode 100644 src/PayPal/GooglePay/Builder/index.php create mode 100644 src/PayPal/GooglePay/DTO/index.php create mode 100644 src/PayPal/GooglePay/Query/index.php diff --git a/controllers/front/googlepay.php b/controllers/front/googlepay.php index f17d53de1..ced8ae7ba 100644 --- a/controllers/front/googlepay.php +++ b/controllers/front/googlepay.php @@ -26,8 +26,8 @@ /** * This controller receive ajax call on customer click on a payment button */ -class Ps_CheckoutGooglepayModuleFrontController extends AbstractFrontController { - +class Ps_CheckoutGooglepayModuleFrontController extends AbstractFrontController +{ /** * @var Ps_checkout */ @@ -41,7 +41,8 @@ class Ps_CheckoutGooglepayModuleFrontController extends AbstractFrontController /** * @see FrontController::postProcess() */ - public function postProcess() { + public function postProcess() + { try { $bodyValues = []; $bodyContent = file_get_contents('php://input'); @@ -74,12 +75,10 @@ public function postProcess() { private function create($bodyValues) { - } private function capture($bodyValues) { - } private function getTransactionInfo($bodyValues) diff --git a/src/PayPal/GooglePay/Builder/index.php b/src/PayPal/GooglePay/Builder/index.php new file mode 100644 index 000000000..296d682e8 --- /dev/null +++ b/src/PayPal/GooglePay/Builder/index.php @@ -0,0 +1,28 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../'); +exit; diff --git a/src/PayPal/GooglePay/DTO/GooglePayDisplayItem.php b/src/PayPal/GooglePay/DTO/GooglePayDisplayItem.php index bc471588b..b542d41c5 100644 --- a/src/PayPal/GooglePay/DTO/GooglePayDisplayItem.php +++ b/src/PayPal/GooglePay/DTO/GooglePayDisplayItem.php @@ -33,7 +33,7 @@ class GooglePayDisplayItem */ private $label; /** - * @var 'LINE_ITEM'|'SUBTOTAL' + * @var 'LINE_ITEM'|'SUBTOTAL'|'TAX' */ private $type; /** @@ -47,11 +47,13 @@ class GooglePayDisplayItem /** * @param string $label + * * @return GooglePayDisplayItem */ public function setLabel($label) { $this->label = $label; + return $this; } @@ -64,12 +66,14 @@ public function getLabel() } /** - * @param string $type + * @param 'LINE_ITEM'|'SUBTOTAL'|'TAX' $type + * * @return GooglePayDisplayItem */ public function setType($type) { $this->type = $type; + return $this; } @@ -83,11 +87,13 @@ public function getType() /** * @param string $price + * * @return GooglePayDisplayItem */ public function setPrice($price) { $this->price = $price; + return $this; } @@ -100,12 +106,14 @@ public function getPrice() } /** - * @param string $status + * @param 'FINAL'|'PENDING' $status + * * @return GooglePayDisplayItem */ public function setStatus($status) { $this->status = $status; + return $this; } diff --git a/src/PayPal/GooglePay/DTO/GooglePayTransactionInfo.php b/src/PayPal/GooglePay/DTO/GooglePayTransactionInfo.php index e463f5a73..7869df2ca 100644 --- a/src/PayPal/GooglePay/DTO/GooglePayTransactionInfo.php +++ b/src/PayPal/GooglePay/DTO/GooglePayTransactionInfo.php @@ -70,11 +70,13 @@ public function getCurrencyCode() /** * @param string $currencyCode + * * @return GooglePayTransactionInfo */ public function setCurrencyCode($currencyCode) { $this->currencyCode = $currencyCode; + return $this; } @@ -85,15 +87,19 @@ public function getCountryCode() { return $this->countryCode; } + /** * @param string $countryCode + * * @return GooglePayTransactionInfo */ public function setCountryCode($countryCode) { $this->countryCode = $countryCode; + return $this; } + /** * @return string */ @@ -101,15 +107,19 @@ public function getTransactionId() { return $this->transactionId; } + /** * @param string $transactionId + * * @return GooglePayTransactionInfo */ public function setTransactionId($transactionId) { $this->transactionId = $transactionId; + return $this; } + /** * @return string */ @@ -117,15 +127,19 @@ public function getTotalPriceStatus() { return $this->totalPriceStatus; } + /** - * @param string $totalPriceStatus + * @param 'ESTIMATED'|'FINAL' $totalPriceStatus + * * @return GooglePayTransactionInfo */ public function setTotalPriceStatus($totalPriceStatus) { $this->totalPriceStatus = $totalPriceStatus; + return $this; } + /** * @return string */ @@ -133,15 +147,19 @@ public function getTotalPrice() { return $this->totalPrice; } + /** * @param string $totalPrice + * * @return GooglePayTransactionInfo */ public function setTotalPrice($totalPrice) { $this->totalPrice = $totalPrice; + return $this; } + /** * @return GooglePayDisplayItem[] */ @@ -149,15 +167,19 @@ public function getDisplayItems() { return $this->displayItems; } + /** * @param GooglePayDisplayItem[] $displayItems + * * @return GooglePayTransactionInfo */ public function setDisplayItems($displayItems) { $this->displayItems = $displayItems; + return $this; } + /** * @return string */ @@ -165,15 +187,19 @@ public function getTotalPriceLabel() { return $this->totalPriceLabel; } + /** * @param string $totalPriceLabel + * * @return GooglePayTransactionInfo */ public function setTotalPriceLabel($totalPriceLabel) { $this->totalPriceLabel = $totalPriceLabel; + return $this; } + /** * @return string */ @@ -181,13 +207,16 @@ public function getCheckoutOption() { return $this->checkoutOption; } + /** - * @param string $checkoutOption + * @param 'DEFAULT'|'COMPLETE_IMMEDIATE_PURCHASE' $checkoutOption + * * @return GooglePayTransactionInfo */ public function setCheckoutOption($checkoutOption) { $this->checkoutOption = $checkoutOption; + return $this; } diff --git a/src/PayPal/GooglePay/DTO/index.php b/src/PayPal/GooglePay/DTO/index.php new file mode 100644 index 000000000..296d682e8 --- /dev/null +++ b/src/PayPal/GooglePay/DTO/index.php @@ -0,0 +1,28 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../'); +exit; diff --git a/src/PayPal/GooglePay/Query/index.php b/src/PayPal/GooglePay/Query/index.php new file mode 100644 index 000000000..296d682e8 --- /dev/null +++ b/src/PayPal/GooglePay/Query/index.php @@ -0,0 +1,28 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ +header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); +header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); + +header('Cache-Control: no-store, no-cache, must-revalidate'); +header('Cache-Control: post-check=0, pre-check=0', false); +header('Pragma: no-cache'); + +header('Location: ../'); +exit; diff --git a/src/PayPal/Sdk/PayPalSdkConfigurationBuilder.php b/src/PayPal/Sdk/PayPalSdkConfigurationBuilder.php index 8e2394147..5f13f2c60 100644 --- a/src/PayPal/Sdk/PayPalSdkConfigurationBuilder.php +++ b/src/PayPal/Sdk/PayPalSdkConfigurationBuilder.php @@ -20,6 +20,7 @@ namespace PrestaShop\Module\PrestashopCheckout\PayPal\Sdk; +use Configuration; use Exception; use PrestaShop\Module\PrestashopCheckout\CommandBus\CommandBusInterface; use PrestaShop\Module\PrestashopCheckout\Context\PrestaShopContext; @@ -33,7 +34,6 @@ use PrestaShop\Module\PrestashopCheckout\PayPal\PayPalConfiguration; use PrestaShop\Module\PrestashopCheckout\PayPal\PayPalPayLaterConfiguration; use PrestaShop\Module\PrestashopCheckout\ShopContext; -use PrestaShop\PrestaShop\Adapter\Shop\Context; use Psr\Log\LoggerInterface; /** @@ -98,16 +98,16 @@ class PayPalSdkConfigurationBuilder * @param FundingSourceEligibilityConstraint $fundingSourceEligibilityConstraint */ public function __construct( - \Ps_checkout $module, - Env $env, - PayPalConfiguration $configuration, - PayPalPayLaterConfiguration $payLaterConfiguration, + \Ps_checkout $module, + Env $env, + PayPalConfiguration $configuration, + PayPalPayLaterConfiguration $payLaterConfiguration, FundingSourceConfigurationRepository $fundingSourceConfigurationRepository, - ExpressCheckoutConfiguration $expressCheckoutConfiguration, - ShopContext $shopContext, - PrestaShopContext $prestaShopContext, - LoggerInterface $logger, - FundingSourceEligibilityConstraint $fundingSourceEligibilityConstraint + ExpressCheckoutConfiguration $expressCheckoutConfiguration, + ShopContext $shopContext, + PrestaShopContext $prestaShopContext, + LoggerInterface $logger, + FundingSourceEligibilityConstraint $fundingSourceEligibilityConstraint ) { $this->configuration = $configuration; $this->payLaterConfiguration = $payLaterConfiguration; @@ -494,7 +494,7 @@ private function shouldIncludeGooglePayComponent() $fundingSource = $this->fundingSourceConfigurationRepository->get('google_pay'); return $fundingSource && $fundingSource['active'] - && \Configuration::get('PS_CHECKOUT_GOOGLE_PAY', false) === '1' + && Configuration::get('PS_CHECKOUT_GOOGLE_PAY') === '1' && in_array($country, $this->fundingSourceEligibilityConstraint->getCountries('google_pay'), true) && in_array($context->currency->iso_code, $this->fundingSourceEligibilityConstraint->getCurrencies('google_pay'), true); } diff --git a/src/Translations/Translations.php b/src/Translations/Translations.php index c2332bbe7..0a81e47fe 100644 --- a/src/Translations/Translations.php +++ b/src/Translations/Translations.php @@ -544,7 +544,7 @@ public function getTranslations() 'subtotal' => $this->module->l('Subtotal', 'translations'), 'handling' => $this->module->l('Handling', 'translations'), 'discount' => $this->module->l('Discount', 'translations'), - ] + ], ]; return $translations; From 55da8aa60badb47ef2745b694c017a251a363364 Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Mon, 8 Jul 2024 11:56:29 +0300 Subject: [PATCH 10/20] Minor improvements --- config/common.yml | 4 ++-- config/query-handlers.yml | 2 +- ...InfoBuilder.php => GooglePayTransactionInfoBuilder.php} | 5 ++--- .../Query/GetGooglePayTransactionInfoQueryHandler.php | 6 +++--- src/PayPal/PayPalConfiguration.php | 7 +++++++ src/PayPal/Sdk/PayPalSdkConfigurationBuilder.php | 3 +-- 6 files changed, 16 insertions(+), 11 deletions(-) rename src/PayPal/GooglePay/Builder/{GoogleTransactionInfoBuilder.php => GooglePayTransactionInfoBuilder.php} (96%) diff --git a/config/common.yml b/config/common.yml index 54bc75f48..8614104f7 100644 --- a/config/common.yml +++ b/config/common.yml @@ -476,8 +476,8 @@ services: arguments: - '@ps_checkout.module' - PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Builder\GoogleTransactionInfoBuilder: - class: 'PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Builder\GoogleTransactionInfoBuilder' + PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Builder\GooglePayTransactionInfoBuilder: + class: 'PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Builder\GooglePayTransactionInfoBuilder' public: true arguments: - '@PrestaShop\Module\PrestashopCheckout\Translations\Translations' diff --git a/config/query-handlers.yml b/config/query-handlers.yml index 390c6f44a..8997caaa4 100644 --- a/config/query-handlers.yml +++ b/config/query-handlers.yml @@ -85,4 +85,4 @@ services: class: 'PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Query\GetGooglePayTransactionInfoQueryHandler' public: true arguments: - - '@PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Builder\GoogleTransactionInfoBuilder' + - '@PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Builder\GooglePayTransactionInfoBuilder' diff --git a/src/PayPal/GooglePay/Builder/GoogleTransactionInfoBuilder.php b/src/PayPal/GooglePay/Builder/GooglePayTransactionInfoBuilder.php similarity index 96% rename from src/PayPal/GooglePay/Builder/GoogleTransactionInfoBuilder.php rename to src/PayPal/GooglePay/Builder/GooglePayTransactionInfoBuilder.php index 8b512bb31..59ba84871 100644 --- a/src/PayPal/GooglePay/Builder/GoogleTransactionInfoBuilder.php +++ b/src/PayPal/GooglePay/Builder/GooglePayTransactionInfoBuilder.php @@ -25,7 +25,7 @@ use PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\DTO\GooglePayTransactionInfo; use PrestaShop\Module\PrestashopCheckout\Translations\Translations; -class GoogleTransactionInfoBuilder +class GooglePayTransactionInfoBuilder { /** * @var Translations @@ -34,8 +34,7 @@ class GoogleTransactionInfoBuilder public function __construct(Translations $translations) { - $isoCode = \Context::getContext()->language->iso_code; - $this->translations = $translations->getTranslations()[$isoCode]['google_pay']; + $this->translations = current($translations->getTranslations())['google_pay']; } /** diff --git a/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryHandler.php b/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryHandler.php index 7bd3badd8..228f0bb59 100644 --- a/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryHandler.php +++ b/src/PayPal/GooglePay/Query/GetGooglePayTransactionInfoQueryHandler.php @@ -21,17 +21,17 @@ namespace PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Query; use PrestaShop\Module\PrestashopCheckout\Builder\Payload\OrderPayloadBuilder; -use PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Builder\GoogleTransactionInfoBuilder; +use PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Builder\GooglePayTransactionInfoBuilder; use PrestaShop\Module\PrestashopCheckout\Presenter\Cart\CartPresenter; class GetGooglePayTransactionInfoQueryHandler { /** - * @var GoogleTransactionInfoBuilder + * @var GooglePayTransactionInfoBuilder */ private $builder; - public function __construct(GoogleTransactionInfoBuilder $builder) + public function __construct(GooglePayTransactionInfoBuilder $builder) { $this->builder = $builder; } diff --git a/src/PayPal/PayPalConfiguration.php b/src/PayPal/PayPalConfiguration.php index b8b5ae475..6ce9e92cb 100644 --- a/src/PayPal/PayPalConfiguration.php +++ b/src/PayPal/PayPalConfiguration.php @@ -50,6 +50,8 @@ class PayPalConfiguration const PS_CHECKOUT_DISPLAY_LOGO_CART = 'PS_CHECKOUT_DISPLAY_LOGO_CART'; const PS_CHECKOUT_VAULTING = 'PS_CHECKOUT_VAULTING'; + const PS_CHECKOUT_GOOGLE_PAY = 'PS_CHECKOUT_GOOGLE_PAY'; + /** * @var PrestaShopConfiguration */ @@ -441,4 +443,9 @@ public function isVaultingEnabled() { return (bool) $this->configuration->get(static::PS_CHECKOUT_VAULTING); } + + public function isGooglePayEligible() + { + return (bool) $this->configuration->get(static::PS_CHECKOUT_GOOGLE_PAY); + } } diff --git a/src/PayPal/Sdk/PayPalSdkConfigurationBuilder.php b/src/PayPal/Sdk/PayPalSdkConfigurationBuilder.php index 5f13f2c60..1042cb48d 100644 --- a/src/PayPal/Sdk/PayPalSdkConfigurationBuilder.php +++ b/src/PayPal/Sdk/PayPalSdkConfigurationBuilder.php @@ -20,7 +20,6 @@ namespace PrestaShop\Module\PrestashopCheckout\PayPal\Sdk; -use Configuration; use Exception; use PrestaShop\Module\PrestashopCheckout\CommandBus\CommandBusInterface; use PrestaShop\Module\PrestashopCheckout\Context\PrestaShopContext; @@ -494,7 +493,7 @@ private function shouldIncludeGooglePayComponent() $fundingSource = $this->fundingSourceConfigurationRepository->get('google_pay'); return $fundingSource && $fundingSource['active'] - && Configuration::get('PS_CHECKOUT_GOOGLE_PAY') === '1' + && $this->configuration->isGooglePayEligible() && in_array($country, $this->fundingSourceEligibilityConstraint->getCountries('google_pay'), true) && in_array($context->currency->iso_code, $this->fundingSourceEligibilityConstraint->getCurrencies('google_pay'), true); } From 7817cdb84c891bf8a844248c2656b9bde1bd3294 Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Tue, 9 Jul 2024 20:07:19 +0300 Subject: [PATCH 11/20] Added GooglePay payment source to order payload builder --- src/Builder/Payload/OrderPayloadBuilder.php | 32 +++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/Builder/Payload/OrderPayloadBuilder.php b/src/Builder/Payload/OrderPayloadBuilder.php index 0237debdb..b680e2c47 100644 --- a/src/Builder/Payload/OrderPayloadBuilder.php +++ b/src/Builder/Payload/OrderPayloadBuilder.php @@ -178,8 +178,15 @@ public function buildFullPayload() $this->buildSupplementaryDataNode(); } - if ($this->fundingSource === 'paypal') { - $this->buildPayPalPaymentSourceNode(); + switch ($this->fundingSource) { + case 'paypal': + $this->buildPayPalPaymentSourceNode(); + break; + case 'google_pay': + $this->buildGooglePayPaymentSourceNode(); + break; + default: + break; } } @@ -731,4 +738,25 @@ private function buildPayPalPaymentSourceNode() $this->getPayload()->addAndMergeItems($node); } + + private function buildGooglePayPaymentSourceNode() { + /** @var \Ps_checkout $module */ + $module = \Module::getInstanceByName('ps_checkout'); + /** @var PayPalConfiguration $paypalConfiguration */ + $paypalConfiguration = $module->getService(PayPalConfiguration::class); + + $node = [ + 'payment_source' => [ + 'google_pay' => [ + 'attributes' => [ + 'verification' => [ + 'method' => $paypalConfiguration->getHostedFieldsContingencies(), + ] + ] + ], + ], + ]; + + $this->getPayload()->addAndMergeItems($node); + } } From 62904b5379fce5bf04f8cd43ebc7592dd61c1a3a Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Tue, 9 Jul 2024 20:09:09 +0300 Subject: [PATCH 12/20] removed create and capture endpoints from Google Pay controller --- controllers/front/googlepay.php | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/controllers/front/googlepay.php b/controllers/front/googlepay.php index ced8ae7ba..150923a8d 100644 --- a/controllers/front/googlepay.php +++ b/controllers/front/googlepay.php @@ -55,18 +55,10 @@ public function postProcess() $this->commandBus = $this->module->getService('ps_checkout.bus.command'); - switch ($action) { - case 'create': - $this->create($bodyValues); - break; - case 'capture': - $this->capture($bodyValues); - break; - case 'getTransactionInfo': - $this->getTransactionInfo($bodyValues); - break; - default: - $this->exitWithExceptionMessage(new Exception('Invalid request', 400)); + if ($action === 'getTransactionInfo') { + $this->getTransactionInfo($bodyValues); + } else { + $this->exitWithExceptionMessage(new Exception('Invalid request', 400)); } } catch (Exception $exception) { $this->exitWithExceptionMessage($exception); From 5194d4b0fd994bb7e2193ce05ade3507451212f1 Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Tue, 9 Jul 2024 20:23:10 +0300 Subject: [PATCH 13/20] Added liability shift check for Google Pay --- src/Checkout/CheckoutChecker.php | 6 ++++-- src/PayPal/Card3DSecure.php | 22 ++++++++++++---------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Checkout/CheckoutChecker.php b/src/Checkout/CheckoutChecker.php index 9ffef68a2..de01781d3 100644 --- a/src/Checkout/CheckoutChecker.php +++ b/src/Checkout/CheckoutChecker.php @@ -57,13 +57,15 @@ public function continueWithAuthorization($cartId, $orderPayPal) throw new PsCheckoutException(sprintf('PayPal Order %s is already captured', $orderPayPal['id'])); } - if (isset($orderPayPal['payment_source']['card'])) { + $paymentSource = current(array_keys($orderPayPal['payment_source'])); + + if (in_array($paymentSource, ['card', 'google_pay']) && isset($orderPayPal['payment_source'][$paymentSource])) { $card3DSecure = (new Card3DSecure())->continueWithAuthorization($orderPayPal); $this->logger->info( '3D Secure authentication result', [ - 'authentication_result' => isset($orderPayPal['payment_source']['card']['authentication_result']) ? $orderPayPal['payment_source']['card']['authentication_result'] : null, + 'authentication_result' => isset($orderPayPal['payment_source'][$paymentSource]['authentication_result']) ? $orderPayPal['payment_source'][$paymentSource]['authentication_result'] : null, 'decision' => str_replace( [ (string) Card3DSecure::NO_DECISION, diff --git a/src/PayPal/Card3DSecure.php b/src/PayPal/Card3DSecure.php index 091eec299..9f95764bc 100644 --- a/src/PayPal/Card3DSecure.php +++ b/src/PayPal/Card3DSecure.php @@ -130,9 +130,9 @@ public function is3DSecureAvailable(array $order) */ public function isLiabilityShifted(array $order) { - $cardAuthenticationResult = $this->getAuthenticationResult($order); - $liabilityShift = $this->getLiabilityShift($cardAuthenticationResult); - $threeDSecure = $this->get3DSecure($cardAuthenticationResult); + $authenticationResult = $this->getAuthenticationResult($order); + $liabilityShift = $this->getLiabilityShift($authenticationResult); + $threeDSecure = $this->get3DSecure($authenticationResult); $authenticationStatus = $this->getAuthenticationStatus($threeDSecure); return ($liabilityShift === self::LIABILITY_SHIFT_POSSIBLE || $liabilityShift === self::LIABILITY_SHIFT_YES) @@ -188,27 +188,29 @@ private function noLiabilityShift(array $cardAuthenticationResult) */ private function getAuthenticationResult(array $order) { - return isset($order['payment_source']['card']['authentication_result']) ? $order['payment_source']['card']['authentication_result'] : null; + $fundingSource = current(array_keys($order['payment_source'])); + + return isset($order['payment_source'][$fundingSource]['authentication_result']) ? $order['payment_source'][$fundingSource]['authentication_result'] : null; } /** - * @param array|null $cardAuthenticationResult + * @param array|null $authenticationResult * * @return string|null */ - private function getLiabilityShift($cardAuthenticationResult) + private function getLiabilityShift($authenticationResult) { - return isset($cardAuthenticationResult['liability_shift']) ? $cardAuthenticationResult['liability_shift'] : null; + return isset($authenticationResult['liability_shift']) ? $authenticationResult['liability_shift'] : null; } /** - * @param array|null $cardAuthenticationResult + * @param array|null $authenticationResult * * @return array|null */ - private function get3DSecure($cardAuthenticationResult) + private function get3DSecure($authenticationResult) { - return isset($cardAuthenticationResult['three_d_secure']) ? $cardAuthenticationResult['three_d_secure'] : null; + return isset($authenticationResult['three_d_secure']) ? $authenticationResult['three_d_secure'] : null; } /** From e4bd4ba1bbb6b81e3112e1dc0f5457b5904580e7 Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Tue, 9 Jul 2024 20:26:43 +0300 Subject: [PATCH 14/20] Updated OrderPresenter with values for Google Pay --- src/Builder/Payload/OrderPayloadBuilder.php | 3 ++- src/Checkout/CheckoutChecker.php | 2 +- src/PayPal/Card3DSecure.php | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Builder/Payload/OrderPayloadBuilder.php b/src/Builder/Payload/OrderPayloadBuilder.php index b680e2c47..008d32f09 100644 --- a/src/Builder/Payload/OrderPayloadBuilder.php +++ b/src/Builder/Payload/OrderPayloadBuilder.php @@ -739,7 +739,8 @@ private function buildPayPalPaymentSourceNode() $this->getPayload()->addAndMergeItems($node); } - private function buildGooglePayPaymentSourceNode() { + private function buildGooglePayPaymentSourceNode() + { /** @var \Ps_checkout $module */ $module = \Module::getInstanceByName('ps_checkout'); /** @var PayPalConfiguration $paypalConfiguration */ diff --git a/src/Checkout/CheckoutChecker.php b/src/Checkout/CheckoutChecker.php index de01781d3..eb292100d 100644 --- a/src/Checkout/CheckoutChecker.php +++ b/src/Checkout/CheckoutChecker.php @@ -57,7 +57,7 @@ public function continueWithAuthorization($cartId, $orderPayPal) throw new PsCheckoutException(sprintf('PayPal Order %s is already captured', $orderPayPal['id'])); } - $paymentSource = current(array_keys($orderPayPal['payment_source'])); + $paymentSource = key($orderPayPal['payment_source']); if (in_array($paymentSource, ['card', 'google_pay']) && isset($orderPayPal['payment_source'][$paymentSource])) { $card3DSecure = (new Card3DSecure())->continueWithAuthorization($orderPayPal); diff --git a/src/PayPal/Card3DSecure.php b/src/PayPal/Card3DSecure.php index 9f95764bc..4c7105bb3 100644 --- a/src/PayPal/Card3DSecure.php +++ b/src/PayPal/Card3DSecure.php @@ -188,7 +188,7 @@ private function noLiabilityShift(array $cardAuthenticationResult) */ private function getAuthenticationResult(array $order) { - $fundingSource = current(array_keys($order['payment_source'])); + $fundingSource = key($order['payment_source']); return isset($order['payment_source'][$fundingSource]['authentication_result']) ? $order['payment_source'][$fundingSource]['authentication_result'] : null; } From e15bc01e03419bbedc6b87e9c360c9aa112a764a Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Wed, 10 Jul 2024 15:56:18 +0300 Subject: [PATCH 15/20] Added error translation for missing Google Pay SDK --- ps_checkout.php | 1 + 1 file changed, 1 insertion(+) diff --git a/ps_checkout.php b/ps_checkout.php index 863512d6d..12420607e 100755 --- a/ps_checkout.php +++ b/ps_checkout.php @@ -1086,6 +1086,7 @@ public function hookActionFrontControllerSetMedia() 'express-button.cart.separator' => $this->l('or'), 'express-button.checkout.express-checkout' => $this->l('Express Checkout'), 'error.paypal-sdk' => $this->l('No PayPal Javascript SDK Instance'), + 'error.google-pay-sdk' => $this->l('No Google Pay Javascript SDK Instance'), 'checkout.payment.others.link.label' => $this->l('Other payment methods'), 'checkout.payment.others.confirm.button.label' => $this->l('I confirm my order'), 'checkout.form.error.label' => $this->l('There was an error during the payment. Please try again or contact the support.'), From dc31458295a9e5627688537a49265ce4f7a00465 Mon Sep 17 00:00:00 2001 From: L3RAZ Date: Wed, 10 Jul 2024 16:49:23 +0300 Subject: [PATCH 16/20] Added order status check before 3DS check --- src/Builder/Payload/OrderPayloadBuilder.php | 4 ++-- src/Checkout/CheckoutChecker.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Builder/Payload/OrderPayloadBuilder.php b/src/Builder/Payload/OrderPayloadBuilder.php index 008d32f09..6b881b3b1 100644 --- a/src/Builder/Payload/OrderPayloadBuilder.php +++ b/src/Builder/Payload/OrderPayloadBuilder.php @@ -752,8 +752,8 @@ private function buildGooglePayPaymentSourceNode() 'attributes' => [ 'verification' => [ 'method' => $paypalConfiguration->getHostedFieldsContingencies(), - ] - ] + ], + ], ], ], ]; diff --git a/src/Checkout/CheckoutChecker.php b/src/Checkout/CheckoutChecker.php index eb292100d..3cedc3342 100644 --- a/src/Checkout/CheckoutChecker.php +++ b/src/Checkout/CheckoutChecker.php @@ -59,7 +59,8 @@ public function continueWithAuthorization($cartId, $orderPayPal) $paymentSource = key($orderPayPal['payment_source']); - if (in_array($paymentSource, ['card', 'google_pay']) && isset($orderPayPal['payment_source'][$paymentSource])) { + if ((($paymentSource === 'google_pay' && $orderPayPal['status'] !== 'APPROVED') + || $paymentSource === 'card') && isset($orderPayPal['payment_source'][$paymentSource])) { $card3DSecure = (new Card3DSecure())->continueWithAuthorization($orderPayPal); $this->logger->info( From d584a64d1f12561d3e3f79762fd31a19c07403d8 Mon Sep 17 00:00:00 2001 From: Matt75 <5262628+Matt75@users.noreply.github.com> Date: Wed, 10 Jul 2024 16:12:31 +0200 Subject: [PATCH 17/20] Remove unused methods --- controllers/front/googlepay.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/controllers/front/googlepay.php b/controllers/front/googlepay.php index 150923a8d..7734798cc 100644 --- a/controllers/front/googlepay.php +++ b/controllers/front/googlepay.php @@ -65,15 +65,7 @@ public function postProcess() } } - private function create($bodyValues) - { - } - - private function capture($bodyValues) - { - } - - private function getTransactionInfo($bodyValues) + private function getTransactionInfo(array $bodyValues) { $transactionInfo = $this->commandBus->handle(new GetGooglePayTransactionInfoQuery(new CartId($this->context->cart->id))); From 84d2bcc42a20b51981e7a47f5bb3865fe031bae8 Mon Sep 17 00:00:00 2001 From: Matt75 <5262628+Matt75@users.noreply.github.com> Date: Wed, 10 Jul 2024 16:55:17 +0200 Subject: [PATCH 18/20] Refactor conditional statement --- src/Checkout/CheckoutChecker.php | 5 ++--- src/PayPal/Card3DSecure.php | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Checkout/CheckoutChecker.php b/src/Checkout/CheckoutChecker.php index 3cedc3342..60c292ce4 100644 --- a/src/Checkout/CheckoutChecker.php +++ b/src/Checkout/CheckoutChecker.php @@ -57,10 +57,9 @@ public function continueWithAuthorization($cartId, $orderPayPal) throw new PsCheckoutException(sprintf('PayPal Order %s is already captured', $orderPayPal['id'])); } - $paymentSource = key($orderPayPal['payment_source']); + $paymentSource = isset($orderPayPal['payment_source']) ? key($orderPayPal['payment_source']) : ''; - if ((($paymentSource === 'google_pay' && $orderPayPal['status'] !== 'APPROVED') - || $paymentSource === 'card') && isset($orderPayPal['payment_source'][$paymentSource])) { + if (in_array($paymentSource, ['google_pay', 'card'], true)) { $card3DSecure = (new Card3DSecure())->continueWithAuthorization($orderPayPal); $this->logger->info( diff --git a/src/PayPal/Card3DSecure.php b/src/PayPal/Card3DSecure.php index 4c7105bb3..c997ca986 100644 --- a/src/PayPal/Card3DSecure.php +++ b/src/PayPal/Card3DSecure.php @@ -188,7 +188,7 @@ private function noLiabilityShift(array $cardAuthenticationResult) */ private function getAuthenticationResult(array $order) { - $fundingSource = key($order['payment_source']); + $fundingSource = isset($order['payment_source']) ? key($order['payment_source']) : ''; return isset($order['payment_source'][$fundingSource]['authentication_result']) ? $order['payment_source'][$fundingSource]['authentication_result'] : null; } From e74862dca15a1549642eeabb72897422e4ba5395 Mon Sep 17 00:00:00 2001 From: Matt75 <5262628+Matt75@users.noreply.github.com> Date: Wed, 10 Jul 2024 16:57:47 +0200 Subject: [PATCH 19/20] Google pay verification method depends on 3D Secure activation --- src/Builder/Payload/OrderPayloadBuilder.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Builder/Payload/OrderPayloadBuilder.php b/src/Builder/Payload/OrderPayloadBuilder.php index 6b881b3b1..9efb05a2e 100644 --- a/src/Builder/Payload/OrderPayloadBuilder.php +++ b/src/Builder/Payload/OrderPayloadBuilder.php @@ -746,6 +746,10 @@ private function buildGooglePayPaymentSourceNode() /** @var PayPalConfiguration $paypalConfiguration */ $paypalConfiguration = $module->getService(PayPalConfiguration::class); + if (!$paypalConfiguration->is3dSecureEnabled()) { + return; + } + $node = [ 'payment_source' => [ 'google_pay' => [ From db8b75008639d1f7ee6045bb6d01eeee65cbda1e Mon Sep 17 00:00:00 2001 From: Matt75 <5262628+Matt75@users.noreply.github.com> Date: Wed, 10 Jul 2024 17:04:31 +0200 Subject: [PATCH 20/20] Remove custom path --- ps_checkout.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ps_checkout.php b/ps_checkout.php index 12420607e..3cf7fa5ea 100755 --- a/ps_checkout.php +++ b/ps_checkout.php @@ -1108,8 +1108,7 @@ public function hookActionFrontControllerSetMedia() if (method_exists($this->context->controller, 'registerJavascript')) { $this->context->controller->registerJavascript( $this->name . 'Front', - 'https://fo-sdk.laurynas-sedys-ext-mytun.prestashop.name/ps_checkout-fo-sdk.js', -// $this->getPathUri() . 'views/js/front.js?version=' . $version->getSemVersion(), + $this->getPathUri() . 'views/js/front.js?version=' . $version->getSemVersion(), [ 'position' => 'bottom', 'priority' => 201,