From a6e8c1da1eba3e627ecdc3ed5a637b635c757b2e Mon Sep 17 00:00:00 2001 From: Pepping Date: Sat, 11 Dec 2021 22:18:11 +0100 Subject: [PATCH 1/5] Fixing cart_paypal issue #23: Adaption to splitted ProcessOrderCreateEvent --- Classes/EventListener/Order/Payment/ClearCart.php | 11 ++++++++++- Configuration/Services.yaml | 6 +++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Classes/EventListener/Order/Payment/ClearCart.php b/Classes/EventListener/Order/Payment/ClearCart.php index 25f95a6..13be22b 100644 --- a/Classes/EventListener/Order/Payment/ClearCart.php +++ b/Classes/EventListener/Order/Payment/ClearCart.php @@ -11,8 +11,17 @@ use Extcode\Cart\Event\Order\EventInterface; -class ClearCart extends \Extcode\Cart\EventListener\ProcessOrderCreate\ClearCart +class ClearCart extends \Extcode\Cart\EventListener\Order\Finish\ClearCart { + public function __construct( + CartUtility $cartUtility, + ParserUtility $parserUtility, + SessionHandler $sessionHandler) + { + // call Grandpa's constructor + parent::__construct($cartUtility, $parserUtility, $sessionHandler); + } + public function __invoke(EventInterface $event): void { $orderItem = $event->getOrderItem(); diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 95766b8..dc17ee4 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -17,6 +17,10 @@ services: $paymentRepository: '@Extcode\Cart\Domain\Repository\Order\PaymentRepository' Extcode\CartPaypal\EventListener\Order\Payment\ClearCart: + arguments: + $cartUtility: '@Extcode\Cart\Utility\CartUtility' + $parserUtility: '@Extcode\Cart\Utility\ParserUtility' + $sessionHandler: '@Extcode\Cart\Service\SessionHandler' tags: - name: event.listener identifier: 'cart-paypal--order--payment--clear-cart' @@ -35,7 +39,7 @@ services: event: Extcode\Cart\Event\Order\PaymentEvent Extcode\CartPaypal\EventListener\Order\Notify\Email: - class: 'Extcode\Cart\EventListener\ProcessOrderCreate\Email' + class: 'Extcode\Cart\EventListener\Order\Finish\Email' tags: - name: event.listener identifier: 'cart-paypal--order--notify--email' From 801f2d751006c7b27f67c84352681de9cfd44bdb Mon Sep 17 00:00:00 2001 From: Pepping Date: Sun, 26 Dec 2021 16:13:43 +0100 Subject: [PATCH 2/5] Fixing cart_paypal issue #23: Adaption to splitted ProcessOrderCreateEvent --- Classes/EventListener/Order/Payment/ClearCart.php | 9 --------- Configuration/Services.yaml | 6 +++--- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/Classes/EventListener/Order/Payment/ClearCart.php b/Classes/EventListener/Order/Payment/ClearCart.php index 13be22b..fcec859 100644 --- a/Classes/EventListener/Order/Payment/ClearCart.php +++ b/Classes/EventListener/Order/Payment/ClearCart.php @@ -13,15 +13,6 @@ class ClearCart extends \Extcode\Cart\EventListener\Order\Finish\ClearCart { - public function __construct( - CartUtility $cartUtility, - ParserUtility $parserUtility, - SessionHandler $sessionHandler) - { - // call Grandpa's constructor - parent::__construct($cartUtility, $parserUtility, $sessionHandler); - } - public function __invoke(EventInterface $event): void { $orderItem = $event->getOrderItem(); diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index dc17ee4..0d05498 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -38,9 +38,9 @@ services: identifier: 'cart-paypal--order--payment--provider-redirect' event: Extcode\Cart\Event\Order\PaymentEvent - Extcode\CartPaypal\EventListener\Order\Notify\Email: + Extcode\Cart\EventListener\Order\Finish\Email: class: 'Extcode\Cart\EventListener\Order\Finish\Email' tags: - name: event.listener - identifier: 'cart-paypal--order--notify--email' - event: Extcode\CartPaypal\Event\Order\NotifyEvent + identifier: 'cart-paypal--order--success--email' + event: Extcode\CartPaypal\Event\Order\SuccessEvent From 51affa5d82d6c3ebd0c113303bc82ec2a5cfc660 Mon Sep 17 00:00:00 2001 From: Pepping Date: Sun, 26 Dec 2021 16:19:59 +0100 Subject: [PATCH 3/5] Restore billing- and shipment address in case the user cancels the payment process for whatever reason. So in case he wants to proceed with ordering there's no need to re-enter the data --- Classes/Controller/Order/PaymentController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Controller/Order/PaymentController.php b/Classes/Controller/Order/PaymentController.php index d547d52..8ea1ade 100644 --- a/Classes/Controller/Order/PaymentController.php +++ b/Classes/Controller/Order/PaymentController.php @@ -160,7 +160,7 @@ public function cancelAction(): void $cancelEvent = new CancelEvent($this->cart->getCart(), $orderItem, $this->cartConf); $this->eventDispatcher->dispatch($cancelEvent); - $this->redirect('show', 'Cart\Cart', 'Cart'); + $this->redirect('show', 'Cart\Cart', 'Cart', ['cart' => $this->cart,'billingAddress' => $orderItem->getBillingAddress(), 'shippingAddress' => $orderItem->getShippingAddress()]); } else { $this->addFlashMessage( LocalizationUtility::translate( From 3574bc23426e817ec41a5bde3dea0e4c97e31f9a Mon Sep 17 00:00:00 2001 From: Pepping Date: Sun, 26 Dec 2021 17:29:00 +0100 Subject: [PATCH 4/5] Fixing cart_paypal issue #23: Adaption to splitted ProcessOrderCreateEvent --- Configuration/Services.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 0d05498..6adff0e 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -38,9 +38,10 @@ services: identifier: 'cart-paypal--order--payment--provider-redirect' event: Extcode\Cart\Event\Order\PaymentEvent - Extcode\Cart\EventListener\Order\Finish\Email: + Extcode\CartPaypal\EventListener\Order\Notify\Email: class: 'Extcode\Cart\EventListener\Order\Finish\Email' tags: - name: event.listener - identifier: 'cart-paypal--order--success--email' - event: Extcode\CartPaypal\Event\Order\SuccessEvent + identifier: 'cart-paypal--order--notify--email' + event: Extcode\CartPaypal\Event\Order\NotifyEvent + From 550ea0073ed1c5eaacc087d883b7880dc61a7b96 Mon Sep 17 00:00:00 2001 From: Pepping Date: Sun, 26 Dec 2021 18:23:39 +0100 Subject: [PATCH 5/5] Add additional provider PAYPAL_CREDIT_CARD to allow forwarding to credit card and direct debit payment in Paypal. Some more feature enhancements to make use of Paypal API --- .../EventListener/Order/Payment/ClearCart.php | 2 +- .../Order/Payment/ProviderRedirect.php | 41 +++++++++++++- .../Configuration/Main/Index.rst | 54 +++++++++++++++++-- .../Configuration/PaymentMethod/Index.rst | 25 +++++++-- 4 files changed, 110 insertions(+), 12 deletions(-) diff --git a/Classes/EventListener/Order/Payment/ClearCart.php b/Classes/EventListener/Order/Payment/ClearCart.php index fcec859..a5b4aaa 100644 --- a/Classes/EventListener/Order/Payment/ClearCart.php +++ b/Classes/EventListener/Order/Payment/ClearCart.php @@ -19,7 +19,7 @@ public function __invoke(EventInterface $event): void $provider = $orderItem->getPayment()->getProvider(); - if (strpos($provider, 'PAYPAL') === 0) { + if ((strpos($provider, 'PAYPAL') === 0) || (strpos($provider, 'PAYPAL_CREDIT_CARD') === 0)) { parent::__invoke($event); } } diff --git a/Classes/EventListener/Order/Payment/ProviderRedirect.php b/Classes/EventListener/Order/Payment/ProviderRedirect.php index 78c7966..e98b36b 100644 --- a/Classes/EventListener/Order/Payment/ProviderRedirect.php +++ b/Classes/EventListener/Order/Payment/ProviderRedirect.php @@ -20,6 +20,7 @@ use TYPO3\CMS\Extbase\Configuration\ConfigurationManager; use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; +use TYPO3\CMS\Core\Log\LogManager; class ProviderRedirect { @@ -85,6 +86,11 @@ class ProviderRedirect * @var array */ protected $cartConf = []; + + /** + * @var logger + */ + protected $logger; public function __construct( ConfigurationManager $configurationManager, @@ -99,6 +105,8 @@ public function __construct( $this->uriBuilder = $uriBuilder; $this->cartRepository = $cartRepository; + $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__); + $this->cartConf = $this->configurationManager->getConfiguration( ConfigurationManager::CONFIGURATION_TYPE_FRAMEWORK, 'Cart' @@ -113,8 +121,8 @@ public function __construct( public function __invoke(PaymentEvent $event): void { $this->orderItem = $event->getOrderItem(); - - if ($this->orderItem->getPayment()->getProvider() !== 'PAYPAL') { + if ($this->orderItem->getPayment()->getProvider() !== 'PAYPAL' && + $this->orderItem->getPayment()->getProvider() !== 'PAYPAL_CREDIT_CARD') { return; } @@ -177,6 +185,35 @@ protected function getQueryFromSettings(): void $this->paymentQuery['upload'] = '1'; $this->paymentQuery['currency_code'] = $this->orderItem->getCurrencyCode(); + + if (strpos($this->orderItem->getPayment()->getProvider(), 'PAYPAL_CREDIT_CARD') === 0) + $this->paymentQuery['landing_page'] = 'billing'; + + $selectedCountry = $this->orderItem->getBillingAddress()->getCountry(); + foreach($this->cartPaypalConf['regionMappings'] as $locale => $countryMapping) + { + if (strpos($selectedCountry, $locale) === 0) + { + $localeAndCountryArray = explode(',', $countryMapping); + + $this->paymentQuery['lc'] = $localeAndCountryArray[1]; + $this->paymentQuery['country_code'] = $localeAndCountryArray[0]; + $this->logger->info("selected locale: " . $locale . " --> lc: " . $localeAndCountryArray[1] . ", country_code: " . $localeAndCountryArray[0]); + } + } + + if ($this->cartPaypalConf['logo']) + { + $site = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Site\SiteFinder::class)->getSiteByPageId((int)$this->cartConf['settings']['order']['pid']); + $logoUrl = $site->getBase() . "/" . $this->cartPaypalConf['logo']; + $this->logger->info($logoUrl); + $this->paymentQuery['image_url'] = $logoUrl; + } + + if ($this->cartPaypalConf['displayShippingAddress']) + $this->paymentQuery['no_shipping'] = '0'; + else + $this->paymentQuery['no_shipping'] = '1'; } protected function getQueryFromCart(): void diff --git a/Documentation/AdministratorManual/Configuration/Main/Index.rst b/Documentation/AdministratorManual/Configuration/Main/Index.rst index 7a7bb58..6b21701 100644 --- a/Documentation/AdministratorManual/Configuration/Main/Index.rst +++ b/Documentation/AdministratorManual/Configuration/Main/Index.rst @@ -16,11 +16,24 @@ The plugin needs to know the merchant e-mail address. :: plugin.tx_cartpaypal { - sandbox = 1 - business = pp-wt-merchant@extco.de - debug = 1 + sandbox = 1 + business = pp-wt-merchant@extco.de + debug = 1 + displayShippingAddress = 1 + logo = fileadmin/cart/somelogo.png + regionMappings { + at = at,AT + de = de,DE + ch = ch,CH + be = be,BE + fr = fr,FR + it = it,IT + lu = lu,LU + nl = nl,NL + sk = sk,SK + si = si,SI + } } - | .. container:: table-row @@ -50,4 +63,35 @@ The plugin needs to know the merchant e-mail address. Data type boolean Description - Enables the logging for some debug messages. \ No newline at end of file + Enables the logging for some debug messages. + +.. container:: table-row + + Property + plugin.tx_cartpaypal.displayShippingAddress + Data type + boolean + Description + Defines if Paypal shall display the shipping address form fields or not (Paypal variable no_shipping). + +.. container:: table-row + + Property + plugin.tx_cartpaypal.logo + Data type + string + Description + Defines the path to a logo being displayed by Paypal. Supported formats are GIF, JPG, PNG with a max of 50KB and dimensions of max 750px width and 90px height. + +.. container:: table-row + + Property + plugin.tx_cartpaypal.regionMappings + Data type + array + Description + Defines the country code and locale being pre-selected in Paypal according to the user-selected target shipment country + (e.g. user selects the Netherlands as target shipment country it makes sense to already pre-select nl,NL as country code and locale) + Left hand is the list of allowed countries as defined for tx_cart (plugin.tx_cart.settings.allowedCountries), right hand side is the combination of country code and locale as defined by Paypal) + Example: en = en,GB --> country code = en, locale = GB + In case no related regionMapping can be found, default bahvior of Paypal is used. diff --git a/Documentation/AdministratorManual/Configuration/PaymentMethod/Index.rst b/Documentation/AdministratorManual/Configuration/PaymentMethod/Index.rst index 110d842..eff9bea 100644 --- a/Documentation/AdministratorManual/Configuration/PaymentMethod/Index.rst +++ b/Documentation/AdministratorManual/Configuration/PaymentMethod/Index.rst @@ -18,10 +18,23 @@ from Cart available. taxClassId = 1 status = open } + 3 { + provider = PAYPAL_CREDIT_CARD + title = Credit Card + extra = 0.00 + taxClassId = 1 + status = open + } + 4 { + provider = PAYPAL_CREDIT_CARD + title = Direct Debit + extra = 0.00 + taxClassId = 1 + status = open + } } } } - | .. container:: table-row @@ -31,6 +44,10 @@ from Cart available. Data type string Description - Defines that the payment provider for PayPal should be used. - This information is mandatory and ensures that the extension Cart PayPal takes control and for the authorization - of payment the user forwards to the PayPal site. + Defines that the payment provider for PayPal should be used. + This information is mandatory and ensures that the extension Cart PayPal takes control for the authorization + of the payment and the user is forwarded to the PayPal site. + The provider 'PAYPAL' forwards to the classic paypal page and a Paypal account is necessary. + The provider 'PAYPAL_CREDIT_CARD' forwards to the billing page of Paypal allowing to pay with credit card and with direct debit. + Generally the user can reach these options from the classic Paypal page as well but it's beneficial to provide the options directly in the shop and forward the user to his preferred option. + However, take note that Cart Paypal cannot detect which payment option is finally used by the user - so please make sure to charge the same amount of fees for all Paypal payment options.