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( diff --git a/Classes/EventListener/Order/Payment/ClearCart.php b/Classes/EventListener/Order/Payment/ClearCart.php index 25f95a6..a5b4aaa 100644 --- a/Classes/EventListener/Order/Payment/ClearCart.php +++ b/Classes/EventListener/Order/Payment/ClearCart.php @@ -11,7 +11,7 @@ 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 __invoke(EventInterface $event): void { @@ -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/Configuration/Services.yaml b/Configuration/Services.yaml index 95766b8..6adff0e 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,8 +39,9 @@ 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' event: Extcode\CartPaypal\Event\Order\NotifyEvent + 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.