First upload
This commit is contained in:
210
shop/source/modules/oe/oepaypal/Component/BasketComponent.php
Normal file
210
shop/source/modules/oe/oepaypal/Component/BasketComponent.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Component;
|
||||
|
||||
/**
|
||||
* Basket component
|
||||
*
|
||||
* @mixin \OxidEsales\Eshop\Application\Component\BasketComponent
|
||||
*/
|
||||
class BasketComponent extends BasketComponent_parent
|
||||
{
|
||||
/**
|
||||
* Show ECS PopUp
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $shopPopUp = false;
|
||||
|
||||
/**
|
||||
* Method returns URL to checkout products OR to show popup.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function actionExpressCheckoutFromDetailsPage()
|
||||
{
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$validator = $this->getValidator();
|
||||
$currentArticle = $this->getCurrentArticle();
|
||||
$validator->setItemToValidate($currentArticle);
|
||||
$validator->setBasket($session->getBasket());
|
||||
if ($validator->isArticleValid()) {
|
||||
//Make express checkout
|
||||
$res = $this->actionAddToBasketAndGoToCheckout();
|
||||
} else {
|
||||
$res = $this->_getRedirectUrl();
|
||||
//if amount is more than 0, do not redirect, show ESC popup instead
|
||||
if ($currentArticle->getArticleAmount() > 0) {
|
||||
$this->shopPopUp = true;
|
||||
$res = null;
|
||||
}
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether ECS popup should be shown
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function shopECSPopUp()
|
||||
{
|
||||
return $this->shopPopUp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Action method to add product to basket and return checkout URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function actionAddToBasketAndGoToCheckout()
|
||||
{
|
||||
parent::tobasket();
|
||||
|
||||
return $this->getExpressCheckoutUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Action method to return checkout URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function actionNotAddToBasketAndGoToCheckout()
|
||||
{
|
||||
return $this->getExpressCheckoutUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns express checkout URL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getExpressCheckoutUrl()
|
||||
{
|
||||
return 'oepaypalexpresscheckoutdispatcher?fnc=setExpressCheckout&displayCartInPayPal=' . (int) $this->getRequest()->getPostParameter('displayCartInPayPal') . '&oePayPalCancelURL=' . $this->getPayPalCancelURL();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method returns serialized current article params.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrentArticleInfo()
|
||||
{
|
||||
$products = $this->_getItems();
|
||||
$currentArticleId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('aid');
|
||||
$params = null;
|
||||
if (!is_null($products[$currentArticleId])) {
|
||||
$params = $products[$currentArticleId];
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method sets params for article and returns it's object.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\ArticleToExpressCheckoutCurrentItem
|
||||
*/
|
||||
protected function getCurrentArticle()
|
||||
{
|
||||
$currentItem = oxNew(\OxidEsales\PayPalModule\Model\ArticleToExpressCheckoutCurrentItem::class);
|
||||
$currentArticleId = $this->getRequest()->getPostParameter('aid');
|
||||
$products = $this->_getItems();
|
||||
$productInfo = $products[$currentArticleId];
|
||||
$currentItem->setArticleId($currentArticleId);
|
||||
$currentItem->setSelectList($productInfo['sel']);
|
||||
$currentItem->setPersistParam($productInfo['persparam']);
|
||||
$currentItem->setArticleAmount($productInfo['am']);
|
||||
|
||||
return $currentItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method returns request object.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
protected function getRequest()
|
||||
{
|
||||
return oxNew(\OxidEsales\PayPalModule\Core\Request::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method sets params for validator and returns it's object.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\ArticleToExpressCheckoutValidator
|
||||
*/
|
||||
protected function getValidator()
|
||||
{
|
||||
$validator = oxNew(\OxidEsales\PayPalModule\Model\ArticleToExpressCheckoutValidator::class);
|
||||
|
||||
return $validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes oePayPalCancelURL by changing popup showing parameter.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalCancelURL()
|
||||
{
|
||||
$url = $this->formatUrl($this->_getRedirectUrl());
|
||||
$replacedURL = str_replace('showECSPopup=1', 'showECSPopup=0', $url);
|
||||
|
||||
return urlencode($replacedURL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats Redirect URL to normal url
|
||||
*
|
||||
* @param string $unformedUrl
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function formatUrl($unformedUrl)
|
||||
{
|
||||
$myConfig = \OxidEsales\Eshop\Core\Registry::getConfig();
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$params = explode('?', $unformedUrl);
|
||||
$pageParams = isset($params[1]) ? $params[1] : null;
|
||||
$params = explode('/', $params[0]);
|
||||
$className = $params[0];
|
||||
|
||||
$header = ($className) ? "cl=$className&" : ''; // adding view name
|
||||
$header .= ($pageParams) ? "$pageParams&" : ''; // adding page params
|
||||
$header .= $session->sid(); // adding session Id
|
||||
|
||||
$url = $myConfig->getCurrentShopUrl($this->isAdmin());
|
||||
|
||||
$url = "{$url}index.php?{$header}";
|
||||
|
||||
$url = \OxidEsales\Eshop\Core\Registry::getUtilsUrl()->processUrl($url);
|
||||
|
||||
$seoIsActive = \OxidEsales\Eshop\Core\Registry::getUtils()->seoIsActive();
|
||||
if ($seoIsActive && $seoUrl = \OxidEsales\Eshop\Core\Registry::getSeoEncoder()->getStaticUrl($url)) {
|
||||
$url = $seoUrl;
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Component\Widget;
|
||||
|
||||
/**
|
||||
* Article box widget
|
||||
*
|
||||
* @mixin \OxidEsales\Eshop\Application\Component\Widget\ArticleDetails
|
||||
*/
|
||||
class ArticleDetails extends ArticleDetails_parent
|
||||
{
|
||||
/**
|
||||
* Returns products amount to .tpl pages.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function oePayPalGetArticleAmount()
|
||||
{
|
||||
$article = $this->oePayPalGetECSArticle();
|
||||
|
||||
return isset($article['am']) ? (int) $article['am'] : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns persistent parameter.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function oePayPalGetPersistentParam()
|
||||
{
|
||||
$article = $this->oePayPalGetECSArticle();
|
||||
|
||||
return $article['persparam']['details'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns selections array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function oePayPalGetSelection()
|
||||
{
|
||||
$article = $this->oePayPalGetECSArticle();
|
||||
|
||||
return $article['sel'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if showECSPopup parameter was passed.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function oePayPalShowECSPopup()
|
||||
{
|
||||
return $this->getComponent('oxcmp_basket')->shopECSPopUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if showECSPopup parameter was passed.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function oePayPalGetCancelUrl()
|
||||
{
|
||||
return $this->getComponent('oxcmp_basket')->getPayPalCancelURL();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if displayCartInPayPal parameter was passed.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function oePayPalDisplayCartInPayPal()
|
||||
{
|
||||
$displayCartInPayPal = false;
|
||||
if ($this->oePayPalGetRequest()->getPostParameter('displayCartInPayPal')) {
|
||||
$displayCartInPayPal = true;
|
||||
}
|
||||
|
||||
return $displayCartInPayPal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method returns request object.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
protected function oePayPalGetRequest()
|
||||
{
|
||||
return oxNew(\OxidEsales\PayPalModule\Core\Request::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets ECSArticle, unserializes and returns it.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function oePayPalGetECSArticle()
|
||||
{
|
||||
$products = $this->getComponent('oxcmp_basket')->getCurrentArticleInfo();
|
||||
|
||||
return $products;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Controller\Admin;
|
||||
|
||||
/**
|
||||
* Adds additional functionality needed for PayPal when managing delivery sets.
|
||||
*
|
||||
* @mixin \OxidEsales\Eshop\Application\Controller\Admin\DeliverySetMain
|
||||
*/
|
||||
class DeliverySetMain extends DeliverySetMain_parent
|
||||
{
|
||||
/**
|
||||
* Add default PayPal mobile payment.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
$template = parent::render();
|
||||
|
||||
$deliverySetId = $this->getEditObjectId();
|
||||
if ($deliverySetId != "-1" && isset($deliverySetId)) {
|
||||
/** @var \OxidEsales\PayPalModule\Core\Config $config */
|
||||
$config = oxNew(\OxidEsales\PayPalModule\Core\Config::class);
|
||||
|
||||
$isPayPalDefaultMobilePayment = ($deliverySetId == $config->getMobileECDefaultShippingId());
|
||||
|
||||
$this->_aViewData['isPayPalDefaultMobilePayment'] = $isPayPalDefaultMobilePayment;
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves default PayPal mobile payment.
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
parent::save();
|
||||
|
||||
$config = \OxidEsales\Eshop\Core\Registry::getConfig();
|
||||
/** @var \OxidEsales\PayPalModule\Core\Config $payPalConfig */
|
||||
$payPalConfig = oxNew(\OxidEsales\PayPalModule\Core\Config::class);
|
||||
|
||||
$deliverySetId = $this->getEditObjectId();
|
||||
$deliverySetMarked = (bool) $config->getRequestParameter('isPayPalDefaultMobilePayment');
|
||||
$mobileECDefaultShippingId = $payPalConfig->getMobileECDefaultShippingId();
|
||||
|
||||
if ($deliverySetMarked && $deliverySetId != $mobileECDefaultShippingId) {
|
||||
$this->saveECDefaultShippingId($config, $deliverySetId, $payPalConfig);
|
||||
} elseif (!$deliverySetMarked && $deliverySetId == $mobileECDefaultShippingId) {
|
||||
$this->saveECDefaultShippingId($config, '', $payPalConfig);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save default shipping id.
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Core\Config $config Config object to save.
|
||||
* @param string $shippingId Shipping id.
|
||||
* @param \OxidEsales\PayPalModule\Core\Config $payPalConfig PayPal config.
|
||||
*/
|
||||
protected function saveECDefaultShippingId($config, $shippingId, $payPalConfig)
|
||||
{
|
||||
$payPalModuleId = 'module:' . $payPalConfig->getModuleId();
|
||||
$config->saveShopConfVar('string', 'sOEPayPalMECDefaultShippingId', $shippingId, null, $payPalModuleId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
namespace OxidEsales\PayPalModule\Controller\Admin;
|
||||
|
||||
/**
|
||||
* Order class wrapper for PayPal module
|
||||
*/
|
||||
class OrderController extends \OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController
|
||||
{
|
||||
/**
|
||||
* Executes parent method parent::render(), creates oxOrder object,
|
||||
* passes it's data to Smarty engine and returns
|
||||
* name of template file "order_paypal.tpl".
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
parent::render();
|
||||
|
||||
$this->_aViewData["sOxid"] = $this->getEditObjectId();
|
||||
if ($this->isNewPayPalOrder()) {
|
||||
$this->_aViewData['oOrder'] = $this->getEditObject();
|
||||
} else {
|
||||
$this->_aViewData['sMessage'] = $this->isPayPalOrder() ? \OxidEsales\Eshop\Core\Registry::getLang()->translateString("OEPAYPAL_ONLY_FOR_NEW_PAYPAL_PAYMENT") :
|
||||
\OxidEsales\Eshop\Core\Registry::getLang()->translateString("OEPAYPAL_ONLY_FOR_PAYPAL_PAYMENT");
|
||||
}
|
||||
|
||||
return "order_paypal.tpl";
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes PayPal actions.
|
||||
*/
|
||||
public function processAction()
|
||||
{
|
||||
try {
|
||||
/** @var \OxidEsales\PayPalModule\Core\Request $request */
|
||||
$request = oxNew(\OxidEsales\PayPalModule\Core\Request::class);
|
||||
$action = $request->getRequestParameter('action');
|
||||
|
||||
$order = $this->getEditObject();
|
||||
|
||||
/** @var \OxidEsales\PayPalModule\Model\Action\OrderActionFactory $actionFactory */
|
||||
$actionFactory = oxNew(\OxidEsales\PayPalModule\Model\Action\OrderActionFactory::class, $request, $order);
|
||||
$action = $actionFactory->createAction($action);
|
||||
|
||||
$action->process();
|
||||
} catch (\OxidEsales\Eshop\Core\Exception\StandardException $exception) {
|
||||
$this->_aViewData["error"] = $exception->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal order action manager.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderActionManager
|
||||
*/
|
||||
public function getOrderActionManager()
|
||||
{
|
||||
/** @var \OxidEsales\PayPalModule\Model\OrderActionManager $manager */
|
||||
$manager = oxNew(\OxidEsales\PayPalModule\Model\OrderActionManager::class);
|
||||
$manager->setOrder($this->getEditObject()->getPayPalOrder());
|
||||
|
||||
return $manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal order action manager
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPaymentActionManager
|
||||
*/
|
||||
public function getOrderPaymentActionManager()
|
||||
{
|
||||
$manager = oxNew(\OxidEsales\PayPalModule\Model\OrderPaymentActionManager::class);
|
||||
|
||||
return $manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal order action manager
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPaymentStatusCalculator
|
||||
*/
|
||||
public function getOrderPaymentStatusCalculator()
|
||||
{
|
||||
/** @var \OxidEsales\PayPalModule\Model\OrderPaymentStatusCalculator $statusCalculator */
|
||||
$statusCalculator = oxNew(\OxidEsales\PayPalModule\Model\OrderPaymentStatusCalculator::class);
|
||||
$statusCalculator->setOrder($this->getEditObject()->getPayPalOrder());
|
||||
|
||||
return $statusCalculator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal order action manager
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPaymentStatusList
|
||||
*/
|
||||
public function getOrderPaymentStatusList()
|
||||
{
|
||||
$list = oxNew(\OxidEsales\PayPalModule\Model\OrderPaymentStatusList::class);
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns editable order object
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\Order
|
||||
*/
|
||||
public function getEditObject()
|
||||
{
|
||||
$soxId = $this->getEditObjectId();
|
||||
if ($this->_oEditObject === null && isset($soxId) && $soxId != '-1') {
|
||||
$this->_oEditObject = oxNew(\OxidEsales\Eshop\Application\Model\Order::class);
|
||||
$this->_oEditObject->load($soxId);
|
||||
}
|
||||
|
||||
return $this->_oEditObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method checks if order was made with current PayPal module, but not eFire PayPal module
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isNewPayPalOrder()
|
||||
{
|
||||
$active = false;
|
||||
|
||||
$order = $this->getEditObject();
|
||||
$orderPayPal = $order->getPayPalOrder();
|
||||
if ($this->isPayPalOrder() && $orderPayPal->isLoaded()) {
|
||||
$active = true;
|
||||
}
|
||||
|
||||
return $active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method checks is order was made with any PayPal module
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isPayPalOrder()
|
||||
{
|
||||
$active = false;
|
||||
|
||||
$order = $this->getEditObject();
|
||||
if ($order && $order->getFieldData('oxpaymenttype') == 'oxidpaypal') {
|
||||
$active = true;
|
||||
}
|
||||
|
||||
return $active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Template getter for price formatting
|
||||
*
|
||||
* @param double $price price
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function formatPrice($price)
|
||||
{
|
||||
return \OxidEsales\Eshop\Core\Registry::getLang()->formatCurrency($price);
|
||||
}
|
||||
}
|
||||
108
shop/source/modules/oe/oepaypal/Controller/Admin/OrderList.php
Normal file
108
shop/source/modules/oe/oepaypal/Controller/Admin/OrderList.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Controller\Admin;
|
||||
|
||||
/**
|
||||
* Order list class wrapper for PayPal module
|
||||
*
|
||||
* @mixin \OxidEsales\Eshop\Application\Controller\Admin\OrderList
|
||||
*/
|
||||
class OrderList extends OrderList_parent
|
||||
{
|
||||
/**
|
||||
* Executes parent method parent::render() and returns name of template
|
||||
* file "order_list.tpl".
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
$template = parent::render();
|
||||
|
||||
$paymentStatus = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("paypalpaymentstatus");
|
||||
$payment = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("paypalpayment");
|
||||
|
||||
$this->_aViewData["spaypalpaymentstatus"] = $paymentStatus ? $paymentStatus : -1;
|
||||
$this->_aViewData["opaypalpaymentstatuslist"] = new \OxidEsales\PayPalModule\Model\OrderPaymentStatusList();
|
||||
|
||||
$this->_aViewData["paypalpayment"] = $payment ? $payment : -1;
|
||||
|
||||
/** @var \OxidEsales\Eshop\Core\Model\ListModel $paymentList */
|
||||
$paymentList = oxNew(\OxidEsales\Eshop\Core\Model\ListModel::class);
|
||||
$paymentList->init(\OxidEsales\Eshop\Application\Model\Payment::class);
|
||||
|
||||
$this->_aViewData["oPayments"] = $paymentList->getList();
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and returns SQL query string. Adds additional order check.
|
||||
*
|
||||
* @param object $listObject list main object.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _buildSelectString($listObject = null)
|
||||
{
|
||||
$query = parent::_buildSelectString($listObject);
|
||||
|
||||
$viewNameGenerator = \OxidEsales\Eshop\Core\Registry::get(\OxidEsales\Eshop\Core\TableViewNameGenerator::class);
|
||||
$viewName = $viewNameGenerator->getViewName("oxpayments");
|
||||
|
||||
$queryPart = ", `oepaypal_order`.`oepaypal_paymentstatus`, `payments`.`oxdesc` as `paymentname` from oxorder
|
||||
LEFT JOIN `oepaypal_order` ON `oepaypal_order`.`oepaypal_orderid` = `oxorder`.`oxid`
|
||||
LEFT JOIN `" . $viewName . "` AS `payments` on `payments`.oxid=oxorder.oxpaymenttype ";
|
||||
|
||||
$query = str_replace('from oxorder', $queryPart, $query);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adding folder check.
|
||||
*
|
||||
* @param array $where SQL condition array.
|
||||
* @param string $sqlFull SQL query string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _prepareWhereQuery($where, $fullQuery)
|
||||
{
|
||||
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
|
||||
$query = parent::_prepareWhereQuery($where, $fullQuery);
|
||||
|
||||
$paymentStatus = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("paypalpaymentstatus");
|
||||
$paymentStatusList = new \OxidEsales\PayPalModule\Model\OrderPaymentStatusList();
|
||||
|
||||
if ($paymentStatus && $paymentStatus != '-1' && in_array($paymentStatus, $paymentStatusList->getArray())) {
|
||||
$query .= " AND ( `oepaypal_order`.`oepaypal_paymentstatus` = " . $database->quote($paymentStatus) . " )";
|
||||
$query .= " AND ( `oepaypal_order`.`oepaypal_orderid` IS NOT NULL ) ";
|
||||
}
|
||||
|
||||
$payment = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("paypalpayment");
|
||||
if ($payment && $payment != '-1') {
|
||||
$query .= " and ( oxorder.oxpaymenttype = " . $database->quote($payment) . " )";
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
168
shop/source/modules/oe/oepaypal/Controller/Dispatcher.php
Normal file
168
shop/source/modules/oe/oepaypal/Controller/Dispatcher.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Controller;
|
||||
|
||||
use OxidEsales\PayPalModule\Model\PaymentManager;
|
||||
|
||||
/**
|
||||
* Abstract PayPal Dispatcher class
|
||||
*/
|
||||
abstract class Dispatcher extends \OxidEsales\PayPalModule\Controller\FrontendController
|
||||
{
|
||||
/**
|
||||
* Service type identifier - Standard Checkout = 1
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $serviceType = PaymentManager::PAYPAL_SERVICE_TYPE_STANDARD;
|
||||
|
||||
/**
|
||||
* PayPal checkout service
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Core\PayPalService
|
||||
*/
|
||||
protected $payPalCheckoutService;
|
||||
|
||||
/**
|
||||
* Default user action for checkout process
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $userAction = "continue";
|
||||
|
||||
/** @var PaymentManager */
|
||||
protected $paymentManager = null;
|
||||
|
||||
/**
|
||||
* Executes "GetExpressCheckoutDetails" and on SUCCESS response - saves
|
||||
* user information and redirects to order page, on failure - sets error
|
||||
* message and redirects to basket page
|
||||
*/
|
||||
abstract public function getExpressCheckoutDetails();
|
||||
|
||||
/**
|
||||
* Sets PayPal checkout service.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\PayPalService $payPalCheckoutService
|
||||
*/
|
||||
public function setPayPalCheckoutService($payPalCheckoutService)
|
||||
{
|
||||
$this->payPalCheckoutService = $payPalCheckoutService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal service
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\PayPalService
|
||||
*/
|
||||
public function getPayPalCheckoutService()
|
||||
{
|
||||
if ($this->payPalCheckoutService === null) {
|
||||
$this->payPalCheckoutService = oxNew(\OxidEsales\PayPalModule\Core\PayPalService::class);
|
||||
}
|
||||
|
||||
return $this->payPalCheckoutService;
|
||||
}
|
||||
|
||||
protected function getPaymentManager(): PaymentManager
|
||||
{
|
||||
if (is_null($this->paymentManager)) {
|
||||
$this->paymentManager = oxNew(PaymentManager::class, $this->getPayPalCheckoutService());
|
||||
}
|
||||
|
||||
return $this->paymentManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \OxidEsales\Eshop\Core\UtilsView
|
||||
*/
|
||||
protected function getUtilsView()
|
||||
{
|
||||
return \OxidEsales\Eshop\Core\Registry::getUtilsView();
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats given float/int value into PayPal friendly form
|
||||
*
|
||||
* @param float $in value to format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function formatFloat($in)
|
||||
{
|
||||
return sprintf("%.2f", $in);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns oxUtils instance
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Core\Utils
|
||||
*/
|
||||
protected function getUtils()
|
||||
{
|
||||
return \OxidEsales\Eshop\Core\Registry::getUtils();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns base url, which is used to construct Callback, Return and Cancel Urls
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getBaseUrl()
|
||||
{
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$url = \OxidEsales\Eshop\Core\Registry::getConfig()->getSslShopUrl() . "index.php?lang=" . \OxidEsales\Eshop\Core\Registry::getLang()->getBaseLanguage() . "&sid=" . $session->getId() . "&rtoken=" . $session->getRemoteAccessToken();
|
||||
$url .= "&shp=" . \OxidEsales\Eshop\Core\Registry::getConfig()->getShopId();
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal order object
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Application\Model\Order|null
|
||||
*/
|
||||
protected function getPayPalOrder()
|
||||
{
|
||||
$order = oxNew(\OxidEsales\Eshop\Application\Model\Order::class);
|
||||
if ($order->loadPayPalOrder()) {
|
||||
return $order;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal payment object
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Application\Model\Payment|null
|
||||
*/
|
||||
protected function getPayPalPayment()
|
||||
{
|
||||
$userPayment = null;
|
||||
|
||||
if (($order = $this->getPayPalOrder())) {
|
||||
$userPayment = oxNew(\OxidEsales\Eshop\Application\Model\UserPayment::class);
|
||||
$userPayment->load($order->oxorder__oxpaymentid->value);
|
||||
}
|
||||
|
||||
return $userPayment;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,697 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Controller;
|
||||
|
||||
use OxidEsales\Eshop\Core\Registry as EshopRegistry;
|
||||
use OxidEsales\PayPalModule\Model\PaymentManager;
|
||||
use OxidEsales\PayPalModule\Model\Response\ResponseGetExpressCheckoutDetails;
|
||||
|
||||
/**
|
||||
* PayPal Express Checkout dispatcher class
|
||||
*/
|
||||
class ExpressCheckoutDispatcher extends \OxidEsales\PayPalModule\Controller\Dispatcher
|
||||
{
|
||||
/**
|
||||
* Service type identifier - Express Checkout = 2
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $serviceType = PaymentManager::PAYPAL_SERVICE_TYPE_EXPRESS;
|
||||
|
||||
/**
|
||||
* Processes PayPal callback for graphql
|
||||
*/
|
||||
public function processGraphQLCallBack()
|
||||
{
|
||||
$basketId = $this->getRequest()->getRequestParameter("basketid");
|
||||
$sessionBasket = $this->getPaymentManager()->prepareCallback($basketId);
|
||||
EshopRegistry::getSession()->setBasket($sessionBasket);
|
||||
|
||||
$this->processCallBack();
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes PayPal callback
|
||||
*/
|
||||
public function processCallBack()
|
||||
{
|
||||
$payPalService = $this->getPayPalCheckoutService();
|
||||
$this->setParamsForCallbackResponse($payPalService);
|
||||
$request = $payPalService->callbackResponse();
|
||||
EshopRegistry::getUtils()->showMessageAndExit($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes "SetExpressCheckout" and on SUCCESS response - redirects to PayPal
|
||||
* login/registration page, on error - returns to configured view (default is "basket"),
|
||||
* which means - redirect to configured view (default basket) and display error message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function setExpressCheckout()
|
||||
{
|
||||
$session = EshopRegistry::getSession();
|
||||
$session->setVariable("oepaypal", PaymentManager::PAYPAL_SERVICE_TYPE_EXPRESS);
|
||||
try {
|
||||
$session->setVariable('paymentid', 'oxidpaypal');
|
||||
$shippingId = '';
|
||||
|
||||
if ($this->getPayPalConfig()->isDeviceMobile()) {
|
||||
$shippingId = (string) $this->getPayPalConfig()->getMobileECDefaultShippingId();
|
||||
}
|
||||
|
||||
$result = $this->getPaymentManager()->setExpressCheckout(
|
||||
$session->getBasket(),
|
||||
$this->getUser() ?: null,
|
||||
$this->getReturnUrl(),
|
||||
$this->getCancelUrl(),
|
||||
$this->getCallBackUrl(),
|
||||
(bool)$this->getRequest()->getRequestParameter("displayCartInPayPal"),
|
||||
$shippingId
|
||||
);
|
||||
} catch (\OxidEsales\Eshop\Core\Exception\StandardException $excp) {
|
||||
// error - unable to set order info - display error message
|
||||
$this->getUtilsView()->addErrorToDisplay($excp);
|
||||
|
||||
// return to requested view
|
||||
$returnTo = $this->getRequestedControllerKey();
|
||||
$returnTo = !empty($returnTo) ? $returnTo : 'basket';
|
||||
return $returnTo;
|
||||
}
|
||||
|
||||
// saving PayPal token into session
|
||||
$session->setVariable("oepaypal-token", $result->getToken());
|
||||
|
||||
// extracting token and building redirect url
|
||||
$url = $this->getPayPalConfig()->getPayPalCommunicationUrl($result->getToken(), $this->userAction);
|
||||
|
||||
// redirecting to PayPal's login/registration page
|
||||
$this->getUtils()->redirect($url, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes "GetExpressCheckoutDetails" and on SUCCESS response - saves
|
||||
* user information and redirects to order page, on failure - sets error
|
||||
* message and redirects to basket page
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getExpressCheckoutDetails()
|
||||
{
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$basket = $session->getBasket();
|
||||
|
||||
try {
|
||||
/** @var ResponseGetExpressCheckoutDetails $details */
|
||||
$details = $this->getPaymentManager()->getExpressCheckoutDetails();
|
||||
|
||||
// Remove flag of "new item added" to not show "Item added" popup when returning to checkout from paypal
|
||||
$basket->isNewItemAdded();
|
||||
|
||||
// creating new or using session user
|
||||
$user = $this->initializeUserData($details);
|
||||
} catch (\OxidEsales\Eshop\Core\Exception\StandardException $excp) {
|
||||
$this->getUtilsView()->addErrorToDisplay($excp);
|
||||
|
||||
$logger = $this->getLogger();
|
||||
$logger->log("PayPal error: " . $excp->getMessage());
|
||||
|
||||
return "basket";
|
||||
}
|
||||
|
||||
// setting PayPal as current active payment
|
||||
$session->setVariable('paymentid', "oxidpaypal");
|
||||
$basket->setPayment("oxidpaypal");
|
||||
|
||||
if (!$this->isPaymentValidForUserCountry($user)) {
|
||||
$this->getUtilsView()->addErrorToDisplay('MESSAGE_PAYMENT_SELECT_ANOTHER_PAYMENT');
|
||||
|
||||
$logger = $this->getLogger();
|
||||
$logger->log("Shop error: PayPal payment validation by user country failed. Payment is not valid for this country.");
|
||||
|
||||
return "payment";
|
||||
}
|
||||
|
||||
$shippingId = $this->extractShippingId(urldecode($details->getShippingOptionName()), $user);
|
||||
|
||||
$this->setAnonymousUser($basket, $user);
|
||||
|
||||
$basket->setShipping($shippingId);
|
||||
$basket->onUpdate();
|
||||
$basket->calculateBasket(true);
|
||||
|
||||
$basketPrice = $basket->getPrice()->getBruttoPrice();
|
||||
|
||||
if (!$this->isPayPalPaymentValid($user, $basketPrice, $basket->getShippingId())) {
|
||||
$this->getUtilsView()->addErrorToDisplay("OEPAYPAL_SELECT_ANOTHER_SHIPMENT");
|
||||
|
||||
return "order";
|
||||
}
|
||||
|
||||
// Checking if any additional discount was applied after we returned from PayPal.
|
||||
if ($basketPrice != $details->getAmount()) {
|
||||
$this->getUtilsView()->addErrorToDisplay("OEPAYPAL_ORDER_TOTAL_HAS_CHANGED");
|
||||
|
||||
return "basket";
|
||||
}
|
||||
|
||||
$session->setVariable("oepaypal-payerId", $details->getPayerId());
|
||||
$session->setVariable("oepaypal-userId", $user->getId());
|
||||
$session->setVariable("oepaypal-basketAmount", $details->getAmount());
|
||||
|
||||
$next = "order";
|
||||
|
||||
if ($this->getPayPalConfig()->finalizeOrderOnPayPalSide()) {
|
||||
$next .= "?fnc=execute";
|
||||
$next .= "&sDeliveryAddressMD5=" . $user->getEncodedDeliveryAddress();
|
||||
$next .= "&stoken=" . $session->getSessionChallengeToken();
|
||||
}
|
||||
|
||||
return $next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns transaction mode.
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Application\Model\Basket $basket
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @deprecated Please use OxidEsales\PayPalModule\Model\PaymentManager::getTransactionMode
|
||||
*/
|
||||
protected function getTransactionMode($basket)
|
||||
{
|
||||
$paymentManager = $this->getPaymentManager();
|
||||
return $paymentManager->getTransactionMode($basket, $this->getPayPalConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns RETURN URL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getReturnUrl()
|
||||
{
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$controllerKey = \OxidEsales\Eshop\Core\Registry::getControllerClassNameResolver()->getIdByClassName(get_class());
|
||||
return $session->processUrl($this->getBaseUrl() . "&cl=" . $controllerKey . "&fnc=getExpressCheckoutDetails");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns CANCEL URL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getCancelUrl()
|
||||
{
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$cancelURLFromRequest = $this->getRequest()->getRequestParameter('oePayPalCancelURL');
|
||||
$cancelUrl = $session->processUrl($this->getBaseUrl() . "&cl=basket");
|
||||
|
||||
if ($cancelURLFromRequest) {
|
||||
$cancelUrl = html_entity_decode(urldecode($cancelURLFromRequest));
|
||||
} elseif ($requestedControllerKey = $this->getRequestedControllerKey()) {
|
||||
$cancelUrl = $session->processUrl($this->getBaseUrl() . '&cl=' . $requestedControllerKey);
|
||||
}
|
||||
|
||||
return $cancelUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract requested controller key.
|
||||
* In case the key makes sense (we find a matching class) it will be returned.
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
protected function getRequestedControllerKey()
|
||||
{
|
||||
$return = null;
|
||||
$requestedControllerKey = $this->getRequest()->getRequestParameter('oePayPalRequestedControllerKey');
|
||||
if (!empty($requestedControllerKey) &&
|
||||
\OxidEsales\Eshop\Core\Registry::getControllerClassNameResolver()->getClassNameById($requestedControllerKey)) {
|
||||
$return = $requestedControllerKey;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns CALLBACK URL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getCallBackUrl()
|
||||
{
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$controllerKey = \OxidEsales\Eshop\Core\Registry::getControllerClassNameResolver()->getIdByClassName(get_class());
|
||||
return $session->processUrl($this->getBaseUrl() . "&cl=" . $controllerKey . "&fnc=processCallBack");
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize new user from user data.
|
||||
*
|
||||
* @param array $data User data array.
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Application\Model\User
|
||||
*/
|
||||
protected function getCallBackUser($data)
|
||||
{
|
||||
// simulating user object
|
||||
$user = oxNew(\OxidEsales\Eshop\Application\Model\User::class);
|
||||
$user->initializeUserForCallBackPayPalUser($data);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets parameters to PayPal callback
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\PayPalService $payPalService PayPal service
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
protected function setParamsForCallbackResponse($payPalService)
|
||||
{
|
||||
//logging request from PayPal
|
||||
$logger = $this->getLogger();
|
||||
$logger->setTitle("CALLBACK REQUEST FROM PAYPAL");
|
||||
$logger->log(http_build_query($_REQUEST, "", "&"));
|
||||
|
||||
// initializing user..
|
||||
$user = $this->getCallBackUser($_REQUEST);
|
||||
|
||||
// unknown country?
|
||||
if (!$this->getUserShippingCountryId($user)) {
|
||||
$logger = $this->getLogger();
|
||||
$logger->log("Callback error: NO SHIPPING COUNTRY ID");
|
||||
|
||||
// unknown country - no delivery
|
||||
$this->setPayPalIsNotAvailable($payPalService);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//basket
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$basket = $session->getBasket();
|
||||
|
||||
// get possible delivery sets
|
||||
$delSetList = $this->getDeliverySetList($user);
|
||||
|
||||
//no shipping methods for user country
|
||||
if (empty($delSetList)) {
|
||||
$logger = $this->getLogger();
|
||||
$logger->log("Callback error: NO DELIVERY LIST SET");
|
||||
|
||||
$this->setPayPalIsNotAvailable($payPalService);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$deliverySetList = $this->makeUniqueNames($delSetList);
|
||||
|
||||
// checking if PayPal is valid payment for selected user country
|
||||
if (!$this->isPaymentValidForUserCountry($user)) {
|
||||
$logger->log("Callback error: NOT VALID COUNTRY ID");
|
||||
|
||||
// PayPal payment is not possible for user country
|
||||
$this->setPayPalIsNotAvailable($payPalService);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$session->setVariable('oepaypal-oxDelSetList', $deliverySetList);
|
||||
|
||||
$totalDeliveries = $this->setDeliverySetListForCallbackResponse($payPalService, $deliverySetList, $user, $basket);
|
||||
|
||||
// if none of deliveries contain PayPal - disabling PayPal
|
||||
if ($totalDeliveries == 0) {
|
||||
$logger->log("Callback error: DELIVERY SET LIST HAS NO PAYPAL");
|
||||
|
||||
$this->setPayPalIsNotAvailable($payPalService);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$payPalService->setParameter("OFFERINSURANCEOPTION", "false");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets delivery sets parameters to PayPal callback
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\PayPalService $payPalService PayPal service.
|
||||
* @param array $deliverySetList Delivery list.
|
||||
* @param \OxidEsales\Eshop\Application\Model\User $user User object.
|
||||
* @param \OxidEsales\Eshop\Application\Model\Basket $basket Basket object.
|
||||
*
|
||||
* @return int Total amount of deliveries
|
||||
*/
|
||||
protected function setDeliverySetListForCallbackResponse($payPalService, $deliverySetList, $user, $basket)
|
||||
{
|
||||
$maxDeliveryAmount = $this->getPayPalConfig()->getMaxPayPalDeliveryAmount();
|
||||
$cur = \OxidEsales\Eshop\Core\Registry::getConfig()->getActShopCurrencyObject();
|
||||
$basketPrice = $basket->getPriceForPayment() / $cur->rate;
|
||||
$actShipSet = $basket->getShippingId();
|
||||
$hasActShipSet = false;
|
||||
$cnt = 0;
|
||||
|
||||
// VAT for delivery will be calculated always
|
||||
$delVATPercent = $basket->getAdditionalServicesVatPercent();
|
||||
|
||||
foreach ($deliverySetList as $delSetId => $delSetName) {
|
||||
// checking if PayPal is valid payment for selected delivery set
|
||||
if (!$this->isPayPalInDeliverySet($delSetId, $basketPrice, $user)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$deliveryListProvider = oxNew(\OxidEsales\Eshop\Application\Model\DeliveryList::class);
|
||||
$deliveryList = array();
|
||||
|
||||
// list of active delivery costs
|
||||
if ($deliveryListProvider->hasDeliveries($basket, $user, $this->getUserShippingCountryId($user), $delSetId)) {
|
||||
$deliveryList = $deliveryListProvider->getDeliveryList($basket, $user, $this->getUserShippingCountryId($user), $delSetId);
|
||||
}
|
||||
|
||||
if (is_array($deliveryList) && !empty($deliveryList)) {
|
||||
$price = 0;
|
||||
|
||||
if (\OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('bl_perfLoadDelivery')) {
|
||||
foreach ($deliveryList as $delivery) {
|
||||
$price += $delivery->getDeliveryPrice($delVATPercent)->getBruttoPrice();
|
||||
}
|
||||
}
|
||||
|
||||
if ($price <= $maxDeliveryAmount) {
|
||||
$payPalService->setParameter("L_SHIPPINGOPTIONNAME{$cnt}", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($delSetName));
|
||||
$payPalService->setParameter("L_SHIPPINGOPTIONLABEL{$cnt}", \OxidEsales\Eshop\Core\Registry::getLang()->translateString("OEPAYPAL_PRICE"));
|
||||
$payPalService->setParameter("L_SHIPPINGOPTIONAMOUNT{$cnt}", $this->formatFloat($price));
|
||||
|
||||
//setting active delivery set
|
||||
if ($delSetId == $actShipSet) {
|
||||
$hasActShipSet = true;
|
||||
$payPalService->setParameter("L_SHIPPINGOPTIONISDEFAULT{$cnt}", "true");
|
||||
} else {
|
||||
$payPalService->setParameter("L_SHIPPINGOPTIONISDEFAULT{$cnt}", "false");
|
||||
}
|
||||
|
||||
if ($basket->isCalculationModeNetto()) {
|
||||
$payPalService->setParameter("L_TAXAMT{$cnt}", $this->formatFloat($basket->getPayPalBasketVatValue()));
|
||||
} else {
|
||||
$payPalService->setParameter("L_TAXAMT{$cnt}", $this->formatFloat(0));
|
||||
}
|
||||
}
|
||||
|
||||
$cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
//checking if active delivery set was set - if not, setting first in the list
|
||||
if ($cnt > 0 && !$hasActShipSet) {
|
||||
$payPalService->setParameter("L_SHIPPINGOPTIONISDEFAULT0", "true");
|
||||
}
|
||||
|
||||
return $cnt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes delivery set array with unique names
|
||||
*
|
||||
* @param array $deliverySetList delivery list
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @deprecated Please use OxidEsales\PayPalModule\Model\PaymentManager::makeUniqueNames
|
||||
*/
|
||||
public function makeUniqueNames($deliverySetList)
|
||||
{
|
||||
return $this->getPaymentManager()->makeUniqueNames($deliverySetList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal user
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Application\Model\User
|
||||
*/
|
||||
protected function getPayPalUser()
|
||||
{
|
||||
$user = oxNew(\OxidEsales\Eshop\Application\Model\User::class);
|
||||
if (!$user->loadUserPayPalUser()) {
|
||||
$user = $this->getUser();
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extracts shipping id from given parameter
|
||||
*
|
||||
* @param string $shippingOptionName Shipping option name, which comes from PayPal.
|
||||
* @param \OxidEsales\Eshop\Application\Model\User $user User object.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function extractShippingId($shippingOptionName, $user)
|
||||
{
|
||||
$deliverySetList = \OxidEsales\Eshop\Core\Registry::getSession()->getVariable("oepaypal-oxDelSetList");
|
||||
|
||||
return $this->getPaymentManager()->extractShippingId($shippingOptionName, $user, $deliverySetList);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new or returns session user
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\Response\ResponseGetExpressCheckoutDetails $details
|
||||
*
|
||||
* @throws \OxidEsales\Eshop\Core\Exception\StandardException
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Application\Model\User
|
||||
*/
|
||||
protected function initializeUserData($details)
|
||||
{
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$userEmail = $details->getEmail();
|
||||
$loggedUser = $this->getUser();
|
||||
if ($loggedUser) {
|
||||
$userEmail = $loggedUser->oxuser__oxusername->value;
|
||||
}
|
||||
|
||||
$user = oxNew(\OxidEsales\Eshop\Application\Model\User::class);
|
||||
if ($userId = $user->isRealPayPalUser($userEmail)) {
|
||||
// if user exist
|
||||
$user->load($userId);
|
||||
|
||||
if (!$loggedUser) {
|
||||
if (!$user->isSamePayPalUser($details)) {
|
||||
/**
|
||||
* @var $exception \OxidEsales\Eshop\Core\Exception\StandardException
|
||||
*/
|
||||
$exception = oxNew(\OxidEsales\Eshop\Core\Exception\StandardException::class);
|
||||
$exception->setMessage('OEPAYPAL_ERROR_USER_ADDRESS');
|
||||
throw $exception;
|
||||
}
|
||||
} elseif (!$user->isSameAddressUserPayPalUser($details) || !$user->isSameAddressPayPalUser($details)) {
|
||||
// user has selected different address in PayPal (not equal with usr shop address)
|
||||
// so adding PayPal address as new user address to shop user account
|
||||
$this->createUserAddress($details, $userId);
|
||||
} else {
|
||||
// removing custom shipping address ID from session as user uses billing
|
||||
// address for shipping
|
||||
$session->deleteVariable('deladrid');
|
||||
}
|
||||
} else {
|
||||
$user->createPayPalUser($details);
|
||||
}
|
||||
|
||||
$session->setVariable('usr', $user->getId());
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates user address and sets address id into session
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\Response\ResponseGetExpressCheckoutDetails $details User address info.
|
||||
* @param string $userId User id.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function createUserAddress($details, $userId)
|
||||
{
|
||||
$address = oxNew(\OxidEsales\Eshop\Application\Model\Address::class);
|
||||
|
||||
return $address->createPayPalAddress($details, $userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checking if PayPal payment is available in user country
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Application\Model\User $user User object.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isPaymentValidForUserCountry($user)
|
||||
{
|
||||
$payment = oxNew(\OxidEsales\Eshop\Application\Model\Payment::class);
|
||||
$payment->load("oxidpaypal");
|
||||
$paymentCountries = $payment->getCountries();
|
||||
|
||||
if (!is_array($paymentCountries) || empty($paymentCountries)) {
|
||||
// not assigned to any country - valid to all countries
|
||||
return true;
|
||||
}
|
||||
|
||||
return in_array($this->getUserShippingCountryId($user), $paymentCountries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if selected delivery set has PayPal payment.
|
||||
*
|
||||
* @param string $delSetId Delivery set ID.
|
||||
* @param double $basketPrice Basket price.
|
||||
* @param \OxidEsales\Eshop\Application\Model\User $user User object.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isPayPalInDeliverySet($delSetId, $basketPrice, $user)
|
||||
{
|
||||
$paymentList = \OxidEsales\Eshop\Core\Registry::get(\OxidEsales\Eshop\Application\Model\PaymentList::class);
|
||||
$paymentList = $paymentList->getPaymentList($delSetId, $basketPrice, $user);
|
||||
|
||||
if (is_array($paymentList) && array_key_exists("oxidpaypal", $paymentList)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables PayPal payment in PayPal side
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\PayPalService $payPalService PayPal service.
|
||||
*/
|
||||
protected function setPayPalIsNotAvailable($payPalService)
|
||||
{
|
||||
// "NO_SHIPPING_OPTION_DETAILS" works only in version 61, so need to switch version
|
||||
$payPalService->setParameter("CALLBACKVERSION", "61.0");
|
||||
$payPalService->setParameter("NO_SHIPPING_OPTION_DETAILS", "1");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get delivery set list for PayPal callback
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Application\Model\User $user User object.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getDeliverySetList($user)
|
||||
{
|
||||
$delSetList = oxNew(\OxidEsales\Eshop\Application\Model\DeliverySetList::class);
|
||||
|
||||
return $delSetList->getDeliverySetList($user, $this->getUserShippingCountryId($user));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns user shipping address country id.
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Application\Model\User $user
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getUserShippingCountryId($user)
|
||||
{
|
||||
if ($user->getSelectedAddressId() && $user->getSelectedAddress()) {
|
||||
$countryId = $user->getSelectedAddress()->oxaddress__oxcountryid->value;
|
||||
} else {
|
||||
$countryId = $user->oxuser__oxcountryid->value;
|
||||
}
|
||||
|
||||
return $countryId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether PayPal payment is available
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Application\Model\User $user
|
||||
* @param double $basketPrice
|
||||
* @param string $shippingId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isPayPalPaymentValid($user, $basketPrice, $shippingId)
|
||||
{
|
||||
$valid = true;
|
||||
|
||||
$payPalPayment = oxNew(\OxidEsales\Eshop\Application\Model\Payment::class);
|
||||
$payPalPayment->load('oxidpaypal');
|
||||
if (!$payPalPayment->isValidPayment(null, null, $user, $basketPrice, $shippingId)) {
|
||||
$valid = $this->isEmptyPaymentValid($user, $basketPrice, $shippingId);
|
||||
}
|
||||
|
||||
return $valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether Empty payment is available.
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Application\Model\User $user
|
||||
* @param double $basketPrice
|
||||
* @param string $shippingId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isEmptyPaymentValid($user, $basketPrice, $shippingId)
|
||||
{
|
||||
$valid = true;
|
||||
|
||||
$emptyPayment = oxNew(\OxidEsales\Eshop\Application\Model\Payment::class);
|
||||
$emptyPayment->load('oxempty');
|
||||
if (!$emptyPayment->isValidPayment(null, null, $user, $basketPrice, $shippingId)) {
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
return $valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* PayPal express checkout might be called before user is set to basket.
|
||||
* This happens if user is not logged in to the Shop
|
||||
* and it goes to PayPal from details page or basket first step.
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Application\Model\Basket $basket
|
||||
* @param \OxidEsales\Eshop\Application\Model\User $user
|
||||
*/
|
||||
private function setAnonymousUser($basket, $user)
|
||||
{
|
||||
$basket->setBasketUser($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $input
|
||||
*
|
||||
* @deprecated Please use OxidEsales\PayPalModule\Model\PaymentManager::reencodeHtmlEntities
|
||||
*/
|
||||
private function reencodeHtmlEntities($input)
|
||||
{
|
||||
$charset = $this->getPayPalConfig()->getCharset();
|
||||
|
||||
return htmlentities(html_entity_decode($input, ENT_QUOTES, $charset), ENT_QUOTES, $charset);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
namespace OxidEsales\PayPalModule\Controller;
|
||||
|
||||
/**
|
||||
* Main PayPal controller
|
||||
*/
|
||||
class FrontendController extends \OxidEsales\Eshop\Application\Controller\FrontendController
|
||||
{
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
protected $request = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Core\Logger
|
||||
*/
|
||||
protected $logger = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Core\Config
|
||||
*/
|
||||
protected $payPalConfig = null;
|
||||
|
||||
/**
|
||||
* Return request object
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
if (is_null($this->request)) {
|
||||
$this->request = oxNew(\OxidEsales\PayPalModule\Core\Request::class);
|
||||
}
|
||||
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return PayPal logger
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Logger
|
||||
*/
|
||||
public function getLogger()
|
||||
{
|
||||
if (is_null($this->logger)) {
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$this->logger = oxNew(\OxidEsales\PayPalModule\Core\Logger::class);
|
||||
$this->logger->setLoggerSessionId($session->getId());
|
||||
}
|
||||
|
||||
return $this->logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return PayPal config
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Config
|
||||
*/
|
||||
public function getPayPalConfig()
|
||||
{
|
||||
if (is_null($this->payPalConfig)) {
|
||||
$this->setPayPalConfig(oxNew(\OxidEsales\PayPalModule\Core\Config::class));
|
||||
}
|
||||
|
||||
return $this->payPalConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PayPal config
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\Config $payPalConfig config
|
||||
*/
|
||||
public function setPayPalConfig($payPalConfig)
|
||||
{
|
||||
$this->payPalConfig = $payPalConfig;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Logs passed value.
|
||||
*
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function log($value)
|
||||
{
|
||||
if ($this->getPayPalConfig()->isLoggingEnabled()) {
|
||||
$this->getLogger()->log($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
197
shop/source/modules/oe/oepaypal/Controller/IPNHandler.php
Normal file
197
shop/source/modules/oe/oepaypal/Controller/IPNHandler.php
Normal file
@@ -0,0 +1,197 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
namespace OxidEsales\PayPalModule\Controller;
|
||||
|
||||
/**
|
||||
* PayPal IPN handler class.
|
||||
*
|
||||
* Handle PayPal notifications.
|
||||
* - Extract data.
|
||||
* - Check if valid.
|
||||
* - Call order methods to save data.
|
||||
*/
|
||||
class IPNHandler extends \OxidEsales\PayPalModule\Controller\FrontendController
|
||||
{
|
||||
/**
|
||||
* Current class default template name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_sThisTemplate = 'ipnhandler.tpl';
|
||||
|
||||
/**
|
||||
* PayPal request handler.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
protected $payPalRequest = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Model\IPNRequestVerifier
|
||||
*/
|
||||
protected $ipnRequestVerifier = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Model\IPNProcessor
|
||||
*/
|
||||
protected $processor = null;
|
||||
|
||||
/**
|
||||
* Set object to handle request.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\Request $payPalRequest object to set.
|
||||
*/
|
||||
public function setPayPalRequest($payPalRequest)
|
||||
{
|
||||
$this->payPalRequest = $payPalRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create object \OxidEsales\PayPalModule\Core\Request to get PayPal request information.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
public function getPayPalRequest()
|
||||
{
|
||||
if ($this->payPalRequest === null) {
|
||||
$this->payPalRequest = oxNew(\OxidEsales\PayPalModule\Core\Request::class);
|
||||
}
|
||||
|
||||
return $this->payPalRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets IPN request verifier.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\IPNRequestVerifier $ipnRequestVerifier
|
||||
*/
|
||||
public function setIPNRequestVerifier($ipnRequestVerifier)
|
||||
{
|
||||
$this->ipnRequestVerifier = $ipnRequestVerifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns IPN request verifier.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\IPNRequestVerifier
|
||||
*/
|
||||
public function getIPNRequestVerifier()
|
||||
{
|
||||
if (is_null($this->ipnRequestVerifier)) {
|
||||
$ipnRequestVerifier = oxNew(\OxidEsales\PayPalModule\Model\IPNRequestVerifier::class);
|
||||
$this->setIPNRequestVerifier($ipnRequestVerifier);
|
||||
}
|
||||
|
||||
return $this->ipnRequestVerifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* \OxidEsales\PayPalModule\Model\IPNProcessor setter.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\IPNProcessor $processor
|
||||
*/
|
||||
public function setProcessor($processor)
|
||||
{
|
||||
$this->processor = $processor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns \OxidEsales\PayPalModule\Model\IPNProcessor object. If object is not set, than it creates it and sets.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\IPNProcessor
|
||||
*/
|
||||
public function getProcessor()
|
||||
{
|
||||
if (is_null($this->processor)) {
|
||||
$processor = oxNew(\OxidEsales\PayPalModule\Model\IPNProcessor::class);
|
||||
$this->setProcessor($processor);
|
||||
}
|
||||
|
||||
return $this->processor;
|
||||
}
|
||||
|
||||
/**
|
||||
* IPN handling function.
|
||||
* - Call to check if request is valid (from PayPal and to correct shop).
|
||||
* - Initiate payment status changes according to IPN information.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handleRequest()
|
||||
{
|
||||
$requestHandled = false;
|
||||
$requestId = md5(microtime(true));
|
||||
|
||||
$request = $this->getPayPalRequest();
|
||||
$logger = $this->getLogger();
|
||||
$logger->setTitle("IPN Request by PayPal");
|
||||
$logger->log([
|
||||
'Request ID' => $requestId,
|
||||
'GET parameters' => $request->getGet(),
|
||||
'POST parameters' => $request->getPost()
|
||||
]);
|
||||
|
||||
$requestValid = $this->requestValid();
|
||||
|
||||
if ($requestValid) {
|
||||
$lang = $this->getPayPalConfig()->getLang();
|
||||
|
||||
$processor = $this->getProcessor();
|
||||
$processor->setRequest($request);
|
||||
$processor->setLang($lang);
|
||||
|
||||
$requestHandled = $processor->process();
|
||||
}
|
||||
|
||||
$logger->setTitle("IPN Process result");
|
||||
$logger->log([
|
||||
'Request ID' => $requestId,
|
||||
'Result' => $requestHandled
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* IPN handling function.
|
||||
* - Verify request with PayPal (if request from PayPal and to correct shop).
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function requestValid()
|
||||
{
|
||||
$requestValid = true;
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
$ipnRequestVerifier = $this->getIPNRequestVerifier();
|
||||
$ipnRequestVerifier->setRequest($request);
|
||||
$ipnRequestVerifier->setShopOwner($this->getPayPalConfig()->getUserEmail());
|
||||
$requestCorrect = $ipnRequestVerifier->requestCorrect();
|
||||
|
||||
if (!$requestCorrect) {
|
||||
$requestValid = false;
|
||||
|
||||
$logger = $this->getLogger();
|
||||
$logger->setTitle("IPN VERIFICATION FAILURE BY PAYPAL");
|
||||
$logger->log($ipnRequestVerifier->getFailureMessage());
|
||||
}
|
||||
|
||||
return $requestValid;
|
||||
}
|
||||
}
|
||||
146
shop/source/modules/oe/oepaypal/Controller/OrderController.php
Normal file
146
shop/source/modules/oe/oepaypal/Controller/OrderController.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Controller;
|
||||
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
|
||||
/**
|
||||
* Order class wrapper for PayPal module
|
||||
*
|
||||
* @mixin \OxidEsales\Eshop\Application\Controller\OrderController
|
||||
*/
|
||||
class OrderController extends OrderController_parent
|
||||
{
|
||||
/**
|
||||
* Checks if payment action is processed by PayPal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isPayPal()
|
||||
{
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
return ($session->getVariable("paymentid") == "oxidpaypal");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal user
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Application\Model\User
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
$user = parent::getUser();
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
|
||||
$userId = $session->getVariable("oepaypal-userId");
|
||||
if ($this->isPayPal() && $userId) {
|
||||
$payPalUser = oxNew(\OxidEsales\Eshop\Application\Model\User::class);
|
||||
if ($payPalUser->load($userId)) {
|
||||
$user = $payPalUser;
|
||||
}
|
||||
}
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal payment object if PayPal is on, or returns parent::getPayment()
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Application\Model\Payment
|
||||
*/
|
||||
public function getPayment()
|
||||
{
|
||||
if (!$this->isPayPal()) {
|
||||
// removing PayPal payment type from session
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$session->deleteVariable('oepaypal');
|
||||
$session->deleteVariable('oepaypal-basketAmount');
|
||||
|
||||
return parent::getPayment();
|
||||
}
|
||||
|
||||
if ($this->payment === null) {
|
||||
// payment is set ?
|
||||
$payment = oxNew(\OxidEsales\Eshop\Application\Model\Payment::class);
|
||||
if ($payment->load('oxidpaypal')) {
|
||||
$this->payment = $payment;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->payment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure orderId is set in sess_challenge session field.
|
||||
* If it's not set and the option to finalize order on paypal checkout is enabled,
|
||||
* the last checkout step - thank you page - will redirect the user to home.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$nextStep = parent::execute();
|
||||
$session = Registry::getSession();
|
||||
|
||||
if (!$session->getVariable('sess_challenge')) {
|
||||
$orderId = $this->getBasket()->getOrderId();
|
||||
$session->setVariable('sess_challenge', $orderId);
|
||||
}
|
||||
|
||||
return $nextStep;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current order object
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Application\Model\Order
|
||||
*/
|
||||
protected function getOrder()
|
||||
{
|
||||
$order = oxNew(\OxidEsales\Eshop\Application\Model\Order::class);
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
|
||||
$order->load($session->getVariable('sess_challenge'));
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if order payment is PayPal and redirects to payment processing part.
|
||||
*
|
||||
* @param int $success order state
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getNextStep($success)
|
||||
{
|
||||
$nextStep = parent::_getNextStep($success);
|
||||
|
||||
// Detecting PayPal & loading order & execute payment only if go wrong
|
||||
if ($this->isPayPal() && ($success == \OxidEsales\Eshop\Application\Model\Order::ORDER_STATE_PAYMENTERROR)) {
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$payPalType = (int) $session->getVariable("oepaypal");
|
||||
$nextStep = ($payPalType == 2) ? "basket" : "order";
|
||||
}
|
||||
|
||||
return $nextStep;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Controller;
|
||||
|
||||
use OxidEsales\PayPalModule\Model\PaymentManager;
|
||||
use OxidEsales\PayPalModule\Core\PayPalService;
|
||||
|
||||
/**
|
||||
* Payment class wrapper for PayPal module
|
||||
*
|
||||
* @mixin \OxidEsales\Eshop\Application\Controller\PaymentController
|
||||
*/
|
||||
class PaymentController extends PaymentController_parent
|
||||
{
|
||||
/**
|
||||
* Detects is current payment must be processed by PayPal and instead of standard validation
|
||||
* redirects to standard PayPal dispatcher
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function validatePayment()
|
||||
{
|
||||
$paymentId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('paymentid');
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$basket = $session->getBasket();
|
||||
if ($paymentId === 'oxidpaypal' && !$this->isConfirmedByPayPal($basket)) {
|
||||
$session->setVariable('paymentid', 'oxidpaypal');
|
||||
|
||||
return 'oepaypalstandarddispatcher?fnc=setExpressCheckout'
|
||||
. '&displayCartInPayPal=' . ((int) \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('displayCartInPayPal'));
|
||||
}
|
||||
|
||||
return parent::validatePayment();
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects if current payment was already successfully processed by PayPal
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Application\Model\Basket $basket basket object
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isConfirmedByPayPal($basket)
|
||||
{
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$oldBasketAmount = $session->getVariable("oepaypal-basketAmount");
|
||||
if (!$oldBasketAmount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$paypalService = oxNew(PayPalService::class);
|
||||
$paymentManager = oxNew(PaymentManager::class, $paypalService);
|
||||
|
||||
return $paymentManager->validateApprovedBasketAmount($basket->getPrice()->getBruttoPrice(), $oldBasketAmount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Controller;
|
||||
|
||||
use OxidEsales\PayPalModule\Model\PaymentManager;
|
||||
|
||||
/**
|
||||
* PayPal Standard Checkout dispatcher class
|
||||
*/
|
||||
class StandardDispatcher extends \OxidEsales\PayPalModule\Controller\Dispatcher
|
||||
{
|
||||
/**
|
||||
* Executes "SetExpressCheckout" and on SUCCESS response - redirects to PayPal
|
||||
* login/registration page, on error - returns "basket", which means - redirect
|
||||
* to basket view and display error message
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
public function setExpressCheckout()
|
||||
{
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$session->setVariable("oepaypal", PaymentManager::PAYPAL_SERVICE_TYPE_STANDARD);
|
||||
try {
|
||||
$selectedAddressId = $this->getUser() ? (string) $this->getUser()->getSelectedAddressId() : '';
|
||||
$paymentManager = $this->getPaymentManager();
|
||||
$result = $paymentManager->setStandardCheckout(
|
||||
$session->getBasket(),
|
||||
$this->getUser() ?: null,
|
||||
$this->getReturnUrl(),
|
||||
$this->getCancelUrl(),
|
||||
(bool)$this->getRequest()->getRequestParameter("displayCartInPayPal"),
|
||||
$selectedAddressId
|
||||
);
|
||||
} catch (\OxidEsales\Eshop\Core\Exception\StandardException $excp) {
|
||||
// error - unable to set order info - display error message
|
||||
$this->getUtilsView()->addErrorToDisplay($excp);
|
||||
|
||||
// return to basket view
|
||||
return "basket";
|
||||
}
|
||||
|
||||
// saving PayPal token into session
|
||||
$session->setVariable("oepaypal-token", $result->getToken());
|
||||
|
||||
// extracting token and building redirect url
|
||||
$url = $this->getPayPalConfig()->getPayPalCommunicationUrl($result->getToken(), $this->userAction);
|
||||
|
||||
// redirecting to PayPal's login/registration page
|
||||
$this->getUtils()->redirect($url, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns transaction mode.
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Application\Model\Basket $basket
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @deprecated Please use OxidEsales\PayPalModule\Model\PaymentManager::getTransactionMode
|
||||
*/
|
||||
protected function getTransactionMode($basket)
|
||||
{
|
||||
$paymentManager = $this->getPaymentManager();
|
||||
return $paymentManager->getTransactionMode($basket, $this->getPayPalConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes "GetExpressCheckoutDetails" and on SUCCESS response - saves
|
||||
* user information and redirects to order page, on failure - sets error
|
||||
* message and redirects to basket page
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getExpressCheckoutDetails()
|
||||
{
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
|
||||
try {
|
||||
$paymentManager = $this->getPaymentManager();
|
||||
$details = $paymentManager->getExpressCheckoutDetails();
|
||||
|
||||
$user = $this->getUser();
|
||||
} catch (\OxidEsales\Eshop\Core\Exception\StandardException $excp) {
|
||||
// display error message
|
||||
$this->getUtilsView()->addErrorToDisplay($excp);
|
||||
|
||||
// problems fetching user info - redirect to payment selection
|
||||
return 'payment';
|
||||
}
|
||||
|
||||
$session->setVariable("oepaypal-payerId", $details->getPayerId());
|
||||
$session->setVariable("oepaypal-basketAmount", $details->getAmount());
|
||||
|
||||
// next step - order page
|
||||
$next = 'order';
|
||||
|
||||
// finalize order on paypal side?
|
||||
if ($this->getPayPalConfig()->finalizeOrderOnPayPalSide()) {
|
||||
$next .= "?fnc=execute";
|
||||
$next .= "&sDeliveryAddressMD5=" . $user->getEncodedDeliveryAddress();
|
||||
$next .= "&stoken=" . $session->getSessionChallengeToken();
|
||||
}
|
||||
|
||||
// everything is fine - redirect to order
|
||||
return $next;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns RETURN URL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getReturnUrl()
|
||||
{
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$controllerKey = \OxidEsales\Eshop\Core\Registry::getControllerClassNameResolver()->getIdByClassName(get_class());
|
||||
return $session->processUrl($this->getBaseUrl() . "&cl=" . $controllerKey . "&fnc=getExpressCheckoutDetails");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns CANCEL URL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCancelUrl()
|
||||
{
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
return $session->processUrl($this->getBaseUrl() . "&cl=payment");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Controller;
|
||||
|
||||
/**
|
||||
* PayPal Wrapping class
|
||||
*
|
||||
* @mixin \OxidEsales\Eshop\Application\Controller\WrappingController
|
||||
*/
|
||||
class WrappingController extends WrappingController_parent
|
||||
{
|
||||
/**
|
||||
* Checks if payment action is processed by PayPal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isPayPal()
|
||||
{
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
return ($session->getVariable("paymentid") == "oxidpaypal") ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects is current payment must be processed by PayPal and instead of standard validation
|
||||
* redirects to standard PayPal dispatcher
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function changeWrapping()
|
||||
{
|
||||
$return = parent::changeWrapping();
|
||||
|
||||
// in case user adds wrapping, basket info must be resubmitted..
|
||||
if ($this->isPayPal()) {
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$payPalType = (int) $session->getVariable("oepaypal");
|
||||
|
||||
if ($payPalType == 1) {
|
||||
$return = "payment";
|
||||
} else {
|
||||
$return = "basket";
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
225
shop/source/modules/oe/oepaypal/Core/Caller.php
Normal file
225
shop/source/modules/oe/oepaypal/Core/Caller.php
Normal file
@@ -0,0 +1,225 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core;
|
||||
|
||||
use OxidEsales\PayPalModule\Core\Exception\PayPalResponseException;
|
||||
|
||||
/**
|
||||
* PayPal caller service class
|
||||
*/
|
||||
class Caller
|
||||
{
|
||||
/**
|
||||
* Service call parameters.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $params = array();
|
||||
|
||||
/**
|
||||
* PayPal logger.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Core\Logger
|
||||
*/
|
||||
protected $logger = null;
|
||||
|
||||
/**
|
||||
* PayPal curl object.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Core\Curl
|
||||
*/
|
||||
protected $curl = null;
|
||||
|
||||
/**
|
||||
* Setter for logger.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\Logger $logger logger
|
||||
*/
|
||||
public function setLogger($logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for PayPal logger.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Logger
|
||||
*/
|
||||
public function getLogger()
|
||||
{
|
||||
return $this->logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PayPal curl object.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\Curl $payPalCurl PayPal curl object.
|
||||
*/
|
||||
public function setCurl($payPalCurl)
|
||||
{
|
||||
$this->curl = $payPalCurl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns curl instance
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Curl
|
||||
*/
|
||||
public function getCurl()
|
||||
{
|
||||
if (is_null($this->curl)) {
|
||||
$curl = oxNew(\OxidEsales\PayPalModule\Core\Curl::class);
|
||||
$this->setCurl($curl);
|
||||
}
|
||||
|
||||
return $this->curl;
|
||||
}
|
||||
|
||||
/**
|
||||
* PayPal request parameters setter.
|
||||
*
|
||||
* @param string $paramName parameter name
|
||||
* @param mixed $paramValue parameter value
|
||||
*/
|
||||
public function setParameter($paramName, $paramValue)
|
||||
{
|
||||
$this->params[$paramName] = $paramValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* PayPal request parameters setter.
|
||||
*
|
||||
* @param array $parameters parameters to use to build request.
|
||||
*/
|
||||
public function setParameters($parameters)
|
||||
{
|
||||
$this->params = array_merge($this->params, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal request parameters array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getParameters()
|
||||
{
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls given remote PayPal method.
|
||||
*
|
||||
* @param string $methodName .
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function call($methodName = null)
|
||||
{
|
||||
$this->setMethod($methodName);
|
||||
|
||||
$curl = $this->getCurl();
|
||||
$curl->setParameters($this->getParameters());
|
||||
|
||||
$this->log($this->getParameters(), 'Request to PayPal');
|
||||
|
||||
$response = $curl->execute();
|
||||
|
||||
$this->log($response, 'Response from PayPal');
|
||||
|
||||
$this->validateResponse($response);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set method name to execute like DoExpressCheckoutPayment or GetExpressCheckoutDetails.
|
||||
*
|
||||
* @param string $name Name of a method
|
||||
*/
|
||||
protected function setMethod($name)
|
||||
{
|
||||
if (!is_null($name)) {
|
||||
$this->setParameter("METHOD", $name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates response from PayPal errors.
|
||||
*
|
||||
* @param array $response
|
||||
*
|
||||
* @throws PayPalResponseException if response has error from PayPal
|
||||
*/
|
||||
protected function validateResponse($response)
|
||||
{
|
||||
if (in_array($response['ACK'], ['SuccessWithWarning', 'FailureWithWarning'])) {
|
||||
$this->log($response, 'Response with warning from PayPal');
|
||||
}
|
||||
|
||||
if (in_array($response['ACK'], ['Failure', 'FailureWithWarning'])) {
|
||||
throw new PayPalResponseException($response['L_LONGMESSAGE0'], $response['L_ERRORCODE0']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs given request data.
|
||||
*
|
||||
* @param string $methodName
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCallBackResponse($methodName)
|
||||
{
|
||||
$this->setParameter("METHOD", $methodName);
|
||||
|
||||
$curl = $this->getCurl();
|
||||
$curl->setParameters($this->getParameters());
|
||||
$request = $curl->getQuery();
|
||||
|
||||
$this->log($request, 'Callback response from O3-Shop to PayPal');
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs given request and responds parameters to log file.
|
||||
*
|
||||
* @param mixed $value request / response parameters
|
||||
* @param string $title section title in log file
|
||||
*/
|
||||
public function log($value, $title = '')
|
||||
{
|
||||
if (!is_null($this->getLogger())) {
|
||||
$this->getLogger()->setTitle($title);
|
||||
$this->getLogger()->log($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set parameter from request.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $request request
|
||||
*/
|
||||
public function setRequest(\OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $request)
|
||||
{
|
||||
$this->setParameters($request->getData());
|
||||
}
|
||||
}
|
||||
803
shop/source/modules/oe/oepaypal/Core/Config.php
Normal file
803
shop/source/modules/oe/oepaypal/Core/Config.php
Normal file
@@ -0,0 +1,803 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core;
|
||||
|
||||
/**
|
||||
* PayPal config class
|
||||
*/
|
||||
class Config
|
||||
{
|
||||
|
||||
/**
|
||||
* PayPal payment was triggered via standard checkout by selecting PP as the payment method.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const OEPAYPAL_ECS = 1;
|
||||
|
||||
/**
|
||||
* PayPal payment was triggered by shortcut button in basket step.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const OEPAYPAL_SHORTCUT = 2;
|
||||
|
||||
/**
|
||||
* Name of session variable that marks how payment was triggered.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const OEPAYPAL_TRIGGER_NAME = 'oepaypal';
|
||||
|
||||
/**
|
||||
* Name of partnercode array key in case payment was triggered by shortcut button.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const PARTNERCODE_SHORTCUT_KEY = 'SHORTCUT';
|
||||
|
||||
/**
|
||||
* PayPal module id.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $payPalId = 'oepaypal';
|
||||
|
||||
/**
|
||||
* PayPal host.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $payPalHost = 'api-3t.paypal.com';
|
||||
|
||||
/**
|
||||
* PayPal sandbox host.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $payPalSandboxHost = 'api-3t.sandbox.paypal.com';
|
||||
|
||||
/**
|
||||
* PayPal sandbox Url where user must be redirected after his session gets PayPal token.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $payPalSandboxUrl = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
|
||||
|
||||
/**
|
||||
* PayPal Url where user must be redirected after his session gets PayPal token.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $payPalUrl = 'https://www.paypal.com/cgi-bin/webscr';
|
||||
|
||||
/**
|
||||
* PayPal sandbox API url.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $payPalSandboxApiUrl = 'https://api-3t.sandbox.paypal.com/nvp';
|
||||
|
||||
/**
|
||||
* PayPal API url.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $payPalApiUrl = 'https://api-3t.paypal.com/nvp';
|
||||
|
||||
/**
|
||||
* Maximum possible delivery costs value.
|
||||
*
|
||||
* @var double
|
||||
*/
|
||||
protected $maxDeliveryAmount = 30;
|
||||
|
||||
/**
|
||||
* Please do not change this place.
|
||||
* It is important to guarantee the future development of this O3-Shop extension and to keep it free of charge.
|
||||
* Thanks!
|
||||
*
|
||||
* @var array Partner codes based on edition
|
||||
*/
|
||||
protected $partnerCodes = array(
|
||||
'CE' => 'O3SHOP_Cart_CommunityECS',
|
||||
'SHORTCUT' => 'O3SHOP_Cart_ECS_Shortcut'
|
||||
);
|
||||
|
||||
/**
|
||||
* Return PayPal module id.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModuleId()
|
||||
{
|
||||
return $this->payPalId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PayPal host.
|
||||
*
|
||||
* @param string $payPalHost
|
||||
*/
|
||||
public function setPayPalHost($payPalHost)
|
||||
{
|
||||
$this->payPalHost = $payPalHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal host.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalHost()
|
||||
{
|
||||
$host = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('sPayPalHost');
|
||||
if ($host) {
|
||||
$this->setPayPalHost($host);
|
||||
}
|
||||
|
||||
return $this->payPalHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PayPal sandbox host.
|
||||
*
|
||||
* @param string $payPalSandboxHost
|
||||
*/
|
||||
public function setPayPalSandboxHost($payPalSandboxHost)
|
||||
{
|
||||
$this->payPalSandboxHost = $payPalSandboxHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal sandbox host.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalSandboxHost()
|
||||
{
|
||||
$host = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('sPayPalSandboxHost');
|
||||
if ($host) {
|
||||
$this->setPayPalSandboxHost($host);
|
||||
}
|
||||
|
||||
return $this->payPalSandboxHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal OR PayPal sandbox host.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHost()
|
||||
{
|
||||
if ($this->isSandboxEnabled()) {
|
||||
$url = $this->getPayPalSandboxHost();
|
||||
} else {
|
||||
$url = $this->getPayPalHost();
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Api Url setter
|
||||
*
|
||||
* @param string $payPalApiUrl
|
||||
*/
|
||||
public function setPayPalApiUrl($payPalApiUrl)
|
||||
{
|
||||
$this->payPalApiUrl = $payPalApiUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Api Url getter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalApiUrl()
|
||||
{
|
||||
$url = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('sPayPalApiUrl');
|
||||
if ($url) {
|
||||
$this->setPayPalApiUrl($url);
|
||||
}
|
||||
|
||||
return $this->payPalApiUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* PayPal sandbox api url setter
|
||||
*
|
||||
* @param string $payPalSandboxApiUrl
|
||||
*/
|
||||
public function setPayPalSandboxApiUrl($payPalSandboxApiUrl)
|
||||
{
|
||||
$this->payPalSandboxApiUrl = $payPalSandboxApiUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* PayPal sandbox api url getter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalSandboxApiUrl()
|
||||
{
|
||||
$url = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('sPayPalSandboxApiUrl');
|
||||
if ($url) {
|
||||
$this->setPayPalSandboxApiUrl($url);
|
||||
}
|
||||
|
||||
return $this->payPalSandboxApiUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns end point url
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getApiUrl()
|
||||
{
|
||||
if ($this->isSandboxEnabled()) {
|
||||
$url = $this->getPayPalSandboxApiUrl();
|
||||
} else {
|
||||
$url = $this->getPayPalApiUrl();
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* PayPal Url Setter
|
||||
*
|
||||
* @param string $payPalUrl
|
||||
*/
|
||||
public function setPayPalUrl($payPalUrl)
|
||||
{
|
||||
$this->payPalUrl = $payPalUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* PayPal sandbox url setter
|
||||
*
|
||||
* @param string $payPalSandboxUrl
|
||||
*/
|
||||
public function setPayPalSandboxUrl($payPalSandboxUrl)
|
||||
{
|
||||
$this->payPalSandboxUrl = $payPalSandboxUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* PayPal sandbox url getter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalUrl()
|
||||
{
|
||||
$url = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('sPayPalUrl');
|
||||
if ($url) {
|
||||
$this->setPayPalUrl($url);
|
||||
}
|
||||
|
||||
return $this->payPalUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* PayPal sandbox url getter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalSandboxUrl()
|
||||
{
|
||||
$url = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('sPayPalSandboxUrl');
|
||||
if ($url) {
|
||||
$this->setPayPalSandboxUrl($url);
|
||||
}
|
||||
|
||||
return $this->payPalSandboxUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PayPal url.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
if ($this->isSandboxEnabled()) {
|
||||
$url = $this->getPayPalSandboxUrl();
|
||||
} else {
|
||||
$url = $this->getPayPalUrl();
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns module config parameter value
|
||||
*
|
||||
* @param string $paramName parameter name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getParameter($paramName)
|
||||
{
|
||||
return \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam($paramName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Express Checkout is ON
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpressCheckoutEnabled()
|
||||
{
|
||||
return $this->getParameter('blOEPayPalExpressCheckout');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Express Checkout is ON in mini basket
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpressCheckoutInMiniBasketEnabled()
|
||||
{
|
||||
return $this->getParameter('blOEPayPalECheckoutInMiniBasket');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Standard PayPal Checkout is ON
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isStandardCheckoutEnabled()
|
||||
{
|
||||
return $this->getParameter('blOEPayPalStandardCheckout');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if logging request/response to PayPal is enabled
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isLoggingEnabled()
|
||||
{
|
||||
return $this->getParameter('blPayPalLoggerEnabled');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Brand/Shop name [OXID ESHOP]
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBrandName()
|
||||
{
|
||||
$shopName = $this->getParameter('sOEPayPalBrandName');
|
||||
|
||||
if (empty($shopName)) {
|
||||
$shop = \OxidEsales\Eshop\Core\Registry::getConfig()->getActiveShop();
|
||||
$shopName = $shop->oxshops__oxname->value;
|
||||
}
|
||||
|
||||
return $shopName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns custom cart border color which is displayed in PayPal side
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getBorderColor()
|
||||
{
|
||||
return $this->getParameter('sOEPayPalBorderColor');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if order finalization on PayPal side is on
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function finalizeOrderOnPayPalSide()
|
||||
{
|
||||
$finalize = $this->getParameter('blOEPayPalFinalizeOrderOnPayPal');
|
||||
|
||||
return $finalize !== null ? $finalize : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send order info to PayPal or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function sendOrderInfoToPayPal()
|
||||
{
|
||||
return $this->getParameter('blOEPayPalSendToPayPal');
|
||||
}
|
||||
|
||||
/**
|
||||
* Send order info to PayPal or not config's default value: checked or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function sendOrderInfoToPayPalDefault()
|
||||
{
|
||||
return $this->getParameter('blOEPayPalDefaultUserChoice');
|
||||
}
|
||||
|
||||
/**
|
||||
* Guest buy mode getter
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isGuestBuyEnabled()
|
||||
{
|
||||
return $this->getParameter('blOEPayPalGuestBuyRole');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true of GiroPay is ON (not implemented yet)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isGiroPayEnabled()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true of sandbox mode is ON
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSandboxEnabled()
|
||||
{
|
||||
return $this->getParameter('blOEPayPalSandboxMode');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Empty Stock Level
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEmptyStockLevel()
|
||||
{
|
||||
return $this->getParameter('sOEPayPalEmptyStockLevel');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal password
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
if ($this->isSandboxEnabled()) {
|
||||
// sandbox password
|
||||
return $this->getParameter('sOEPayPalSandboxPassword');
|
||||
}
|
||||
|
||||
// password
|
||||
return $this->getParameter('sOEPayPalPassword');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal user name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUserName()
|
||||
{
|
||||
if ($this->isSandboxEnabled()) {
|
||||
// sandbox login
|
||||
return $this->getParameter('sOEPayPalSandboxUsername');
|
||||
}
|
||||
|
||||
// login
|
||||
return $this->getParameter('sOEPayPalUsername');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal user name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUserEmail()
|
||||
{
|
||||
if ($this->isSandboxEnabled()) {
|
||||
// sandbox login
|
||||
return $this->getParameter('sOEPayPalSandboxUserEmail');
|
||||
}
|
||||
|
||||
// login
|
||||
return $this->getParameter('sOEPayPalUserEmail');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal signature
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSignature()
|
||||
{
|
||||
if ($this->isSandboxEnabled()) {
|
||||
// sandbox signature
|
||||
return $this->getParameter('sOEPayPalSandboxSignature');
|
||||
}
|
||||
|
||||
// test sandbox signature
|
||||
return $this->getParameter('sOEPayPalSignature');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal transaction mode
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTransactionMode()
|
||||
{
|
||||
return $this->getParameter('sOEPayPalTransactionMode');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns redirect url.
|
||||
*
|
||||
* @param string $token token to append to redirect url.
|
||||
* @param string $userAction checkout button action - continue (standard checkout) or commit (express checkout)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalCommunicationUrl($token = null, $userAction = 'continue')
|
||||
{
|
||||
return $this->getUrl() . '&cmd=_express-checkout&token=' . (string) $token . '&useraction=' . (string) $userAction;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get logo Url based on selected settings
|
||||
* Returns shop url, or false
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function getLogoUrl()
|
||||
{
|
||||
$logoUrl = false;
|
||||
|
||||
$logoName = $this->getLogoImageName();
|
||||
|
||||
if (!empty($logoName)) {
|
||||
$logo = oxNew(\OxidEsales\PayPalModule\Core\ShopLogo::class);
|
||||
$logo->setImageDir(\OxidEsales\Eshop\Core\Registry::getConfig()->getImageDir());
|
||||
$logo->setImageDirUrl(\OxidEsales\Eshop\Core\Registry::getConfig()->getImageUrl());
|
||||
$logo->setImageName($logoName);
|
||||
$logo->setImageHandler(\OxidEsales\Eshop\Core\Registry::getUtilsPic());
|
||||
|
||||
$logoUrl = $logo->getShopLogoUrl();
|
||||
}
|
||||
|
||||
return $logoUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns IPN callback url
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIPNCallbackUrl()
|
||||
{
|
||||
return $this->getShopUrl() . 'index.php?cl=oepaypalipnhandler&fnc=handleRequest&shp=' . $this->getShopId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Methods checks if sending of IPN callback url to PayPal is supressed by configuration.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function suppressIPNCallbackUrl()
|
||||
{
|
||||
return (bool) \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('OEPayPalDisableIPN');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns SSL or non SSL shop URL without index.php depending on Mall
|
||||
* affecting environment is admin mode and current ssl usage status
|
||||
*
|
||||
* @param bool $admin if admin
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getShopUrl($admin = null)
|
||||
{
|
||||
return \OxidEsales\Eshop\Core\Registry::getConfig()->getCurrentShopUrl($admin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to get language object from registry.
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Core\Language
|
||||
*/
|
||||
public function getLang()
|
||||
{
|
||||
return \OxidEsales\Eshop\Core\Registry::getLang();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to get utils object from registry.
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Core\Utils
|
||||
*/
|
||||
public function getUtils()
|
||||
{
|
||||
return \OxidEsales\Eshop\Core\Registry::getUtils();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns shop charset
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCharset()
|
||||
{
|
||||
$charset = 'UTF-8';
|
||||
|
||||
return $charset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated in dev-master (2018-04-27); Use OxidEsales\PayPalModule\Core\IPnConfig::getIPNResponseUrl()
|
||||
*
|
||||
* Returns Url for IPN response call to notify PayPal
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIPNResponseUrl()
|
||||
{
|
||||
return $this->getUrl() . '&cmd=_notify-validate';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Express Checkout is in details page
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpressCheckoutInDetailsPage()
|
||||
{
|
||||
return $this->getParameter('blOEPayPalECheckoutInDetails');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current URL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrentUrl()
|
||||
{
|
||||
return \OxidEsales\Eshop\Core\Registry::getUtilsUrl()->getCurrentUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns max delivery amount.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getMaxPayPalDeliveryAmount()
|
||||
{
|
||||
$maxDeliveryAmount = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('dMaxPayPalDeliveryAmount');
|
||||
if (!$maxDeliveryAmount) {
|
||||
$maxDeliveryAmount = $this->maxDeliveryAmount;
|
||||
}
|
||||
|
||||
return $maxDeliveryAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Please do not change this place.
|
||||
* It is important to guarantee the future development of this O3-Shop extension and to keep it free of charge.
|
||||
* Thanks!
|
||||
*
|
||||
* @return string partner code.
|
||||
*/
|
||||
public function getPartnerCode()
|
||||
{
|
||||
$facts = new \OxidEsales\Facts\Facts();
|
||||
$key = $this->isShortcutPayment() ? self::PARTNERCODE_SHORTCUT_KEY : $facts->getEdition();
|
||||
|
||||
return $this->partnerCodes[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects device type
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDeviceMobile()
|
||||
{
|
||||
$userAgent = oxNew(\OxidEsales\PayPalModule\Core\UserAgent::class);
|
||||
|
||||
return ($userAgent->getDeviceType() == 'mobile');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns id of shipping assigned for EC for mobile devices
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMobileECDefaultShippingId()
|
||||
{
|
||||
return \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('sOEPayPalMECDefaultShippingId');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns logo image name according to parameter
|
||||
*
|
||||
* @return mixed|string
|
||||
*/
|
||||
protected function getLogoImageName()
|
||||
{
|
||||
$option = $this->getParameter('sOEPayPalLogoImageOption');
|
||||
switch ($option) {
|
||||
case 'shopLogo':
|
||||
$logo = $this->getParameter('sShopLogo');
|
||||
break;
|
||||
case 'customLogo':
|
||||
$logo = $this->getParameter('sOEPayPalCustomShopLogoImage');
|
||||
break;
|
||||
case 'noLogo':
|
||||
default:
|
||||
$logo = '';
|
||||
|
||||
return $logo;
|
||||
}
|
||||
|
||||
return $logo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns active shop id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getShopId()
|
||||
{
|
||||
return \OxidEsales\Eshop\Core\Registry::getConfig()->getShopId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns oxConfig instance
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Core\Config
|
||||
*/
|
||||
protected function getConfig()
|
||||
{
|
||||
return \OxidEsales\Eshop\Core\Registry::getConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Was the payment triggered by shortcut button or not?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isShortcutPayment()
|
||||
{
|
||||
$trigger = (int) \OxidEsales\Eshop\Core\Registry::getSession()->getVariable(self::OEPAYPAL_TRIGGER_NAME);
|
||||
return (bool) ($trigger == self::OEPAYPAL_SHORTCUT);
|
||||
}
|
||||
}
|
||||
473
shop/source/modules/oe/oepaypal/Core/Curl.php
Normal file
473
shop/source/modules/oe/oepaypal/Core/Curl.php
Normal file
@@ -0,0 +1,473 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core;
|
||||
|
||||
if (!defined('CURL_SSLVERSION_TLSV1_2')) {
|
||||
define('CURL_SSLVERSION_TLSV1_2', 6);
|
||||
}
|
||||
|
||||
/**
|
||||
* PayPal Curl class
|
||||
*/
|
||||
class Curl
|
||||
{
|
||||
/**
|
||||
* Host for header.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $host = null;
|
||||
|
||||
/**
|
||||
* Curl instance.
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
protected $curl = null;
|
||||
|
||||
/**
|
||||
* Connection Charset.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $connectionCharset = "UTF-8";
|
||||
|
||||
/**
|
||||
* Data Charset.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $dataCharset = "UTF-8";
|
||||
|
||||
/**
|
||||
* Curl default parameters.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $environmentParameters = array(
|
||||
'CURLOPT_VERBOSE' => 0,
|
||||
'CURLOPT_SSL_VERIFYPEER' => false,
|
||||
'CURLOPT_SSL_VERIFYHOST' => false,
|
||||
'CURLOPT_SSLVERSION' => CURL_SSLVERSION_TLSV1_2,
|
||||
'CURLOPT_RETURNTRANSFER' => 1,
|
||||
'CURLOPT_POST' => 1,
|
||||
'CURLOPT_HTTP_VERSION' => CURL_HTTP_VERSION_1_1,
|
||||
);
|
||||
|
||||
/**
|
||||
* Parameter to be added to call url
|
||||
*
|
||||
* @var array | null
|
||||
*/
|
||||
protected $parameters = null;
|
||||
|
||||
|
||||
/**
|
||||
* PayPal URL to call. Usually API address.
|
||||
*
|
||||
* @var string | null
|
||||
*/
|
||||
protected $urlToCall = null;
|
||||
|
||||
/**
|
||||
* Query like "param1=value1¶m2=values2.."
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected $query = null;
|
||||
|
||||
/**
|
||||
* Curl call header.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $header = null;
|
||||
|
||||
/**
|
||||
* Sets host.
|
||||
*
|
||||
* @param string $host
|
||||
*/
|
||||
public function setHost($host)
|
||||
{
|
||||
$this->host = $host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns host.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHost()
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set header.
|
||||
*
|
||||
* @param array $header
|
||||
*/
|
||||
public function setHeader($header)
|
||||
{
|
||||
$this->header = $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forms header from host.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getHeader()
|
||||
{
|
||||
if (is_null($this->header)) {
|
||||
$host = $this->getHost();
|
||||
|
||||
$header = array();
|
||||
$header[] = 'POST /cgi-bin/webscr HTTP/1.1';
|
||||
$header[] = 'Content-Type: application/x-www-form-urlencoded';
|
||||
if (isset($host)) {
|
||||
$header[] = 'Host: ' . $host;
|
||||
}
|
||||
$header[] = 'Connection: close';
|
||||
|
||||
$this->setHeader($header);
|
||||
}
|
||||
|
||||
return $this->header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set connection charset
|
||||
*
|
||||
* @param string $charset charset
|
||||
*/
|
||||
public function setConnectionCharset($charset)
|
||||
{
|
||||
$this->connectionCharset = $charset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return connection charset
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getConnectionCharset()
|
||||
{
|
||||
return $this->connectionCharset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set data charset
|
||||
*
|
||||
* @param string $dataCharset
|
||||
*/
|
||||
public function setDataCharset($dataCharset)
|
||||
{
|
||||
$this->dataCharset = $dataCharset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return data charset
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDataCharset()
|
||||
{
|
||||
return $this->dataCharset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return environment parameters
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getEnvironmentParameters()
|
||||
{
|
||||
return $this->environmentParameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets one of Curl parameter.
|
||||
*
|
||||
* @param string $name Curl parameter name.
|
||||
* @param mixed $value Curl parameter value
|
||||
*/
|
||||
public function setEnvironmentParameter($name, $value)
|
||||
{
|
||||
$this->environmentParameters[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets parameters to be added to call url.
|
||||
*
|
||||
* @param array $parameters parameters
|
||||
*/
|
||||
public function setParameters($parameters)
|
||||
{
|
||||
$this->parameters = $parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return parameters to be added to call url.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getParameters()
|
||||
{
|
||||
return $this->parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set query like "param1=value1¶m2=values2.."
|
||||
*
|
||||
* @param string $query
|
||||
*/
|
||||
public function setQuery($query)
|
||||
{
|
||||
$this->query = $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds query like "param1=value1¶m2=values2.."
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getQuery()
|
||||
{
|
||||
if (is_null($this->query)) {
|
||||
$params = $this->getParameters();
|
||||
$params = array_map(array($this, 'htmlDecode'), $params);
|
||||
$params = array_map(array($this, 'encode'), $params);
|
||||
|
||||
$this->setQuery(http_build_query($params, "", "&"));
|
||||
}
|
||||
|
||||
return $this->query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PayPal URL to call.
|
||||
*
|
||||
* @param string $urlToCall PayPal URL to call.
|
||||
*
|
||||
* @throws \OxidEsales\PayPalModule\Core\Exception\PayPalException if url is not valid
|
||||
*/
|
||||
public function setUrlToCall($urlToCall)
|
||||
{
|
||||
if (false === filter_var($urlToCall, FILTER_VALIDATE_URL)) {
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Core\Exception\PayPalException $exception
|
||||
*/
|
||||
$exception = oxNew(\OxidEsales\PayPalModule\Core\Exception\PayPalException::class, 'URL to call is not valid.');
|
||||
throw $exception;
|
||||
}
|
||||
$this->urlToCall = $urlToCall;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get url
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrlToCall()
|
||||
{
|
||||
return $this->urlToCall;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets resource
|
||||
*
|
||||
* @param resource $curl curl.
|
||||
*/
|
||||
protected function setResource($curl)
|
||||
{
|
||||
$this->curl = $curl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns curl resource
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
protected function getResource()
|
||||
{
|
||||
if (is_null($this->curl)) {
|
||||
$this->setResource(curl_init());
|
||||
}
|
||||
|
||||
return $this->curl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes curl call and returns response data as associative array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$this->setOptions();
|
||||
|
||||
$response = $this->parseResponse($this->curlExecute());
|
||||
|
||||
$this->close();
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Curl Parameters.
|
||||
*/
|
||||
protected function setOptions()
|
||||
{
|
||||
foreach ($this->getEnvironmentParameters() as $name => $value) {
|
||||
$this->setOption(constant($name), $value);
|
||||
}
|
||||
|
||||
$this->setOption(CURLOPT_HTTPHEADER, $this->getHeader());
|
||||
$this->setOption(CURLOPT_URL, $this->getUrlToCall());
|
||||
$this->setOption(CURLOPT_POSTFIELDS, $this->getQuery());
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper function to be mocked for testing.
|
||||
*
|
||||
* @param string $name curl field name to set value to.
|
||||
* @param mixed $value curl field value to set.
|
||||
*/
|
||||
protected function setOption($name, $value)
|
||||
{
|
||||
curl_setopt($this->getResource(), $name, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper function to be mocked for testing.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \OxidEsales\PayPalModule\Core\Exception\PayPalException on curl errors
|
||||
*/
|
||||
protected function curlExecute()
|
||||
{
|
||||
$response = curl_exec($this->getResource());
|
||||
|
||||
$curlErrorNumber = $this->getErrorNumber();
|
||||
if ($curlErrorNumber) {
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Core\Exception\PayPalException $exception
|
||||
*/
|
||||
$exception = oxNew(\OxidEsales\PayPalModule\Core\Exception\PayPalException::class, 'Curl error: ' . $curlErrorNumber);
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper function to be mocked for testing.
|
||||
*/
|
||||
protected function close()
|
||||
{
|
||||
curl_close($this->getResource());
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse curl response and strip it to safe form.
|
||||
*
|
||||
* @param string $response curl response.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function parseResponse($response)
|
||||
{
|
||||
$result = [];
|
||||
|
||||
// processing results
|
||||
parse_str($response, $result);
|
||||
|
||||
// stripping slashes
|
||||
$result = array_map(array($this, 'decode'), $result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if curl has errors. Set error message if has.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getErrorNumber()
|
||||
{
|
||||
return curl_errno($this->getResource());
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode (if needed) given query from UTF8
|
||||
*
|
||||
* @param string $string query
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function htmlDecode($string)
|
||||
{
|
||||
$string = html_entity_decode($string, ENT_QUOTES, $this->getConnectionCharset());
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode (if needed) given query from UTF8
|
||||
*
|
||||
* @param string $string query
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function decode($string)
|
||||
{
|
||||
$charset = $this->getDataCharset();
|
||||
if ($charset !== $this->getConnectionCharset()) {
|
||||
$string = iconv($this->getConnectionCharset(), $charset, $string);
|
||||
}
|
||||
|
||||
if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
|
||||
$string = stripslashes($string);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes (if needed) given query to UTF8
|
||||
*
|
||||
* @param string $string query
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function encode($string)
|
||||
{
|
||||
$charset = $this->getDataCharset();
|
||||
if ($charset !== $this->getConnectionCharset()) {
|
||||
$string = iconv($charset, $this->getConnectionCharset(), $string);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
93
shop/source/modules/oe/oepaypal/Core/Escape.php
Normal file
93
shop/source/modules/oe/oepaypal/Core/Escape.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core;
|
||||
|
||||
/**
|
||||
* PayPal escape class
|
||||
*/
|
||||
class Escape
|
||||
{
|
||||
/**
|
||||
* Checks if passed parameter has special chars and replaces them.
|
||||
* Returns checked value.
|
||||
*
|
||||
* @param mixed $value value to process escaping
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function escapeSpecialChars($value)
|
||||
{
|
||||
if (is_object($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
$value = $this->escapeArraySpecialChars($value);
|
||||
} elseif (is_string($value)) {
|
||||
$value = $this->escapeStringSpecialChars($value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if passed parameter has special chars and replaces them.
|
||||
* Returns checked value.
|
||||
*
|
||||
* @param array $value value to process escaping
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function escapeArraySpecialChars($value)
|
||||
{
|
||||
$newValue = array();
|
||||
foreach ($value as $key => $val) {
|
||||
$validKey = $key;
|
||||
$validKey = $this->escapeSpecialChars($validKey);
|
||||
$val = $this->escapeSpecialChars($val);
|
||||
if ($validKey != $key) {
|
||||
unset($value[$key]);
|
||||
}
|
||||
$newValue[$validKey] = $val;
|
||||
}
|
||||
|
||||
return $newValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if passed parameter has special chars and replaces them.
|
||||
* Returns checked value.
|
||||
*
|
||||
* @param string $value value to process escaping
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function escapeStringSpecialChars($value)
|
||||
{
|
||||
$value = str_replace(
|
||||
array('&', '<', '>', '"', "'", chr(0), '\\'),
|
||||
array('&', '<', '>', '"', ''', '', '\'),
|
||||
$value
|
||||
);
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
314
shop/source/modules/oe/oepaypal/Core/Events.php
Normal file
314
shop/source/modules/oe/oepaypal/Core/Events.php
Normal file
@@ -0,0 +1,314 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core;
|
||||
|
||||
/**
|
||||
* Class defines what module does on Shop events.
|
||||
*/
|
||||
class Events
|
||||
{
|
||||
/**
|
||||
* Add additional fields: payment status, captured amount, refunded amount in oxOrder table
|
||||
*/
|
||||
public static function addOrderTable()
|
||||
{
|
||||
$query = "CREATE TABLE IF NOT EXISTS `oepaypal_order` (
|
||||
`OEPAYPAL_ORDERID` char(32) character set latin1 collate latin1_general_ci NOT NULL,
|
||||
`OEPAYPAL_PAYMENTSTATUS` enum('pending','completed','failed','canceled') NOT NULL DEFAULT 'pending',
|
||||
`OEPAYPAL_CAPTUREDAMOUNT` decimal(9,2) NOT NULL,
|
||||
`OEPAYPAL_REFUNDEDAMOUNT` decimal(9,2) NOT NULL,
|
||||
`OEPAYPAL_VOIDEDAMOUNT` decimal(9,2) NOT NULL,
|
||||
`OEPAYPAL_TOTALORDERSUM` decimal(9,2) NOT NULL,
|
||||
`OEPAYPAL_CURRENCY` varchar(32) NOT NULL,
|
||||
`OEPAYPAL_TRANSACTIONMODE` enum('Sale','Authorization') NOT NULL DEFAULT 'Sale',
|
||||
`OEPAYPAL_TIMESTAMP` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`OEPAYPAL_ORDERID`),
|
||||
KEY `OEPAYPAL_PAYMENTSTATUS` (`OEPAYPAL_PAYMENTSTATUS`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;";
|
||||
|
||||
\OxidEsales\Eshop\Core\DatabaseProvider::getDb()->execute($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add PayPal payment method set EN and DE long descriptions
|
||||
*/
|
||||
public static function addPaymentMethod()
|
||||
{
|
||||
$paymentDescriptions = array(
|
||||
'en' => '<div>When selecting this payment method you are being redirected to PayPal where you can login into your account or open a new account. In PayPal you are able to authorize the payment. As soon you have authorized the payment, you are again redirected to our shop where you can confirm your order.</div> <div style="margin-top: 5px">Only after confirming the order, transfer of money takes place.</div>',
|
||||
'de' => '<div>Bei Auswahl der Zahlungsart PayPal werden Sie im nächsten Schritt zu PayPal weitergeleitet. Dort können Sie sich in Ihr PayPal-Konto einloggen oder ein neues PayPal-Konto eröffnen und die Zahlung autorisieren. Sobald Sie Ihre Daten für die Zahlung bestätigt haben, werden Sie automatisch wieder zurück in den Shop geleitet, um die Bestellung abzuschließen.</div> <div style="margin-top: 5px">Erst dann wird die Zahlung ausgeführt.</div>'
|
||||
);
|
||||
|
||||
$payment = oxNew(\OxidEsales\Eshop\Application\Model\Payment::class);
|
||||
if (!$payment->load('oxidpaypal')) {
|
||||
$payment->setId('oxidpaypal');
|
||||
$payment->oxpayments__oxactive = new \OxidEsales\Eshop\Core\Field(1);
|
||||
$payment->oxpayments__oxdesc = new \OxidEsales\Eshop\Core\Field('PayPal');
|
||||
$payment->oxpayments__oxaddsum = new \OxidEsales\Eshop\Core\Field(0);
|
||||
$payment->oxpayments__oxaddsumtype = new \OxidEsales\Eshop\Core\Field('abs');
|
||||
$payment->oxpayments__oxfromboni = new \OxidEsales\Eshop\Core\Field(0);
|
||||
$payment->oxpayments__oxfromamount = new \OxidEsales\Eshop\Core\Field(0);
|
||||
$payment->oxpayments__oxtoamount = new \OxidEsales\Eshop\Core\Field(10000);
|
||||
|
||||
$language = \OxidEsales\Eshop\Core\Registry::getLang();
|
||||
$languages = $language->getLanguageIds();
|
||||
foreach ($paymentDescriptions as $languageAbbreviation => $description) {
|
||||
$languageId = array_search($languageAbbreviation, $languages);
|
||||
if ($languageId !== false) {
|
||||
$payment->setLanguage($languageId);
|
||||
$payment->oxpayments__oxlongdesc = new \OxidEsales\Eshop\Core\Field($description);
|
||||
$payment->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if PayPal is used for sub-shops.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isPayPalActiveOnSubShops()
|
||||
{
|
||||
$active = false;
|
||||
$config = \OxidEsales\Eshop\Core\Registry::getConfig();
|
||||
$extensionChecker = oxNew(\OxidEsales\PayPalModule\Core\ExtensionChecker::class);
|
||||
$shops = $config->getShopIds();
|
||||
$activeShopId = $config->getShopId();
|
||||
|
||||
foreach ($shops as $shopId) {
|
||||
if ($shopId != $activeShopId) {
|
||||
$extensionChecker->setShopId($shopId);
|
||||
$extensionChecker->setExtensionId('oepaypal');
|
||||
if ($extensionChecker->isActive()) {
|
||||
$active = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $active;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables PayPal payment method
|
||||
*/
|
||||
public static function disablePaymentMethod()
|
||||
{
|
||||
$payment = oxNew(\OxidEsales\Eshop\Application\Model\Payment::class);
|
||||
if ($payment->load('oxidpaypal')) {
|
||||
$payment->oxpayments__oxactive = new \OxidEsales\Eshop\Core\Field(0);
|
||||
$payment->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates PayPal payment method
|
||||
*/
|
||||
public static function enablePaymentMethod()
|
||||
{
|
||||
$payment = oxNew(\OxidEsales\Eshop\Application\Model\Payment::class);
|
||||
$payment->load('oxidpaypal');
|
||||
$payment->oxpayments__oxactive = new \OxidEsales\Eshop\Core\Field(1);
|
||||
$payment->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Order payments table in to database if not exist
|
||||
*/
|
||||
public static function addOrderPaymentsTable()
|
||||
{
|
||||
$query = "CREATE TABLE IF NOT EXISTS `oepaypal_orderpayments` (
|
||||
`OEPAYPAL_PAYMENTID` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`OEPAYPAL_ACTION` enum('capture', 'authorization', 're-authorization', 'refund', 'void') NOT NULL DEFAULT 'capture',
|
||||
`OEPAYPAL_ORDERID` char(32) character set latin1 collate latin1_general_ci NOT NULL,
|
||||
`OEPAYPAL_TRANSACTIONID` varchar(32) NOT NULL,
|
||||
`OEPAYPAL_CORRELATIONID` varchar(32) NOT NULL,
|
||||
`OEPAYPAL_AMOUNT` decimal(9,2) NOT NULL,
|
||||
`OEPAYPAL_CURRENCY` varchar(3) NOT NULL,
|
||||
`OEPAYPAL_REFUNDEDAMOUNT` decimal(9,2) NOT NULL,
|
||||
`OEPAYPAL_DATE` datetime NOT NULL,
|
||||
`OEPAYPAL_STATUS` varchar(20) NOT NULL,
|
||||
`OEPAYPAL_TIMESTAMP` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`OEPAYPAL_PAYMENTID`),
|
||||
KEY `OEPAYPAL_ORDERID` (`OEPAYPAL_ORDERID`),
|
||||
KEY `OEPAYPAL_DATE` (`OEPAYPAL_DATE`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;";
|
||||
|
||||
\OxidEsales\Eshop\Core\DatabaseProvider::getDb()->execute($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Order payments Comments table in to database if not exist
|
||||
*/
|
||||
public static function addOrderPaymentsCommentsTable()
|
||||
{
|
||||
$query = "CREATE TABLE IF NOT EXISTS `oepaypal_orderpaymentcomments` (
|
||||
`OEPAYPAL_COMMENTID` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`OEPAYPAL_PAYMENTID` int(11) unsigned NOT NULL,
|
||||
`OEPAYPAL_COMMENT` varchar(256) NOT NULL,
|
||||
`OEPAYPAL_DATE` datetime NOT NULL,
|
||||
`OEPAYPAL_TIMESTAMP` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`OEPAYPAL_COMMENTID`),
|
||||
KEY `OEPAYPAL_ORDERID` (`OEPAYPAL_PAYMENTID`),
|
||||
KEY `OEPAYPAL_DATE` (`OEPAYPAL_DATE`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;";
|
||||
|
||||
\OxidEsales\Eshop\Core\DatabaseProvider::getDb()->execute($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables PayPal RDF
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public static function enablePayPalRDFA()
|
||||
{
|
||||
// If PayPal activated on other sub shops do not change global RDF setting.
|
||||
if ('EE' == \OxidEsales\Eshop\Core\Registry::getConfig()->getEdition() && self::isPayPalActiveOnSubShops()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query = "INSERT IGNORE INTO `oxobject2payment` (`OXID`, `OXPAYMENTID`, `OXOBJECTID`, `OXTYPE`) VALUES('oepaypalrdfa', 'oxidpaypal', 'PayPal', 'rdfapayment')";
|
||||
\OxidEsales\Eshop\Core\DatabaseProvider::getDb()->execute($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable PayPal RDF
|
||||
*/
|
||||
public static function disablePayPalRDFA()
|
||||
{
|
||||
$query = "DELETE FROM `oxobject2payment` WHERE `OXID` = 'oepaypalrdfa'";
|
||||
|
||||
\OxidEsales\Eshop\Core\DatabaseProvider::getDb()->execute($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add missing field if it activates on old DB
|
||||
*/
|
||||
public static function addMissingFieldsOnUpdate()
|
||||
{
|
||||
$dbMetaDataHandler = oxNew(\OxidEsales\Eshop\Core\DbMetaDataHandler::class);
|
||||
|
||||
$tableFields = array(
|
||||
'oepaypal_order' => 'OEPAYPAL_TIMESTAMP',
|
||||
'oepaypal_orderpayments' => 'OEPAYPAL_TIMESTAMP',
|
||||
'oepaypal_orderpaymentcomments' => 'OEPAYPAL_TIMESTAMP',
|
||||
);
|
||||
|
||||
foreach ($tableFields as $tableName => $fieldName) {
|
||||
if (!$dbMetaDataHandler->fieldExists($fieldName, $tableName)) {
|
||||
\OxidEsales\Eshop\Core\DatabaseProvider::getDb()->execute(
|
||||
"ALTER TABLE `" . $tableName
|
||||
. "` ADD `" . $fieldName . "` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP;"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update tables and its fields encoding/collation if activated on old DB
|
||||
*/
|
||||
public static function ensureCorrectFieldsEncodingOnUpdate()
|
||||
{
|
||||
$dbMetaDataHandler = oxNew(\OxidEsales\Eshop\Core\DbMetaDataHandler::class);
|
||||
if ($dbMetaDataHandler->tableExists("oepaypal_order")) {
|
||||
$query = "ALTER TABLE `oepaypal_order` DEFAULT CHARACTER SET utf8 collate utf8_general_ci;";
|
||||
\OxidEsales\Eshop\Core\DatabaseProvider::getDb()->execute($query);
|
||||
|
||||
$query = "ALTER TABLE `oepaypal_orderpaymentcomments` DEFAULT CHARACTER SET utf8 collate utf8_general_ci;";
|
||||
\OxidEsales\Eshop\Core\DatabaseProvider::getDb()->execute($query);
|
||||
|
||||
$query = "ALTER TABLE `oepaypal_orderpayments` DEFAULT CHARACTER SET utf8 collate utf8_general_ci;";
|
||||
\OxidEsales\Eshop\Core\DatabaseProvider::getDb()->execute($query);
|
||||
|
||||
$query = "ALTER TABLE `oepaypal_order`
|
||||
MODIFY `OEPAYPAL_CURRENCY` varchar(32) character set utf8 collate utf8_general_ci NOT NULL,
|
||||
MODIFY `OEPAYPAL_PAYMENTSTATUS` enum('pending','completed','failed','canceled') CHARACTER SET utf8 collate utf8_general_ci NOT NULL DEFAULT 'pending',
|
||||
MODIFY `OEPAYPAL_TRANSACTIONMODE` enum('Sale','Authorization') CHARACTER SET utf8 collate utf8_general_ci NOT NULL DEFAULT 'Sale';";
|
||||
\OxidEsales\Eshop\Core\DatabaseProvider::getDb()->execute($query);
|
||||
|
||||
$query = "ALTER TABLE `oepaypal_orderpaymentcomments`
|
||||
MODIFY `OEPAYPAL_COMMENT` varchar(256) character set utf8 collate utf8_general_ci NOT NULL;";
|
||||
\OxidEsales\Eshop\Core\DatabaseProvider::getDb()->execute($query);
|
||||
|
||||
$query = "ALTER TABLE `oepaypal_orderpayments`
|
||||
MODIFY `OEPAYPAL_ACTION` enum('capture','authorization','re-authorization','refund','void') CHARACTER SET utf8 collate utf8_general_ci NOT NULL DEFAULT 'capture',
|
||||
MODIFY `OEPAYPAL_TRANSACTIONID` varchar(32) character set utf8 collate utf8_general_ci NOT NULL,
|
||||
MODIFY `OEPAYPAL_CORRELATIONID` varchar(32) character set utf8 collate utf8_general_ci NOT NULL,
|
||||
MODIFY `OEPAYPAL_CURRENCY` varchar(3) character set utf8 collate utf8_general_ci NOT NULL,
|
||||
MODIFY `OEPAYPAL_STATUS` varchar(20) character set utf8 collate utf8_general_ci NOT NULL;";
|
||||
\OxidEsales\Eshop\Core\DatabaseProvider::getDb()->execute($query);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute action on activate event
|
||||
*/
|
||||
public static function onActivate()
|
||||
{
|
||||
// add additional field to order
|
||||
self::addOrderTable();
|
||||
|
||||
// create orders payments table
|
||||
self::addOrderPaymentsTable();
|
||||
|
||||
// payment comments
|
||||
self::addOrderPaymentsCommentsTable();
|
||||
|
||||
self::addMissingFieldsOnUpdate();
|
||||
self::ensureCorrectFieldsEncodingOnUpdate();
|
||||
|
||||
// adding record to oxPayment table
|
||||
self::addPaymentMethod();
|
||||
|
||||
// enabling PayPal payment method
|
||||
self::enablePaymentMethod();
|
||||
|
||||
// enable PayPal RDF
|
||||
self::enablePayPalRDFA();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the basket object, which is saved in the session, as it is an instance of \OxidEsales\PayPalModule\Model\Basket
|
||||
* and it is no longer a valid object after the module has been deactivated.
|
||||
*/
|
||||
public static function deleteSessionBasket()
|
||||
{
|
||||
\OxidEsales\Eshop\Core\Registry::getSession()->delBasket();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute action on deactivate event
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public static function onDeactivate()
|
||||
{
|
||||
// If PayPal activated on other sub shops do not remove payment method and RDF setting
|
||||
if ('EE' == \OxidEsales\Eshop\Core\Registry::getConfig()->getEdition() && self::isPayPalActiveOnSubShops()) {
|
||||
return;
|
||||
}
|
||||
self::disablePaymentMethod();
|
||||
self::disablePayPalRDFA();
|
||||
self::deleteSessionBasket();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core\Exception;
|
||||
|
||||
/**
|
||||
* Exception base class for PayPal
|
||||
*/
|
||||
class PayPalException extends \OxidEsales\Eshop\Core\Exception\StandardException
|
||||
{
|
||||
/**
|
||||
* Exception constructor.
|
||||
*
|
||||
* @param string $message exception message
|
||||
* @param integer $code exception code
|
||||
*/
|
||||
public function __construct($message = "", $code = 0)
|
||||
{
|
||||
parent::__construct($message, $code);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core\Exception;
|
||||
|
||||
/**
|
||||
* Exception Invalid Action exception
|
||||
*/
|
||||
class PayPalInvalidActionException extends \OxidEsales\PayPalModule\Core\Exception\PayPalException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core\Exception;
|
||||
|
||||
/**
|
||||
* Exception missing parameter exception
|
||||
*/
|
||||
class PayPalMissingParameterException extends \OxidEsales\PayPalModule\Core\Exception\PayPalException
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core\Exception;
|
||||
|
||||
/**
|
||||
* Exception class for PayPal returned exceptions
|
||||
*/
|
||||
class PayPalResponseException extends \OxidEsales\PayPalModule\Core\Exception\PayPalException
|
||||
{
|
||||
/**
|
||||
* Exception constructor. Adds additional prefix string to error message.
|
||||
*
|
||||
* @param string $message exception message
|
||||
* @param integer $code exception code
|
||||
*/
|
||||
public function __construct($message = "", $code = 0)
|
||||
{
|
||||
$prefix = \OxidEsales\Eshop\Core\Registry::getLang()->translateString("OEPAYPAL_RESPONSE_FROM_PAYPAL");
|
||||
|
||||
parent::__construct($prefix . $message, $code);
|
||||
}
|
||||
}
|
||||
157
shop/source/modules/oe/oepaypal/Core/ExtensionChecker.php
Normal file
157
shop/source/modules/oe/oepaypal/Core/ExtensionChecker.php
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core;
|
||||
|
||||
/**
|
||||
* PayPal Extension checker, check if extension is active on shop/sub-shop
|
||||
*/
|
||||
class ExtensionChecker
|
||||
{
|
||||
/**
|
||||
* Shop id
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $shopId = null;
|
||||
|
||||
/**
|
||||
* Extension id
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $extensionId = '';
|
||||
|
||||
/**
|
||||
* Set shop id
|
||||
*
|
||||
* @param string $shopId shop id
|
||||
*/
|
||||
public function setShopId($shopId)
|
||||
{
|
||||
$this->shopId = $shopId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return shop id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getShopId()
|
||||
{
|
||||
if (is_null($this->shopId)) {
|
||||
$this->setShopId(\OxidEsales\Eshop\Core\Registry::getConfig()->getShopId());
|
||||
}
|
||||
|
||||
return $this->shopId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set extension id
|
||||
*
|
||||
* @param string $extensionId extension id
|
||||
*/
|
||||
public function setExtensionId($extensionId)
|
||||
{
|
||||
$this->extensionId = $extensionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return extension id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getExtensionId()
|
||||
{
|
||||
return $this->extensionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return return extended classes array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getExtendedClasses()
|
||||
{
|
||||
return $this->getConfigValue('aModules');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return disabled modules array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getDisabledModules()
|
||||
{
|
||||
return $this->getConfigValue('aDisabledModules');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return config value
|
||||
*
|
||||
* @param string $configName - config parameter name were stored arrays od extended classes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getConfigValue($configName)
|
||||
{
|
||||
$db = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
|
||||
$config = \OxidEsales\Eshop\Core\Registry::getConfig();
|
||||
|
||||
$select = "SELECT `oxvarvalue` " .
|
||||
"FROM `oxconfig` WHERE `oxvarname` = " . $db->quote($configName) . " AND `oxshopid` = " . $db->quote($this->getShopId());
|
||||
|
||||
return unserialize($db->getOne($select));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if module is active.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isActive()
|
||||
{
|
||||
$moduleId = $this->getExtensionId();
|
||||
$moduleIsActive = false;
|
||||
|
||||
$modules = $this->getExtendedClasses();
|
||||
|
||||
if (is_array($modules)) {
|
||||
// Check if module was ever installed.
|
||||
$moduleExists = false;
|
||||
foreach ($modules as $extendPath) {
|
||||
if (false !== strpos($extendPath, '/' . $moduleId . '/')) {
|
||||
$moduleExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If module exists, check if it is not disabled.
|
||||
if ($moduleExists) {
|
||||
$disabledModules = $this->getDisabledModules();
|
||||
if (!(is_array($disabledModules) && in_array($moduleId, $disabledModules))) {
|
||||
$moduleIsActive = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $moduleIsActive;
|
||||
}
|
||||
}
|
||||
78
shop/source/modules/oe/oepaypal/Core/FullName.php
Normal file
78
shop/source/modules/oe/oepaypal/Core/FullName.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core;
|
||||
|
||||
/**
|
||||
* Class for splitting user name.
|
||||
*
|
||||
* @package core
|
||||
*/
|
||||
class FullName
|
||||
{
|
||||
/** @var string */
|
||||
private $firstName = '';
|
||||
|
||||
/** @var string */
|
||||
private $lastName = '';
|
||||
|
||||
/**
|
||||
* User first name and second name.
|
||||
*
|
||||
* @param string $fullName
|
||||
*/
|
||||
public function __construct($fullName)
|
||||
{
|
||||
$this->split($fullName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return user first name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFirstName()
|
||||
{
|
||||
return $this->firstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return user second name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLastName()
|
||||
{
|
||||
return $this->lastName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Split user full name to first name and second name.
|
||||
*
|
||||
* @param string $fullName
|
||||
*/
|
||||
protected function split($fullName)
|
||||
{
|
||||
$names = explode(" ", trim($fullName), 2);
|
||||
|
||||
$this->firstName = trim($names[0]);
|
||||
$this->lastName = trim($names[1]);
|
||||
}
|
||||
}
|
||||
290
shop/source/modules/oe/oepaypal/Core/IpnConfig.php
Normal file
290
shop/source/modules/oe/oepaypal/Core/IpnConfig.php
Normal file
@@ -0,0 +1,290 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core;
|
||||
|
||||
/**
|
||||
* PayPal IPN config class
|
||||
*/
|
||||
class IpnConfig
|
||||
{
|
||||
/**
|
||||
* Name of sandbox IPN host configuration variable.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const OEPAYPAL_SANDBOX_IPNHOST_CONFIGVAR = 'sPayPalSandboxIpnHost';
|
||||
|
||||
/**
|
||||
* Name of sandbox mode configuration variable.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const OEPAYPAL_IPNHOST_CONFIGVAR = 'sPayPalIpnHost';
|
||||
|
||||
/**
|
||||
* Name of sandbox IPN url configuration variable.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const OEPAYPAL_SANDBOX_IPN_URL_CONFIGVAR = 'sPayPalSandboxIpnUrl';
|
||||
|
||||
/**
|
||||
* Name of IPN url configuration variable.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const OEPAYPAL_IPN_URL_CONFIGVAR = 'sPayPalIpnUrl';
|
||||
|
||||
/**
|
||||
* PayPal IPN host.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const OEPAYPAL_IPN_HOST = 'ipnpb.paypal.com';
|
||||
|
||||
/**
|
||||
* PayPal IPN sandbox host.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const OEPAYPAL_IPN_SANDBOX_HOST = 'ipnpb.sandbox.paypal.com';
|
||||
|
||||
/**
|
||||
* PayPal sandbox url to send IPN callback to for verification.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const OEPAYPAL_SANDBOX_IPN_CALLBACK_URL = 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr';
|
||||
|
||||
/**
|
||||
* PayPal sandbox url to send IPN callback to for verification.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const OEPAYPAL_IPN_CALLBACK_URL = 'https://ipnpb.paypal.com/cgi-bin/webscr';
|
||||
|
||||
/**
|
||||
* @var
|
||||
*/
|
||||
protected $payPalConfig = null;
|
||||
|
||||
/**
|
||||
* PayPal IPN host.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $payPalIpnHost = '';
|
||||
|
||||
/**
|
||||
* PayPal IPN sandbox host.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $payPalIpnSandboxHost = '';
|
||||
|
||||
/**
|
||||
* PayPal sandbox url to send IPN callback to for verification.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $payPalSandboxIpnUrl = '';
|
||||
|
||||
/**
|
||||
* PayPal sandbox url to send IPN callback to for verification.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $payPalIpnUrl = '';
|
||||
|
||||
/**
|
||||
* IpnConfig constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
if ($host = $this->getPayPalConfig()->getParameter(self::getPayPalIpnHost())) {
|
||||
$this->setPayPalIpnHost($host);
|
||||
}
|
||||
|
||||
if ($sandboxHost = $this->getPayPalConfig()->getParameter(self::OEPAYPAL_SANDBOX_IPNHOST_CONFIGVAR)) {
|
||||
$this->setPayPalSandboxIpnHost($sandboxHost);
|
||||
}
|
||||
|
||||
if ($url = $this->getPayPalConfig()->getParameter(self::OEPAYPAL_IPN_URL_CONFIGVAR)) {
|
||||
$this->setPayPalIpnUrl($url);
|
||||
}
|
||||
|
||||
if ($sandboxUrl = $this->getPayPalConfig()->getParameter(self::OEPAYPAL_SANDBOX_IPN_URL_CONFIGVAR)) {
|
||||
$this->setPayPalSandboxIPNUrl($sandboxUrl);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PayPal IPN host.
|
||||
*
|
||||
* @param string $payPalIpnHost
|
||||
*/
|
||||
public function setPayPalIpnHost($payPalIpnHost)
|
||||
{
|
||||
$this->payPalIpnHost = $payPalIpnHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal IPN host.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalIpnHost()
|
||||
{
|
||||
if (empty($this->payPalIpnHost)) {
|
||||
$this->payPalIpnHost = self::OEPAYPAL_IPN_HOST;
|
||||
}
|
||||
|
||||
return $this->payPalIpnHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PayPal IPN sandbox host.
|
||||
*
|
||||
* @param string $payPalIpnSandboxHost
|
||||
*/
|
||||
public function setPayPalSandboxIpnHost($payPalIpnSandboxHost)
|
||||
{
|
||||
$this->payPalIpnSandboxHost = $payPalIpnSandboxHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal sandbox host.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalSandboxIpnHost()
|
||||
{
|
||||
if (empty($this->payPalIpnSandboxHost)) {
|
||||
$this->payPalIpnSandboxHost = self::OEPAYPAL_IPN_SANDBOX_HOST;
|
||||
}
|
||||
|
||||
return $this->payPalIpnSandboxHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal OR PayPal IPN sandbox host.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIpnHost()
|
||||
{
|
||||
if ($this->getPayPalConfig()->isSandboxEnabled()) {
|
||||
$url = $this->getPayPalSandboxIpnHost();
|
||||
} else {
|
||||
$url = $this->getPayPalIpnHost();
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* PayPal IPN Url Setter
|
||||
*
|
||||
* @param string $payPalUrl
|
||||
*/
|
||||
public function setPayPalIpnUrl($payPalIpnUrl)
|
||||
{
|
||||
$this->payPalIpnUrl = $payPalIpnUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* IPN Url getter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalIpnUrl()
|
||||
{
|
||||
if (empty($this->payPalIpnUrl)) {
|
||||
$this->payPalIpnUrl = self::OEPAYPAL_IPN_CALLBACK_URL;
|
||||
}
|
||||
|
||||
return $this->payPalIpnUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* PayPal sandbox IPN url setter
|
||||
*
|
||||
* @param string $payPalSandboxIPNUrl
|
||||
*/
|
||||
public function setPayPalSandboxIpnUrl($payPalSandboxIpnUrl)
|
||||
{
|
||||
$this->payPalSandboxIpnUrl = $payPalSandboxIpnUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* PayPal sandbox IPN url getter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalSandboxIpnUrl()
|
||||
{
|
||||
if (empty($this->payPalSandboxIpnUrl)) {
|
||||
$this->payPalSandboxIpnUrl = self::OEPAYPAL_SANDBOX_IPN_CALLBACK_URL;
|
||||
}
|
||||
|
||||
return $this->payPalSandboxIpnUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns end point url
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIpnUrl()
|
||||
{
|
||||
if ($this->getPayPalConfig()->isSandboxEnabled()) {
|
||||
$url = $this->getPayPalSandboxIpnUrl();
|
||||
} else {
|
||||
$url = $this->getPayPalIpnUrl();
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Url for IPN response call to notify PayPal
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIPNResponseUrl()
|
||||
{
|
||||
return $this->getIpnUrl() . '&cmd=_notify-validate';
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for oepaypal config.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Config
|
||||
*/
|
||||
protected function getPayPalConfig()
|
||||
{
|
||||
if (is_null($this->payPalConfig)) {
|
||||
$this->payPalConfig = oxNew(\OxidEsales\PayPalModule\Core\Config::class);
|
||||
}
|
||||
|
||||
return $this->payPalConfig;
|
||||
}
|
||||
}
|
||||
124
shop/source/modules/oe/oepaypal/Core/Logger.php
Normal file
124
shop/source/modules/oe/oepaypal/Core/Logger.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core;
|
||||
|
||||
/**
|
||||
* Base logger class
|
||||
*/
|
||||
class Logger
|
||||
{
|
||||
/**
|
||||
* Logger session id.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $loggerSessionId;
|
||||
|
||||
/**
|
||||
* Log title
|
||||
*/
|
||||
protected $logTitle = '';
|
||||
|
||||
/**
|
||||
* Sets logger session id.
|
||||
*
|
||||
* @param string $id session id
|
||||
*/
|
||||
public function setLoggerSessionId($id)
|
||||
{
|
||||
$this->loggerSessionId = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns loggers session id.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLoggerSessionId()
|
||||
{
|
||||
return $this->loggerSessionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns full log file path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getLogFilePath()
|
||||
{
|
||||
$logDirectoryPath = \OxidEsales\Eshop\Core\Registry::getConfig()->getLogsDir();
|
||||
|
||||
return $logDirectoryPath . 'oepaypal.log';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set log title.
|
||||
*
|
||||
* @param string $title Log title
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->logTitle = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get title.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->logTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes log message.
|
||||
*
|
||||
* @param mixed $logData logger data
|
||||
*/
|
||||
public function log($logData)
|
||||
{
|
||||
$handle = fopen($this->getLogFilePath(), "a+");
|
||||
if ($handle !== false) {
|
||||
if (is_string($logData)) {
|
||||
parse_str($logData, $result);
|
||||
} else {
|
||||
$result = $logData;
|
||||
}
|
||||
|
||||
if (is_array($result)) {
|
||||
foreach ($result as $key => $value) {
|
||||
if (is_string($value)) {
|
||||
$result[$key] = urldecode($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fwrite($handle, "======================= " . $this->getTitle() . " [" . date("Y-m-d H:i:s") . "] ======================= #\n\n");
|
||||
fwrite($handle, "SESS ID: " . $this->getLoggerSessionId() . "\n");
|
||||
fwrite($handle, trim(var_export($result, true)) . "\n\n");
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
//resetting log title
|
||||
$this->setTitle('');
|
||||
}
|
||||
}
|
||||
185
shop/source/modules/oe/oepaypal/Core/Model.php
Normal file
185
shop/source/modules/oe/oepaypal/Core/Model.php
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core;
|
||||
|
||||
/**
|
||||
* Abstract model class
|
||||
*/
|
||||
abstract class Model
|
||||
{
|
||||
/**
|
||||
* Data base gateway.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Core\ModelDbGateway
|
||||
*/
|
||||
protected $dbGateway = null;
|
||||
|
||||
/**
|
||||
* Model data.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $data = null;
|
||||
|
||||
/**
|
||||
* Was object information found in database.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $isLoaded = false;
|
||||
|
||||
/**
|
||||
* Set response data.
|
||||
*
|
||||
* @param array $data model data
|
||||
*/
|
||||
public function setData($data)
|
||||
{
|
||||
$data = array_change_key_case($data, CASE_LOWER);
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return response data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return value from data by given key.
|
||||
*
|
||||
* @param string $key key of data value
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getValue($key)
|
||||
{
|
||||
$data = $this->getData();
|
||||
|
||||
return $data[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return value from data by given key.
|
||||
*
|
||||
* @param string $key key of data value
|
||||
* @param string $value data value
|
||||
*/
|
||||
protected function setValue($key, $value)
|
||||
{
|
||||
$this->data[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns model database gateway.
|
||||
*
|
||||
* @var $dbGateway
|
||||
*/
|
||||
abstract protected function getDbGateway();
|
||||
|
||||
/**
|
||||
* Set model database gateway.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\ModelDbGateway $dbGateway
|
||||
*/
|
||||
protected function setDbGateway($dbGateway)
|
||||
{
|
||||
$this->dbGateway = $dbGateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for model saving (insert and update data).
|
||||
*
|
||||
* @return int|false
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$id = $this->getDbGateway()->save($this->getData());
|
||||
$this->setId($id);
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete model data from db.
|
||||
*
|
||||
* @param string $id model id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($id = null)
|
||||
{
|
||||
if (!is_null($id)) {
|
||||
$this->setId($id);
|
||||
}
|
||||
|
||||
return $this->getDbGateway()->delete($this->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for loading model, if loaded returns true.
|
||||
*
|
||||
* @param string $id model id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function load($id = null)
|
||||
{
|
||||
if (!is_null($id)) {
|
||||
$this->setId($id);
|
||||
}
|
||||
|
||||
$this->isLoaded = false;
|
||||
$data = $this->getDbGateway()->load($this->getId());
|
||||
if ($data) {
|
||||
$this->setData($data);
|
||||
$this->isLoaded = true;
|
||||
}
|
||||
|
||||
return $this->isLoaded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether object information found in database.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isLoaded()
|
||||
{
|
||||
return $this->isLoaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract method for delete model.
|
||||
*
|
||||
* @param string $id model id
|
||||
*/
|
||||
abstract public function setId($id);
|
||||
|
||||
/**
|
||||
* Abstract method for getting id.
|
||||
*/
|
||||
abstract public function getId();
|
||||
}
|
||||
60
shop/source/modules/oe/oepaypal/Core/ModelDbGateway.php
Normal file
60
shop/source/modules/oe/oepaypal/Core/ModelDbGateway.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core;
|
||||
|
||||
/**
|
||||
* Abstract model db gateway class.
|
||||
*
|
||||
* @todo: maybe this class lives better in the \OxidEsales\PayPalModule\Model namespace as DbGateway?!
|
||||
*/
|
||||
abstract class ModelDbGateway
|
||||
{
|
||||
/**
|
||||
* Returns data base resource.
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface
|
||||
*/
|
||||
protected function getDb()
|
||||
{
|
||||
return \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract method for data saving (insert and update).
|
||||
*
|
||||
* @param array $data model data
|
||||
*/
|
||||
abstract public function save($data);
|
||||
|
||||
/**
|
||||
* Abstract method for loading model data.
|
||||
*
|
||||
* @param string $id model id
|
||||
*/
|
||||
abstract public function load($id);
|
||||
|
||||
/**
|
||||
* Abstract method for delete model data.
|
||||
*
|
||||
* @param string $id model id
|
||||
*/
|
||||
abstract public function delete($id);
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core;
|
||||
|
||||
/**
|
||||
* Validates changed basket amount. Checks if it is bigger than previous price.
|
||||
* Than returns false to recheck new basket amount in PayPal.
|
||||
*/
|
||||
class PayPalCheckValidator
|
||||
{
|
||||
/**
|
||||
* Basket new amount
|
||||
*
|
||||
* @var double
|
||||
*/
|
||||
protected $newBasketAmount = null;
|
||||
|
||||
/**
|
||||
* Basket old amount
|
||||
*
|
||||
* @var double
|
||||
*/
|
||||
protected $oldBasketAmount = null;
|
||||
|
||||
/**
|
||||
* Returns if order should be rechecked by PayPal
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isPayPalCheckValid()
|
||||
{
|
||||
$newBasketAmount = $this->getNewBasketAmount();
|
||||
$prevBasketAmount = $this->getOldBasketAmount();
|
||||
// check only if new price is different and bigger than old price
|
||||
if ($newBasketAmount > $prevBasketAmount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets new basket amount
|
||||
*
|
||||
* @param double $newBasketAmount changed basket amount
|
||||
*/
|
||||
public function setNewBasketAmount($newBasketAmount)
|
||||
{
|
||||
$this->newBasketAmount = $newBasketAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns new basket amount
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function getNewBasketAmount()
|
||||
{
|
||||
return (float) $this->newBasketAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets old basket amount
|
||||
*
|
||||
* @param double $oldBasketAmount old basket amount
|
||||
*/
|
||||
public function setOldBasketAmount($oldBasketAmount)
|
||||
{
|
||||
$this->oldBasketAmount = $oldBasketAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns old basket amount
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function getOldBasketAmount()
|
||||
{
|
||||
return (float) $this->oldBasketAmount;
|
||||
}
|
||||
}
|
||||
206
shop/source/modules/oe/oepaypal/Core/PayPalList.php
Normal file
206
shop/source/modules/oe/oepaypal/Core/PayPalList.php
Normal file
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core;
|
||||
|
||||
use Countable;
|
||||
use Iterator;
|
||||
|
||||
/**
|
||||
* List manager class.
|
||||
*/
|
||||
class PayPalList implements Iterator, Countable
|
||||
{
|
||||
/**
|
||||
* Array of objects (some object list).
|
||||
*
|
||||
* @var array $_aArray
|
||||
*/
|
||||
protected $array = array();
|
||||
|
||||
/**
|
||||
* Save the state, that active element was unset
|
||||
* needed for proper foreach iterator functionality.
|
||||
*
|
||||
* @var bool $_blRemovedActive
|
||||
*/
|
||||
protected $removedActive = false;
|
||||
|
||||
/**
|
||||
* Flag if array is ok or not.
|
||||
*
|
||||
* @var boolean $_blValid
|
||||
*/
|
||||
private $valid = true;
|
||||
|
||||
/**
|
||||
* -----------------------------------------------------------------------------------------------------
|
||||
*
|
||||
* Implementation of SPL Array classes functions follows here
|
||||
*
|
||||
* -----------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns SPL array keys.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function arrayKeys()
|
||||
{
|
||||
return array_keys($this->array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewind for SPL.
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
$this->removedActive = false;
|
||||
$this->valid = (false !== reset($this->array));
|
||||
}
|
||||
|
||||
/**
|
||||
* Current for SPL.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function current()
|
||||
{
|
||||
return current($this->array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Key for SPL.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function key()
|
||||
{
|
||||
return key($this->array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Previous / first array element.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function prev()
|
||||
{
|
||||
$var = prev($this->array);
|
||||
if ($var === false) {
|
||||
// the first element, reset pointer
|
||||
$var = reset($this->array);
|
||||
}
|
||||
$this->removedActive = false;
|
||||
|
||||
return $var;
|
||||
}
|
||||
|
||||
/**
|
||||
* Next for SPL.
|
||||
*/
|
||||
public function next()
|
||||
{
|
||||
if ($this->removedActive === true && current($this->array)) {
|
||||
$var = $this->prev();
|
||||
} else {
|
||||
$var = next($this->array);
|
||||
}
|
||||
|
||||
$this->valid = (false !== $var);
|
||||
}
|
||||
|
||||
/**
|
||||
* Valid for SPL.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function valid()
|
||||
{
|
||||
return $this->valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count for SPL.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return count($this->array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears/destroys list contents.
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->array = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* copies a given array over the objects internal array (something like old $myList->aList = $array).
|
||||
*
|
||||
* @param array $array array of list items
|
||||
*/
|
||||
public function setArray($array)
|
||||
{
|
||||
$this->array = $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the array reversed, the internal array remains untouched.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function reverse()
|
||||
{
|
||||
return array_reverse($this->array);
|
||||
}
|
||||
|
||||
/**
|
||||
* -----------------------------------------------------------------------------------------------------
|
||||
* SPL implementation end
|
||||
* -----------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Backward compatibility method.
|
||||
*
|
||||
* @param string $name Variable name
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($name)
|
||||
{
|
||||
return $this->array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list items array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getArray()
|
||||
{
|
||||
return $this->array;
|
||||
}
|
||||
}
|
||||
327
shop/source/modules/oe/oepaypal/Core/PayPalService.php
Normal file
327
shop/source/modules/oe/oepaypal/Core/PayPalService.php
Normal file
@@ -0,0 +1,327 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core;
|
||||
|
||||
/**
|
||||
* PayPal Service class
|
||||
*/
|
||||
class PayPalService
|
||||
{
|
||||
/**
|
||||
* PayPal Caller
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Core\Caller
|
||||
*/
|
||||
protected $caller = null;
|
||||
|
||||
/**
|
||||
* PayPal Caller.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Core\Config
|
||||
*/
|
||||
protected $payPalConfig = null;
|
||||
|
||||
/**
|
||||
* PayPal IPN config.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Core\IpnConfig
|
||||
*/
|
||||
protected $payPalIpnConfig = null;
|
||||
|
||||
/**
|
||||
* PayPal config setter.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\Config $payPalConfig
|
||||
*/
|
||||
public function setPayPalConfig($payPalConfig)
|
||||
{
|
||||
$this->payPalConfig = $payPalConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* PayPal config getter.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Config
|
||||
*/
|
||||
public function getPayPalConfig()
|
||||
{
|
||||
if (is_null($this->payPalConfig)) {
|
||||
$this->setPayPalConfig(oxNew(\OxidEsales\PayPalModule\Core\Config::class));
|
||||
}
|
||||
|
||||
return $this->payPalConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* PayPal Ipn config setter.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\IpnConfig $payPalIpnConfig
|
||||
*/
|
||||
public function setPayPalIpnConfig($payPalIpnConfig)
|
||||
{
|
||||
$this->payPalIpnConfig = $payPalIpnConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* PayPal config getter.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\IpnConfig
|
||||
*/
|
||||
public function getPayPalIpnConfig()
|
||||
{
|
||||
if (is_null($this->payPalIpnConfig)) {
|
||||
$this->setPayPalIPnConfig(oxNew(\OxidEsales\PayPalModule\Core\IpnConfig::class));
|
||||
}
|
||||
|
||||
return $this->payPalIpnConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* PayPal caller setter.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\Caller $caller
|
||||
*/
|
||||
public function setCaller($caller)
|
||||
{
|
||||
$this->caller = $caller;
|
||||
}
|
||||
|
||||
/**
|
||||
* PayPal caller getter.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Caller
|
||||
*/
|
||||
public function getCaller()
|
||||
{
|
||||
if (is_null($this->caller)) {
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Core\Caller $caller
|
||||
*/
|
||||
$caller = oxNew(\OxidEsales\PayPalModule\Core\Caller::class);
|
||||
|
||||
$config = $this->getPayPalConfig();
|
||||
|
||||
$caller->setParameter('VERSION', '84.0');
|
||||
$caller->setParameter('PWD', $config->getPassword());
|
||||
$caller->setParameter('USER', $config->getUserName());
|
||||
$caller->setParameter('SIGNATURE', $config->getSignature());
|
||||
|
||||
$curl = oxNew(\OxidEsales\PayPalModule\Core\Curl::class);
|
||||
$curl->setDataCharset($config->getCharset());
|
||||
$curl->setHost($config->getHost());
|
||||
$curl->setUrlToCall($config->getApiUrl());
|
||||
|
||||
$caller->setCurl($curl);
|
||||
|
||||
if ($config->isLoggingEnabled()) {
|
||||
$logger = oxNew(\OxidEsales\PayPalModule\Core\Logger::class);
|
||||
$logger->setLoggerSessionId(\OxidEsales\Eshop\Core\Registry::getSession()->getId());
|
||||
$caller->setLogger($logger);
|
||||
}
|
||||
|
||||
$this->setCaller($caller);
|
||||
}
|
||||
|
||||
return $this->caller;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes "SetExpressCheckout". Returns response object from PayPal.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $request
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\Response\ResponseSetExpressCheckout
|
||||
*/
|
||||
public function setExpressCheckout($request)
|
||||
{
|
||||
$caller = $this->getCaller();
|
||||
$caller->setRequest($request);
|
||||
|
||||
$response = oxNew(\OxidEsales\PayPalModule\Model\Response\ResponseSetExpressCheckout::class);
|
||||
$response->setData($caller->call('SetExpressCheckout'));
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes "GetExpressCheckoutDetails". Returns response object from PayPal.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $request
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\Response\ResponseGetExpressCheckoutDetails
|
||||
*/
|
||||
public function getExpressCheckoutDetails($request)
|
||||
{
|
||||
$caller = $this->getCaller();
|
||||
$caller->setRequest($request);
|
||||
|
||||
$response = oxNew(\OxidEsales\PayPalModule\Model\Response\ResponseGetExpressCheckoutDetails::class);
|
||||
$response->setData($caller->call('GetExpressCheckoutDetails'));
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes "DoExpressCheckoutPayment". Returns response object from PayPal.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $request
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\Response\ResponseDoExpressCheckoutPayment
|
||||
*/
|
||||
public function doExpressCheckoutPayment($request)
|
||||
{
|
||||
$caller = $this->getCaller();
|
||||
$caller->setRequest($request);
|
||||
|
||||
$response = oxNew(\OxidEsales\PayPalModule\Model\Response\ResponseDoExpressCheckoutPayment::class);
|
||||
$response->setData($caller->call('DoExpressCheckoutPayment'));
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes PayPal callback request
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function callbackResponse()
|
||||
{
|
||||
// cleanup
|
||||
$this->getCaller()->setParameter("VERSION", null);
|
||||
$this->getCaller()->setParameter("PWD", null);
|
||||
$this->getCaller()->setParameter("USER", null);
|
||||
$this->getCaller()->setParameter("SIGNATURE", null);
|
||||
|
||||
return $this->getCaller()->getCallBackResponse("CallbackResponse");
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes "DoVoid". Returns response array from PayPal
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $request
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\Response\Response
|
||||
*/
|
||||
public function doVoid($request)
|
||||
{
|
||||
$caller = $this->getCaller();
|
||||
$caller->setRequest($request);
|
||||
|
||||
$response = oxNew(\OxidEsales\PayPalModule\Model\Response\ResponseDoVoid::class);
|
||||
$response->setData($caller->call('DoVoid'));
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes "RefundTransaction". Returns response array from PayPal
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $request
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\Response\Response
|
||||
*/
|
||||
public function refundTransaction($request)
|
||||
{
|
||||
$caller = $this->getCaller();
|
||||
$caller->setRequest($request);
|
||||
|
||||
$response = oxNew(\OxidEsales\PayPalModule\Model\Response\ResponseDoRefund::class);
|
||||
$response->setData($caller->call('RefundTransaction'));
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes "DoCapture". Returns response array from PayPal
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $request request
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\Response\Response
|
||||
*/
|
||||
public function doCapture($request)
|
||||
{
|
||||
$caller = $this->getCaller();
|
||||
$caller->setRequest($request);
|
||||
|
||||
$response = oxNew(\OxidEsales\PayPalModule\Model\Response\ResponseDoCapture::class);
|
||||
$response->setData($caller->call('DoCapture'));
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes "DoReauthorization". Returns response array from PayPal.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $request
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\Response\Response
|
||||
*/
|
||||
public function doReAuthorization($request)
|
||||
{
|
||||
$caller = $this->getCaller();
|
||||
$caller->setRequest($request);
|
||||
|
||||
$response = oxNew(\OxidEsales\PayPalModule\Model\Response\ResponseDoReAuthorize::class);
|
||||
$response->setData($caller->call('DoReauthorization'));
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes call to PayPal IPN.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $request
|
||||
* @param string $charset
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\Response\Response
|
||||
*/
|
||||
public function doVerifyWithPayPal($request, $charset)
|
||||
{
|
||||
$caller = $this->getCaller();
|
||||
$caller->setRequest($request);
|
||||
|
||||
$caller = $this->getCaller();
|
||||
$curl = $caller->getCurl();
|
||||
$curl->setConnectionCharset($charset);
|
||||
$curl->setDataCharset($charset);
|
||||
$curl->setHost($this->getPayPalIpnConfig()->getIpnHost());
|
||||
$curl->setUrlToCall($this->getPayPalIpnConfig()->getIPNResponseUrl());
|
||||
|
||||
$response = oxNew(\OxidEsales\PayPalModule\Model\Response\ResponseDoVerifyWithPayPal::class);
|
||||
$response->setData($caller->call());
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set parameter to caller by it's key.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $value
|
||||
*
|
||||
* @deprecated still use in callback.
|
||||
*/
|
||||
public function setParameter($key, $value)
|
||||
{
|
||||
$this->getCaller()->setParameter($key, $value);
|
||||
}
|
||||
}
|
||||
141
shop/source/modules/oe/oepaypal/Core/Request.php
Normal file
141
shop/source/modules/oe/oepaypal/Core/Request.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core;
|
||||
|
||||
/**
|
||||
* PayPal Request class
|
||||
*/
|
||||
class Request
|
||||
{
|
||||
/**
|
||||
* Get post.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPost()
|
||||
{
|
||||
$post = array();
|
||||
|
||||
if (!empty($_POST)) {
|
||||
$post = $_POST;
|
||||
}
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get get.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getGet()
|
||||
{
|
||||
$get = array();
|
||||
|
||||
if (!empty($_GET)) {
|
||||
$get = $_GET;
|
||||
}
|
||||
|
||||
return $get;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns value of parameter stored in POST,GET.
|
||||
*
|
||||
* @param string $name Name of parameter
|
||||
* @param bool $raw mark to return not escaped parameter
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRequestParameter($name, $raw = false)
|
||||
{
|
||||
$value = null;
|
||||
|
||||
$value = $this->getPostParameter($name, $raw);
|
||||
if (!isset($value)) {
|
||||
$value = $this->getGetParameter($name, $raw);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns value of parameter stored in POST.
|
||||
*
|
||||
* @param string $name Name of parameter
|
||||
* @param bool $raw mark to return not escaped parameter
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPostParameter($name, $raw = false)
|
||||
{
|
||||
$value = null;
|
||||
$post = $this->getPost();
|
||||
|
||||
if (isset($post[$name])) {
|
||||
$value = $post[$name];
|
||||
}
|
||||
|
||||
if ($value !== null && !$raw) {
|
||||
$value = $this->escapeSpecialChars($value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns value of parameter stored in GET.
|
||||
*
|
||||
* @param string $name Name of parameter
|
||||
* @param bool $raw mark to return not escaped parameter
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getGetParameter($name, $raw = false)
|
||||
{
|
||||
$value = null;
|
||||
$get = $this->getGet();
|
||||
|
||||
if (isset($get[$name])) {
|
||||
$value = $get[$name];
|
||||
}
|
||||
|
||||
if ($value !== null && !$raw) {
|
||||
$value = $this->escapeSpecialChars($value);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for PayPal escape class.
|
||||
*
|
||||
* @param mixed $value value to escape
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function escapeSpecialChars($value)
|
||||
{
|
||||
$payPalEscape = oxNew(\OxidEsales\PayPalModule\Core\Escape::class);
|
||||
|
||||
return $payPalEscape->escapeSpecialChars($value);
|
||||
}
|
||||
}
|
||||
386
shop/source/modules/oe/oepaypal/Core/ShopLogo.php
Normal file
386
shop/source/modules/oe/oepaypal/Core/ShopLogo.php
Normal file
@@ -0,0 +1,386 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core;
|
||||
|
||||
/**
|
||||
* PayPal shop logo class.
|
||||
*/
|
||||
class ShopLogo
|
||||
{
|
||||
/**
|
||||
* Suffix for image resizing.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_suffix = "resized_";
|
||||
|
||||
/**
|
||||
* Image directory to work in.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $imageDir = null;
|
||||
|
||||
/**
|
||||
* Image directory to work in.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $imageDirUrl = null;
|
||||
|
||||
/**
|
||||
* Image name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $imageName = null;
|
||||
|
||||
/**
|
||||
* Path to an image, not null only when it exists.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $imagePath = null;
|
||||
/**
|
||||
* Image maximum width.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $width = 190;
|
||||
|
||||
/**
|
||||
* Image maximum height.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $height = 160;
|
||||
|
||||
/**
|
||||
* Provided image handler.
|
||||
*
|
||||
* @var \OxidEsales\Eshop\Core\UtilsPic
|
||||
*/
|
||||
protected $imageHandler = null;
|
||||
|
||||
/**
|
||||
* Set image handler to handle images.
|
||||
* Needs to have resizeImage method.
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Core\UtilsPic $imageHandler
|
||||
*/
|
||||
public function setImageHandler($imageHandler)
|
||||
{
|
||||
$this->imageHandler = $imageHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns image handler object.
|
||||
*
|
||||
* @return object|oxUtilsPic
|
||||
*/
|
||||
public function getImageHandler()
|
||||
{
|
||||
return $this->imageHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets image maximum width.
|
||||
*
|
||||
* @param int $width
|
||||
*/
|
||||
public function setWidth($width)
|
||||
{
|
||||
$this->width = $width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return image maximum width.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getWidth()
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets image maximum height.
|
||||
*
|
||||
* @param int $height
|
||||
*/
|
||||
public function setHeight($height)
|
||||
{
|
||||
$this->height = $height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return image maximum height.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getHeight()
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates if logo should be resized.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function getResize()
|
||||
{
|
||||
$resize = false;
|
||||
$imagePath = $this->getImagePath();
|
||||
if ($imagePath) {
|
||||
$imageSize = $this->getImageSize($imagePath);
|
||||
|
||||
if ($imageSize['width'] > $this->getWidth() ||
|
||||
$imageSize['height'] > $this->getHeight()
|
||||
) {
|
||||
$resize = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $resize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets image directory.
|
||||
*
|
||||
* @param string $imagePath
|
||||
*/
|
||||
public function setImageDir($imagePath)
|
||||
{
|
||||
$this->imageDir = $imagePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns image directory.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getImageDir()
|
||||
{
|
||||
return $this->imageDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set image directory URL.
|
||||
*
|
||||
* @param string $imageDirUrl
|
||||
*/
|
||||
public function setImageDirUrl($imageDirUrl)
|
||||
{
|
||||
$this->imageDirUrl = $imageDirUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for image directory URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getImageDirUrl()
|
||||
{
|
||||
return $this->imageDirUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set name of an image.
|
||||
*
|
||||
* @param string $imageName
|
||||
*/
|
||||
public function setImageName($imageName)
|
||||
{
|
||||
$this->imageName = $imageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name of an image.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getImageName()
|
||||
{
|
||||
return $this->imageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives new name for image to be resized.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getResizedImageName()
|
||||
{
|
||||
$resizedImageName = "";
|
||||
if ($this->getImageName()) {
|
||||
$resizedImageName = $this->_suffix . $this->getImageName();
|
||||
}
|
||||
|
||||
return $resizedImageName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns path to an image.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getImagePath()
|
||||
{
|
||||
if (null == $this->imagePath) {
|
||||
$dir = $this->getImageDir();
|
||||
$name = $this->getImageName();
|
||||
|
||||
if ($dir && $name && $this->fileExists($dir . $name)) {
|
||||
$this->imagePath = $dir . $name;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->imagePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns path to an image.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getImageUrl()
|
||||
{
|
||||
$imageUrl = "";
|
||||
|
||||
if ($this->getImagePath()) {
|
||||
$imageUrl = $this->getImageDirUrl() . $this->getImageName();
|
||||
}
|
||||
|
||||
return $imageUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns resized image path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getResizedImagePath()
|
||||
{
|
||||
$resizedImagePath = "";
|
||||
$dir = $this->getImageDir();
|
||||
$name = $this->getResizedImageName();
|
||||
|
||||
if ($dir && $name) {
|
||||
$resizedImagePath = $dir . $name;
|
||||
}
|
||||
|
||||
return $resizedImagePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns resized image path.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getResizedImageUrl()
|
||||
{
|
||||
$imageUrl = "";
|
||||
|
||||
if ($this->getResizedImagePath()) {
|
||||
$imageUrl = $this->getImageDirUrl() . $this->getResizedImageName();
|
||||
}
|
||||
|
||||
return $imageUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get logo image path for PayPal express checkout.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getShopLogoUrl()
|
||||
{
|
||||
$imagePath = $this->getImageUrl();
|
||||
$resizedImagePath = $this->getResizedImageUrl();
|
||||
|
||||
if ($this->getResize()) {
|
||||
$shopLogoPath = $resizedImagePath;
|
||||
|
||||
if (!$this->fileExists($resizedImagePath)) {
|
||||
if (!$this->resizeImage()) {
|
||||
// fallback to original image if can not be resized
|
||||
$shopLogoPath = $imagePath;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$shopLogoPath = $imagePath;
|
||||
}
|
||||
|
||||
return $shopLogoPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if given image file exists.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function fileExists($path)
|
||||
{
|
||||
return file_exists($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns array with width and height of given image
|
||||
*
|
||||
* @param string $imagePath
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getImageSize($imagePath)
|
||||
{
|
||||
$imageSize = getimagesize($imagePath);
|
||||
|
||||
return array(
|
||||
'width' => $imageSize[0],
|
||||
'height' => $imageSize[1]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resizes logo if needed to the size provided
|
||||
* Returns false when image does'nt exist, or can't be resized
|
||||
* Returns original image name when image is within boundaries
|
||||
* Returns resized image name when image is too large than defined
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function resizeImage()
|
||||
{
|
||||
$resized = false;
|
||||
|
||||
if ($utilsPic = $this->getImageHandler()) {
|
||||
// checks if image can be resized, and resizes the image
|
||||
if ($utilsPic->resizeImage($this->getImagePath(), $this->getResizedImagePath(), $this->getWidth(), $this->getHeight())) {
|
||||
$resized = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $resized;
|
||||
}
|
||||
}
|
||||
102
shop/source/modules/oe/oepaypal/Core/UserAgent.php
Normal file
102
shop/source/modules/oe/oepaypal/Core/UserAgent.php
Normal file
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core;
|
||||
|
||||
/**
|
||||
* Class for User Agent.
|
||||
*
|
||||
* @package core
|
||||
*/
|
||||
class UserAgent
|
||||
{
|
||||
/**
|
||||
* Detected device type
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $deviceType = null;
|
||||
|
||||
/**
|
||||
* Mobile device types.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $mobileDevicesTypes = 'iphone|ipod|android|webos|htc|fennec|iemobile|blackberry|symbianos|opera mobi';
|
||||
|
||||
/**
|
||||
* Function returns all supported mobile devices types.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMobileDeviceTypes()
|
||||
{
|
||||
return $this->mobileDevicesTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns device type: mobile | desktop.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDeviceType()
|
||||
{
|
||||
if ($this->deviceType === null) {
|
||||
$this->setDeviceType($this->detectDeviceType());
|
||||
}
|
||||
|
||||
return $this->deviceType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set device type.
|
||||
*
|
||||
* @param string $deviceType
|
||||
*/
|
||||
public function setDeviceType($deviceType)
|
||||
{
|
||||
$this->deviceType = $deviceType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set mobile device types.
|
||||
*
|
||||
* @param string $mobileDeviceTypes
|
||||
*/
|
||||
public function setMobileDeviceTypes($mobileDeviceTypes)
|
||||
{
|
||||
$this->mobileDevicesTypes = $mobileDeviceTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects device type from global variable. Device types: mobile, desktop.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function detectDeviceType()
|
||||
{
|
||||
$deviceType = 'desktop';
|
||||
if (preg_match('/(' . $this->getMobileDeviceTypes() . ')/is', $_SERVER['HTTP_USER_AGENT'])) {
|
||||
$deviceType = 'mobile';
|
||||
}
|
||||
|
||||
return $deviceType;
|
||||
}
|
||||
}
|
||||
446
shop/source/modules/oe/oepaypal/Core/ViewConfig.php
Normal file
446
shop/source/modules/oe/oepaypal/Core/ViewConfig.php
Normal file
@@ -0,0 +1,446 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Core;
|
||||
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
|
||||
/**
|
||||
* ViewConfig class wrapper for PayPal module.
|
||||
*
|
||||
* @mixin \OxidEsales\Eshop\Core\ViewConfig
|
||||
*/
|
||||
class ViewConfig extends ViewConfig_parent
|
||||
{
|
||||
/** @var null \OxidEsales\PayPalModule\Core\Config */
|
||||
protected $payPalConfig = null;
|
||||
|
||||
/**
|
||||
* PayPal payment object.
|
||||
*
|
||||
* @var \OxidEsales\Eshop\Application\Model\Payment|bool
|
||||
*/
|
||||
protected $payPalPayment = null;
|
||||
|
||||
/**
|
||||
* Status if Express checkout is ON.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $expressCheckoutEnabled = null;
|
||||
|
||||
/**
|
||||
* Status if Standard checkout is ON.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $standardCheckoutEnabled = null;
|
||||
|
||||
/**
|
||||
* Status if PayPal is ON.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $payPalEnabled = null;
|
||||
|
||||
/**
|
||||
* PayPal Payment Validator object.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Model\PaymentValidator
|
||||
*/
|
||||
protected $paymentValidator = null;
|
||||
|
||||
/**
|
||||
* Set \OxidEsales\PayPalModule\Model\PaymentValidator.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PaymentValidator $paymentValidator
|
||||
*/
|
||||
public function setPaymentValidator($paymentValidator)
|
||||
{
|
||||
$this->paymentValidator = $paymentValidator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get \OxidEsales\PayPalModule\Model\PaymentValidator. Create new if does not exist.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PaymentValidator
|
||||
*/
|
||||
public function getPaymentValidator()
|
||||
{
|
||||
if (is_null($this->paymentValidator)) {
|
||||
$this->setPaymentValidator(oxNew(\OxidEsales\PayPalModule\Model\PaymentValidator::class));
|
||||
}
|
||||
|
||||
return $this->paymentValidator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if express checkout is enabled.
|
||||
* Does payment amount or user country/group check.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpressCheckoutEnabled()
|
||||
{
|
||||
if ($this->expressCheckoutEnabled === null) {
|
||||
$this->expressCheckoutEnabled = false;
|
||||
if ($this->getPayPalConfig()->isExpressCheckoutEnabled()) {
|
||||
$user = $this->getUser();
|
||||
$validator = $this->getPaymentValidator();
|
||||
$validator->setUser($user);
|
||||
$validator->setConfig(\OxidEsales\Eshop\Core\Registry::getConfig());
|
||||
$validator->setCheckCountry(false);
|
||||
|
||||
$this->expressCheckoutEnabled = $validator->isPaymentValid();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->expressCheckoutEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if express checkout and displaying it in mini basket is enabled.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpressCheckoutEnabledInMiniBasket()
|
||||
{
|
||||
$expressCheckoutEnabledInMiniBasket = false;
|
||||
if ($this->isExpressCheckoutEnabled() && $this->getPayPalConfig()->isExpressCheckoutInMiniBasketEnabled()) {
|
||||
$expressCheckoutEnabledInMiniBasket = true;
|
||||
}
|
||||
|
||||
return $expressCheckoutEnabledInMiniBasket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if express checkout is enabled.
|
||||
* Does payment amount or user country/group check.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpressCheckoutEnabledInDetails()
|
||||
{
|
||||
$expressCheckoutEnabledInDetails = false;
|
||||
if ($this->isExpressCheckoutEnabled() && $this->getPayPalConfig()->isExpressCheckoutInDetailsPage()) {
|
||||
$expressCheckoutEnabledInDetails = true;
|
||||
}
|
||||
|
||||
return $expressCheckoutEnabledInDetails;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if standard checkout is enabled.
|
||||
* Does payment amount or user country/group check.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isStandardCheckoutEnabled()
|
||||
{
|
||||
if ($this->standardCheckoutEnabled === null) {
|
||||
$this->standardCheckoutEnabled = false;
|
||||
if ($this->getPayPalConfig()->isStandardCheckoutEnabled()) {
|
||||
$user = $this->getUser();
|
||||
$validator = $this->getPaymentValidator();
|
||||
$validator->setUser($user);
|
||||
$validator->setConfig(\OxidEsales\Eshop\Core\Registry::getConfig());
|
||||
|
||||
$this->standardCheckoutEnabled = $validator->isPaymentValid();
|
||||
}
|
||||
}
|
||||
|
||||
return $this->standardCheckoutEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if PayPal standard or express checkout is enabled.
|
||||
* Does not do payment amount or user country/group check.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isPayPalActive()
|
||||
{
|
||||
return $this->getPaymentValidator()->isPaymentActive();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal payment description text.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalPaymentDescription()
|
||||
{
|
||||
$desc = "";
|
||||
if (($payPalPayment = $this->getPayPalPayment())) {
|
||||
$desc = $payPalPayment->oxpayments__oxlongdesc->getRawValue();
|
||||
}
|
||||
|
||||
return $desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal payment object.
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Application\Model\Payment
|
||||
*/
|
||||
public function getPayPalPayment()
|
||||
{
|
||||
if ($this->payPalPayment === null) {
|
||||
$this->payPalPayment = false;
|
||||
$payPalPayment = oxNew(\OxidEsales\Eshop\Application\Model\Payment::class);
|
||||
|
||||
// payment is not available/active?
|
||||
if ($payPalPayment->load("oxidpaypal") && $payPalPayment->oxpayments__oxactive->value) {
|
||||
$this->payPalPayment = $payPalPayment;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->payPalPayment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns state if order info should be send to PayPal.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function sendOrderInfoToPayPal()
|
||||
{
|
||||
$sendInfoToPayPalEnabled = $this->getPayPalConfig()->sendOrderInfoToPayPal();
|
||||
if ($sendInfoToPayPalEnabled) {
|
||||
/** @var \OxidEsales\PayPalModule\Model\Basket $basket */
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$basket = $session->getBasket();
|
||||
$sendInfoToPayPalEnabled = !$basket->isFractionQuantityItemsPresent();
|
||||
}
|
||||
|
||||
return $sendInfoToPayPalEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns default (on/off) state if order info should be send to PayPal.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function sendOrderInfoToPayPalDefault()
|
||||
{
|
||||
return $this->getPayPalConfig()->sendOrderInfoToPayPalDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal config.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Config
|
||||
*/
|
||||
protected function getPayPalConfig()
|
||||
{
|
||||
if (is_null($this->payPalConfig)) {
|
||||
$this->payPalConfig = oxNew(\OxidEsales\PayPalModule\Core\Config::class);
|
||||
}
|
||||
|
||||
return $this->payPalConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns current URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrentUrl()
|
||||
{
|
||||
return $this->getPayPalConfig()->getCurrentUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalClientId(): string
|
||||
{
|
||||
return Registry::getConfig()->getConfigParam('oePayPalClientId');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether PayPal banners should be shown on the start page
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function showPayPalBannerOnStartPage()
|
||||
{
|
||||
$config = Registry::getConfig();
|
||||
return (
|
||||
!$config->getConfigParam('oePayPalBannersHideAll') &&
|
||||
$config->getConfigParam('oePayPalBannersStartPage') &&
|
||||
$config->getConfigParam('oePayPalBannersStartPageSelector') &&
|
||||
$config->getConfigParam('bl_perfLoadPrice')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal banners selector for the start page
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalBannerStartPageSelector()
|
||||
{
|
||||
$config = Registry::getConfig();
|
||||
return $config->getConfigParam('oePayPalBannersStartPageSelector');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether PayPal banners should be shown on the category page
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function showPayPalBannerOnCategoryPage()
|
||||
{
|
||||
$config = Registry::getConfig();
|
||||
return (
|
||||
!$config->getConfigParam('oePayPalBannersHideAll') &&
|
||||
$config->getConfigParam('oePayPalBannersCategoryPage') &&
|
||||
$config->getConfigParam('oePayPalBannersCategoryPageSelector') &&
|
||||
$config->getConfigParam('bl_perfLoadPrice')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal banners selector for the category page
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalBannerCategoryPageSelector()
|
||||
{
|
||||
$config = Registry::getConfig();
|
||||
return $config->getConfigParam('oePayPalBannersCategoryPageSelector');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether PayPal banners should be shown on the search results page
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function showPayPalBannerOnSearchResultsPage()
|
||||
{
|
||||
$config = Registry::getConfig();
|
||||
return (
|
||||
!$config->getConfigParam('oePayPalBannersHideAll') &&
|
||||
$config->getConfigParam('oePayPalBannersSearchResultsPage') &&
|
||||
$config->getConfigParam('oePayPalBannersSearchResultsPageSelector') &&
|
||||
$config->getConfigParam('bl_perfLoadPrice')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal banners selector for the search page
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalBannerSearchPageSelector()
|
||||
{
|
||||
$config = Registry::getConfig();
|
||||
return $config->getConfigParam('oePayPalBannersSearchResultsPageSelector');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether PayPal banners should be shown on the product details page
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function showPayPalBannerOnProductDetailsPage()
|
||||
{
|
||||
$config = Registry::getConfig();
|
||||
return (
|
||||
!$config->getConfigParam('oePayPalBannersHideAll') &&
|
||||
$config->getConfigParam('oePayPalBannersProductDetailsPage') &&
|
||||
$config->getConfigParam('oePayPalBannersProductDetailsPageSelector') &&
|
||||
$config->getConfigParam('bl_perfLoadPrice')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal banners selector for the product detail page
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalBannerProductDetailsPageSelector()
|
||||
{
|
||||
$config = Registry::getConfig();
|
||||
return $config->getConfigParam('oePayPalBannersProductDetailsPageSelector');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether PayPal banners should be shown on the checkout page
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function showPayPalBannerOnCheckoutPage()
|
||||
{
|
||||
$showBanner = false;
|
||||
$actionClassName = $this->getActionClassName();
|
||||
$config = Registry::getConfig();
|
||||
if ($actionClassName === 'basket') {
|
||||
$showBanner = (
|
||||
!$config->getConfigParam('oePayPalBannersHideAll') &&
|
||||
$config->getConfigParam('oePayPalBannersCheckoutPage') &&
|
||||
$config->getConfigParam('oePayPalBannersCartPageSelector') &&
|
||||
$config->getConfigParam('bl_perfLoadPrice')
|
||||
);
|
||||
} elseif ($actionClassName === 'payment') {
|
||||
$showBanner = (
|
||||
!$config->getConfigParam('oePayPalBannersHideAll') &&
|
||||
$config->getConfigParam('oePayPalBannersCheckoutPage') &&
|
||||
$config->getConfigParam('oePayPalBannersPaymentPageSelector') &&
|
||||
$config->getConfigParam('bl_perfLoadPrice')
|
||||
);
|
||||
}
|
||||
|
||||
return $showBanner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal banners selector for the cart page
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalBannerCartPageSelector()
|
||||
{
|
||||
$config = Registry::getConfig();
|
||||
return $config->getConfigParam('oePayPalBannersCartPageSelector');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal banners selector for the payment page
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalBannerPaymentPageSelector()
|
||||
{
|
||||
$config = Registry::getConfig();
|
||||
return $config->getConfigParam('oePayPalBannersPaymentPageSelector');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the PayPal banners colour scheme
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalBannersColorScheme()
|
||||
{
|
||||
return Registry::getConfig()->getConfigParam('oePayPalBannersColorScheme');
|
||||
}
|
||||
}
|
||||
135
shop/source/modules/oe/oepaypal/GraphQL/Controller/Payment.php
Normal file
135
shop/source/modules/oe/oepaypal/GraphQL/Controller/Payment.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OxidEsales\PayPalModule\GraphQL\Controller;
|
||||
|
||||
use OxidEsales\GraphQL\Storefront\Basket\Service\Basket as StorefrontBasketService;
|
||||
use OxidEsales\PayPalModule\GraphQL\DataType\PayPalCommunicationInformation;
|
||||
use OxidEsales\PayPalModule\GraphQL\DataType\PayPalTokenStatus;
|
||||
use OxidEsales\PayPalModule\GraphQL\Exception\GraphQLServiceNotFound;
|
||||
use OxidEsales\PayPalModule\GraphQL\Service\Basket as BasketService;
|
||||
use OxidEsales\PayPalModule\GraphQL\Service\Payment as PaymentService;
|
||||
use TheCodingMachine\GraphQLite\Annotations\Logged;
|
||||
use TheCodingMachine\GraphQLite\Annotations\Query;
|
||||
use TheCodingMachine\GraphQLite\Annotations\Right;
|
||||
use TheCodingMachine\GraphQLite\Types\ID;
|
||||
|
||||
final class Payment
|
||||
{
|
||||
/** @var PaymentService */
|
||||
private $paymentService;
|
||||
|
||||
/** @var BasketService */
|
||||
private $basketService;
|
||||
|
||||
/** @var StorefrontBasketService */
|
||||
private $storefrontBasketService;
|
||||
|
||||
public function __construct(
|
||||
PaymentService $paymentService,
|
||||
BasketService $basketService,
|
||||
StorefrontBasketService $storefrontBasketService = null
|
||||
) {
|
||||
$this->paymentService = $paymentService;
|
||||
$this->basketService = $basketService;
|
||||
$this->storefrontBasketService = $storefrontBasketService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Query
|
||||
* @Logged()
|
||||
*/
|
||||
public function paypalApprovalProcess(
|
||||
ID $basketId,
|
||||
string $returnUrl,
|
||||
string $cancelUrl,
|
||||
bool $displayBasketInPayPal
|
||||
): PayPalCommunicationInformation {
|
||||
$this->validateState();
|
||||
|
||||
$basket = $this->storefrontBasketService->getAuthenticatedCustomerBasket($basketId);
|
||||
|
||||
// validate if basket payment method is correct
|
||||
$this->basketService->validateBasketPaymentMethod($basket);
|
||||
|
||||
$communicationInformation = $this->paymentService->getPayPalCommunicationInformation(
|
||||
$basket,
|
||||
$returnUrl,
|
||||
$cancelUrl,
|
||||
$displayBasketInPayPal
|
||||
);
|
||||
|
||||
$this->basketService->updateBasketToken($basket, $communicationInformation->getToken());
|
||||
|
||||
return $communicationInformation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Query
|
||||
* @Right("PAYPAL_EXPRESS_APPROVAL")
|
||||
*/
|
||||
public function paypalExpressApprovalProcess(
|
||||
ID $basketId,
|
||||
string $returnUrl,
|
||||
string $cancelUrl,
|
||||
bool $displayBasketInPayPal
|
||||
): PayPalCommunicationInformation
|
||||
{
|
||||
$this->validateState();
|
||||
|
||||
$basket = $this->storefrontBasketService->getAuthenticatedCustomerBasket($basketId);
|
||||
|
||||
// validate if pp express payment is available
|
||||
$this->basketService->validateBasketExpressPaymentMethod();
|
||||
|
||||
$communicationInformation = $this->paymentService->getPayPalExpressCommunicationInformation(
|
||||
$basket,
|
||||
$returnUrl,
|
||||
$cancelUrl,
|
||||
$displayBasketInPayPal
|
||||
);
|
||||
|
||||
$this->basketService->updateExpressBasketInformation(
|
||||
$basket,
|
||||
$communicationInformation->getToken()
|
||||
);
|
||||
|
||||
return $communicationInformation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Query()
|
||||
* @Right("PAYPAL_TOKEN_STATUS")
|
||||
*/
|
||||
public function paypalTokenStatus(string $paypalToken): PayPalTokenStatus
|
||||
{
|
||||
return $this->paymentService->getPayPalTokenStatus($paypalToken);
|
||||
}
|
||||
|
||||
protected function validateState(): void
|
||||
{
|
||||
if (is_null($this->storefrontBasketService)) {
|
||||
throw GraphQLServiceNotFound::byServiceName(StorefrontBasketService::class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OxidEsales\PayPalModule\GraphQL\DataType;
|
||||
|
||||
use TheCodingMachine\GraphQLite\Annotations\Field;
|
||||
use TheCodingMachine\GraphQLite\Annotations\Type;
|
||||
|
||||
/**
|
||||
* @Type()
|
||||
*/
|
||||
final class PayPalCommunicationInformation
|
||||
{
|
||||
/** @var string */
|
||||
private $token;
|
||||
|
||||
/** @var string */
|
||||
private $communicationUrl;
|
||||
|
||||
public function __construct(string $token, string $communicationUrl)
|
||||
{
|
||||
$this->token = $token;
|
||||
$this->communicationUrl = $communicationUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Field()
|
||||
*/
|
||||
public function getToken(): string
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Field()
|
||||
*/
|
||||
public function getCommunicationUrl(): string
|
||||
{
|
||||
return $this->communicationUrl;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OxidEsales\PayPalModule\GraphQL\DataType;
|
||||
|
||||
use TheCodingMachine\GraphQLite\Annotations\Field;
|
||||
use TheCodingMachine\GraphQLite\Annotations\Type;
|
||||
|
||||
/**
|
||||
* @Type()
|
||||
*/
|
||||
final class PayPalTokenStatus
|
||||
{
|
||||
/** @var string */
|
||||
private $token;
|
||||
|
||||
/** @var bool */
|
||||
private $status;
|
||||
|
||||
/** @var string */
|
||||
private $payerId;
|
||||
|
||||
public function __construct(string $token, bool $status, string $payerId)
|
||||
{
|
||||
$this->token = $token;
|
||||
$this->status = $status;
|
||||
$this->payerId = $payerId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Field()
|
||||
*/
|
||||
public function getToken(): string
|
||||
{
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Field()
|
||||
*/
|
||||
public function isTokenApproved(): bool
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
// for internal user only
|
||||
public function getPayerId(): string
|
||||
{
|
||||
return $this->payerId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OxidEsales\PayPalModule\GraphQL\Exception;
|
||||
|
||||
use OxidEsales\GraphQL\Base\Exception\InvalidRequest;
|
||||
|
||||
final class BasketCommunication extends InvalidRequest
|
||||
{
|
||||
public static function notStarted(string $basketId): self
|
||||
{
|
||||
return new self(sprintf("PayPal communication for basket %s is not started", $basketId));
|
||||
}
|
||||
|
||||
public static function notConfirmed(string $basketId): self
|
||||
{
|
||||
return new self(sprintf("PayPal communication for basket %s is not confirmed", $basketId));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OxidEsales\PayPalModule\GraphQL\Exception;
|
||||
|
||||
use OxidEsales\GraphQL\Base\Exception\InvalidRequest;
|
||||
|
||||
final class BasketValidation extends InvalidRequest
|
||||
{
|
||||
public static function basketChange(string $basketId): self
|
||||
{
|
||||
return new self(sprintf("Content change discovered for basket %s. Please run paypal approval process again.", $basketId));
|
||||
}
|
||||
|
||||
public static function basketAddressChange(string $basketId): self
|
||||
{
|
||||
return new self(sprintf("Address change discovered for basket %s. Please run paypal approval process again.", $basketId));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OxidEsales\PayPalModule\GraphQL\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
final class GraphQLServiceNotFound extends Exception
|
||||
{
|
||||
public static function byServiceName(string $name): self
|
||||
{
|
||||
return new self(sprintf("GraphQL service %s is not available.", $name));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OxidEsales\PayPalModule\GraphQL\Exception;
|
||||
|
||||
use OxidEsales\GraphQL\Base\Exception\InvalidRequest;
|
||||
|
||||
final class PaymentValidation extends InvalidRequest
|
||||
{
|
||||
public static function paymentMethodIsNotPaypal(): self
|
||||
{
|
||||
return new self('Payment method should be PayPal.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OxidEsales\PayPalModule\GraphQL\Infrastructure;
|
||||
|
||||
use OxidEsales\PayPalModule\Core\Config as PayPalConfig;
|
||||
use OxidEsales\PayPalModule\Core\PayPalService;
|
||||
use OxidEsales\PayPalModule\Model\PaymentManager;
|
||||
|
||||
final class Request
|
||||
{
|
||||
public function getPaymentManager(): PaymentManager
|
||||
{
|
||||
$payPalCheckoutService = oxNew(PayPalService::class);
|
||||
return oxNew(PaymentManager::class, $payPalCheckoutService);
|
||||
}
|
||||
|
||||
public function getPayPalConfig(): PayPalConfig
|
||||
{
|
||||
return oxNew(PayPalConfig::class);
|
||||
}
|
||||
}
|
||||
144
shop/source/modules/oe/oepaypal/GraphQL/Service/Basket.php
Normal file
144
shop/source/modules/oe/oepaypal/GraphQL/Service/Basket.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OxidEsales\PayPalModule\GraphQL\Service;
|
||||
|
||||
use OxidEsales\Eshop\Core\Registry as EshopRegistry;
|
||||
use OxidEsales\GraphQL\Storefront\Basket\DataType\Basket as BasketDataType;
|
||||
use OxidEsales\GraphQL\Storefront\Basket\Service\BasketRelationService;
|
||||
use OxidEsales\GraphQL\Storefront\Payment\DataType\Payment as PaymentDataType;
|
||||
use OxidEsales\GraphQL\Storefront\Payment\Exception\PaymentNotFound;
|
||||
use OxidEsales\GraphQL\Storefront\Payment\Exception\UnavailablePayment;
|
||||
use OxidEsales\GraphQL\Storefront\Payment\Service\Payment as StorefrontPaymentService;
|
||||
use OxidEsales\PayPalModule\Core\Config as PayPalConfig;
|
||||
use OxidEsales\PayPalModule\GraphQL\Exception\GraphQLServiceNotFound;
|
||||
use OxidEsales\PayPalModule\GraphQL\Exception\PaymentValidation;
|
||||
use OxidEsales\PayPalModule\Model\PaymentManager;
|
||||
|
||||
final class Basket
|
||||
{
|
||||
/** @var BasketRelationService */
|
||||
private $basketRelationService;
|
||||
|
||||
/** @var StorefrontPaymentService */
|
||||
private $storefrontPaymentService;
|
||||
|
||||
/** @var PayPalConfig */
|
||||
private $paypalConfig;
|
||||
|
||||
public function __construct(
|
||||
BasketRelationService $basketRelationService = null,
|
||||
StorefrontPaymentService $storefrontPaymentService = null,
|
||||
PayPalConfig $paypalConfig
|
||||
) {
|
||||
$this->basketRelationService = $basketRelationService;
|
||||
$this->storefrontPaymentService = $storefrontPaymentService;
|
||||
$this->paypalConfig = $paypalConfig;
|
||||
}
|
||||
|
||||
public function checkBasketPaymentMethodIsPayPal(BasketDataType $basket): bool
|
||||
{
|
||||
$this->validateState();
|
||||
|
||||
$paymentMethod = $this->basketRelationService->payment($basket);
|
||||
$result = false;
|
||||
|
||||
if (!is_null($paymentMethod) && $paymentMethod->getId()->val() === 'oxidpaypal') {
|
||||
$result = true;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws PaymentValidation
|
||||
*/
|
||||
public function validateBasketPaymentMethod(BasketDataType $basket): void
|
||||
{
|
||||
if (!$this->checkBasketPaymentMethodIsPayPal($basket)) {
|
||||
throw PaymentValidation::paymentMethodIsNotPaypal();
|
||||
}
|
||||
|
||||
if (!$this->paypalConfig->isStandardCheckoutEnabled()) {
|
||||
throw UnavailablePayment::byId('oxidpaypal');
|
||||
}
|
||||
}
|
||||
|
||||
public function validateBasketExpressPaymentMethod(): void
|
||||
{
|
||||
if (!$this->paypalConfig->isExpressCheckoutEnabled()) {
|
||||
throw UnavailablePayment::byId('oxidpaypal');
|
||||
}
|
||||
|
||||
try {
|
||||
$payment = $this->storefrontPaymentService->payment('oxidpaypal');
|
||||
} catch (PaymentNotFound $e) {
|
||||
throw UnavailablePayment::byId('oxidpaypal');
|
||||
}
|
||||
|
||||
if (!$payment instanceof PaymentDataType) {
|
||||
throw UnavailablePayment::byId('oxidpaypal');
|
||||
}
|
||||
}
|
||||
|
||||
public function updateBasketToken(BasketDataType $basket, string $token): void
|
||||
{
|
||||
/**
|
||||
* @TODO: check if we can/need to revoke the old token.
|
||||
*/
|
||||
|
||||
$userBasketModel = $basket->getEshopModel();
|
||||
$userBasketModel->assign([
|
||||
'OEPAYPAL_PAYMENT_TOKEN' => $token
|
||||
]);
|
||||
$userBasketModel->save();
|
||||
}
|
||||
|
||||
public function updateExpressBasketInformation(BasketDataType $basket, string $token): void
|
||||
{
|
||||
$userBasketModel = $basket->getEshopModel();
|
||||
$userBasketModel->assign(
|
||||
[
|
||||
'OEPAYPAL_PAYMENT_TOKEN' => $token,
|
||||
'OEPAYPAL_SERVICE_TYPE' => PaymentManager::PAYPAL_SERVICE_TYPE_EXPRESS,
|
||||
'OEGQL_PAYMENTID' => 'oxidpaypal'
|
||||
]
|
||||
);
|
||||
$userBasketModel->save();
|
||||
|
||||
EshopRegistry::getSession()->setVariable(
|
||||
PayPalConfig::OEPAYPAL_TRIGGER_NAME,
|
||||
PaymentManager::PAYPAL_SERVICE_TYPE_EXPRESS
|
||||
);
|
||||
}
|
||||
|
||||
protected function validateState(): void
|
||||
{
|
||||
if (is_null($this->basketRelationService)) {
|
||||
throw GraphQLServiceNotFound::byServiceName(BasketRelationService::class);
|
||||
}
|
||||
|
||||
if (is_null($this->storefrontPaymentService)) {
|
||||
throw GraphQLServiceNotFound::byServiceName(StorefrontPaymentService::class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OxidEsales\PayPalModule\GraphQL\Service;
|
||||
|
||||
use OxidEsales\GraphQL\Storefront\Basket\DataType\Basket as BasketDataType;
|
||||
use TheCodingMachine\GraphQLite\Annotations\ExtendType;
|
||||
use TheCodingMachine\GraphQLite\Annotations\Field;
|
||||
|
||||
/**
|
||||
* @ExtendType(class=BasketDataType::class)
|
||||
*/
|
||||
final class BasketExtendType
|
||||
{
|
||||
/**
|
||||
* @Field()
|
||||
*/
|
||||
public function paypalToken(BasketDataType $basket): string
|
||||
{
|
||||
return $basket->getEshopModel()->getFieldData('OEPAYPAL_PAYMENT_TOKEN');
|
||||
}
|
||||
|
||||
/**
|
||||
* @Field()
|
||||
*/
|
||||
public function paypalServiceType(BasketDataType $basket): int
|
||||
{
|
||||
return (int) $basket->getEshopModel()->getFieldData('OEPAYPAL_SERVICE_TYPE');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OxidEsales\PayPalModule\GraphQL\Service;
|
||||
|
||||
use OxidEsales\Eshop\Core\Registry as EshopRegistry;
|
||||
use OxidEsales\GraphQL\Storefront\Basket\Event\BeforePlaceOrder as BeforePlaceOrderEvent;
|
||||
use OxidEsales\PayPalModule\Core\Config as PayPalConfig;
|
||||
use OxidEsales\PayPalModule\GraphQL\Exception\BasketCommunication;
|
||||
use OxidEsales\PayPalModule\GraphQL\Service\Basket as BasketService;
|
||||
use OxidEsales\PayPalModule\GraphQL\Service\Payment as PaymentService;
|
||||
use OxidEsales\PayPalModule\Model\Response\ResponseGetExpressCheckoutDetails;
|
||||
use OxidEsales\GraphQL\Storefront\Basket\Service\Basket as StorefrontBasketService;
|
||||
use OxidEsales\PayPalModule\GraphQL\Exception\GraphQLServiceNotFound;
|
||||
|
||||
final class BeforePlaceOrder
|
||||
{
|
||||
/** @var PaymentService */
|
||||
private $paymentService;
|
||||
|
||||
/** @var BasketService */
|
||||
private $basketService;
|
||||
|
||||
/** @var StorefrontBasketService */
|
||||
private $storefrontBasketService;
|
||||
|
||||
public function __construct(
|
||||
PaymentService $paymentService,
|
||||
BasketService $basketService,
|
||||
StorefrontBasketService $storefrontBasketService = null
|
||||
) {
|
||||
$this->paymentService = $paymentService;
|
||||
$this->basketService = $basketService;
|
||||
$this->storefrontBasketService = $storefrontBasketService;
|
||||
}
|
||||
|
||||
public function handle(BeforePlaceOrderEvent $event): void
|
||||
{
|
||||
$this->validateState();
|
||||
|
||||
$userBasket = $this->storefrontBasketService->getAuthenticatedCustomerBasket($event->getBasketId());
|
||||
if ($this->basketService->checkBasketPaymentMethodIsPayPal($userBasket)) {
|
||||
$extendUserBasket = new BasketExtendType();
|
||||
|
||||
$token = $extendUserBasket->paypalToken($userBasket);
|
||||
if (!$token) {
|
||||
throw BasketCommunication::notStarted($userBasket->id()->val());
|
||||
}
|
||||
|
||||
//call PayPal API once for ExpressCheckoutDetails
|
||||
/** @var ResponseGetExpressCheckoutDetails $expressCheckoutDetails */
|
||||
$expressCheckoutDetails = $this->paymentService->getExpressCheckoutDetails($token);
|
||||
|
||||
$tokenStatus = $this->paymentService->getPayPalTokenStatus($token, $expressCheckoutDetails);
|
||||
if (!$tokenStatus->isTokenApproved()) {
|
||||
throw BasketCommunication::notConfirmed($userBasket->id()->val());
|
||||
}
|
||||
|
||||
$sessionBasket = $this->paymentService->getValidEshopBasketModel($userBasket, $expressCheckoutDetails);
|
||||
|
||||
// In order to be able to finalize order, using PayPal as payment method,
|
||||
// we need to prepare the following session variables.
|
||||
$session = EshopRegistry::getSession();
|
||||
$session->setBasket($sessionBasket);
|
||||
$session->setVariable('oepaypal-token', $token);
|
||||
$session->setVariable("oepaypal-userId", $sessionBasket->getUser()->getId());
|
||||
$session->setVariable('oepaypal-payerId', $tokenStatus->getPayerId());
|
||||
$session->setVariable(
|
||||
PayPalConfig::OEPAYPAL_TRIGGER_NAME,
|
||||
$extendUserBasket->paypalServiceType($userBasket)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function validateState(): void
|
||||
{
|
||||
if (is_null($this->storefrontBasketService)) {
|
||||
throw GraphQLServiceNotFound::byServiceName(StorefrontBasketService::class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OxidEsales\PayPalModule\GraphQL\Service;
|
||||
|
||||
final class NamespaceMapper
|
||||
{
|
||||
public function getControllerNamespaceMapping(): array
|
||||
{
|
||||
return [
|
||||
'\\OxidEsales\\PayPalModule\\GraphQL\\Controller' => __DIR__ . '/../Controller/',
|
||||
];
|
||||
}
|
||||
|
||||
public function getTypeNamespaceMapping(): array
|
||||
{
|
||||
return [
|
||||
'\\OxidEsales\\PayPalModule\\GraphQL\\DataType' => __DIR__ . '/../DataType/',
|
||||
'\\OxidEsales\\PayPalModule\\GraphQL\\Service' => __DIR__ . '/../Service/',
|
||||
];
|
||||
}
|
||||
}
|
||||
297
shop/source/modules/oe/oepaypal/GraphQL/Service/Payment.php
Normal file
297
shop/source/modules/oe/oepaypal/GraphQL/Service/Payment.php
Normal file
@@ -0,0 +1,297 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OxidEsales\PayPalModule\GraphQL\Service;
|
||||
|
||||
use OxidEsales\Eshop\Core\Model\BaseModel;
|
||||
use OxidEsales\Eshop\Core\Registry as EshopRegistry;
|
||||
use OxidEsales\GraphQL\Base\Exception\InvalidLogin;
|
||||
use OxidEsales\GraphQL\Storefront\Basket\DataType\Basket as BasketDataType;
|
||||
use OxidEsales\GraphQL\Storefront\Basket\DataType\BasketOwner as BasketOwnerDataType;
|
||||
use OxidEsales\GraphQL\Storefront\Customer\Exception\CustomerNotFound;
|
||||
use OxidEsales\GraphQL\Storefront\Shared\Infrastructure\Basket as SharedBasketInfrastructure;
|
||||
use OxidEsales\GraphQL\Storefront\Basket\Service\BasketRelationService;
|
||||
use OxidEsales\PayPalModule\GraphQL\DataType\PayPalCommunicationInformation;
|
||||
use OxidEsales\PayPalModule\GraphQL\DataType\PayPalTokenStatus;
|
||||
use OxidEsales\PayPalModule\GraphQL\Exception\BasketValidation;
|
||||
use OxidEsales\PayPalModule\GraphQL\Exception\GraphQLServiceNotFound;
|
||||
use OxidEsales\PayPalModule\GraphQL\Infrastructure\Request as RequestInfrastructure;
|
||||
use OxidEsales\PayPalModule\Model\PaymentManager;
|
||||
use OxidEsales\PayPalModule\Model\Response\ResponseGetExpressCheckoutDetails;
|
||||
use OxidEsales\Eshop\Application\Model\Basket as EshopBasketModel;
|
||||
use OxidEsales\Eshop\Application\Model\User as EshopUserModel;
|
||||
use OxidEsales\Eshop\Application\Model\Address as EshopAddressModel;
|
||||
|
||||
final class Payment
|
||||
{
|
||||
/** @var RequestInfrastructure */
|
||||
private $requestInfrastructure;
|
||||
|
||||
/** @var SharedBasketInfrastructure */
|
||||
private $sharedBasketInfrastructure;
|
||||
|
||||
/** @var BasketRelationService */
|
||||
private $basketRelationService;
|
||||
|
||||
public function __construct(
|
||||
RequestInfrastructure $requestInfrastructure,
|
||||
SharedBasketInfrastructure $sharedBasketInfrastructure = null,
|
||||
BasketRelationService $basketRelationService = null
|
||||
) {
|
||||
$this->requestInfrastructure = $requestInfrastructure;
|
||||
$this->sharedBasketInfrastructure = $sharedBasketInfrastructure;
|
||||
$this->basketRelationService = $basketRelationService;
|
||||
}
|
||||
|
||||
public function getPayPalTokenStatus(
|
||||
string $token,
|
||||
ResponseGetExpressCheckoutDetails $details = null
|
||||
): PayPalTokenStatus {
|
||||
//NOTE: only when the approval was finished on PayPal site
|
||||
//(payment channel and delivery address registered with PayPal)
|
||||
//the getExpressCheckoutResponse will contain the PayerId. So we can use this to get information
|
||||
//about token status. If anything is amiss, PayPal will no let the order pass.
|
||||
|
||||
if (is_null($details)) {
|
||||
$details = $this->getExpressCheckoutDetails($token);
|
||||
}
|
||||
|
||||
$payerId = $details->getPayerId();
|
||||
|
||||
return new PayPalTokenStatus(
|
||||
$token,
|
||||
$payerId ? true : false,
|
||||
$payerId
|
||||
);
|
||||
}
|
||||
|
||||
public function getExpressCheckoutDetails(string $token): ResponseGetExpressCheckoutDetails
|
||||
{
|
||||
$paymentManager = $this->requestInfrastructure->getPaymentManager();
|
||||
return $paymentManager->getExpressCheckoutDetails($token);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BasketValidation
|
||||
*/
|
||||
public function getValidEshopBasketModel(
|
||||
BasketDataType $userBasket,
|
||||
ResponseGetExpressCheckoutDetails $expressCheckoutDetails
|
||||
): EshopBasketModel {
|
||||
|
||||
$this->validateState();
|
||||
|
||||
//At this point we need to check if we have PayPal Express or paypal as standard payment method checkout
|
||||
// and act accordingly
|
||||
if (PaymentManager::PAYPAL_SERVICE_TYPE_EXPRESS == $userBasket->getEshopModel()->getFieldData('OEPAYPAL_SERVICE_TYPE')) {
|
||||
$paymentManager = $this->requestInfrastructure->getPaymentManager();
|
||||
$user = $paymentManager->initializeUserData($expressCheckoutDetails, (string) $userBasket->getUserId());
|
||||
|
||||
$userBasket->getEshopModel()->setUser($user);
|
||||
|
||||
if (is_null($user->getSelectedAddressId())) {
|
||||
EshopRegistry::getSession()->deleteVariable('deladrid');
|
||||
}
|
||||
|
||||
EshopRegistry::getSession()->setVariable('usr', $user->getId());
|
||||
EshopRegistry::getSession()->setUser($user);
|
||||
|
||||
$deliveryMethodId = $paymentManager->extractShippingId($expressCheckoutDetails->getShippingOptionName(), $user);
|
||||
$userBasket->getEshopModel()->assign([
|
||||
'OEGQL_DELIVERYMETHODID' => $deliveryMethodId,
|
||||
'OEGQL_DELADDRESSID' => $user->getSelectedAddressId()
|
||||
]);
|
||||
$userBasket->getEshopModel()->save();
|
||||
}
|
||||
|
||||
$sessionBasket = $this->sharedBasketInfrastructure->getCalculatedBasket($userBasket);
|
||||
|
||||
$this->validateApprovedBasketAmount($sessionBasket, $expressCheckoutDetails, $userBasket);
|
||||
$this->validateApprovedBasketAddress($sessionBasket, $expressCheckoutDetails, $userBasket);
|
||||
|
||||
return $sessionBasket;
|
||||
}
|
||||
|
||||
private function validateApprovedBasketAddress(
|
||||
EshopBasketModel $sessionBasket,
|
||||
ResponseGetExpressCheckoutDetails $expressCheckoutDetails,
|
||||
BasketDataType $userBasket
|
||||
): void {
|
||||
$modelWithAddress = $this->calculateDeliveryAddressModel($sessionBasket, $userBasket);
|
||||
|
||||
//Ensure delivery address registered with PayPal is the same as shop will use
|
||||
$paypalAddressModel = oxNew(EshopAddressModel::class);
|
||||
$paypalAddressData = $paypalAddressModel->prepareDataPayPalAddress($expressCheckoutDetails);
|
||||
|
||||
$compareWith = [];
|
||||
foreach ($paypalAddressData as $key => $value) {
|
||||
$compareWith[$key] = $modelWithAddress->getFieldData($key);
|
||||
}
|
||||
|
||||
$diff = array_diff($paypalAddressData, $compareWith);
|
||||
if (!empty($diff)) {
|
||||
throw BasketValidation::basketAddressChange($userBasket->id()->val());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delivery address is currently related to user basket
|
||||
* if that one is null, the user's invoice address is used as delivery address
|
||||
*/
|
||||
private function calculateDeliveryAddressModel(
|
||||
EshopBasketModel $sessionBasket,
|
||||
BasketDataType $userBasket
|
||||
): BaseModel {
|
||||
$this->validateState();
|
||||
|
||||
$shipToAddress = $this->basketRelationService->deliveryAddress($userBasket);
|
||||
if (!is_null($shipToAddress)) {
|
||||
/** @var EshopAddressModel $eshopModel */
|
||||
$modelWithAddress = $shipToAddress->getEshopModel();
|
||||
} else {
|
||||
/** @var EshopUserModel $modelWithAddress */
|
||||
$modelWithAddress = $sessionBasket->getUser();
|
||||
}
|
||||
|
||||
return $modelWithAddress;
|
||||
}
|
||||
|
||||
private function validateApprovedBasketAmount(
|
||||
EshopBasketModel $sessionBasket,
|
||||
ResponseGetExpressCheckoutDetails $expressCheckoutDetails,
|
||||
BasketDataType $userBasket
|
||||
): void {
|
||||
$paymentManager = $this->requestInfrastructure->getPaymentManager();
|
||||
|
||||
/** @var \OxidEsales\Eshop\Core\Price $price */
|
||||
$price = $sessionBasket->getPrice();
|
||||
if (
|
||||
!$price ||
|
||||
!$paymentManager->validateApprovedBasketAmount(
|
||||
$price->getBruttoPrice(),
|
||||
$expressCheckoutDetails->getAmount()
|
||||
)
|
||||
) {
|
||||
throw BasketValidation::basketChange($userBasket->id()->val());
|
||||
}
|
||||
}
|
||||
|
||||
public function getPayPalCommunicationInformation(
|
||||
BasketDataType $basket,
|
||||
string $returnUrl,
|
||||
string $cancelUrl,
|
||||
bool $displayBasketInPayPal
|
||||
): PayPalCommunicationInformation {
|
||||
$this->validateState();
|
||||
|
||||
$paymentManager = $this->requestInfrastructure->getPaymentManager();
|
||||
|
||||
$shipToAddress = $this->basketRelationService->deliveryAddress($basket);
|
||||
$shipToAddressId = $shipToAddress ? (string) $shipToAddress->id(): '';
|
||||
|
||||
$response = $paymentManager->setStandardCheckout(
|
||||
$this->sharedBasketInfrastructure->getBasket($basket),
|
||||
$this->basketRelationService->owner($basket)->getEshopModel(),
|
||||
$returnUrl,
|
||||
$cancelUrl,
|
||||
$displayBasketInPayPal,
|
||||
$shipToAddressId
|
||||
);
|
||||
|
||||
$token = (string) $response->getToken();
|
||||
|
||||
return new PayPalCommunicationInformation(
|
||||
$token,
|
||||
$this->getPayPalCommunicationUrl($token)
|
||||
);
|
||||
}
|
||||
|
||||
public function getPayPalExpressCommunicationInformation(
|
||||
BasketDataType $basket,
|
||||
string $returnUrl,
|
||||
string $cancelUrl,
|
||||
bool $displayBasketInPayPal
|
||||
): PayPalCommunicationInformation {
|
||||
$this->validateState();
|
||||
|
||||
$paymentManager = $this->requestInfrastructure->getPaymentManager();
|
||||
$shipToAddressId = $this->getDeliveryAddressId($basket);
|
||||
$deliveryMethod = $this->basketRelationService->deliveryMethod($basket);
|
||||
$shippingMethodId = $deliveryMethod ? (string) $deliveryMethod->id() : 'oxidstandard';
|
||||
|
||||
//for Express checkout, the user might not yet exist (anonymous user)
|
||||
try {
|
||||
/** @var BasketOwnerDataType $customer */
|
||||
$owner = $this->basketRelationService->owner($basket);
|
||||
$user = $owner->getEshopModel();
|
||||
$user->setSelectedAddressId($shipToAddressId);
|
||||
} catch (CustomerNotFound $e) {
|
||||
$user = null;
|
||||
}
|
||||
|
||||
$response = $paymentManager->setExpressCheckout(
|
||||
$this->sharedBasketInfrastructure->getBasket($basket),
|
||||
$user,
|
||||
$returnUrl,
|
||||
$cancelUrl,
|
||||
$paymentManager->getGraphQLCallBackUrl((string) $basket->id()),
|
||||
$displayBasketInPayPal,
|
||||
$shippingMethodId
|
||||
);
|
||||
|
||||
$token = (string) $response->getToken();
|
||||
|
||||
return new PayPalCommunicationInformation(
|
||||
$token,
|
||||
$this->getPayPalCommunicationUrl($token)
|
||||
);
|
||||
}
|
||||
|
||||
public function getPayPalCommunicationUrl($token): string
|
||||
{
|
||||
$payPalConfig = $this->requestInfrastructure->getPayPalConfig();
|
||||
return $payPalConfig->getPayPalCommunicationUrl($token);
|
||||
}
|
||||
|
||||
protected function validateState(): void
|
||||
{
|
||||
if (is_null($this->sharedBasketInfrastructure)) {
|
||||
throw GraphQLServiceNotFound::byServiceName(SharedBasketInfrastructure::class);
|
||||
}
|
||||
|
||||
if (is_null($this->basketRelationService)) {
|
||||
throw GraphQLServiceNotFound::byServiceName(BasketRelationService::class);
|
||||
}
|
||||
}
|
||||
|
||||
protected function getDeliveryAddressId(BasketDataType $basket): String
|
||||
{
|
||||
try {
|
||||
//use might be logged in to his existing shop account
|
||||
$shipToAddress = $this->basketRelationService->deliveryAddress($basket);
|
||||
} catch (InvalidLogin $e) {
|
||||
//in case of anonymous user access of delivery address is forbidden
|
||||
}
|
||||
|
||||
return $shipToAddress ? (string) $shipToAddress->id(): '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OxidEsales\PayPalModule\GraphQL\Service;
|
||||
|
||||
final class PermissionProvider
|
||||
{
|
||||
public function getPermissions(): array
|
||||
{
|
||||
return [
|
||||
'oxidcustomer' => [
|
||||
'PAYPAL_EXPRESS_APPROVAL',
|
||||
'PAYPAL_TOKEN_STATUS'
|
||||
],
|
||||
'oxidnotyetordered' => [
|
||||
'PAYPAL_EXPRESS_APPROVAL',
|
||||
'PAYPAL_TOKEN_STATUS'
|
||||
],
|
||||
'oxidanonymous' => [
|
||||
'CREATE_BASKET',
|
||||
'VIEW_BASKET',
|
||||
'ADD_PRODUCT_TO_BASKET',
|
||||
'REMOVE_BASKET_PRODUCT',
|
||||
'ADD_VOUCHER',
|
||||
'REMOVE_VOUCHER',
|
||||
'PLACE_ORDER',
|
||||
'PAYPAL_EXPRESS_APPROVAL',
|
||||
'PAYPAL_TOKEN_STATUS'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OxidEsales\PayPalModule\GraphQL\Subscriber;
|
||||
|
||||
use OxidEsales\Eshop\Core\Registry as EshopRegistry;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Event\AbstractShopAwareEventSubscriber;
|
||||
use OxidEsales\GraphQL\Storefront\Basket\Event\BeforeBasketPayments as BeforeBasketPaymentsEvent;
|
||||
use OxidEsales\GraphQL\Storefront\Basket\Service\Basket as StorefrontBasketService;
|
||||
use OxidEsales\PayPalModule\Core\Config as PayPalConfig;
|
||||
use OxidEsales\PayPalModule\GraphQL\Exception\GraphQLServiceNotFound;
|
||||
use OxidEsales\PayPalModule\GraphQL\Service\Basket as BasketService;
|
||||
use OxidEsales\PayPalModule\GraphQL\Service\BasketExtendType;
|
||||
|
||||
class BeforeBasketPayments extends AbstractShopAwareEventSubscriber
|
||||
{
|
||||
/** @var BasketService */
|
||||
private $basketService;
|
||||
|
||||
/** @var StorefrontBasketService */
|
||||
private $storefrontBasketService;
|
||||
|
||||
public function __construct(
|
||||
BasketService $basketService,
|
||||
StorefrontBasketService $storefrontBasketService = null
|
||||
) {
|
||||
$this->basketService = $basketService;
|
||||
$this->storefrontBasketService = $storefrontBasketService;
|
||||
}
|
||||
|
||||
public function handle(BeforeBasketPaymentsEvent $event): BeforeBasketPaymentsEvent
|
||||
{
|
||||
$this->validateState();
|
||||
|
||||
$basketDataType = $this->storefrontBasketService->getAuthenticatedCustomerBasket($event->getBasketId());
|
||||
if ($this->basketService->checkBasketPaymentMethodIsPayPal($basketDataType)) {
|
||||
$extendUserBasket = new BasketExtendType();
|
||||
$session = EshopRegistry::getSession();
|
||||
$session->setVariable(
|
||||
PayPalConfig::OEPAYPAL_TRIGGER_NAME,
|
||||
$extendUserBasket->paypalServiceType($basketDataType)
|
||||
);
|
||||
}
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
'OxidEsales\GraphQL\Storefront\Basket\Event\BeforeBasketPayments' => 'handle'
|
||||
];
|
||||
}
|
||||
|
||||
protected function validateState(): void
|
||||
{
|
||||
if (is_null($this->storefrontBasketService)) {
|
||||
throw GraphQLServiceNotFound::byServiceName(StorefrontBasketService::class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OxidEsales\PayPalModule\GraphQL\Subscriber;
|
||||
|
||||
use OxidEsales\PayPalModule\GraphQL\Exception\GraphQLServiceNotFound;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Event\AbstractShopAwareEventSubscriber;
|
||||
use OxidEsales\PayPalModule\GraphQL\Service\BeforePlaceOrder as BeforePlaceOrderService;
|
||||
|
||||
class BeforePlaceOrder extends AbstractShopAwareEventSubscriber
|
||||
{
|
||||
/** @var BeforePlaceOrderService */
|
||||
private $beforePlaceOrderService;
|
||||
|
||||
public function __construct(BeforePlaceOrderService $beforePlaceOrderService)
|
||||
{
|
||||
$this->beforePlaceOrderService = $beforePlaceOrderService;
|
||||
}
|
||||
|
||||
public function handle(Event $event): Event
|
||||
{
|
||||
$this->validateState();
|
||||
|
||||
$this->beforePlaceOrderService->handle($event);
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
'OxidEsales\GraphQL\Storefront\Basket\Event\BeforePlaceOrder' => 'handle'
|
||||
];
|
||||
}
|
||||
|
||||
protected function validateState(): void
|
||||
{
|
||||
if (is_null($this->beforePlaceOrderService)) {
|
||||
throw GraphQLServiceNotFound::byServiceName(BeforePlaceOrderService::class);
|
||||
}
|
||||
}
|
||||
}
|
||||
674
shop/source/modules/oe/oepaypal/LICENSE
Normal file
674
shop/source/modules/oe/oepaypal/LICENSE
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\Action\Data;
|
||||
|
||||
/**
|
||||
* PayPal order action factory class
|
||||
*/
|
||||
class OrderActionData
|
||||
{
|
||||
/**
|
||||
* Request object
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
protected $request = null;
|
||||
|
||||
/**
|
||||
* Order object
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Model\Order
|
||||
*/
|
||||
protected $order = null;
|
||||
|
||||
/**
|
||||
* Sets dependencies.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\Request $request
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalOrder $order
|
||||
*/
|
||||
public function __construct($request, $order)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Request object
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal Order object
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\Order
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns action amount
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthorizationId()
|
||||
{
|
||||
return $this->getOrder()->oxorder__oxtransid->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns comment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getComment()
|
||||
{
|
||||
return $this->getRequest()->getRequestParameter('action_comment');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns order status
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOrderStatus()
|
||||
{
|
||||
return $this->getRequest()->getRequestParameter('order_status');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\Action\Data;
|
||||
|
||||
/**
|
||||
* PayPal order action factory class
|
||||
*/
|
||||
class OrderCaptureActionData extends \OxidEsales\PayPalModule\Model\Action\Data\OrderActionData
|
||||
{
|
||||
/**
|
||||
* returns action type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->getRequest()->getRequestParameter('capture_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* returns action amount
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAmount()
|
||||
{
|
||||
$amount = $this->getRequest()->getRequestParameter('capture_amount');
|
||||
$validDecimalAmount = preg_replace('/,(?=\d{0,2}$)/', '.', $amount) ?? $amount;
|
||||
|
||||
return $validDecimalAmount ? $validDecimalAmount : $this->getOrder()->getPayPalOrder()->getRemainingOrderSum();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns currency
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrency()
|
||||
{
|
||||
return $this->getOrder()->getPayPalOrder()->getCurrency();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\Action\Data;
|
||||
|
||||
/**
|
||||
* PayPal order action factory class.
|
||||
*/
|
||||
class OrderReauthorizeActionData extends \OxidEsales\PayPalModule\Model\Action\Data\OrderActionData
|
||||
{
|
||||
/**
|
||||
* Returns action amount.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAmount()
|
||||
{
|
||||
return $this->getOrder()->getPayPalOrder()->getRemainingOrderSum();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns currency.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrency()
|
||||
{
|
||||
return $this->getOrder()->getPayPalOrder()->getCurrency();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\Action\Data;
|
||||
|
||||
/**
|
||||
* PayPal order action factory class
|
||||
*/
|
||||
class OrderRefundActionData extends \OxidEsales\PayPalModule\Model\Action\Data\OrderActionData
|
||||
{
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Model\OrderPayment::class
|
||||
*/
|
||||
public $paymentBeingRefunded = null;
|
||||
|
||||
/**
|
||||
* Returns action type.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
return $this->getRequest()->getRequestParameter('refund_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns action amount.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTransactionId()
|
||||
{
|
||||
return $this->getRequest()->getRequestParameter('transaction_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns amount to refund.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getAmount()
|
||||
{
|
||||
$amount = $this->getRequest()->getRequestParameter('refund_amount');
|
||||
$validDecimalAmount = preg_replace('/,(?=\d{0,2}$)/', '.', $amount) ?? $amount;
|
||||
|
||||
return $validDecimalAmount ? $validDecimalAmount : $this->getPaymentBeingRefunded()->getRemainingRefundAmount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns currency.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrency()
|
||||
{
|
||||
return $this->getOrder()->getPayPalOrder()->getCurrency();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns payment to refund.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPayment
|
||||
*/
|
||||
public function getPaymentBeingRefunded()
|
||||
{
|
||||
if (is_null($this->paymentBeingRefunded)) {
|
||||
$this->paymentBeingRefunded = oxNew(\OxidEsales\PayPalModule\Model\OrderPayment::class);
|
||||
$this->paymentBeingRefunded->loadByTransactionId($this->getTransactionId());
|
||||
}
|
||||
|
||||
return $this->paymentBeingRefunded;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\Action\Data;
|
||||
|
||||
/**
|
||||
* PayPal order action factory class
|
||||
*/
|
||||
class OrderVoidActionData extends \OxidEsales\PayPalModule\Model\Action\Data\OrderActionData
|
||||
{
|
||||
/**
|
||||
* Returns action amount.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAmount()
|
||||
{
|
||||
return $this->getOrder()->getPayPalOrder()->getRemainingOrderSum();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns currency.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrency()
|
||||
{
|
||||
return $this->getOrder()->getPayPalOrder()->getCurrency();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\Action\Handler;
|
||||
|
||||
/**
|
||||
* PayPal order action class
|
||||
*/
|
||||
abstract class OrderActionHandler
|
||||
{
|
||||
/**
|
||||
* @var object
|
||||
*/
|
||||
protected $data = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Core\PayPalService
|
||||
*/
|
||||
protected $payPalService = null;
|
||||
|
||||
/**
|
||||
* PayPal order
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Model\PayPalOrder
|
||||
*/
|
||||
protected $payPalRequestBuilder = null;
|
||||
|
||||
/**
|
||||
* Sets data object.
|
||||
*
|
||||
* @param object $data
|
||||
*/
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Data object
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PayPal request builder
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequestBuilder $builder
|
||||
*/
|
||||
public function setPayPalRequestBuilder($builder)
|
||||
{
|
||||
$this->payPalRequestBuilder = $builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal request builder
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequestBuilder
|
||||
*/
|
||||
public function getPayPalRequestBuilder()
|
||||
{
|
||||
if ($this->payPalRequestBuilder === null) {
|
||||
$this->payPalRequestBuilder = oxNew(\OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequestBuilder::class);
|
||||
}
|
||||
|
||||
return $this->payPalRequestBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PayPal service
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\PayPalService $service
|
||||
*/
|
||||
public function setPayPalService($service)
|
||||
{
|
||||
$this->payPalService = $service;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal service
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\PayPalService
|
||||
*/
|
||||
public function getPayPalService()
|
||||
{
|
||||
if ($this->payPalService === null) {
|
||||
$this->payPalService = oxNew(\OxidEsales\PayPalModule\Core\PayPalService::class);
|
||||
}
|
||||
|
||||
return $this->payPalService;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\Action\Handler;
|
||||
|
||||
/**
|
||||
* PayPal order action capture class
|
||||
*/
|
||||
class OrderCaptureActionHandler extends \OxidEsales\PayPalModule\Model\Action\Handler\OrderActionHandler
|
||||
{
|
||||
/**
|
||||
* PayPal Request
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
protected $payPalRequest = null;
|
||||
|
||||
/**
|
||||
* Returns PayPal response; calls PayPal if not set
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPayPalResponse()
|
||||
{
|
||||
$service = $this->getPayPalService();
|
||||
$request = $this->getPayPalRequest();
|
||||
|
||||
return $service->doCapture($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal request; initializes if not set
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
|
||||
*/
|
||||
public function getPayPalRequest()
|
||||
{
|
||||
if (is_null($this->payPalRequest)) {
|
||||
$requestBuilder = $this->getPayPalRequestBuilder();
|
||||
|
||||
$data = $this->getData();
|
||||
|
||||
$requestBuilder->setAuthorizationId($data->getAuthorizationId());
|
||||
$requestBuilder->setAmount($data->getAmount(), $data->getCurrency());
|
||||
$requestBuilder->setCompleteType($data->getType());
|
||||
$requestBuilder->setComment($data->getComment());
|
||||
|
||||
$this->payPalRequest = $requestBuilder->getRequest();
|
||||
}
|
||||
|
||||
return $this->payPalRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PayPal request
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\Request $payPalRequest
|
||||
*/
|
||||
public function setPayPalRequest($payPalRequest)
|
||||
{
|
||||
$this->payPalRequest = $payPalRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\Action\Handler;
|
||||
|
||||
/**
|
||||
* PayPal order action reauthorize class
|
||||
*/
|
||||
class OrderReauthorizeActionHandler extends \OxidEsales\PayPalModule\Model\Action\Handler\OrderActionHandler
|
||||
{
|
||||
/**
|
||||
* PayPal Request.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
protected $payPalRequest = null;
|
||||
|
||||
/**
|
||||
* Returns PayPal response; initiates if not set.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\Response\ResponseDoRefund|\OxidEsales\PayPalModule\Model\Response\Response
|
||||
*/
|
||||
public function getPayPalResponse()
|
||||
{
|
||||
$service = $this->getPayPalService();
|
||||
$request = $this->getPayPalRequest();
|
||||
|
||||
return $service->doReAuthorization($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal request; initiates if not set.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
|
||||
*/
|
||||
public function getPayPalRequest()
|
||||
{
|
||||
if (is_null($this->payPalRequest)) {
|
||||
$requestBuilder = $this->getPayPalRequestBuilder();
|
||||
|
||||
$data = $this->getData();
|
||||
|
||||
$requestBuilder->setAuthorizationId($data->getAuthorizationId());
|
||||
$requestBuilder->setAmount($data->getAmount(), $data->getCurrency());
|
||||
|
||||
$this->payPalRequest = $requestBuilder->getRequest();
|
||||
}
|
||||
|
||||
return $this->payPalRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PayPal request.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $payPalRequest
|
||||
*/
|
||||
public function setPayPalRequest($payPalRequest)
|
||||
{
|
||||
$this->payPalRequest = $payPalRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\Action\Handler;
|
||||
|
||||
/**
|
||||
* PayPal order action refund class
|
||||
*/
|
||||
class OrderRefundActionHandler extends \OxidEsales\PayPalModule\Model\Action\Handler\OrderActionHandler
|
||||
{
|
||||
/**
|
||||
* PayPal Request
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
protected $payPalRequest = null;
|
||||
|
||||
/**
|
||||
* Returns PayPal response; calls PayPal if not set
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPayPalResponse()
|
||||
{
|
||||
$service = $this->getPayPalService();
|
||||
$request = $this->getPayPalRequest();
|
||||
|
||||
return $service->refundTransaction($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal request; initiates if not set
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
|
||||
*/
|
||||
public function getPayPalRequest()
|
||||
{
|
||||
if (is_null($this->payPalRequest)) {
|
||||
$requestBuilder = $this->getPayPalRequestBuilder();
|
||||
|
||||
$data = $this->getData();
|
||||
|
||||
$requestBuilder->setTransactionId($data->getTransactionId());
|
||||
$requestBuilder->setAmount($data->getAmount(), $data->getCurrency());
|
||||
$requestBuilder->setRefundType($data->getType());
|
||||
$requestBuilder->setComment($data->getComment());
|
||||
|
||||
$this->payPalRequest = $requestBuilder->getRequest();
|
||||
}
|
||||
|
||||
return $this->payPalRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PayPal request
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\Request $payPalRequest
|
||||
*/
|
||||
public function setPayPalRequest($payPalRequest)
|
||||
{
|
||||
$this->payPalRequest = $payPalRequest;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\Action\Handler;
|
||||
|
||||
/**
|
||||
* PayPal order action void class.
|
||||
*/
|
||||
class OrderVoidActionHandler extends \OxidEsales\PayPalModule\Model\Action\Handler\OrderActionHandler
|
||||
{
|
||||
/**
|
||||
* PayPal Request.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
protected $payPalRequest = null;
|
||||
|
||||
/**
|
||||
* Returns PayPal response; initiates if not set.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPayPalResponse()
|
||||
{
|
||||
$service = $this->getPayPalService();
|
||||
$request = $this->getPayPalRequest();
|
||||
|
||||
return $service->doVoid($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal request; initiates if not set.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
|
||||
*/
|
||||
public function getPayPalRequest()
|
||||
{
|
||||
if (is_null($this->payPalRequest)) {
|
||||
$requestBuilder = $this->getPayPalRequestBuilder();
|
||||
|
||||
$data = $this->getData();
|
||||
|
||||
$requestBuilder->setAuthorizationId($data->getAuthorizationId());
|
||||
$requestBuilder->setAmount($data->getAmount(), $data->getCurrency());
|
||||
$requestBuilder->setComment($data->getComment());
|
||||
|
||||
$this->payPalRequest = $requestBuilder->getRequest();
|
||||
}
|
||||
|
||||
return $this->payPalRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PayPal request.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\Request $payPalRequest Request object.
|
||||
*/
|
||||
public function setPayPalRequest($payPalRequest)
|
||||
{
|
||||
$this->payPalRequest = $payPalRequest;
|
||||
}
|
||||
}
|
||||
92
shop/source/modules/oe/oepaypal/Model/Action/OrderAction.php
Normal file
92
shop/source/modules/oe/oepaypal/Model/Action/OrderAction.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\Action;
|
||||
|
||||
/**
|
||||
* PayPal order action class
|
||||
*/
|
||||
abstract class OrderAction
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Model\PayPalOrder
|
||||
*/
|
||||
protected $_oOrder = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $orderStatus = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Model\Action\Handler\OrderCaptureActionHandler
|
||||
*/
|
||||
protected $handler = null;
|
||||
|
||||
/**
|
||||
* Sets handler and order.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\Action\Handler\OrderCaptureActionHandler $handler
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalOrder $order
|
||||
*/
|
||||
public function __construct($handler, $order)
|
||||
{
|
||||
$this->handler = $handler;
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns \OxidEsales\PayPalModule\Model\Action\Handler\OrderCaptureActionHandler object.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\Action\Handler\OrderCaptureActionHandler
|
||||
*/
|
||||
public function getHandler()
|
||||
{
|
||||
return $this->handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns \OxidEsales\PayPalModule\Model\PayPalOrder object.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalOrder
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns formatted date
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDate()
|
||||
{
|
||||
$utilsDate = \OxidEsales\Eshop\Core\Registry::getUtilsDate();
|
||||
|
||||
return date('Y-m-d H:i:s', $utilsDate->getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes PayPal action
|
||||
*/
|
||||
abstract public function process();
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\Action;
|
||||
|
||||
/**
|
||||
* PayPal order action factory class
|
||||
*/
|
||||
class OrderActionFactory
|
||||
{
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
protected $_oRequest = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Model\Order
|
||||
*/
|
||||
protected $order = null;
|
||||
|
||||
/**
|
||||
* Sets dependencies
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\Request $request
|
||||
* @param \OxidEsales\PayPalModule\Model\Order $order
|
||||
*/
|
||||
public function __construct($request, $order)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Request object
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Order object
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\Order
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates action object by given action name.
|
||||
*
|
||||
* @param string $action
|
||||
*
|
||||
* @return object
|
||||
*
|
||||
* @throws \OxidEsales\PayPalModule\Core\Exception\PayPalInvalidActionException
|
||||
*/
|
||||
public function createAction($action)
|
||||
{
|
||||
$method = "get" . ucfirst($action) . "Action";
|
||||
|
||||
if (!method_exists($this, $method)) {
|
||||
/** @var \OxidEsales\PayPalModule\Core\Exception\PayPalInvalidActionException $exception */
|
||||
$exception = oxNew(\OxidEsales\PayPalModule\Core\Exception\PayPalInvalidActionException::class);
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
return $this->$method();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns capture action object
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\Action\OrderCaptureAction
|
||||
*/
|
||||
public function getCaptureAction()
|
||||
{
|
||||
$order = $this->getOrder();
|
||||
$request = $this->getRequest();
|
||||
|
||||
$data = oxNew(\OxidEsales\PayPalModule\Model\Action\Data\OrderCaptureActionData::class, $request, $order);
|
||||
$handler = oxNew(\OxidEsales\PayPalModule\Model\Action\Handler\OrderCaptureActionHandler::class, $data);
|
||||
|
||||
$reauthorizeData = oxNew(\OxidEsales\PayPalModule\Model\Action\Data\OrderReauthorizeActionData::class, $request, $order);
|
||||
$reauthorizeHandler = oxNew(\OxidEsales\PayPalModule\Model\Action\Handler\OrderReauthorizeActionHandler::class, $reauthorizeData);
|
||||
|
||||
$action = oxNew(\OxidEsales\PayPalModule\Model\Action\OrderCaptureAction::class, $handler, $order->getPayPalOrder(), $reauthorizeHandler);
|
||||
|
||||
return $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns refund action object
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\Action\OrderRefundAction
|
||||
*/
|
||||
public function getRefundAction()
|
||||
{
|
||||
$order = $this->getOrder();
|
||||
$data = oxNew(\OxidEsales\PayPalModule\Model\Action\Data\OrderRefundActionData::class, $this->getRequest(), $order);
|
||||
$handler = oxNew(\OxidEsales\PayPalModule\Model\Action\Handler\OrderRefundActionHandler::class, $data);
|
||||
|
||||
$action = oxNew(\OxidEsales\PayPalModule\Model\Action\OrderRefundAction::class, $handler, $order->getPayPalOrder());
|
||||
|
||||
return $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns void action object
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\Action\OrderVoidAction
|
||||
*/
|
||||
public function getVoidAction()
|
||||
{
|
||||
$order = $this->getOrder();
|
||||
$data = oxNew(\OxidEsales\PayPalModule\Model\Action\Data\OrderVoidActionData::class, $this->getRequest(), $order);
|
||||
$handler = oxNew(\OxidEsales\PayPalModule\Model\Action\Handler\OrderVoidActionHandler::class, $data);
|
||||
|
||||
$action = oxNew(\OxidEsales\PayPalModule\Model\Action\OrderVoidAction::class, $handler, $order->getPayPalOrder());
|
||||
|
||||
return $action;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\Action;
|
||||
|
||||
/**
|
||||
* PayPal order action capture class
|
||||
*/
|
||||
class OrderCaptureAction extends \OxidEsales\PayPalModule\Model\Action\OrderAction
|
||||
{
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Model\Action\Handler\OrderReauthorizeActionHandler
|
||||
*/
|
||||
protected $reauthorizeHandler = null;
|
||||
|
||||
/**
|
||||
* Sets dependencies.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\Action\Handler\OrderCaptureActionHandler $handler
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalOrder $order
|
||||
* @param \OxidEsales\PayPalModule\Model\Action\Handler\OrderReauthorizeActionHandler $reauthorizeHandler
|
||||
*/
|
||||
public function __construct($handler, $order, $reauthorizeHandler)
|
||||
{
|
||||
parent::__construct($handler, $order);
|
||||
|
||||
$this->reauthorizeHandler = $reauthorizeHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns reauthorize action handler.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\Action\Handler\OrderReauthorizeActionHandler
|
||||
*/
|
||||
public function getReauthorizeHandler()
|
||||
{
|
||||
return $this->reauthorizeHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes PayPal response.
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
$this->reauthorize();
|
||||
|
||||
$handler = $this->getHandler();
|
||||
|
||||
$response = $handler->getPayPalResponse();
|
||||
$data = $handler->getData();
|
||||
|
||||
$this->updateOrder($response, $data);
|
||||
|
||||
$payment = $this->createPayment($response);
|
||||
$paymentList = $this->getOrder()->getPaymentList();
|
||||
$payment = $paymentList->addPayment($payment);
|
||||
|
||||
$this->addComment($payment, $data->getComment());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reauthorizes payment if order was captured at least once.
|
||||
*/
|
||||
protected function reauthorize()
|
||||
{
|
||||
$order = $this->getOrder();
|
||||
|
||||
if ($order->getCapturedAmount() > 0) {
|
||||
$handler = $this->getReauthorizeHandler();
|
||||
try {
|
||||
$response = $handler->getPayPalResponse();
|
||||
|
||||
$payment = oxNew(\OxidEsales\PayPalModule\Model\OrderPayment::class);
|
||||
$payment->setDate($this->getDate());
|
||||
$payment->setTransactionId($response->getAuthorizationId());
|
||||
$payment->setCorrelationId($response->getCorrelationId());
|
||||
$payment->setAction('re-authorization');
|
||||
$payment->setStatus($response->getPaymentStatus());
|
||||
|
||||
$order->getPaymentList()->addPayment($payment);
|
||||
} catch (\OxidEsales\PayPalModule\Core\Exception\PayPalResponseException $e) {
|
||||
// Ignore PayPal response exceptions
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates order with PayPal response info.
|
||||
*
|
||||
* @param object $response
|
||||
* @param object $data
|
||||
*/
|
||||
protected function updateOrder($response, $data)
|
||||
{
|
||||
$order = $this->getOrder();
|
||||
$order->addCapturedAmount($response->getCapturedAmount());
|
||||
$order->setPaymentStatus($data->getOrderStatus());
|
||||
$order->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates Payment object with PayPal response data.
|
||||
*
|
||||
* @param object $response
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPayment::class
|
||||
*/
|
||||
protected function createPayment($response)
|
||||
{
|
||||
$payment = oxNew(\OxidEsales\PayPalModule\Model\OrderPayment::class);
|
||||
$payment->setDate($this->getDate());
|
||||
$payment->setTransactionId($response->getTransactionId());
|
||||
$payment->setCorrelationId($response->getCorrelationId());
|
||||
$payment->setAction('capture');
|
||||
$payment->setStatus($response->getPaymentStatus());
|
||||
$payment->setAmount($response->getCapturedAmount());
|
||||
$payment->setCurrency($response->getCurrency());
|
||||
|
||||
return $payment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds comment to given Payment object.
|
||||
*
|
||||
* @param object $payment
|
||||
* @param string $comment
|
||||
*/
|
||||
protected function addComment($payment, $commentContent)
|
||||
{
|
||||
if ($commentContent) {
|
||||
$comment = oxNew(\OxidEsales\PayPalModule\Model\OrderPaymentComment::class);
|
||||
$comment->setComment($commentContent);
|
||||
|
||||
$payment->addComment($comment);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\Action;
|
||||
|
||||
/**
|
||||
* PayPal order action refund class
|
||||
*/
|
||||
class OrderRefundAction extends \OxidEsales\PayPalModule\Model\Action\OrderAction
|
||||
{
|
||||
/**
|
||||
* Processes PayPal response
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
$handler = $this->getHandler();
|
||||
$response = $handler->getPayPalResponse();
|
||||
$data = $handler->getData();
|
||||
|
||||
$order = $this->getOrder();
|
||||
$order->addRefundedAmount($response->getRefundAmount());
|
||||
$order->setPaymentStatus($data->getOrderStatus());
|
||||
$order->save();
|
||||
|
||||
$payment = oxNew(\OxidEsales\PayPalModule\Model\OrderPayment::class);
|
||||
$payment->setDate($this->getDate());
|
||||
$payment->setTransactionId($response->getTransactionId());
|
||||
$payment->setCorrelationId($response->getCorrelationId());
|
||||
$payment->setAction('refund');
|
||||
$payment->setStatus($response->getPaymentStatus());
|
||||
$payment->setAmount($response->getRefundAmount());
|
||||
$payment->setCurrency($response->getCurrency());
|
||||
|
||||
$refundedPayment = $data->getPaymentBeingRefunded();
|
||||
$refundedPayment->addRefundedAmount($response->getRefundAmount());
|
||||
$refundedPayment->save();
|
||||
|
||||
$payment = $order->getPaymentList()->addPayment($payment);
|
||||
|
||||
if ($data->getComment()) {
|
||||
$comment = oxNew(\OxidEsales\PayPalModule\Model\OrderPaymentComment::class);
|
||||
$comment->setComment($data->getComment());
|
||||
$payment->addComment($comment);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\Action;
|
||||
|
||||
/**
|
||||
* PayPal order action void class
|
||||
*/
|
||||
class OrderVoidAction extends \OxidEsales\PayPalModule\Model\Action\OrderAction
|
||||
{
|
||||
/**
|
||||
* Processes PayPal response
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
$handler = $this->getHandler();
|
||||
$response = $handler->getPayPalResponse();
|
||||
$data = $handler->getData();
|
||||
|
||||
$order = $this->getOrder();
|
||||
$amount = $order->getRemainingOrderSum();
|
||||
$order->setVoidedAmount($amount);
|
||||
$order->setPaymentStatus($data->getOrderStatus());
|
||||
$order->save();
|
||||
|
||||
$payment = oxNew(\OxidEsales\PayPalModule\Model\OrderPayment::class);
|
||||
$payment->setDate($this->getDate());
|
||||
$payment->setTransactionId($response->getAuthorizationId());
|
||||
$payment->setCorrelationId($response->getCorrelationId());
|
||||
$payment->setAction('void');
|
||||
$payment->setStatus('Voided');
|
||||
$payment->setAmount($amount);
|
||||
|
||||
$payment = $order->getPaymentList()->addPayment($payment);
|
||||
|
||||
if ($data->getComment()) {
|
||||
$comment = oxNew(\OxidEsales\PayPalModule\Model\OrderPaymentComment::class);
|
||||
$comment->setComment($data->getComment());
|
||||
$payment->addComment($comment);
|
||||
}
|
||||
}
|
||||
}
|
||||
190
shop/source/modules/oe/oepaypal/Model/Address.php
Normal file
190
shop/source/modules/oe/oepaypal/Model/Address.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal oxAddress class
|
||||
*
|
||||
* @mixin \OxidEsales\Eshop\Application\Model\Address
|
||||
*/
|
||||
class Address extends Address_parent
|
||||
{
|
||||
/**
|
||||
* Creates user shipping address from PayPal data and set to session.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\Response\ResponseGetExpressCheckoutDetails $details PayPal data.
|
||||
* @param string $userId user id.
|
||||
*/
|
||||
public function createPayPalAddress($details, $userId)
|
||||
{
|
||||
$addressData = $this->prepareDataPayPalAddress($details);
|
||||
|
||||
if ($addressId = $this->existPayPalAddress($addressData)) {
|
||||
\OxidEsales\Eshop\Core\Registry::getSession()->setVariable("deladrid", $addressId);
|
||||
} else {
|
||||
$this->oxaddress__oxuserid = new \OxidEsales\Eshop\Core\Field($userId);
|
||||
$this->oxaddress__oxfname = new \OxidEsales\Eshop\Core\Field($addressData['oxfname']);
|
||||
$this->oxaddress__oxlname = new \OxidEsales\Eshop\Core\Field($addressData['oxlname']);
|
||||
$this->oxaddress__oxstreet = new \OxidEsales\Eshop\Core\Field($addressData['oxstreet']);
|
||||
$this->oxaddress__oxstreetnr = new \OxidEsales\Eshop\Core\Field($addressData['oxstreetnr']);
|
||||
$this->oxaddress__oxaddinfo = new \OxidEsales\Eshop\Core\Field($addressData['oxaddinfo']);
|
||||
$this->oxaddress__oxcity = new \OxidEsales\Eshop\Core\Field($addressData['oxcity']);
|
||||
$this->oxaddress__oxcountryid = new \OxidEsales\Eshop\Core\Field($addressData['oxcountryid']);
|
||||
$this->oxaddress__oxstateid = new \OxidEsales\Eshop\Core\Field($addressData['oxstateid']);
|
||||
$this->oxaddress__oxzip = new \OxidEsales\Eshop\Core\Field($addressData['oxzip']);
|
||||
$this->oxaddress__oxfon = new \OxidEsales\Eshop\Core\Field($addressData['oxfon']);
|
||||
$this->save();
|
||||
|
||||
\OxidEsales\Eshop\Core\Registry::getSession()->setVariable("deladrid", $this->getId());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare address data array from PayPal response data.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\Response\ResponseGetExpressCheckoutDetails $details - PayPal data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function prepareDataPayPalAddress($details)
|
||||
{
|
||||
$addressData = array();
|
||||
|
||||
$fullName = oxNew(\OxidEsales\PayPalModule\Core\FullName::class, $details->getShipToName());
|
||||
|
||||
$addressData['oxfname'] = $fullName->getFirstName();
|
||||
$addressData['oxlname'] = $fullName->getLastName();
|
||||
|
||||
$street = $this->splitShipToStreetPayPalAddress($details->getShipToStreet());
|
||||
$addressData['oxstreet'] = $street['street'];
|
||||
$addressData['oxstreetnr'] = $street['streetnr'];
|
||||
|
||||
$addressData['oxcity'] = $details->getShipToCity();
|
||||
|
||||
$country = oxNew(\OxidEsales\Eshop\Application\Model\Country::class);
|
||||
$countryId = $country->getIdByCode($details->getShipToCountryCode());
|
||||
$addressData['oxcountryid'] = $countryId;
|
||||
|
||||
if ($details->getShipToState()) {
|
||||
$state = oxNew(\OxidEsales\Eshop\Application\Model\State::class);
|
||||
$stateId = $state->getIdByCode($details->getShipToState(), $countryId);
|
||||
}
|
||||
$addressData['oxstateid'] = $stateId;
|
||||
|
||||
$addressData['oxzip'] = $details->getShipToZip();
|
||||
$addressData['oxfon'] = $details->getShipToPhoneNumber();
|
||||
$addressData['oxaddinfo'] = $details->getShipToStreet2();
|
||||
|
||||
return $addressData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check required fields.
|
||||
*
|
||||
* @param array $addressData - PayPal data.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function checkRequiredFieldsPayPalAddress($addressData)
|
||||
{
|
||||
$reqFields = \OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('aMustFillFields');
|
||||
|
||||
$result = true;
|
||||
|
||||
foreach ($reqFields as $field) {
|
||||
if (strpos($field, 'oxaddress__') === 0 && empty($addressData[str_replace('oxaddress__', '', $field)])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if exists PayPal address.
|
||||
*
|
||||
* @param array $addressData
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
protected function existPayPalAddress($addressData)
|
||||
{
|
||||
$db = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
|
||||
|
||||
$query = "SELECT `oxid` FROM `oxaddress` WHERE 1 ";
|
||||
$query .= " AND `oxfname` = " . $db->quote($addressData['oxfname']);
|
||||
$query .= " AND `oxlname` = " . $db->quote($addressData['oxlname']);
|
||||
$query .= " AND `oxstreet` = " . $db->quote($addressData['oxstreet']);
|
||||
$query .= " AND `oxstreetnr` = " . $db->quote($addressData['oxstreetnr']);
|
||||
$query .= " AND `oxcity` = " . $db->quote($addressData['oxcity']);
|
||||
$query .= " AND `oxcountryid` = " . $db->quote($addressData['oxcountryid']);
|
||||
$query .= " AND `oxstateid` = " . $db->quote($addressData['oxstateid']);
|
||||
$query .= " AND `oxzip` = " . $db->quote($addressData['oxzip']);
|
||||
$query .= " AND `oxfon` = " . $db->quote($addressData['oxfon']);
|
||||
|
||||
if ($addressId = $db->getOne($query)) {
|
||||
return $addressId;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Split street nr from address
|
||||
*
|
||||
* @param string $shipToStreet address string
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function splitShipToStreetPayPalAddress($shipToStreet)
|
||||
{
|
||||
$address = array();
|
||||
$shipToStreet = trim($shipToStreet);
|
||||
|
||||
// checking if street number is at the end of the address
|
||||
preg_match("/(.*\S)\s+(\d+\s*\S*)$/", $shipToStreet, $address);
|
||||
|
||||
// checking if street name and number was found
|
||||
if (!empty($address[1]) && $address[2]) {
|
||||
$address['street'] = $address[1];
|
||||
$address['streetnr'] = $address[2];
|
||||
|
||||
return $address;
|
||||
}
|
||||
|
||||
// checking if street number is at the begining of the address
|
||||
preg_match("/(\d+\S*)\s+(.*)$/", $shipToStreet, $address);
|
||||
|
||||
// checking if street name and number was found
|
||||
if (!empty($address[1]) && $address[2]) {
|
||||
$address['street'] = $address[2];
|
||||
$address['streetnr'] = $address[1];
|
||||
|
||||
return $address;
|
||||
}
|
||||
|
||||
// it is not possible to resolve address, so assign it without any parsing
|
||||
$address['street'] = $shipToStreet;
|
||||
$address['streetnr'] = "";
|
||||
|
||||
return $address;
|
||||
}
|
||||
}
|
||||
60
shop/source/modules/oe/oepaypal/Model/Article.php
Normal file
60
shop/source/modules/oe/oepaypal/Model/Article.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal oxArticle class
|
||||
*
|
||||
* @mixin \OxidEsales\Eshop\Application\Model\Article
|
||||
*/
|
||||
class Article extends Article_parent
|
||||
{
|
||||
/**
|
||||
* Check if Product is virtual: is non material and is downloadable
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isVirtualPayPalArticle()
|
||||
{
|
||||
$virtual = true;
|
||||
|
||||
// non material products
|
||||
if (!$this->oxarticles__oxnonmaterial->value) {
|
||||
$virtual = false;
|
||||
} elseif (isset($this->oxarticles__oxisdownloadable) &&
|
||||
!$this->oxarticles__oxisdownloadable->value
|
||||
) {
|
||||
$virtual = false;
|
||||
}
|
||||
|
||||
return $virtual;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets stock amount for article
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getStockAmount()
|
||||
{
|
||||
return $this->oxarticles__oxstock->value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal Current item Article container class.
|
||||
*/
|
||||
class ArticleToExpressCheckoutCurrentItem
|
||||
{
|
||||
/**
|
||||
* Article id
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $articleId;
|
||||
|
||||
/**
|
||||
* Select list
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $selectList;
|
||||
|
||||
/**
|
||||
* Persistent param
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $persistParam;
|
||||
|
||||
/**
|
||||
* Article amount
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $articleAmount;
|
||||
|
||||
/**
|
||||
* Method sets persistent param.
|
||||
*
|
||||
* @param array $persistParam
|
||||
*/
|
||||
public function setPersistParam($persistParam)
|
||||
{
|
||||
$this->persistParam = $persistParam;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method returns persistent param.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPersistParam()
|
||||
{
|
||||
return $this->persistParam;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method sets select list.
|
||||
*
|
||||
* @param array $selectList
|
||||
*/
|
||||
public function setSelectList($selectList)
|
||||
{
|
||||
$this->selectList = $selectList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method returns select list.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getSelectList()
|
||||
{
|
||||
return $this->selectList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method sets article id.
|
||||
*
|
||||
* @param string $articleId
|
||||
*/
|
||||
public function setArticleId($articleId)
|
||||
{
|
||||
$this->articleId = $articleId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method returns article id.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getArticleId()
|
||||
{
|
||||
return $this->articleId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method sets article amount.
|
||||
*
|
||||
* @param int $articleAmount
|
||||
*/
|
||||
public function setArticleAmount($articleAmount)
|
||||
{
|
||||
$this->articleAmount = $articleAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method returns article amount.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getArticleAmount()
|
||||
{
|
||||
return (int) $this->articleAmount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal Current item Article validator class.
|
||||
*/
|
||||
class ArticleToExpressCheckoutValidator
|
||||
{
|
||||
/**
|
||||
* Item that will be validated.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $itemToValidate;
|
||||
|
||||
/**
|
||||
* User basket
|
||||
*
|
||||
* @var \OxidEsales\Eshop\Application\Model\Basket
|
||||
*/
|
||||
protected $basket;
|
||||
|
||||
/**
|
||||
*Sets current item of details page.
|
||||
*
|
||||
* @param object $itemToValidate
|
||||
*/
|
||||
public function setItemToValidate($itemToValidate)
|
||||
{
|
||||
$this->itemToValidate = $itemToValidate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns details page current item.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\ArticleToExpressCheckoutCurrentItem|object
|
||||
*/
|
||||
public function getItemToValidate()
|
||||
{
|
||||
return $this->itemToValidate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method sets basket object.
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Application\Model\Basket $basket
|
||||
*/
|
||||
public function setBasket($basket)
|
||||
{
|
||||
$this->basket = $basket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Methods returns basket object.
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Application\Model\Basket
|
||||
*/
|
||||
public function getBasket()
|
||||
{
|
||||
return $this->basket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method returns if article valid
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isArticleValid()
|
||||
{
|
||||
$valid = true;
|
||||
if ($this->isArticleAmountZero() || $this->isSameItemInBasket()) {
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
return $valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if same article is in basket.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isSameItemInBasket()
|
||||
{
|
||||
$basketContents = $this->getBasket()->getContents();
|
||||
foreach ($basketContents as $basketItem) {
|
||||
if ($this->isArticleParamsEqual($basketItem)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if Article params equals with current items params.
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Application\Model\BasketItem $basketItem
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isArticleParamsEqual($basketItem)
|
||||
{
|
||||
return ($basketItem->getProductId() == $this->getItemToValidate()->getArticleId() &&
|
||||
$basketItem->getPersParams() == $this->getItemToValidate()->getPersistParam() &&
|
||||
$basketItem->getSelList() == $this->getItemToValidate()->getSelectList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if article amount 0.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isArticleAmountZero()
|
||||
{
|
||||
$articleAmount = $this->getItemToValidate()->getArticleAmount();
|
||||
|
||||
return 0 == $articleAmount;
|
||||
}
|
||||
}
|
||||
285
shop/source/modules/oe/oepaypal/Model/Basket.php
Normal file
285
shop/source/modules/oe/oepaypal/Model/Basket.php
Normal file
@@ -0,0 +1,285 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
use OxidEsales\Eshop\Application\Model\Article as EshopArticle;
|
||||
|
||||
/**
|
||||
* PayPal basket class
|
||||
*
|
||||
* @mixin \OxidEsales\Eshop\Application\Model\Basket
|
||||
*/
|
||||
class Basket extends Basket_parent
|
||||
{
|
||||
/**
|
||||
* Checks if products in basket ar virtual and does not require real delivery.
|
||||
* Returns TRUE if virtual
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isVirtualPayPalBasket()
|
||||
{
|
||||
$isVirtual = true;
|
||||
|
||||
$products = $this->getBasketArticles();
|
||||
foreach ($products as $product) {
|
||||
if (!$product->isVirtualPayPalArticle()) {
|
||||
$isVirtual = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $isVirtual;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if fraction quantity items (with 1.3 amount) exists in basket.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isFractionQuantityItemsPresent()
|
||||
{
|
||||
$fractionItemsPresent = false;
|
||||
|
||||
foreach ($this->getContents() as $basketItem) {
|
||||
$amount = $basketItem->getAmount();
|
||||
if ((int) $amount != $amount) {
|
||||
$fractionItemsPresent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $fractionItemsPresent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns wrapping cost value
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function getPayPalWrappingCosts()
|
||||
{
|
||||
$amount = 0.0;
|
||||
|
||||
$wrappingCost = $this->getCosts('oxwrapping');
|
||||
if ($wrappingCost) {
|
||||
$amount = $this->isCalculationModeNetto() ? $wrappingCost->getNettoPrice() : $wrappingCost->getBruttoPrice();
|
||||
}
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns greeting card cost value
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function getPayPalGiftCardCosts()
|
||||
{
|
||||
$amount = 0.0;
|
||||
|
||||
$giftCardCost = $this->getCosts('oxgiftcard');
|
||||
if ($giftCardCost) {
|
||||
$amount = $this->isCalculationModeNetto() ? $giftCardCost->getNettoPrice() : $giftCardCost->getBruttoPrice();
|
||||
}
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns payment costs netto or brutto value.
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function getPayPalPaymentCosts()
|
||||
{
|
||||
$amount = 0.0;
|
||||
|
||||
$paymentCost = $this->getCosts('oxpayment');
|
||||
if ($paymentCost) {
|
||||
$amount = $this->isCalculationModeNetto() ? $paymentCost->getNettoPrice() : $paymentCost->getBruttoPrice();
|
||||
}
|
||||
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects all basket discounts (basket, payment and vouchers)
|
||||
* and returns sum of collected discounts.
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function getDiscountSumPayPalBasket()
|
||||
{
|
||||
// collect discounts
|
||||
$discount = 0.0;
|
||||
|
||||
$totalDiscount = $this->getTotalDiscount();
|
||||
|
||||
if ($totalDiscount) {
|
||||
$discount += $totalDiscount->getBruttoPrice();
|
||||
}
|
||||
|
||||
//if payment costs are negative, adding them to discount
|
||||
if (($costs = $this->getPaymentCosts()) < 0) {
|
||||
$discount += ($costs * -1);
|
||||
}
|
||||
|
||||
// vouchers..
|
||||
$vouchers = (array) $this->getVouchers();
|
||||
foreach ($vouchers as $voucher) {
|
||||
$discount += round($voucher->dVoucherdiscount, 2);
|
||||
}
|
||||
|
||||
return $discount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates basket costs (payment, GiftCard and gift card)
|
||||
* and returns sum of all costs.
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function getSumOfCostOfAllItemsPayPalBasket()
|
||||
{
|
||||
// basket items sum
|
||||
$allCosts = $this->getProductsPrice()->getSum($this->isCalculationModeNetto());
|
||||
|
||||
//adding to additional costs only if payment is > 0
|
||||
if (($costs = $this->getPayPalPaymentCosts()) > 0) {
|
||||
$allCosts += $costs;
|
||||
}
|
||||
|
||||
// wrapping costs
|
||||
$allCosts += $this->getPayPalWrappingCosts();
|
||||
|
||||
// greeting card costs
|
||||
$allCosts += $this->getPayPalGiftCardCosts();
|
||||
|
||||
return $allCosts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns absolute VAT value.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getPayPalBasketVatValue()
|
||||
{
|
||||
$basketVatValue = 0;
|
||||
$basketVatValue += $this->getPayPalProductVat();
|
||||
$basketVatValue += $this->getPayPalWrappingVat();
|
||||
$basketVatValue += $this->getPayPalGiftCardVat();
|
||||
$basketVatValue += $this->getPayPalPayCostVat();
|
||||
|
||||
if ($this->getDeliveryCosts() < round($this->getDeliveryCosts(), 2)) {
|
||||
return floor($basketVatValue * 100) / 100;
|
||||
}
|
||||
|
||||
return $basketVatValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return products VAT.
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function getPayPalProductVat()
|
||||
{
|
||||
$productVatList = $this->getProductVats(false);
|
||||
$productVatSum = array_sum($productVatList);
|
||||
|
||||
return $productVatSum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return wrapping VAT.
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function getPayPalWrappingVat()
|
||||
{
|
||||
$wrappingVat = 0.0;
|
||||
|
||||
$wrapping = $this->getCosts('oxwrapping');
|
||||
if ($wrapping && $wrapping->getVatValue()) {
|
||||
$wrappingVat = $wrapping->getVatValue();
|
||||
}
|
||||
|
||||
return $wrappingVat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return gift card VAT.
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function getPayPalGiftCardVat()
|
||||
{
|
||||
$giftCardVat = 0.0;
|
||||
|
||||
$giftCard = $this->getCosts('oxgiftcard');
|
||||
if ($giftCard && $giftCard->getVatValue()) {
|
||||
$giftCardVat = $giftCard->getVatValue();
|
||||
}
|
||||
|
||||
return $giftCardVat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return payment VAT.
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function getPayPalPayCostVat()
|
||||
{
|
||||
$paymentVAT = 0.0;
|
||||
|
||||
$paymentCost = $this->getCosts('oxpayment');
|
||||
if ($paymentCost && $paymentCost->getVatValue()) {
|
||||
$paymentVAT = $paymentCost->getVatValue();
|
||||
}
|
||||
|
||||
return $paymentVAT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if variants of the given product are already in the basket
|
||||
*
|
||||
* @param EshopArticle $product
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasProductVariantInBasket(EshopArticle $product)
|
||||
{
|
||||
$return = false;
|
||||
|
||||
$variantIds = $product->getVariantIds();
|
||||
foreach ($variantIds as $id) {
|
||||
if ($this->getArtStockInBasket($id)) {
|
||||
$return = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\DbGateways;
|
||||
|
||||
/**
|
||||
* Order payment comment db gateway class.
|
||||
*/
|
||||
class OrderPaymentCommentDbGateway extends \OxidEsales\PayPalModule\Core\ModelDbGateway
|
||||
{
|
||||
/**
|
||||
* Save PayPal order payment comment data to database.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function save($data)
|
||||
{
|
||||
$db = $this->getDb();
|
||||
|
||||
foreach ($data as $field => $value) {
|
||||
$fields[] = '`' . $field . '` = ' . $db->quote($value);
|
||||
}
|
||||
|
||||
$query = 'INSERT INTO `oepaypal_orderpaymentcomments` SET ';
|
||||
$query .= implode(', ', $fields);
|
||||
$query .= ' ON DUPLICATE KEY UPDATE ';
|
||||
$query .= ' `oepaypal_commentid`=LAST_INSERT_ID(`oepaypal_commentid`), ';
|
||||
$query .= implode(', ', $fields);
|
||||
$db->execute($query);
|
||||
|
||||
$commentId = $data['oepaypal_commentid'];
|
||||
if (empty($commentId)) {
|
||||
$commentId = $db->getOne('SELECT LAST_INSERT_ID()');
|
||||
}
|
||||
|
||||
return $commentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load PayPal order payment comment data from Db.
|
||||
*
|
||||
* @param string $paymentId order id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getList($paymentId)
|
||||
{
|
||||
$db = $this->getDb();
|
||||
$data = $db->getAll('SELECT * FROM `oepaypal_orderpaymentcomments` WHERE `oepaypal_paymentid` = ' . $db->quote($paymentId) . ' ORDER BY `oepaypal_date` DESC');
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load PayPal order payment comment data from Db.
|
||||
*
|
||||
* @param string $commentId Order id.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function load($commentId)
|
||||
{
|
||||
$db = $this->getDb();
|
||||
$data = $db->getRow('SELECT * FROM `oepaypal_orderpaymentcomments` WHERE `oepaypal_commentid` = ' . $db->quote($commentId));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete PayPal order payment comment data from database.
|
||||
*
|
||||
* @param string $commentId Order id.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($commentId)
|
||||
{
|
||||
$db = $this->getDb();
|
||||
$db->startTransaction();
|
||||
|
||||
$deleteResult = $db->execute('DELETE FROM `oepaypal_orderpaymentcomments` WHERE `oepaypal_commentid` = ' . $db->quote($commentId));
|
||||
|
||||
$result = ($deleteResult !== false);
|
||||
|
||||
if ($result) {
|
||||
$db->commitTransaction();
|
||||
} else {
|
||||
$db->rollbackTransaction();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\DbGateways;
|
||||
|
||||
/**
|
||||
* Order payment db gateway class
|
||||
*/
|
||||
class OrderPaymentDbGateway extends \OxidEsales\PayPalModule\Core\ModelDbGateway
|
||||
{
|
||||
/**
|
||||
* Save PayPal order payment data to database.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function save($data)
|
||||
{
|
||||
$db = $this->getDb();
|
||||
|
||||
foreach ($data as $field => $value) {
|
||||
$fields[] = '`' . $field . '` = ' . $db->quote($value);
|
||||
}
|
||||
|
||||
$query = 'INSERT INTO `oepaypal_orderpayments` SET ';
|
||||
$query .= implode(', ', $fields);
|
||||
$query .= ' ON DUPLICATE KEY UPDATE ';
|
||||
$query .= ' `oepaypal_paymentid`=LAST_INSERT_ID(`oepaypal_paymentid`), ';
|
||||
$query .= implode(', ', $fields);
|
||||
$db->execute($query);
|
||||
|
||||
$id = $data['oepaypal_paymentid'];
|
||||
if (empty($id)) {
|
||||
$id = $db->getOne('SELECT LAST_INSERT_ID()');
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load PayPal order payment data from Db.
|
||||
*
|
||||
* @param string $paymentId Order id.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function load($paymentId)
|
||||
{
|
||||
$db = $this->getDb();
|
||||
$data = $db->getRow('SELECT * FROM `oepaypal_orderpayments` WHERE `oepaypal_paymentid` = ' . $db->quote($paymentId));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load PayPal order payment data from Db.
|
||||
*
|
||||
* @param string $transactionId Order id.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function loadByTransactionId($transactionId)
|
||||
{
|
||||
$db = $this->getDb();
|
||||
$data = $db->getRow('SELECT * FROM `oepaypal_orderpayments` WHERE `oepaypal_transactionid` = ' . $db->quote($transactionId));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete PayPal order payment data from database.
|
||||
*
|
||||
* @param string $paymentId Order id.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($paymentId)
|
||||
{
|
||||
$db = $this->getDb();
|
||||
$db->startTransaction();
|
||||
|
||||
$deleteResult = $db->execute('DELETE FROM `oepaypal_orderpayments` WHERE `oepaypal_paymentid` = ' . $db->quote($paymentId));
|
||||
$deleteCommentResult = $db->execute('DELETE FROM `oepaypal_orderpaymentcomments` WHERE `oepaypal_paymentid` = ' . $db->quote($paymentId));
|
||||
|
||||
$result = ($deleteResult !== false) || ($deleteCommentResult !== false);
|
||||
|
||||
if ($result) {
|
||||
$db->commitTransaction();
|
||||
} else {
|
||||
$db->rollbackTransaction();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load PayPal order payment data from Db.
|
||||
*
|
||||
* @param string $orderId Order id.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getList($orderId)
|
||||
{
|
||||
$db = $this->getDb();
|
||||
$data = $db->getAll('SELECT * FROM `oepaypal_orderpayments` WHERE `oepaypal_orderid` = ' . $db->quote($orderId) . ' ORDER BY `oepaypal_date` DESC');
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\DbGateways;
|
||||
|
||||
/**
|
||||
* Order db gateway class
|
||||
*/
|
||||
class PayPalOrderDbGateway extends \OxidEsales\PayPalModule\Core\ModelDbGateway
|
||||
{
|
||||
/**
|
||||
* Save PayPal order data to database.
|
||||
*
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function save($data)
|
||||
{
|
||||
$db = $this->getDb();
|
||||
$fields = [];
|
||||
|
||||
foreach ($data as $field => $value) {
|
||||
$fields[] = '`' . $field . '` = ' . $db->quote($value);
|
||||
}
|
||||
|
||||
$query = 'INSERT INTO `oepaypal_order` SET ';
|
||||
$query .= implode(', ', $fields);
|
||||
$query .= ' ON DUPLICATE KEY UPDATE ';
|
||||
$query .= ' `oepaypal_orderid`=LAST_INSERT_ID(`oepaypal_orderid`), ';
|
||||
$query .= implode(', ', $fields);
|
||||
|
||||
$db->execute($query);
|
||||
|
||||
$id = $data['oepaypal_orderid'];
|
||||
if (empty($id)) {
|
||||
$id = $db->getOne('SELECT LAST_INSERT_ID()');
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load PayPal order data from Db.
|
||||
*
|
||||
* @param string $orderId Order id.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function load($orderId)
|
||||
{
|
||||
$db = $this->getDb();
|
||||
$data = $db->getRow('SELECT * FROM `oepaypal_order` WHERE `oepaypal_orderid` = ' . $db->quote($orderId));
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete PayPal order data from database.
|
||||
*
|
||||
* @param string $orderId Order id.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($orderId)
|
||||
{
|
||||
$db = $this->getDb();
|
||||
$db->startTransaction();
|
||||
|
||||
$deleteCommentsResult = $db->execute(
|
||||
'DELETE
|
||||
`oepaypal_orderpaymentcomments`
|
||||
FROM `oepaypal_orderpaymentcomments`
|
||||
INNER JOIN `oepaypal_orderpayments` ON `oepaypal_orderpayments`.`oepaypal_paymentid` = `oepaypal_orderpaymentcomments`.`oepaypal_paymentid`
|
||||
WHERE `oepaypal_orderpayments`.`oepaypal_orderid` = ' . $db->quote($orderId)
|
||||
);
|
||||
$deleteOrderPaymentResult = $db->execute('DELETE FROM `oepaypal_orderpayments` WHERE `oepaypal_orderid` = ' . $db->quote($orderId));
|
||||
$deleteOrderResult = $db->execute('DELETE FROM `oepaypal_order` WHERE `oepaypal_orderid` = ' . $db->quote($orderId));
|
||||
|
||||
$result = ($deleteOrderResult !== false) || ($deleteOrderPaymentResult !== false) || ($deleteCommentsResult !== false);
|
||||
|
||||
if ($result) {
|
||||
$db->commitTransaction();
|
||||
} else {
|
||||
$db->rollbackTransaction();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
270
shop/source/modules/oe/oepaypal/Model/IPNPaymentBuilder.php
Normal file
270
shop/source/modules/oe/oepaypal/Model/IPNPaymentBuilder.php
Normal file
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal IPN payment builder class.
|
||||
*/
|
||||
class IPNPaymentBuilder
|
||||
{
|
||||
/** @var \OxidEsales\PayPalModule\Core\Request */
|
||||
protected $request = null;
|
||||
|
||||
/** @var \OxidEsales\PayPalModule\Model\IPNRequestPaymentSetter */
|
||||
protected $payPalIPNPaymentSetter = null;
|
||||
|
||||
/** @var \OxidEsales\PayPalModule\Model\OrderPayment */
|
||||
protected $orderPayment = null;
|
||||
|
||||
/** @var \OxidEsales\PayPalModule\Model\IPNPaymentValidator */
|
||||
protected $payPalIPNPaymentValidator = null;
|
||||
|
||||
/** @var \OxidEsales\PayPalModule\Model\IPNPaymentCreator */
|
||||
protected $payPalIPNPaymentCreator = null;
|
||||
|
||||
/** @var \OxidEsales\Eshop\Core\Language */
|
||||
protected $lang = null;
|
||||
|
||||
/**
|
||||
* Sets \OxidEsales\PayPalModule\Model\IPNRequestPaymentSetter.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\IPNRequestPaymentSetter $payPalIPNPaymentSetter
|
||||
*/
|
||||
public function setOrderPaymentSetter($payPalIPNPaymentSetter)
|
||||
{
|
||||
$this->payPalIPNPaymentSetter = $payPalIPNPaymentSetter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and sets \OxidEsales\PayPalModule\Model\IPNRequestPaymentSetter object if it was not set.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\IPNRequestPaymentSetter
|
||||
*/
|
||||
public function getOrderPaymentSetter()
|
||||
{
|
||||
if (is_null($this->payPalIPNPaymentSetter)) {
|
||||
$payPalIPNPaymentSetter = oxNew(\OxidEsales\PayPalModule\Model\IPNRequestPaymentSetter::class);
|
||||
$this->setOrderPaymentSetter($payPalIPNPaymentSetter);
|
||||
}
|
||||
|
||||
return $this->payPalIPNPaymentSetter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets \OxidEsales\PayPalModule\Model\IPNPaymentValidator object.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\IPNPaymentValidator $payPalIPNPaymentValidator
|
||||
*/
|
||||
public function setOrderPaymentValidator($payPalIPNPaymentValidator)
|
||||
{
|
||||
$this->payPalIPNPaymentValidator = $payPalIPNPaymentValidator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and sets \OxidEsales\PayPalModule\Model\IPNPaymentValidator object if it was not set.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\IPNPaymentValidator
|
||||
*/
|
||||
public function getOrderPaymentValidator()
|
||||
{
|
||||
if (is_null($this->payPalIPNPaymentValidator)) {
|
||||
$payPalIPNPaymentValidator = oxNew(\OxidEsales\PayPalModule\Model\IPNPaymentValidator::class);
|
||||
$this->setOrderPaymentValidator($payPalIPNPaymentValidator);
|
||||
}
|
||||
|
||||
return $this->payPalIPNPaymentValidator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets \OxidEsales\PayPalModule\Model\IPNPaymentCreator.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\IPNPaymentCreator $oePayPalIPNPaymentCreator
|
||||
*/
|
||||
public function setPaymentCreator($oePayPalIPNPaymentCreator)
|
||||
{
|
||||
$this->payPalIPNPaymentCreator = $oePayPalIPNPaymentCreator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and sets \OxidEsales\PayPalModule\Model\IPNPaymentCreator object if it was not set.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\IPNPaymentCreator
|
||||
*/
|
||||
public function getPaymentCreator()
|
||||
{
|
||||
if (is_null($this->payPalIPNPaymentCreator)) {
|
||||
$payPalIPNPaymentCreator = oxNew(\OxidEsales\PayPalModule\Model\IPNPaymentCreator::class);
|
||||
$payPalIPNPaymentCreator->setRequest($this->getRequest());
|
||||
$this->setPaymentCreator($payPalIPNPaymentCreator);
|
||||
}
|
||||
|
||||
return $this->payPalIPNPaymentCreator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets request object.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\Request $request
|
||||
*/
|
||||
public function setRequest($request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns \OxidEsales\PayPalModule\Core\Request.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets oxLang object
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Core\Language $lang
|
||||
*/
|
||||
public function setLang($lang)
|
||||
{
|
||||
$this->lang = $lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns oxLang object.
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Core\Language
|
||||
*/
|
||||
public function getLang()
|
||||
{
|
||||
return $this->lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create payment from given request.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPayment|null
|
||||
*/
|
||||
public function buildPayment()
|
||||
{
|
||||
$return = null;
|
||||
|
||||
// Setter forms request payment from request parameters.
|
||||
$requestOrderPayment = $this->prepareRequestOrderPayment();
|
||||
|
||||
// Create order payment from database to check if it match created from request.
|
||||
$orderPayment = $this->loadOrderPayment($requestOrderPayment->getTransactionId());
|
||||
|
||||
// Only need validate if there is order in database.
|
||||
// If request payment do not have matching payment with order return null.
|
||||
if ($orderPayment->getOrderId()) {
|
||||
// Validator change request payment by adding information if it is valid.
|
||||
$orderPayment = $this->addPaymentValidationInformation($requestOrderPayment, $orderPayment);
|
||||
$orderPayment = $this->changePaymentStatusInfo($requestOrderPayment, $orderPayment);
|
||||
$orderPayment->save();
|
||||
$return = $orderPayment;
|
||||
} else {
|
||||
//IPN request might be for a transaction that does not yet exist in the shop database.
|
||||
$paymentCreator = $this->getPaymentCreator();
|
||||
$return = $paymentCreator->handleOrderPayment($requestOrderPayment);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load order payment from transaction id.
|
||||
*
|
||||
* @param string $transactionId transaction id to load object.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPayment|null
|
||||
*/
|
||||
protected function loadOrderPayment($transactionId)
|
||||
{
|
||||
$orderPayment = oxNew(\OxidEsales\PayPalModule\Model\OrderPayment::class);
|
||||
$orderPayment->loadByTransactionId($transactionId);
|
||||
|
||||
return $orderPayment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to set parameters to order payment from request.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPayment
|
||||
*/
|
||||
protected function prepareRequestOrderPayment()
|
||||
{
|
||||
$requestOrderPayment = oxNew(\OxidEsales\PayPalModule\Model\OrderPayment::class);
|
||||
$request = $this->getRequest();
|
||||
|
||||
$requestPaymentSetter = $this->getOrderPaymentSetter();
|
||||
$requestPaymentSetter->setRequest($request);
|
||||
$requestPaymentSetter->setRequestOrderPayment($requestOrderPayment);
|
||||
|
||||
$requestOrderPayment = $requestPaymentSetter->getRequestOrderPayment();
|
||||
|
||||
return $requestOrderPayment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds payment validation information.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $requestOrderPayment
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $orderPayment
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPayment
|
||||
*/
|
||||
protected function addPaymentValidationInformation($requestOrderPayment, $orderPayment)
|
||||
{
|
||||
$lang = $this->getLang();
|
||||
|
||||
$paymentValidator = $this->getOrderPaymentValidator();
|
||||
$paymentValidator->setRequestOrderPayment($requestOrderPayment);
|
||||
$paymentValidator->setOrderPayment($orderPayment);
|
||||
$paymentValidator->setLang($lang);
|
||||
|
||||
$paymentIsValid = $paymentValidator->isValid();
|
||||
if (!$paymentIsValid) {
|
||||
$orderPayment->setIsValid($paymentIsValid);
|
||||
$comment = oxNew(\OxidEsales\PayPalModule\Model\OrderPaymentComment::class);
|
||||
$comment->setComment($paymentValidator->getValidationFailureMessage());
|
||||
$orderPayment->addComment($comment);
|
||||
}
|
||||
|
||||
return $orderPayment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Payment Status information to object from database from object created from from PayPal request.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $requestOrderPayment
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $orderPayment
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPayment
|
||||
*/
|
||||
protected function changePaymentStatusInfo($requestOrderPayment, $orderPayment)
|
||||
{
|
||||
$orderPayment->setStatus($requestOrderPayment->getStatus());
|
||||
|
||||
return $orderPayment;
|
||||
}
|
||||
}
|
||||
185
shop/source/modules/oe/oepaypal/Model/IPNPaymentCreator.php
Normal file
185
shop/source/modules/oe/oepaypal/Model/IPNPaymentCreator.php
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal IPN payment creator class.
|
||||
* Handles inserting of new IPN data into database including
|
||||
* updating parent transactions if needed.
|
||||
*/
|
||||
class IPNPaymentCreator
|
||||
{
|
||||
/** @var string IPN request parameter names. */
|
||||
const PAYPAL_IPN_AUTH_ID = 'auth_id';
|
||||
|
||||
/** @var string IPN request parameter names. */
|
||||
const PAYPAL_IPN_AUTH_STATUS = 'auth_status';
|
||||
|
||||
/** @var string IPN request parameter names. */
|
||||
const PAYPAL_IPN_PARENT_TRANSACTION_ID = 'parent_txn_id';
|
||||
|
||||
/** @var string String PayPal transaction entity. */
|
||||
const PAYPAL_IPN_TRANSACTION_ENTITY = 'transaction_entity';
|
||||
|
||||
/** @var string Class only handles IPN transaction payments. */
|
||||
const HANDLE_TRANSACTION_ENTITY = 'payment';
|
||||
|
||||
/** @var string PayPal payment comment. */
|
||||
const PAYPAL_IPN_MEMO = 'memo';
|
||||
|
||||
/** @var \OxidEsales\PayPalModule\Core\Request */
|
||||
protected $request = null;
|
||||
|
||||
/**
|
||||
* Sets request object.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\Request $request
|
||||
*/
|
||||
public function setRequest($request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns \OxidEsales\PayPalModule\Core\Request.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handling of IPN data that has not yet a paypal order payment
|
||||
* entry in shop database.
|
||||
* Checks if information from IPN is relevant for Shop. That is the case
|
||||
* if the related PayPal parent transaction can be found in table oepaypal_orderpayments.
|
||||
*
|
||||
* If data is relevant, we need to
|
||||
* - create paypal order payment, store it in database and return it.
|
||||
* - if it is a refund, update the parent transaction's refunded amount
|
||||
* - update authorization status (can be Pending, In Progress, Completed)
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $requestOrderPayment
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPayment|null
|
||||
*/
|
||||
public function handleOrderPayment($requestOrderPayment)
|
||||
{
|
||||
$return = null;
|
||||
|
||||
$authId = $this->getRequest()->getRequestParameter(self::PAYPAL_IPN_AUTH_ID);
|
||||
$transactionEntity = $this->getRequest()->getRequestParameter(self::PAYPAL_IPN_TRANSACTION_ENTITY);
|
||||
$parentTransactionId = $this->getRequest()->getRequestParameter(self::PAYPAL_IPN_PARENT_TRANSACTION_ID);
|
||||
|
||||
$orderPaymentAuthorization = $this->loadOrderPayment($authId);
|
||||
$orderPaymentParent = $this->loadOrderPayment($parentTransactionId);
|
||||
$orderId = $orderPaymentParent->getOrderId();
|
||||
|
||||
if ((self::HANDLE_TRANSACTION_ENTITY == $transactionEntity) && $orderId) {
|
||||
$requestOrderPayment->setOrderId($orderId);
|
||||
$requestOrderPayment->save();
|
||||
$requestOrderPayment = $this->addRequestPaymentComment($requestOrderPayment);
|
||||
|
||||
if (\OxidEsales\PayPalModule\Model\IPNRequestPaymentSetter::REFUND_ACTION == $requestOrderPayment->getAction()) {
|
||||
$this->updateParentTransactionRefundAmount($orderPaymentParent, $requestOrderPayment->getAmount());
|
||||
}
|
||||
if ((\OxidEsales\PayPalModule\Model\IPNRequestPaymentSetter::AUTHORIZATION_ACTION == $orderPaymentAuthorization->getAction())
|
||||
&& ($orderId == $orderPaymentAuthorization->getOrderId())
|
||||
) {
|
||||
$this->updateOrderPaymentAuthorizationStatus($orderPaymentAuthorization);
|
||||
}
|
||||
$return = $requestOrderPayment;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the parent transaction's refund amount.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $orderPaymentParent
|
||||
* @param float $amount
|
||||
*/
|
||||
private function updateParentTransactionRefundAmount($orderPaymentParent, $amount)
|
||||
{
|
||||
$orderPaymentParent->addRefundedAmount($amount);
|
||||
$orderPaymentParent->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* The status of the related authorization transaction might have changed.
|
||||
* We need to update that transaction status as well if we got a value in IPN request data.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $orderPaymentAuthorization Authorization PayPal order payment
|
||||
*/
|
||||
private function updateOrderPaymentAuthorizationStatus($orderPaymentAuthorization)
|
||||
{
|
||||
$authStatus = $this->getRequest()->getRequestParameter(self::PAYPAL_IPN_AUTH_STATUS);
|
||||
|
||||
if ($authStatus) {
|
||||
$orderPaymentAuthorization->setStatus($authStatus);
|
||||
$orderPaymentAuthorization->save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load order payment from transaction id.
|
||||
*
|
||||
* @param string $transactionId transaction id to load object.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPayment|null
|
||||
*/
|
||||
private function loadOrderPayment($transactionId)
|
||||
{
|
||||
$orderPayment = oxNew(\OxidEsales\PayPalModule\Model\OrderPayment::class);
|
||||
$orderPayment->loadByTransactionId($transactionId);
|
||||
|
||||
return $orderPayment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add comment for request payment if comment exists.
|
||||
* Function must only be called when the payment object this
|
||||
* comment is related to is already stored in the database and has an oxid.
|
||||
* Comment will be immediately saved to database.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $paypalOrderPayment
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPayment
|
||||
*/
|
||||
private function addRequestPaymentComment($paypalOrderPayment)
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$memo = $request->getRequestParameter(self::PAYPAL_IPN_MEMO);
|
||||
|
||||
if ($memo) {
|
||||
$comment = oxNew(\OxidEsales\PayPalModule\Model\OrderPaymentComment::class);
|
||||
$comment->setComment($memo);
|
||||
$paypalOrderPayment->addComment($comment);
|
||||
if (0 < $paypalOrderPayment->getId()) {
|
||||
$paypalOrderPayment->save();
|
||||
}
|
||||
}
|
||||
return $paypalOrderPayment;
|
||||
}
|
||||
}
|
||||
149
shop/source/modules/oe/oepaypal/Model/IPNPaymentValidator.php
Normal file
149
shop/source/modules/oe/oepaypal/Model/IPNPaymentValidator.php
Normal file
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal IPN Payment validator class.
|
||||
*/
|
||||
class IPNPaymentValidator
|
||||
{
|
||||
/**
|
||||
* Language object to get translations from.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $lang = null;
|
||||
|
||||
/**
|
||||
* Payment created from PayPal request.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Model\OrderPayment
|
||||
*/
|
||||
protected $requestPayment = null;
|
||||
|
||||
/**
|
||||
* Payment created by PayPal request id.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Model\OrderPayment
|
||||
*/
|
||||
protected $orderPayment = null;
|
||||
|
||||
/**
|
||||
* Sets language object to get translations from.
|
||||
*
|
||||
* @param object $lang get translations from.
|
||||
*/
|
||||
public function setLang($lang)
|
||||
{
|
||||
$this->lang = $lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets language object to get translations from.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getLang()
|
||||
{
|
||||
return $this->lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets request object.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $requestPayment
|
||||
*/
|
||||
public function setRequestOrderPayment($requestPayment)
|
||||
{
|
||||
$this->requestPayment = $requestPayment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns request payment object.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPayment
|
||||
*/
|
||||
public function getRequestOrderPayment()
|
||||
{
|
||||
return $this->requestPayment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets order payment object.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $payment
|
||||
*/
|
||||
public function setOrderPayment($payment)
|
||||
{
|
||||
$this->orderPayment = $payment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns order payment object.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPayment
|
||||
*/
|
||||
public function getOrderPayment()
|
||||
{
|
||||
return $this->orderPayment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns validation failure message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValidationFailureMessage()
|
||||
{
|
||||
$requestPayment = $this->getRequestOrderPayment();
|
||||
$orderPayment = $this->getOrderPayment();
|
||||
|
||||
$currencyPayPal = $requestPayment->getCurrency();
|
||||
$pricePayPal = $requestPayment->getAmount();
|
||||
|
||||
$currencyPayment = $orderPayment->getCurrency();
|
||||
$amountPayment = $orderPayment->getAmount();
|
||||
|
||||
$lang = $this->getLang();
|
||||
$validationMessage = $lang->translateString('OEPAYPAL_PAYMENT_INFORMATION') . ': ' . $amountPayment . ' ' . $currencyPayment . '. ' . $lang->translateString('OEPAYPAL_INFORMATION') . ': ' . $pricePayPal . ' ' . $currencyPayPal . '.';
|
||||
|
||||
return $validationMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if PayPal response fits payment information.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
$requestPayment = $this->getRequestOrderPayment();
|
||||
$orderPayment = $this->getOrderPayment();
|
||||
|
||||
$currencyPayPal = $requestPayment->getCurrency();
|
||||
$pricePayPal = $requestPayment->getAmount();
|
||||
|
||||
$currencyPayment = $orderPayment->getCurrency();
|
||||
$amountPayment = $orderPayment->getAmount();
|
||||
|
||||
return ($currencyPayPal == $currencyPayment && $pricePayPal == $amountPayment);
|
||||
}
|
||||
}
|
||||
155
shop/source/modules/oe/oepaypal/Model/IPNProcessor.php
Normal file
155
shop/source/modules/oe/oepaypal/Model/IPNProcessor.php
Normal file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal IPN processor class.
|
||||
*/
|
||||
class IPNProcessor
|
||||
{
|
||||
/**
|
||||
* PayPal request handler.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
protected $request = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Model\IPNPaymentBuilder
|
||||
*/
|
||||
protected $paymentBuilder = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Model\OrderManager
|
||||
*/
|
||||
protected $orderManager = null;
|
||||
|
||||
/**
|
||||
* Set object \OxidEsales\PayPalModule\Core\Request.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\Request $request object to set.
|
||||
*/
|
||||
public function setRequest($request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create object \OxidEsales\PayPalModule\Core\Request to get PayPal request information.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets language object.
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Core\Language $lang
|
||||
*/
|
||||
public function setLang($lang)
|
||||
{
|
||||
$this->lang = $lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns language object.
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Core\Language
|
||||
*/
|
||||
public function getLang()
|
||||
{
|
||||
return $this->lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets payment builder.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\IPNPaymentBuilder $paymentBuilder
|
||||
*/
|
||||
public function setPaymentBuilder($paymentBuilder)
|
||||
{
|
||||
$this->paymentBuilder = $paymentBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates \OxidEsales\PayPalModule\Model\IPNPaymentBuilder, sets if it was not set and than returns it.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\IPNPaymentBuilder
|
||||
*/
|
||||
public function getPaymentBuilder()
|
||||
{
|
||||
if (is_null($this->paymentBuilder)) {
|
||||
$this->paymentBuilder = oxNew(\OxidEsales\PayPalModule\Model\IPNPaymentBuilder::class);
|
||||
}
|
||||
|
||||
return $this->paymentBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets order manager.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderManager $payPalOrderManager
|
||||
*/
|
||||
public function setOrderManager($payPalOrderManager)
|
||||
{
|
||||
$this->orderManager = $payPalOrderManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns order manager.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderManager
|
||||
*/
|
||||
public function getOrderManager()
|
||||
{
|
||||
if (is_null($this->orderManager)) {
|
||||
$this->orderManager = oxNew(\OxidEsales\PayPalModule\Model\OrderManager::class);
|
||||
}
|
||||
|
||||
return $this->orderManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate payment status changes according to IPN information.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function process()
|
||||
{
|
||||
$lang = $this->getLang();
|
||||
$request = $this->getRequest();
|
||||
$paymentBuilder = $this->getPaymentBuilder();
|
||||
$payPalOrderManager = $this->getOrderManager();
|
||||
|
||||
// Create Payment from Request.
|
||||
$paymentBuilder->setLang($lang);
|
||||
$paymentBuilder->setRequest($request);
|
||||
$orderPayment = $paymentBuilder->buildPayment();
|
||||
|
||||
$payPalOrderManager->setOrderPayment($orderPayment);
|
||||
$processSuccess = $payPalOrderManager->updateOrderStatus();
|
||||
|
||||
return $processSuccess;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal IPN request payment setter class.
|
||||
*/
|
||||
class IPNRequestPaymentSetter
|
||||
{
|
||||
/** @var string PayPal action that triggered this transaction. */
|
||||
const CAPTURE_ACTION = 'capture';
|
||||
const REFUND_ACTION = 'refund';
|
||||
const AUTHORIZATION_ACTION = 'authorization';
|
||||
|
||||
/** @var string Sandbox mode parameter name. */
|
||||
const PAYPAL_SANDBOX = 'test_ipn';
|
||||
|
||||
/** @var string String PayPal payment status parameter name. */
|
||||
const PAYPAL_PAYMENT_STATUS = 'payment_status';
|
||||
|
||||
/** @var string PayPal transaction id. */
|
||||
const PAYPAL_TRANSACTION_ID = 'txn_id';
|
||||
|
||||
/** @var string PayPal whole price including payment and shipment. */
|
||||
const MC_GROSS = 'mc_gross';
|
||||
|
||||
/** @var string PayPal payment currency. */
|
||||
const MC_CURRENCY = 'mc_currency';
|
||||
|
||||
/** @var string PayPal payment date. */
|
||||
const PAYMENT_DATE = 'payment_date';
|
||||
|
||||
/** @var string PayPal payment correlation id. */
|
||||
const CORRELATION_ID = 'correlation_id';
|
||||
|
||||
/** @var string PayPal payment ipn tracking id, might come instead of correlation id. */
|
||||
const IPN_TRACK_ID = 'ipn_track_id';
|
||||
|
||||
/** @var string PayPal status for successful refund. */
|
||||
const PAYPAL_STATUS_REFUND_DONE = 'Refunded';
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
protected $request = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Model\OrderPayment
|
||||
*/
|
||||
protected $requestOrderPayment = null;
|
||||
|
||||
/**
|
||||
* Sets request object to get params for IPN request.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\Request $request
|
||||
*/
|
||||
public function setRequest($request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets request object to get params for IPN request.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets request order payment object.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $orderPayment
|
||||
*/
|
||||
public function setRequestOrderPayment($orderPayment)
|
||||
{
|
||||
$this->requestOrderPayment = $orderPayment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns order payment object.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPayment
|
||||
*/
|
||||
public function getRequestOrderPayment()
|
||||
{
|
||||
$this->prepareOrderPayment($this->requestOrderPayment);
|
||||
|
||||
return $this->requestOrderPayment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare PayPal payment. Fill up with request values.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $requestOrderPayment order to set params.
|
||||
*/
|
||||
protected function prepareOrderPayment($requestOrderPayment)
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
|
||||
$requestOrderPayment->setStatus($request->getRequestParameter(self::PAYPAL_PAYMENT_STATUS));
|
||||
$requestOrderPayment->setTransactionId($request->getRequestParameter(self::PAYPAL_TRANSACTION_ID));
|
||||
$requestOrderPayment->setCurrency($request->getRequestParameter(self::MC_CURRENCY));
|
||||
$requestOrderPayment->setAmount($this->getAmount());
|
||||
$requestOrderPayment->setAction($this->getAction());
|
||||
|
||||
$correlationId = $request->getRequestParameter(self::CORRELATION_ID);
|
||||
if (!$correlationId) {
|
||||
$correlationId = $request->getRequestParameter(self::IPN_TRACK_ID);
|
||||
}
|
||||
$requestOrderPayment->setCorrelationId($correlationId);
|
||||
|
||||
$date = 0 < strlen($request->getRequestParameter(self::PAYMENT_DATE)) ?
|
||||
date('Y-m-d H:i:s', strtotime($request->getRequestParameter(self::PAYMENT_DATE))) : null;
|
||||
$requestOrderPayment->setDate($date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PayPal action from request, we might have a refund.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getAction()
|
||||
{
|
||||
$action = self::CAPTURE_ACTION;
|
||||
$request = $this->getRequest();
|
||||
$rawAmount = $request->getRequestParameter(self::MC_GROSS);
|
||||
$status = $request->getRequestParameter(self::PAYPAL_PAYMENT_STATUS);
|
||||
|
||||
if ((0 > $rawAmount) && (self::PAYPAL_STATUS_REFUND_DONE == $status)) {
|
||||
$action = self::REFUND_ACTION;
|
||||
}
|
||||
|
||||
return $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get amount from request.
|
||||
*
|
||||
* @return number
|
||||
*/
|
||||
protected function getAmount()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
return !is_null($request->getRequestParameter(self::MC_GROSS)) ? abs($request->getRequestParameter(self::MC_GROSS)) : null;
|
||||
}
|
||||
}
|
||||
153
shop/source/modules/oe/oepaypal/Model/IPNRequestValidator.php
Normal file
153
shop/source/modules/oe/oepaypal/Model/IPNRequestValidator.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal IPN request validator class.
|
||||
*/
|
||||
class IPNRequestValidator
|
||||
{
|
||||
/**
|
||||
* String PayPal receiver email. It should be same as shop owner credential for PayPal.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const RECEIVER_EMAIL = 'receiver_email';
|
||||
|
||||
/**
|
||||
* Shop owner Email from configuration of PayPal module.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $shopOwnerUserName = null;
|
||||
|
||||
/**
|
||||
* PayPal response if OK.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Model\Response\ResponseDoVerifyWithPayPal
|
||||
*/
|
||||
protected $payPalResponse = null;
|
||||
|
||||
/**
|
||||
* PayPal request to get email.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $payPalRequest = null;
|
||||
|
||||
/**
|
||||
* Set shop owner user name - payPal ID.
|
||||
*
|
||||
* @param string $shopOwnerUserName
|
||||
*/
|
||||
public function setShopOwnerUserName($shopOwnerUserName)
|
||||
{
|
||||
$this->shopOwnerUserName = $shopOwnerUserName;
|
||||
}
|
||||
|
||||
/**
|
||||
* get shop owner user name - payPal ID.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getShopOwnerUserName()
|
||||
{
|
||||
return $this->shopOwnerUserName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PayPal response object.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\Response\ResponseDoVerifyWithPayPal|Response\Response $payPalResponse
|
||||
*/
|
||||
public function setPayPalResponse($payPalResponse)
|
||||
{
|
||||
$this->payPalResponse = $payPalResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PayPal response object.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\Response\ResponseDoVerifyWithPayPal
|
||||
*/
|
||||
public function getPayPalResponse()
|
||||
{
|
||||
return $this->payPalResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PayPal request array.
|
||||
*
|
||||
* @param array $payPalRequest
|
||||
*/
|
||||
public function setPayPalRequest($payPalRequest)
|
||||
{
|
||||
$this->payPalRequest = $payPalRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PayPal request array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPayPalRequest()
|
||||
{
|
||||
return $this->payPalRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns validation failure messages.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValidationFailureMessage()
|
||||
{
|
||||
$payPalRequest = $this->getPayPalRequest();
|
||||
$payPalResponse = $this->getPayPalResponse();
|
||||
$shopOwnerUserName = $this->getShopOwnerUserName();
|
||||
$receiverEmailPayPal = $payPalRequest[self::RECEIVER_EMAIL];
|
||||
|
||||
$validationMessage = array(
|
||||
'Shop owner' => (string) $shopOwnerUserName,
|
||||
'PayPal ID' => (string) $receiverEmailPayPal,
|
||||
'PayPal ACK' => ($payPalResponse->isPayPalAck() ? 'VERIFIED' : 'NOT VERIFIED'),
|
||||
'PayPal Full Request' => print_r($payPalRequest, true),
|
||||
'PayPal Full Response' => print_r($payPalResponse->getData(), true),
|
||||
);
|
||||
|
||||
return $validationMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate if IPN request from PayPal and to correct shop.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
$payPalRequest = $this->getPayPalRequest();
|
||||
$payPalResponse = $this->getPayPalResponse();
|
||||
$shopOwnerUserName = $this->getShopOwnerUserName();
|
||||
$receiverEmailPayPal = $payPalRequest[self::RECEIVER_EMAIL];
|
||||
|
||||
return ($payPalResponse->isPayPalAck() && $receiverEmailPayPal == $shopOwnerUserName);
|
||||
}
|
||||
}
|
||||
241
shop/source/modules/oe/oepaypal/Model/IPNRequestVerifier.php
Normal file
241
shop/source/modules/oe/oepaypal/Model/IPNRequestVerifier.php
Normal file
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal IPN request verifier class.
|
||||
*/
|
||||
class IPNRequestVerifier
|
||||
{
|
||||
/**
|
||||
* PayPal \OxidEsales\PayPalModule\Core\Request
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
protected $request = null;
|
||||
|
||||
/**
|
||||
* Shop owner email - PayPal ID.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $shopOwner = null;
|
||||
|
||||
/**
|
||||
* PayPal Service
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Core\PayPalService
|
||||
*/
|
||||
protected $communicationService = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Model\IPNRequestValidator
|
||||
*/
|
||||
protected $ipnRequestValidator = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
|
||||
*/
|
||||
protected $payPalRequest = null;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $failureMessage = null;
|
||||
|
||||
/**
|
||||
* Set object \OxidEsales\PayPalModule\Core\Request.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\Request $request object to set.
|
||||
*/
|
||||
public function setRequest($request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create object \OxidEsales\PayPalModule\Core\Request to get PayPal request information.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Request
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets shop owner.
|
||||
*
|
||||
* @param string $shopOwner
|
||||
*/
|
||||
public function setShopOwner($shopOwner)
|
||||
{
|
||||
$this->shopOwner = $shopOwner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns shop owner.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getShopOwner()
|
||||
{
|
||||
return $this->shopOwner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets oeIPNCallerService.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\PayPalService $callerService object to set..
|
||||
*/
|
||||
public function setCommunicationService($callerService)
|
||||
{
|
||||
$this->communicationService = $callerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the PayPal service
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\PayPalService
|
||||
*/
|
||||
public function getCommunicationService()
|
||||
{
|
||||
if ($this->communicationService === null) {
|
||||
$this->communicationService = oxNew(\OxidEsales\PayPalModule\Core\PayPalService::class);
|
||||
}
|
||||
|
||||
return $this->communicationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets IPN request validator.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\IPNRequestValidator $ipnRequestValidator
|
||||
*/
|
||||
public function setIPNRequestValidator($ipnRequestValidator)
|
||||
{
|
||||
$this->ipnRequestValidator = $ipnRequestValidator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns IPN request validator object.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\IPNRequestValidator
|
||||
*/
|
||||
public function getIPNRequestValidator()
|
||||
{
|
||||
if ($this->ipnRequestValidator === null) {
|
||||
$this->ipnRequestValidator = oxNew(\OxidEsales\PayPalModule\Model\IPNRequestValidator::class);
|
||||
}
|
||||
|
||||
return $this->ipnRequestValidator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets request object.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $payPalRequest
|
||||
*/
|
||||
public function setPayPalRequest($payPalRequest)
|
||||
{
|
||||
$this->payPalRequest = $payPalRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return, create object to call PayPal with.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
|
||||
*/
|
||||
public function getPayPalRequest()
|
||||
{
|
||||
if (is_null($this->payPalRequest)) {
|
||||
$this->payPalRequest = oxNew(\OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest::class);
|
||||
}
|
||||
|
||||
return $this->payPalRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets failure message.
|
||||
*
|
||||
* @param array $failureMessage
|
||||
*/
|
||||
public function setFailureMessage($failureMessage)
|
||||
{
|
||||
$this->failureMessage = $failureMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns failure message.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFailureMessage()
|
||||
{
|
||||
return $this->failureMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* IPN handling function.
|
||||
* - verify with PayPal.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function requestCorrect()
|
||||
{
|
||||
$request = $this->getRequest();
|
||||
$rawRequestData = $request->getPost();
|
||||
|
||||
$responseDoVerifyWithPayPal = $this->doVerifyWithPayPal($rawRequestData);
|
||||
|
||||
$ipnRequestValidator = $this->getIPNRequestValidator();
|
||||
$ipnRequestValidator->setPayPalRequest($rawRequestData);
|
||||
$ipnRequestValidator->setPayPalResponse($responseDoVerifyWithPayPal);
|
||||
$ipnRequestValidator->setShopOwnerUserName($this->getShopOwner());
|
||||
|
||||
$requestCorrect = $ipnRequestValidator->isValid();
|
||||
if (!$requestCorrect) {
|
||||
$failureMessage = $ipnRequestValidator->getValidationFailureMessage();
|
||||
$this->setFailureMessage($failureMessage);
|
||||
}
|
||||
|
||||
return $requestCorrect;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call PayPal to check if IPN request originally from PayPal.
|
||||
*
|
||||
* @param array $requestData data of request.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\Response\Response
|
||||
*/
|
||||
protected function doVerifyWithPayPal($requestData)
|
||||
{
|
||||
$callerService = $this->getCommunicationService();
|
||||
$payPalPayPalRequest = $this->getPayPalRequest();
|
||||
foreach ($requestData as $requestParameterName => $requestParameterValue) {
|
||||
$payPalPayPalRequest->setParameter($requestParameterName, $requestParameterValue);
|
||||
}
|
||||
$responseDoVerifyWithPayPal = $callerService->doVerifyWithPayPal($payPalPayPalRequest, $requestData['charset']);
|
||||
|
||||
return $responseDoVerifyWithPayPal;
|
||||
}
|
||||
}
|
||||
332
shop/source/modules/oe/oepaypal/Model/Order.php
Normal file
332
shop/source/modules/oe/oepaypal/Model/Order.php
Normal file
@@ -0,0 +1,332 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal oxOrder class
|
||||
*
|
||||
* @mixin \OxidEsales\Eshop\Application\Model\Order
|
||||
*/
|
||||
class Order extends Order_parent
|
||||
{
|
||||
/** Transaction was finished successfully. */
|
||||
const OEPAYPAL_TRANSACTION_STATUS_OK = 'OK';
|
||||
|
||||
/** Transaction is not finished or failed. */
|
||||
const OEPAYPAL_TRANSACTION_STATUS_NOT_FINISHED = 'NOT_FINISHED';
|
||||
|
||||
/**
|
||||
* PayPal order information
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Model\PayPalOrder
|
||||
*/
|
||||
protected $payPalOrder = null;
|
||||
|
||||
/**
|
||||
* Loads order associated with current PayPal order
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function loadPayPalOrder()
|
||||
{
|
||||
$orderId = \OxidEsales\Eshop\Core\Registry::getSession()->getVariable("sess_challenge");
|
||||
|
||||
// if order is not created yet - generating it
|
||||
if ($orderId === null) {
|
||||
$orderId = \OxidEsales\Eshop\Core\UtilsObject::getInstance()->generateUID();
|
||||
$this->setId($orderId);
|
||||
$this->save();
|
||||
\OxidEsales\Eshop\Core\Registry::getSession()->setVariable("sess_challenge", $orderId);
|
||||
}
|
||||
|
||||
return $this->load($orderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates order number.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function oePayPalUpdateOrderNumber()
|
||||
{
|
||||
if ($this->oxorder__oxordernr->value) {
|
||||
$updated = (bool) oxNew(\OxidEsales\Eshop\Core\Counter::class)->update($this->_getCounterIdent(), $this->oxorder__oxordernr->value);
|
||||
} else {
|
||||
$updated = $this->_setNumber();
|
||||
}
|
||||
|
||||
return $updated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete order created by current PayPal ordering process
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function deletePayPalOrder()
|
||||
{
|
||||
$result = false;
|
||||
if ($this->loadPayPalOrder()) {
|
||||
$this->getPayPalOrder()->delete();
|
||||
|
||||
$result = $this->delete();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete order together with PayPal order data.
|
||||
*
|
||||
* @param string $oxId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function delete($oxId = null)
|
||||
{
|
||||
$this->getPayPalOrder($oxId)->delete();
|
||||
|
||||
return parent::delete($oxId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates order transaction status, ID and date.
|
||||
*
|
||||
* @param string $transactionId Order transaction ID
|
||||
*/
|
||||
protected function setPaymentInfoPayPalOrder($transactionId)
|
||||
{
|
||||
// set transaction ID and payment date to order
|
||||
$db = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
|
||||
|
||||
$query = 'update oxorder set oxtransid=' . $db->quote($transactionId) . ' where oxid=' . $db->quote($this->getId());
|
||||
$db->execute($query);
|
||||
|
||||
//updating order object
|
||||
$this->oxorder__oxtransid = new \OxidEsales\Eshop\Core\Field($transactionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalizes PayPal order.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\Response\ResponseDoExpressCheckoutPayment $result PayPal results array.
|
||||
* @param \OxidEsales\Eshop\Application\Model\Basket $basket Basket object.
|
||||
* @param string $transactionMode Transaction mode Sale|Authorization.
|
||||
*/
|
||||
public function finalizePayPalOrder($result, $basket, $transactionMode)
|
||||
{
|
||||
$utilsDate = \OxidEsales\Eshop\Core\Registry::getUtilsDate();
|
||||
$date = date('Y-m-d H:i:s', $utilsDate->getTime());
|
||||
|
||||
// set order status, transaction ID and payment date to order
|
||||
$this->setPaymentInfoPayPalOrder($result->getTransactionId());
|
||||
|
||||
$currency = $result->getCurrencyCode();
|
||||
if (!$currency) {
|
||||
$currency = $this->getOrderCurrency()->name;
|
||||
}
|
||||
|
||||
// PayPal order info
|
||||
$payPalOrder = $this->getPayPalOrder();
|
||||
$payPalOrder->setOrderId($this->getId());
|
||||
$payPalOrder->setPaymentStatus('pending');
|
||||
$payPalOrder->setTransactionMode($transactionMode);
|
||||
$payPalOrder->setCurrency($currency);
|
||||
$payPalOrder->setTotalOrderSum($basket->getPrice()->getBruttoPrice());
|
||||
if ($transactionMode == 'Sale') {
|
||||
$payPalOrder->setCapturedAmount($basket->getPrice()->getBruttoPrice());
|
||||
}
|
||||
$payPalOrder->save();
|
||||
|
||||
$orderPayment = oxNew(\OxidEsales\PayPalModule\Model\OrderPayment::class);
|
||||
$orderPayment->setTransactionId($result->getTransactionId());
|
||||
$orderPayment->setCorrelationId($result->getCorrelationId());
|
||||
$orderPayment->setDate($date);
|
||||
$orderPayment->setAction(($transactionMode == 'Sale') ? 'capture' : 'authorization');
|
||||
$orderPayment->setStatus($result->getPaymentStatus());
|
||||
$orderPayment->setAmount($result->getAmount());
|
||||
$orderPayment->setCurrency($result->getCurrencyCode());
|
||||
|
||||
//Adding payment information
|
||||
$paymentList = $this->getPayPalOrder()->getPaymentList();
|
||||
$paymentList->addPayment($orderPayment);
|
||||
|
||||
//setting order payment status after
|
||||
$paymentStatusCalculator = oxNew(\OxidEsales\PayPalModule\Model\OrderPaymentStatusCalculator::class);
|
||||
$paymentStatusCalculator->setOrder($this->getPayPalOrder());
|
||||
$this->getPayPalOrder()->setPaymentStatus($paymentStatusCalculator->getStatus(), $this);
|
||||
$this->getPayPalOrder()->save();
|
||||
|
||||
//clear PayPal identification
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$session->deleteVariable('oepaypal');
|
||||
$session->deleteVariable("oepaypal-payerId");
|
||||
$session->deleteVariable("oepaypal-userId");
|
||||
$session->deleteVariable('oepaypal-basketAmount');
|
||||
}
|
||||
|
||||
/**
|
||||
* Paypal specific status checking.
|
||||
*
|
||||
* If status comes as OK, lets check real paypal payment state,
|
||||
* and if really ok, so lets set it, otherwise dont change status.
|
||||
*
|
||||
* @param string $status order transaction status
|
||||
*/
|
||||
protected function _setOrderStatus($status)
|
||||
{
|
||||
$paymentTypeObject = $this->getPaymentType();
|
||||
$paymentType = $paymentTypeObject ? $paymentTypeObject->getFieldData('oxpaymentsid') : null;
|
||||
if ($paymentType != 'oxidpaypal' || $status != self::OEPAYPAL_TRANSACTION_STATUS_OK) {
|
||||
parent::_setOrderStatus($status);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update order oxpaid to current time.
|
||||
*/
|
||||
public function markOrderPaid()
|
||||
{
|
||||
parent::_setOrderStatus(self::OEPAYPAL_TRANSACTION_STATUS_OK);
|
||||
|
||||
$db = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
|
||||
$utilsDate = \OxidEsales\Eshop\Core\Registry::getUtilsDate();
|
||||
$date = date('Y-m-d H:i:s', $utilsDate->getTime());
|
||||
|
||||
$query = 'update oxorder set oxpaid=? where oxid=?';
|
||||
$db->execute($query, array($date, $this->getId()));
|
||||
|
||||
//updating order object
|
||||
$this->oxorder__oxpaid = new \OxidEsales\Eshop\Core\Field($date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if delivery set used for current order is available and active.
|
||||
* Throws exception if not available
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Application\Model\Basket $basket basket object
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function validateDelivery($basket)
|
||||
{
|
||||
if ($basket->getPaymentId() == 'oxidpaypal') {
|
||||
$shippingId = $basket->getShippingId();
|
||||
$basketPrice = $basket->getPrice()->getBruttoPrice();
|
||||
$user = oxNew(\OxidEsales\Eshop\Application\Model\User::class);
|
||||
if (!$user->loadUserPayPalUser()) {
|
||||
$user = $this->getUser();
|
||||
}
|
||||
|
||||
$validState = null;
|
||||
if (!$this->isPayPalPaymentValid($user, $basketPrice, $shippingId)) {
|
||||
$validState = self::ORDER_STATE_INVALIDDELIVERY;
|
||||
}
|
||||
} else {
|
||||
$validState = parent::validateDelivery($basket);
|
||||
}
|
||||
|
||||
return $validState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal order object.
|
||||
*
|
||||
* @param string $oxId
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalOrder|null
|
||||
*/
|
||||
public function getPayPalOrder($oxId = null)
|
||||
{
|
||||
if (is_null($this->payPalOrder)) {
|
||||
$orderId = is_null($oxId) ? $this->getId() : $oxId;
|
||||
$order = oxNew(\OxidEsales\PayPalModule\Model\PayPalOrder::class);
|
||||
$order->load($orderId);
|
||||
$this->payPalOrder = $order;
|
||||
}
|
||||
|
||||
return $this->payPalOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get payment status
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPayPalPaymentStatus()
|
||||
{
|
||||
return $this->getPayPalOrder()->getPaymentStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal Authorization id.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthorizationId()
|
||||
{
|
||||
return $this->oxorder__oxtransid->value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether PayPal payment is available.
|
||||
*
|
||||
* @param object $user
|
||||
* @param double $basketPrice
|
||||
* @param string $shippingId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isPayPalPaymentValid($user, $basketPrice, $shippingId)
|
||||
{
|
||||
$valid = true;
|
||||
|
||||
$payPalPayment = oxNew(\OxidEsales\Eshop\Application\Model\Payment::class);
|
||||
$payPalPayment->load('oxidpaypal');
|
||||
if (!$payPalPayment->isValidPayment(null, null, $user, $basketPrice, $shippingId)) {
|
||||
$valid = $this->isEmptyPaymentValid($user, $basketPrice, $shippingId);
|
||||
}
|
||||
|
||||
return $valid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether Empty payment is available.
|
||||
*
|
||||
* @param object $user
|
||||
* @param double $basketPrice
|
||||
* @param string $shippingId
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isEmptyPaymentValid($user, $basketPrice, $shippingId)
|
||||
{
|
||||
$valid = true;
|
||||
|
||||
$emptyPayment = oxNew(\OxidEsales\Eshop\Application\Model\Payment::class);
|
||||
$emptyPayment->load('oxempty');
|
||||
if (!$emptyPayment->isValidPayment(null, null, $user, $basketPrice, $shippingId)) {
|
||||
$valid = false;
|
||||
}
|
||||
|
||||
return $valid;
|
||||
}
|
||||
}
|
||||
110
shop/source/modules/oe/oepaypal/Model/OrderActionManager.php
Normal file
110
shop/source/modules/oe/oepaypal/Model/OrderActionManager.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal order action manager class
|
||||
*/
|
||||
class OrderActionManager
|
||||
{
|
||||
/**
|
||||
* States related with transaction mode
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Model\PayPalOrder
|
||||
*/
|
||||
protected $availableActions = array(
|
||||
'Sale' => array(),
|
||||
'Authorization' => array('capture', 'reauthorize', 'void'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Order object
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Model\PayPalOrder
|
||||
*/
|
||||
protected $order = null;
|
||||
|
||||
/**
|
||||
* Sets order
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalOrder $order
|
||||
*/
|
||||
public function setOrder($order)
|
||||
{
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns order
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalOrder
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return state for given transaction mode
|
||||
*
|
||||
* @param string $mode transaction mode
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAvailableAction($mode)
|
||||
{
|
||||
$actions = $this->availableActions[$mode];
|
||||
|
||||
return $actions ? $actions : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether action is available for given order
|
||||
*
|
||||
* @param string $action
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isActionAvailable($action)
|
||||
{
|
||||
$order = $this->getOrder();
|
||||
|
||||
$availableActions = $this->getAvailableAction($order->getTransactionMode());
|
||||
|
||||
$isAvailable = in_array($action, $availableActions);
|
||||
|
||||
if ($isAvailable) {
|
||||
$isAvailable = false;
|
||||
|
||||
switch ($action) {
|
||||
case 'capture':
|
||||
case 'reauthorize':
|
||||
case 'void':
|
||||
if ($order->getRemainingOrderSum() > 0 && $order->getVoidedAmount() < $order->getRemainingOrderSum()) {
|
||||
$isAvailable = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $isAvailable;
|
||||
}
|
||||
}
|
||||
244
shop/source/modules/oe/oepaypal/Model/OrderManager.php
Normal file
244
shop/source/modules/oe/oepaypal/Model/OrderManager.php
Normal file
@@ -0,0 +1,244 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* Class \OxidEsales\PayPalModule\Model\OrderManager.
|
||||
*/
|
||||
class OrderManager
|
||||
{
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Model\OrderPayment::class
|
||||
*/
|
||||
protected $orderPayment = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Model\PayPalOrder
|
||||
*/
|
||||
protected $order = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Model\OrderPaymentStatusCalculator
|
||||
*/
|
||||
protected $orderPaymentStatusCalculator = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Model\OrderPaymentListCalculator
|
||||
*/
|
||||
protected $orderPaymentListCalculator = null;
|
||||
|
||||
/**
|
||||
* Sets order payment.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $orderPayment
|
||||
*/
|
||||
public function setOrderPayment($orderPayment)
|
||||
{
|
||||
$this->orderPayment = $orderPayment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns order payment.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPayment::class
|
||||
*/
|
||||
public function getOrderPayment()
|
||||
{
|
||||
return $this->orderPayment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets order.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalOrder $order
|
||||
*/
|
||||
public function setOrder($order)
|
||||
{
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create object \OxidEsales\PayPalModule\Model\PayPalOrder.
|
||||
* If Order is not set, create order from Order Payment.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalOrder
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
if ($this->order === null) {
|
||||
$orderPayment = $this->getOrderPayment();
|
||||
$order = $this->getOrderFromPayment($orderPayment);
|
||||
$this->setOrder($order);
|
||||
}
|
||||
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets \OxidEsales\PayPalModule\Model\OrderPaymentStatusCalculator.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPaymentStatusCalculator $orderPaymentStatusCalculator
|
||||
*/
|
||||
public function setOrderPaymentStatusCalculator($orderPaymentStatusCalculator)
|
||||
{
|
||||
$this->orderPaymentStatusCalculator = $orderPaymentStatusCalculator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns \OxidEsales\PayPalModule\Model\OrderPaymentStatusCalculator.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPaymentStatusCalculator
|
||||
*/
|
||||
public function getOrderPaymentStatusCalculator()
|
||||
{
|
||||
if (is_null($this->orderPaymentStatusCalculator)) {
|
||||
$orderPaymentStatusCalculator = oxNew(\OxidEsales\PayPalModule\Model\OrderPaymentStatusCalculator::class);
|
||||
$this->setOrderPaymentStatusCalculator($orderPaymentStatusCalculator);
|
||||
}
|
||||
|
||||
return $this->orderPaymentStatusCalculator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets \OxidEsales\PayPalModule\Model\OrderPaymentListCalculator.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPaymentListCalculator $orderPaymentListCalculator
|
||||
*/
|
||||
public function setOrderPaymentListCalculator($orderPaymentListCalculator)
|
||||
{
|
||||
$this->orderPaymentListCalculator = $orderPaymentListCalculator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns \OxidEsales\PayPalModule\Model\OrderPaymentListCalculator.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPaymentListCalculator
|
||||
*/
|
||||
public function getOrderPaymentListCalculator()
|
||||
{
|
||||
if (is_null($this->orderPaymentListCalculator)) {
|
||||
$orderPaymentListCalculator = oxNew(\OxidEsales\PayPalModule\Model\OrderPaymentListCalculator::class);
|
||||
$this->setOrderPaymentListCalculator($orderPaymentListCalculator);
|
||||
}
|
||||
|
||||
return $this->orderPaymentListCalculator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update order manager to status get from order status calculator.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function updateOrderStatus()
|
||||
{
|
||||
$orderUpdated = false;
|
||||
$order = $this->getOrder();
|
||||
|
||||
if (!is_null($order)) {
|
||||
$orderPayment = $this->getOrderPayment();
|
||||
$order = $this->recalculateAmounts($order);
|
||||
$newOrderStatus = $this->calculateOrderStatus($orderPayment, $order);
|
||||
$this->persistNewOrderStatus($order, $newOrderStatus);
|
||||
$orderUpdated = true;
|
||||
}
|
||||
|
||||
return $orderUpdated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recalculate order amounts from connected PayPal payment list.
|
||||
* This is especially needed if some new PayPal order payment
|
||||
* entry was created by IPN handler or if we e.g. got a void
|
||||
* on an existing authorization by IPN.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalOrder $order
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function recalculateAmounts($order)
|
||||
{
|
||||
$paymentList = $order->getPaymentList();
|
||||
$orderPaymentListCalculator = $this->getOrderPaymentListCalculator();
|
||||
$orderPaymentListCalculator->setPaymentList($paymentList);
|
||||
$orderPaymentListCalculator->calculate();
|
||||
|
||||
$order->setCapturedAmount($orderPaymentListCalculator->getCapturedAmount());
|
||||
$order->setVoidedAmount($orderPaymentListCalculator->getVoidedAmount());
|
||||
$order->setRefundedAmount($orderPaymentListCalculator->getRefundedAmount());
|
||||
$order->save();
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for order payment calculator.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $orderPayment Order payment to set to calculator.
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalOrder $order Order to be set to validator.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
protected function calculateOrderStatus($orderPayment, $order)
|
||||
{
|
||||
$orderPaymentStatusCalculator = $this->getOrderPaymentStatusCalculator();
|
||||
$orderPaymentStatusCalculator->setOrderPayment($orderPayment);
|
||||
$orderPaymentStatusCalculator->setOrder($order);
|
||||
|
||||
$newOrderStatus = $orderPaymentStatusCalculator->getStatus();
|
||||
|
||||
return $newOrderStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update order to given status.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalOrder $order Order to be updated.
|
||||
* @param string $newOrderStatus New order status.
|
||||
*/
|
||||
protected function persistNewOrderStatus($order, $newOrderStatus)
|
||||
{
|
||||
$order->setPaymentStatus($newOrderStatus);
|
||||
$order->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load order by order id from order payment.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $orderPayment order payment to get order id.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalOrder|null
|
||||
*/
|
||||
protected function getOrderFromPayment($orderPayment)
|
||||
{
|
||||
$orderId = null;
|
||||
$order = null;
|
||||
if (!is_null($orderPayment)) {
|
||||
$orderId = $orderPayment->getOrderId();
|
||||
}
|
||||
if (!is_null($orderId)) {
|
||||
$order = oxNew(\OxidEsales\PayPalModule\Model\PayPalOrder::class);
|
||||
$order->setOrderId($orderId);
|
||||
$order->load();
|
||||
}
|
||||
|
||||
return $order;
|
||||
}
|
||||
}
|
||||
373
shop/source/modules/oe/oepaypal/Model/OrderPayment.php
Normal file
373
shop/source/modules/oe/oepaypal/Model/OrderPayment.php
Normal file
@@ -0,0 +1,373 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal order payment class.
|
||||
*/
|
||||
class OrderPayment extends \OxidEsales\PayPalModule\Core\Model
|
||||
{
|
||||
/**
|
||||
* Set PayPal order comment Id.
|
||||
*
|
||||
* @param string $paymentId
|
||||
*/
|
||||
public function setId($paymentId)
|
||||
{
|
||||
$this->setPaymentId($paymentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PayPal comment Id.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->getPaymentId();
|
||||
}
|
||||
|
||||
/**
|
||||
* If Payment is valid.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $isValid = true;
|
||||
|
||||
/**
|
||||
* Payment comments
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commentList = null;
|
||||
|
||||
|
||||
/**
|
||||
* Set PayPal order comment Id.
|
||||
*
|
||||
* @param string $paymentId
|
||||
*/
|
||||
public function setPaymentId($paymentId)
|
||||
{
|
||||
$this->setValue('oepaypal_paymentid', $paymentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PayPal comment Id.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPaymentId()
|
||||
{
|
||||
return $this->getValue('oepaypal_paymentid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PayPal payment actions.
|
||||
*
|
||||
* @param string $value
|
||||
*/
|
||||
public function setAction($value)
|
||||
{
|
||||
$this->setValue('oepaypal_action', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal payment action.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAction()
|
||||
{
|
||||
return $this->getValue('oepaypal_action');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PayPal payment OrderId.
|
||||
*
|
||||
* @param string $value
|
||||
*/
|
||||
public function setOrderId($value)
|
||||
{
|
||||
$this->setValue('oepaypal_orderid', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal payment OrderId.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOrderId()
|
||||
{
|
||||
return $this->getValue('oepaypal_orderid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PayPal payment amount
|
||||
*
|
||||
* @param float $value
|
||||
*/
|
||||
public function setAmount($value)
|
||||
{
|
||||
$this->setValue('oepaypal_amount', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal payment amount.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getAmount()
|
||||
{
|
||||
return $this->getValue('oepaypal_amount');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PayPal refunded amount.
|
||||
*
|
||||
* @param double $amount
|
||||
*/
|
||||
public function setRefundedAmount($amount)
|
||||
{
|
||||
$this->setValue('oepaypal_refundedamount', $amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds given amount to PayPal refunded amount.
|
||||
*
|
||||
* @param double $amount
|
||||
*/
|
||||
public function addRefundedAmount($amount)
|
||||
{
|
||||
$this->setRefundedAmount($amount + $this->getRefundedAmount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PayPal refunded amount
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function getRefundedAmount()
|
||||
{
|
||||
return (double) $this->getValue('oepaypal_refundedamount');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns not yet captured (remaining) order sum
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRemainingRefundAmount()
|
||||
{
|
||||
$amount = $this->getAmount() - $this->getRefundedAmount();
|
||||
|
||||
return sprintf("%.2f", round($amount, 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal payment status.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
return $this->getValue('oepaypal_status');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal payment status.
|
||||
*
|
||||
* @param string $value status
|
||||
*/
|
||||
public function setStatus($value)
|
||||
{
|
||||
$this->setValue('oepaypal_status', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PayPal payment date.
|
||||
*
|
||||
* @param string $value
|
||||
*/
|
||||
public function setDate($value)
|
||||
{
|
||||
$this->setValue('oepaypal_date', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal payment date.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDate()
|
||||
{
|
||||
return $this->getValue('oepaypal_date');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal payment currency.
|
||||
*
|
||||
* @param string $currency
|
||||
*/
|
||||
public function setCurrency($currency)
|
||||
{
|
||||
$this->setValue('oepaypal_currency', $currency);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PayPal payment currency
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrency()
|
||||
{
|
||||
return $this->getValue('oepaypal_currency');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PayPal payment transaction id.
|
||||
*
|
||||
* @param string $transactionId
|
||||
*/
|
||||
public function setTransactionId($transactionId)
|
||||
{
|
||||
$this->setValue('oepaypal_transactionid', $transactionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal payment transaction id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTransactionId()
|
||||
{
|
||||
return $this->getValue('oepaypal_transactionid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PayPal payment correlation id
|
||||
*
|
||||
* @param string $correlationId
|
||||
*/
|
||||
public function setCorrelationId($correlationId)
|
||||
{
|
||||
$this->setValue('oepaypal_correlationid', $correlationId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal payment correlation id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCorrelationId()
|
||||
{
|
||||
return $this->getValue('oepaypal_correlationid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load payment data by given transaction id
|
||||
*
|
||||
* @param string $transactionId transaction id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function loadByTransactionId($transactionId)
|
||||
{
|
||||
$result = false;
|
||||
$data = $this->getDbGateway()->loadByTransactionId($transactionId);
|
||||
if ($data) {
|
||||
$this->setData($data);
|
||||
$result = true;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if payment is valid.
|
||||
*
|
||||
* @param boolean $isValid payment is valid.
|
||||
*/
|
||||
public function setIsValid($isValid)
|
||||
{
|
||||
$this->isValid = (bool) $isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if payment pass validation.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getIsValid()
|
||||
{
|
||||
return $this->isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get comments
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCommentList()
|
||||
{
|
||||
if (is_null($this->commentList)) {
|
||||
$comments = oxNew(\OxidEsales\PayPalModule\Model\OrderPaymentCommentList::class);
|
||||
$comments->load($this->getPaymentId());
|
||||
$this->setCommentList($comments);
|
||||
}
|
||||
|
||||
return $this->commentList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set comments.
|
||||
*
|
||||
* @param array $comments
|
||||
*/
|
||||
public function setCommentList($comments)
|
||||
{
|
||||
$this->commentList = $comments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add comment.
|
||||
*
|
||||
* @param \oePaypalOrderPaymentComment $comment comment
|
||||
*/
|
||||
public function addComment($comment)
|
||||
{
|
||||
$this->getCommentList()->addComment($comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return database gateway.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\DbGateways\OrderPaymentDbGateway|\OxidEsales\PayPalModule\Core\ModelDbGateway
|
||||
*/
|
||||
protected function getDbGateway()
|
||||
{
|
||||
if (is_null($this->dbGateway)) {
|
||||
$this->setDbGateway(oxNew(\OxidEsales\PayPalModule\Model\DbGateways\OrderPaymentDbGateway::class));
|
||||
}
|
||||
|
||||
return $this->dbGateway;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal Order payment action manager class
|
||||
*/
|
||||
class OrderPaymentActionManager
|
||||
{
|
||||
/**
|
||||
* Array of available actions for payment action.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $availableActions = array(
|
||||
"capture" => array(
|
||||
"Completed" => array(
|
||||
'refund'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Order object.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Model\OrderPayment
|
||||
*/
|
||||
protected $payment = null;
|
||||
|
||||
/**
|
||||
* Sets order.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $payment
|
||||
*/
|
||||
public function setPayment($payment)
|
||||
{
|
||||
$this->payment = $payment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns order.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPayment
|
||||
*/
|
||||
public function getPayment()
|
||||
{
|
||||
return $this->payment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns available actions for given payment action
|
||||
*
|
||||
* @param string $paymentAction
|
||||
* @param string $paymentStatus
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAvailableActions($paymentAction, $paymentStatus)
|
||||
{
|
||||
$actions = $this->availableActions[$paymentAction][$paymentStatus];
|
||||
|
||||
return $actions ? $actions : array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks whether action is available for given order
|
||||
*
|
||||
* @param string $action
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $payment
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isActionAvailable($action, $payment = null)
|
||||
{
|
||||
if ($payment) {
|
||||
$this->setPayment($payment);
|
||||
}
|
||||
|
||||
$payment = $this->getPayment();
|
||||
|
||||
$isAvailable = in_array($action, $this->getAvailableActions($payment->getAction(), $payment->getStatus()));
|
||||
|
||||
if ($isAvailable) {
|
||||
$isAvailable = false;
|
||||
|
||||
switch ($action) {
|
||||
case 'refund':
|
||||
$isAvailable = ($payment->getAmount() > $payment->getRefundedAmount());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $isAvailable;
|
||||
}
|
||||
}
|
||||
151
shop/source/modules/oe/oepaypal/Model/OrderPaymentComment.php
Normal file
151
shop/source/modules/oe/oepaypal/Model/OrderPaymentComment.php
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal order payment comment class
|
||||
*/
|
||||
class OrderPaymentComment extends \OxidEsales\PayPalModule\Core\Model
|
||||
{
|
||||
/**
|
||||
* Sets date value.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$utilsDate = \OxidEsales\Eshop\Core\Registry::getUtilsDate();
|
||||
|
||||
$this->setValue('oepaypal_date', date('Y-m-d H:i:s', $utilsDate->getTime()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets comment id.
|
||||
*
|
||||
* @param string $commentId
|
||||
*/
|
||||
public function setId($commentId)
|
||||
{
|
||||
$this->setCommentId($commentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns comment id.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->getCommentId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PayPal order comment Id
|
||||
*
|
||||
* @param string $commentId
|
||||
*/
|
||||
public function setCommentId($commentId)
|
||||
{
|
||||
$this->setValue('oepaypal_commentid', $commentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PayPal comment Id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCommentId()
|
||||
{
|
||||
return $this->getValue('oepaypal_commentid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PayPal order payment Id
|
||||
*
|
||||
* @param string $paymentId
|
||||
*/
|
||||
public function setPaymentId($paymentId)
|
||||
{
|
||||
$this->setValue('oepaypal_paymentid', $paymentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PayPal order payment Id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPaymentId()
|
||||
{
|
||||
return $this->getValue('oepaypal_paymentid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set date
|
||||
*
|
||||
* @param string $date
|
||||
*/
|
||||
public function setDate($date)
|
||||
{
|
||||
$this->setValue('oepaypal_date', $date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get date
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDate()
|
||||
{
|
||||
return $this->getValue('oepaypal_date');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set comment
|
||||
*
|
||||
* @param string $comment
|
||||
*/
|
||||
public function setComment($comment)
|
||||
{
|
||||
$this->setValue('oepaypal_comment', $comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get comment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getComment()
|
||||
{
|
||||
return $this->getValue('oepaypal_comment');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return database gateway
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\DbGateways\OrderPaymentCommentDbGateway|\OxidEsales\PayPalModule\Core\ModelDbGateway
|
||||
*/
|
||||
protected function getDbGateway()
|
||||
{
|
||||
if (is_null($this->dbGateway)) {
|
||||
$this->setDbGateway(oxNew(\OxidEsales\PayPalModule\Model\DbGateways\OrderPaymentCommentDbGateway::class));
|
||||
}
|
||||
|
||||
return $this->dbGateway;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal order payment comment list class
|
||||
*/
|
||||
class OrderPaymentCommentList extends \OxidEsales\PayPalModule\Core\PayPalList
|
||||
{
|
||||
/**
|
||||
* Data base gateway
|
||||
*
|
||||
* @var oePayPalPayPalDbGateway
|
||||
*/
|
||||
protected $dbGateway = null;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $paymentId = null;
|
||||
|
||||
/**
|
||||
* Sets payment id.
|
||||
*
|
||||
* @param string $paymentId
|
||||
*/
|
||||
public function setPaymentId($paymentId)
|
||||
{
|
||||
$this->paymentId = $paymentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns payment id.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getPaymentId()
|
||||
{
|
||||
return $this->paymentId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns DB gateway. If it's not set- creates object and sets.
|
||||
*
|
||||
* @return oePayPalPayPalDbGateway
|
||||
*/
|
||||
protected function getDbGateway()
|
||||
{
|
||||
if (is_null($this->dbGateway)) {
|
||||
$this->setDbGateway(oxNew(\OxidEsales\PayPalModule\Model\DbGateways\OrderPaymentCommentDbGateway::class));
|
||||
}
|
||||
|
||||
return $this->dbGateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set model database gateway.
|
||||
*
|
||||
* @param object $dbGateway
|
||||
*/
|
||||
protected function setDbGateway($dbGateway)
|
||||
{
|
||||
$this->dbGateway = $dbGateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects and loads order payment history.
|
||||
*
|
||||
* @param string $paymentId Order id.
|
||||
*/
|
||||
public function load($paymentId)
|
||||
{
|
||||
$this->setPaymentId($paymentId);
|
||||
|
||||
$comments = array();
|
||||
$commentsData = $this->getDbGateway()->getList($this->getPaymentId());
|
||||
if (is_array($commentsData) && count($commentsData)) {
|
||||
$comments = array();
|
||||
foreach ($commentsData as $data) {
|
||||
$comment = oxNew(\OxidEsales\PayPalModule\Model\OrderPaymentComment::class);
|
||||
$comment->setData($data);
|
||||
$comments[] = $comment;
|
||||
}
|
||||
}
|
||||
|
||||
$this->setArray($comments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add comment.
|
||||
*
|
||||
* @param object $comment
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function addComment($comment)
|
||||
{
|
||||
$comment->setPaymentId($this->getPaymentId());
|
||||
$comment->save();
|
||||
|
||||
$this->load($this->getPaymentId());
|
||||
|
||||
return $comment;
|
||||
}
|
||||
}
|
||||
168
shop/source/modules/oe/oepaypal/Model/OrderPaymentList.php
Normal file
168
shop/source/modules/oe/oepaypal/Model/OrderPaymentList.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal order payment list class
|
||||
*/
|
||||
class OrderPaymentList extends \OxidEsales\PayPalModule\Core\PayPalList
|
||||
{
|
||||
/**
|
||||
* Data base gateway
|
||||
*
|
||||
* @var oePayPalPayPalDbGateway
|
||||
*/
|
||||
protected $dbGateway = null;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $orderId = null;
|
||||
|
||||
/**
|
||||
* Sets order id.
|
||||
*
|
||||
* @param string $orderId
|
||||
*/
|
||||
public function setOrderId($orderId)
|
||||
{
|
||||
$this->orderId = $orderId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns order id.
|
||||
*
|
||||
* @return null|string
|
||||
*/
|
||||
public function getOrderId()
|
||||
{
|
||||
return $this->orderId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns oePayPalPayPalDbGateway or creates and sets it if it was not set.
|
||||
*
|
||||
* @return oePayPalPayPalDbGateway
|
||||
*/
|
||||
protected function getDbGateway()
|
||||
{
|
||||
if (is_null($this->dbGateway)) {
|
||||
$this->setDbGateway(oxNew(\OxidEsales\PayPalModule\Model\DbGateways\OrderPaymentDbGateway::class));
|
||||
}
|
||||
|
||||
return $this->dbGateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set model database gateway.
|
||||
*
|
||||
* @param object $dbGateway
|
||||
*/
|
||||
protected function setDbGateway($dbGateway)
|
||||
{
|
||||
$this->dbGateway = $dbGateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects and loads order payment history.
|
||||
*
|
||||
* @param string $orderId Order id.
|
||||
*/
|
||||
public function load($orderId)
|
||||
{
|
||||
$this->setOrderId($orderId);
|
||||
|
||||
$payments = array();
|
||||
$paymentsData = $this->getDbGateway()->getList($this->getOrderId());
|
||||
if (is_array($paymentsData) && count($paymentsData)) {
|
||||
$payments = array();
|
||||
foreach ($paymentsData as $data) {
|
||||
$payment = oxNew(\OxidEsales\PayPalModule\Model\OrderPayment::class);
|
||||
$payment->setData($data);
|
||||
$payments[] = $payment;
|
||||
}
|
||||
}
|
||||
|
||||
$this->setArray($payments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if list has payment with defined status.
|
||||
*
|
||||
* @param string $status Payment status.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function hasPaymentWithStatus($status)
|
||||
{
|
||||
$hasStatus = false;
|
||||
$payments = $this->getArray();
|
||||
|
||||
foreach ($payments as $payment) {
|
||||
if ($status == $payment->getStatus()) {
|
||||
$hasStatus = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $hasStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if list has pending payment.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPendingPayment()
|
||||
{
|
||||
return $this->hasPaymentWithStatus('Pending');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if list has failed payment.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasFailedPayment()
|
||||
{
|
||||
return $this->hasPaymentWithStatus('Failed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns not yet captured (remaining) order sum.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $payment order payment
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPayment
|
||||
*/
|
||||
public function addPayment(\OxidEsales\PayPalModule\Model\OrderPayment $payment)
|
||||
{
|
||||
//order payment info
|
||||
if ($this->getOrderId()) {
|
||||
$payment->setOrderId($this->getOrderId());
|
||||
$payment->save();
|
||||
}
|
||||
|
||||
$this->load($this->getOrderId());
|
||||
|
||||
return $payment;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* Class \OxidEsales\PayPalModule\Model\OrderPaymentListCalculator
|
||||
*/
|
||||
class OrderPaymentListCalculator
|
||||
{
|
||||
/** @var \OxidEsales\PayPalModule\Model\OrderPaymentList */
|
||||
private $paymentList = array();
|
||||
|
||||
/** @var float Amount of void action. */
|
||||
private $voidedAmount = 0.0;
|
||||
|
||||
/** @var float Amount of voided authorization action. */
|
||||
private $voidedAuthAmount = 0.0;
|
||||
|
||||
/**@var float Amount of capture action. */
|
||||
private $capturedAmount = 0.0;
|
||||
|
||||
/** @var float Amount of refund action. */
|
||||
private $refundedAmount = 0.0;
|
||||
|
||||
/** @var array Payment and status match. */
|
||||
private $paymentMatch = array(
|
||||
'capturedAmount' => array(
|
||||
'action' => array('capture'),
|
||||
'status' => array('Completed')
|
||||
),
|
||||
'refundedAmount' => array(
|
||||
'action' => array('refund'),
|
||||
'status' => array('Refunded')
|
||||
),
|
||||
'voidedAuthAmount' => array(
|
||||
'action' => array('authorization'),
|
||||
'status' => array('Voided')
|
||||
),
|
||||
'voidedAmount' => array(
|
||||
'action' => array('void'),
|
||||
'status' => array('Voided')
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Sets paypal order payment list.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPaymentList $paymentList
|
||||
*/
|
||||
public function setPaymentList($paymentList)
|
||||
{
|
||||
$this->paymentList = $paymentList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for paypal order payment list.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPaymentList
|
||||
*/
|
||||
public function getPaymentList()
|
||||
{
|
||||
return $this->paymentList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sum up payment amounts for capture, void, refund.
|
||||
* Take into account successful transactions only.
|
||||
*/
|
||||
public function calculate()
|
||||
{
|
||||
$this->init();
|
||||
|
||||
foreach ($this->getPaymentList() as $payment) {
|
||||
$status = $payment->getStatus();
|
||||
$action = $payment->getAction();
|
||||
$amount = $payment->getAmount();
|
||||
|
||||
$this->aggregateAmounts($action, $status, $amount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for captured amount
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getCapturedAmount()
|
||||
{
|
||||
return $this->capturedAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for refunded amount
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getRefundedAmount()
|
||||
{
|
||||
return $this->refundedAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for voided amount.
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getVoidedAmount()
|
||||
{
|
||||
$return = 0.0;
|
||||
|
||||
if (0 < $this->voidedAmount) {
|
||||
//void action is only logged when executed via shop admin
|
||||
$return = $this->voidedAmount;
|
||||
} elseif (0 < $this->voidedAuthAmount) {
|
||||
//no data from void actions means we might have a voided Authorization
|
||||
$return = $this->voidedAuthAmount - $this->capturedAmount;
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize results.
|
||||
* Needs to be done e.g. before calling calculate.
|
||||
*/
|
||||
private function init()
|
||||
{
|
||||
foreach (array_keys($this->paymentMatch) as $target) {
|
||||
$this->$target = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $action PayPal order payment action type (e.g. cpture, refund, void)
|
||||
* @param string $status PayPal order payment status.
|
||||
* @param double $amount PayPal order payment amount.
|
||||
*/
|
||||
private function aggregateAmounts($action, $status, $amount)
|
||||
{
|
||||
foreach ($this->paymentMatch as $target => $check) {
|
||||
if (in_array($action, $check['action']) && in_array($status, $check['status'])) {
|
||||
$this->$target += $amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* Class for calculation PayPal order statuses after IPN and order creations.
|
||||
* Also calculates statuses for suggestion on void, refund, capture operation on PayPal order.
|
||||
*/
|
||||
class OrderPaymentStatusCalculator
|
||||
{
|
||||
/**
|
||||
* PayPal Order.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Model\PayPalOrder
|
||||
*/
|
||||
protected $order = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Model\OrderPayment::class
|
||||
*/
|
||||
protected $orderPayment = null;
|
||||
|
||||
/**
|
||||
* Set PayPal Order.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalOrder $order PayPal order
|
||||
*/
|
||||
public function setOrder($order)
|
||||
{
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return PayPal Order.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalOrder
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PayPal OrderPayment.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $orderPayment
|
||||
*/
|
||||
public function setOrderPayment($orderPayment)
|
||||
{
|
||||
$this->orderPayment = $orderPayment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return PayPal OrderPayment.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPayment::class
|
||||
*/
|
||||
public function getOrderPayment()
|
||||
{
|
||||
return $this->orderPayment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return status for suggestion on void operation.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function getSuggestStatusOnVoid()
|
||||
{
|
||||
$status = 'canceled';
|
||||
|
||||
if ($this->getOrder()->getCapturedAmount() > 0) {
|
||||
$status = 'completed';
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if order statuses can be changed automatically.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isOrderPaymentStatusFinal()
|
||||
{
|
||||
$orderPaymentStatus = $this->getOrder()->getPaymentStatus();
|
||||
|
||||
return $orderPaymentStatus == 'failed' || $orderPaymentStatus == 'canceled';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns order payment status which should be set after order creation or IPN.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getStatus()
|
||||
{
|
||||
if (is_null($this->getOrder())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$status = $this->getOrderPaymentStatusFinal();
|
||||
|
||||
if (is_null($status)) {
|
||||
$status = $this->getOrderPaymentStatusPaymentValid();
|
||||
}
|
||||
if (is_null($status)) {
|
||||
$status = $this->getOrderPaymentStatusPayments();
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns order suggestion for payment status on given action and on given payment.
|
||||
*
|
||||
* @param string $action - action with order payment: void, refund, capture, refund_partial, capture_partial
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSuggestStatus($action)
|
||||
{
|
||||
if (is_null($this->getOrder())) {
|
||||
return;
|
||||
}
|
||||
|
||||
$status = $this->getOrderPaymentStatusPaymentValid();
|
||||
if (is_null($status)) {
|
||||
$status = $this->getStatusByAction($action);
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns order payment status if order has final status.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function getOrderPaymentStatusFinal()
|
||||
{
|
||||
$status = null;
|
||||
if ($this->isOrderPaymentStatusFinal()) {
|
||||
$status = $this->getOrder()->getPaymentStatus();
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns order payment status by checking if set payment is valid.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function getOrderPaymentStatusPaymentValid()
|
||||
{
|
||||
$status = null;
|
||||
$orderPayment = $this->getOrderPayment();
|
||||
if (isset($orderPayment) && !$orderPayment->getIsValid()) {
|
||||
$status = 'failed';
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns order payment status calculated from existing payments.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function getOrderPaymentStatusPayments()
|
||||
{
|
||||
$status = 'completed';
|
||||
$paymentList = $this->getOrder()->getPaymentList();
|
||||
|
||||
if ($paymentList->hasPendingPayment()) {
|
||||
$status = 'pending';
|
||||
} elseif ($paymentList->hasFailedPayment()) {
|
||||
$status = 'failed';
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns order suggestion for payment status on given action.
|
||||
*
|
||||
* @param string $action performed action.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getStatusByAction($action)
|
||||
{
|
||||
$status = null;
|
||||
switch ($action) {
|
||||
case 'void':
|
||||
$status = $this->getSuggestStatusOnVoid();
|
||||
break;
|
||||
case 'refund_partial':
|
||||
case 'reauthorize':
|
||||
$status = $this->getOrder()->getPaymentStatus();
|
||||
break;
|
||||
case 'refund':
|
||||
case 'capture':
|
||||
case 'capture_partial':
|
||||
$status = 'completed';
|
||||
break;
|
||||
default:
|
||||
$status = 'completed';
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal order payment status list class
|
||||
*/
|
||||
class OrderPaymentStatusList extends \OxidEsales\PayPalModule\Core\PayPalList
|
||||
{
|
||||
/**
|
||||
* All available statuses
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected $array = array(
|
||||
'completed',
|
||||
'pending',
|
||||
'canceled',
|
||||
'failed'
|
||||
);
|
||||
|
||||
/**
|
||||
* Available statuses depending on action
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $availableStatuses = array(
|
||||
'capture' => array('completed'),
|
||||
'capture_partial' => array('completed', 'pending'),
|
||||
'refund' => array('completed', 'pending', 'canceled'),
|
||||
'refund_partial' => array('completed', 'pending', 'canceled'),
|
||||
'void' => array('completed', 'pending', 'canceled'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns the list of available statuses to choose from for admin
|
||||
*
|
||||
* @param string $action
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAvailableStatuses($action)
|
||||
{
|
||||
$list = $this->availableStatuses[$action];
|
||||
|
||||
return $list ? $list : array();
|
||||
}
|
||||
}
|
||||
103
shop/source/modules/oe/oepaypal/Model/OutOfStockValidator.php
Normal file
103
shop/source/modules/oe/oepaypal/Model/OutOfStockValidator.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal out of stock validator class
|
||||
*/
|
||||
class OutOfStockValidator
|
||||
{
|
||||
/**
|
||||
* Basket object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private $basket;
|
||||
|
||||
/**
|
||||
* Level of empty stock level
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $emptyStockLevel;
|
||||
|
||||
/**
|
||||
* Sets empty stock level.
|
||||
*
|
||||
* @param int $emptyStockLevel
|
||||
*/
|
||||
public function setEmptyStockLevel($emptyStockLevel)
|
||||
{
|
||||
$this->emptyStockLevel = $emptyStockLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns empty stock level.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getEmptyStockLevel()
|
||||
{
|
||||
return $this->emptyStockLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets basket object.
|
||||
*
|
||||
* @param object $basket
|
||||
*/
|
||||
public function setBasket($basket)
|
||||
{
|
||||
$this->basket = $basket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns basket object.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getBasket()
|
||||
{
|
||||
return $this->basket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if basket has Articles that are out of stock.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasOutOfStockArticles()
|
||||
{
|
||||
$result = false;
|
||||
|
||||
$basketContents = $this->getBasket()->getContents();
|
||||
|
||||
foreach ($basketContents as $basketItem) {
|
||||
$article = $basketItem->getArticle();
|
||||
if (($article->getStockAmount() - $basketItem->getAmount()) < $this->getEmptyStockLevel()) {
|
||||
$result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
324
shop/source/modules/oe/oepaypal/Model/PayPalOrder.php
Normal file
324
shop/source/modules/oe/oepaypal/Model/PayPalOrder.php
Normal file
@@ -0,0 +1,324 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model;
|
||||
|
||||
/**
|
||||
* PayPal PayPalOrder class
|
||||
*/
|
||||
class PayPalOrder extends \OxidEsales\PayPalModule\Core\Model
|
||||
{
|
||||
/** Completion status */
|
||||
const PAYPAL_ORDER_STATE_COMPLETED = 'completed';
|
||||
|
||||
/**
|
||||
* List of order payments.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Model\OrderPaymentList
|
||||
*/
|
||||
protected $paymentList = null;
|
||||
|
||||
/**
|
||||
* Sets order id.
|
||||
*
|
||||
* @param string $orderId
|
||||
*/
|
||||
public function setId($orderId)
|
||||
{
|
||||
$this->setOrderId($orderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns order id.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->getOrderId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PayPal order Id.
|
||||
*
|
||||
* @param string $orderId
|
||||
*/
|
||||
public function setOrderId($orderId)
|
||||
{
|
||||
$this->setValue('oepaypal_orderid', $orderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PayPal order Id.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOrderId()
|
||||
{
|
||||
return $this->getValue('oepaypal_orderid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PayPal captured amount.
|
||||
*
|
||||
* @param double $amount
|
||||
*/
|
||||
public function setCapturedAmount($amount)
|
||||
{
|
||||
$this->setValue('oepaypal_capturedamount', $amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds given amount to PayPal captured amount.
|
||||
*
|
||||
* @param double $amount
|
||||
*/
|
||||
public function addCapturedAmount($amount)
|
||||
{
|
||||
$this->setCapturedAmount($amount + $this->getCapturedAmount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PayPal captured amount.
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function getCapturedAmount()
|
||||
{
|
||||
return (double) $this->getValue('oepaypal_capturedamount');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PayPal refunded amount.
|
||||
*
|
||||
* @param double $amount
|
||||
*/
|
||||
public function setRefundedAmount($amount)
|
||||
{
|
||||
$this->setValue('oepaypal_refundedamount', $amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds given amount to PayPal refunded amount.
|
||||
*
|
||||
* @param double $amount
|
||||
*/
|
||||
public function addRefundedAmount($amount)
|
||||
{
|
||||
$this->setRefundedAmount($amount + $this->getRefundedAmount());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PayPal refunded amount.
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function getRefundedAmount()
|
||||
{
|
||||
return (double) $this->getValue('oepaypal_refundedamount');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns not yet captured (remaining) order sum.
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function getRemainingRefundAmount()
|
||||
{
|
||||
return round($this->getCapturedAmount() - $this->getRefundedAmount(), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PayPal refunded amount.
|
||||
*
|
||||
* @param double $amount
|
||||
*/
|
||||
public function setVoidedAmount($amount)
|
||||
{
|
||||
$this->setValue('oepaypal_voidedamount', $amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PayPal refunded amount.
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function getVoidedAmount()
|
||||
{
|
||||
return (double) $this->getValue('oepaypal_voidedamount');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set transaction mode.
|
||||
*
|
||||
* @param string $mode
|
||||
*/
|
||||
public function setTransactionMode($mode)
|
||||
{
|
||||
$this->setValue('oepaypal_transactionmode', $mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get transaction mode.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTransactionMode()
|
||||
{
|
||||
return $this->getValue('oepaypal_transactionmode');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set payment status.
|
||||
*
|
||||
* @param string $status
|
||||
* @param \OxidEsales\Eshop\Application\Model\Order $order Shop order object
|
||||
*/
|
||||
public function setPaymentStatus($status, \OxidEsales\Eshop\Application\Model\Order $order = null)
|
||||
{
|
||||
$this->setValue('oepaypal_paymentstatus', $status);
|
||||
|
||||
// if payment completed, set order paid
|
||||
if ($status == \OxidEsales\PayPalModule\Model\PayPalOrder::PAYPAL_ORDER_STATE_COMPLETED) {
|
||||
if (is_null($order)) {
|
||||
$order = oxNew(\OxidEsales\Eshop\Application\Model\Order::class);
|
||||
$order->load($this->getOrderId());
|
||||
}
|
||||
$order->markOrderPaid();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get payment status.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPaymentStatus()
|
||||
{
|
||||
$state = $this->getValue('oepaypal_paymentstatus');
|
||||
if (empty($state)) {
|
||||
$state = self::PAYPAL_ORDER_STATE_COMPLETED;
|
||||
}
|
||||
|
||||
return $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets total order sum.
|
||||
*
|
||||
* @param double $amount
|
||||
*/
|
||||
public function setTotalOrderSum($amount)
|
||||
{
|
||||
$this->setValue('oepaypal_totalordersum', $amount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns total order sum.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTotalOrderSum()
|
||||
{
|
||||
return $this->getValue('oepaypal_totalordersum');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns not yet captured (remaining) order sum.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRemainingOrderSum()
|
||||
{
|
||||
return $this->getTotalOrderSum() - $this->getCapturedAmount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set order currency.
|
||||
*
|
||||
* @param string $status
|
||||
*/
|
||||
public function setCurrency($status)
|
||||
{
|
||||
$this->setValue('oepaypal_currency', $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns order currency.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrency()
|
||||
{
|
||||
return $this->getValue('oepaypal_currency');
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds new payment.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\OrderPayment $payment order payment
|
||||
*/
|
||||
public function addPayment(\OxidEsales\PayPalModule\Model\OrderPayment $payment)
|
||||
{
|
||||
$paymentList = $this->getPaymentList();
|
||||
$paymentList->addPayment($payment);
|
||||
$this->setPaymentList(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return database gateway.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\DbGateways\PayPalOrderDbGateway|\OxidEsales\PayPalModule\Core\ModelDbGateway
|
||||
*/
|
||||
protected function getDbGateway()
|
||||
{
|
||||
if (is_null($this->dbGateway)) {
|
||||
$this->setDbGateway(oxNew(\OxidEsales\PayPalModule\Model\DbGateways\PayPalOrderDbGateway::class));
|
||||
}
|
||||
|
||||
return $this->dbGateway;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return order payment list.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\OrderPaymentList
|
||||
*/
|
||||
public function getPaymentList()
|
||||
{
|
||||
if (is_null($this->paymentList)) {
|
||||
$paymentList = oxNew(\OxidEsales\PayPalModule\Model\OrderPaymentList::class);
|
||||
$paymentList->load($this->getOrderId());
|
||||
$this->setPaymentList($paymentList);
|
||||
}
|
||||
|
||||
return $this->paymentList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return order payment list.
|
||||
*
|
||||
* @param oePayPal $paymentList Payment list.
|
||||
*/
|
||||
public function setPaymentList($paymentList)
|
||||
{
|
||||
$this->paymentList = $paymentList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,374 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\PayPalRequest;
|
||||
|
||||
/**
|
||||
* PayPal request builder class for do express checkout payment
|
||||
*/
|
||||
class DoExpressCheckoutPaymentRequestBuilder
|
||||
{
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
|
||||
*/
|
||||
protected $request = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Core\Config
|
||||
*/
|
||||
protected $payPalConfig = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\Eshop\Application\Model\Basket
|
||||
*/
|
||||
protected $basket = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\Eshop\Application\Model\User
|
||||
*/
|
||||
protected $user = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\Eshop\Core\Session
|
||||
*/
|
||||
protected $session = null;
|
||||
|
||||
/**
|
||||
* @var sTransactionMode : Sale or Authorization
|
||||
*/
|
||||
protected $transactionMode;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\Eshop\Application\Model\Order
|
||||
*/
|
||||
protected $order = null;
|
||||
|
||||
/**
|
||||
* @var \OxidEsales\Eshop\Core\Language
|
||||
*/
|
||||
protected $lang = null;
|
||||
|
||||
/**
|
||||
* Sets request object.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $request
|
||||
*/
|
||||
public function setRequest($request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns request object.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
if ($this->request === null) {
|
||||
$this->request = oxNew(\OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest::class);
|
||||
}
|
||||
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns request object
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\Config $config
|
||||
*/
|
||||
public function setPayPalConfig($config)
|
||||
{
|
||||
$this->payPalConfig = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns \OxidEsales\PayPalModule\Core\Config object.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Config
|
||||
*/
|
||||
public function getPayPalConfig()
|
||||
{
|
||||
return $this->payPalConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets basket.
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Application\Model\Basket $basket
|
||||
*/
|
||||
public function setBasket($basket)
|
||||
{
|
||||
$this->basket = $basket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns basket object.
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Application\Model\Basket
|
||||
*
|
||||
* @throws \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException
|
||||
*/
|
||||
public function getBasket()
|
||||
{
|
||||
if (is_null($this->basket)) {
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException $exception
|
||||
*/
|
||||
$exception = oxNew(\OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException::class);
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
return $this->basket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets order object.
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Application\Model\Order $order
|
||||
*/
|
||||
public function setOrder($order)
|
||||
{
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to return basket object, but if fails throws exception.
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Application\Model\Order
|
||||
*
|
||||
* @throws \OxidEsales\PayPalModule\Core\Exception\PayPalResponseException
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
if (is_null($this->order)) {
|
||||
/** @var \OxidEsales\PayPalModule\Core\Exception\PayPalResponseException $exception */
|
||||
$exception = oxNew(\OxidEsales\PayPalModule\Core\Exception\PayPalResponseException::class, 'OEPAYPAL_ORDER_ERROR');
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets session.
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Core\Session $session
|
||||
*/
|
||||
public function setSession($session)
|
||||
{
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns session.
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Core\Session
|
||||
*/
|
||||
public function getSession()
|
||||
{
|
||||
return $this->session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns request object.
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Core\Language $lang
|
||||
*/
|
||||
public function setLang($lang)
|
||||
{
|
||||
$this->lang = $lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns request object.
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Core\Language
|
||||
*/
|
||||
public function getLang()
|
||||
{
|
||||
if ($this->lang === null) {
|
||||
$this->lang = $this->getPayPalConfig()->getLang();
|
||||
}
|
||||
|
||||
return $this->lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets transaction mode.
|
||||
*
|
||||
* @param string $transactionMode
|
||||
*/
|
||||
public function setTransactionMode($transactionMode)
|
||||
{
|
||||
$this->transactionMode = $transactionMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns transaction mode.
|
||||
*
|
||||
* @return string $transactionMode
|
||||
*/
|
||||
public function getTransactionMode()
|
||||
{
|
||||
return $this->transactionMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets User object.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\User $user
|
||||
*/
|
||||
public function setUser($user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns User object
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Application\Model\User
|
||||
*
|
||||
* @throws \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
if (is_null($this->user)) {
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException $exception
|
||||
*/
|
||||
$exception = oxNew(\OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException::class);
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets base parameters to request.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
|
||||
*/
|
||||
public function buildRequest()
|
||||
{
|
||||
$this->addBaseParams();
|
||||
$this->addAddressParams();
|
||||
|
||||
return $this->getRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Address parameters to request.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function addAddressParams()
|
||||
{
|
||||
$user = $this->getUser();
|
||||
if (!$user) {
|
||||
return;
|
||||
}
|
||||
$request = $this->getRequest();
|
||||
|
||||
$addressId = $user->getSelectedAddressId();
|
||||
if ($addressId) {
|
||||
$address = oxNew(\OxidEsales\Eshop\Application\Model\Address::class);
|
||||
$address->load($addressId);
|
||||
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTONAME", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($address->oxaddress__oxfname->value . " " . $address->oxaddress__oxlname->value));
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOSTREET", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($address->oxaddress__oxstreet->value . " " . $address->oxaddress__oxstreetnr->value));
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOCITY", $address->oxaddress__oxcity->value);
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOZIP", $address->oxaddress__oxzip->value);
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOPHONENUM", $address->oxaddress__oxfon->value);
|
||||
|
||||
$country = oxNew(\OxidEsales\Eshop\Application\Model\Country::class);
|
||||
$country->load($address->oxaddress__oxcountryid->value);
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE", $country->oxcountry__oxisoalpha2->value);
|
||||
|
||||
if ($address->oxaddress__oxstateid->value) {
|
||||
$state = oxNew(\OxidEsales\Eshop\Application\Model\State::class);
|
||||
$state->load($address->oxaddress__oxstateid->value);
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOSTATE", $state->oxstates__oxisoalpha2->value);
|
||||
}
|
||||
} else {
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTONAME", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($user->oxuser__oxfname->value . " " . $user->oxuser__oxlname->value));
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOSTREET", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($user->oxuser__oxstreet->value . " " . $user->oxuser__oxstreetnr->value));
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOCITY", $user->oxuser__oxcity->value);
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOZIP", $user->oxuser__oxzip->value);
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOPHONENUM", $user->oxuser__oxfon->value);
|
||||
|
||||
$country = oxNew(\OxidEsales\Eshop\Application\Model\Country::class);
|
||||
$country->load($user->oxuser__oxcountryid->value);
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE", $country->oxcountry__oxisoalpha2->value);
|
||||
|
||||
if ($user->oxuser__oxstateid->value) {
|
||||
$state = oxNew(\OxidEsales\Eshop\Application\Model\State::class);
|
||||
$state->load($user->oxuser__oxstateid->value);
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOSTATE", $state->oxstates__oxisoalpha2->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets basic parameters to request.
|
||||
*/
|
||||
public function addBaseParams()
|
||||
{
|
||||
$order = $this->getOrder();
|
||||
$config = $this->getPayPalConfig();
|
||||
$basket = $this->getBasket();
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$lang = $this->getLang();
|
||||
$request = $this->getRequest();
|
||||
|
||||
$request->setParameter("TOKEN", $session->getVariable("oepaypal-token"));
|
||||
$request->setParameter("PAYERID", $session->getVariable("oepaypal-payerId"));
|
||||
|
||||
$request->setParameter("PAYMENTREQUEST_0_PAYMENTACTION", $this->getTransactionMode());
|
||||
$request->setParameter("PAYMENTREQUEST_0_AMT", $this->formatFloat($basket->getPrice()->getBruttoPrice()));
|
||||
$request->setParameter("PAYMENTREQUEST_0_CURRENCYCODE", $basket->getBasketCurrency()->name);
|
||||
// IPN notify URL for PayPal
|
||||
if (!$config->suppressIPNCallbackUrl()) {
|
||||
$request->setParameter("PAYMENTREQUEST_0_NOTIFYURL", $config->getIPNCallbackUrl());
|
||||
}
|
||||
|
||||
// payment description
|
||||
$subj = sprintf($lang->translateString("OEPAYPAL_ORDER_CONF_SUBJECT"), $order->oxorder__oxordernr->value);
|
||||
$request->setParameter("PAYMENTREQUEST_0_DESC", $subj);
|
||||
$request->setParameter("PAYMENTREQUEST_0_CUSTOM", $subj);
|
||||
|
||||
// Please do not change this place.
|
||||
// It is important to guarantee the future development of this O3-Shop extension and to keep it free of charge.
|
||||
// Thanks!
|
||||
$request->setParameter("BUTTONSOURCE", $config->getPartnerCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats given float/int value into PayPal friendly form
|
||||
*
|
||||
* @param float $in value to format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function formatFloat($in)
|
||||
{
|
||||
return sprintf("%.2f", $in);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\PayPalRequest;
|
||||
|
||||
/**
|
||||
* PayPal request builder class for get express checkout details
|
||||
*/
|
||||
class GetExpressCheckoutDetailsRequestBuilder
|
||||
{
|
||||
/**
|
||||
* PayPal Request
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
|
||||
*/
|
||||
protected $payPalRequest = null;
|
||||
|
||||
/**
|
||||
* Session object
|
||||
*
|
||||
* @var \OxidEsales\Eshop\Core\Session
|
||||
*
|
||||
* @deprecated Session property is never used in this class
|
||||
*/
|
||||
protected $session = null;
|
||||
|
||||
/** @var ?string */
|
||||
protected $token = null;
|
||||
|
||||
/**
|
||||
* Sets PayPal request object.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $request
|
||||
*/
|
||||
public function setPayPalRequest($request)
|
||||
{
|
||||
$this->payPalRequest = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal request object.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
|
||||
*/
|
||||
public function getPayPalRequest()
|
||||
{
|
||||
if ($this->payPalRequest === null) {
|
||||
$this->payPalRequest = oxNew(\OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest::class);
|
||||
}
|
||||
|
||||
return $this->payPalRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Session.
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Core\Session $session
|
||||
* @deprecated Use self::setToken to set token or omit this method if it should be taken from session
|
||||
*/
|
||||
public function setSession($session)
|
||||
{
|
||||
$this->session = $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Session.
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Core\Session
|
||||
*
|
||||
* @throws \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException
|
||||
*
|
||||
* @deprecated Session property is never used in this class
|
||||
*/
|
||||
public function getSession()
|
||||
{
|
||||
if (!$this->session) {
|
||||
/**
|
||||
* @var \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException $exception
|
||||
*/
|
||||
$exception = oxNew(\OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException::class);
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
return $this->session;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getToken(): ?string
|
||||
{
|
||||
if (!$this->token) {
|
||||
$session = \OxidEsales\Eshop\Core\Registry::getSession();
|
||||
$this->token = $session->getVariable('oepaypal-token');
|
||||
}
|
||||
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $token
|
||||
*/
|
||||
public function setToken(?string $token)
|
||||
{
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds Request.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
|
||||
*/
|
||||
public function buildRequest()
|
||||
{
|
||||
$request = $this->getPayPalRequest();
|
||||
$request->setParameter('TOKEN', $this->getToken());
|
||||
|
||||
return $request;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\PayPalRequest;
|
||||
|
||||
/**
|
||||
* PayPal request class
|
||||
*/
|
||||
class PayPalRequest
|
||||
{
|
||||
/**
|
||||
* PayPal response data
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $data = array();
|
||||
|
||||
/**
|
||||
* Sets value to data by given key.
|
||||
*
|
||||
* @param string $key Key of data value.
|
||||
* @param string $value Data value.
|
||||
*/
|
||||
public function setParameter($key, $value)
|
||||
{
|
||||
$this->data[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns value by given key.
|
||||
*
|
||||
* @param string $key Key of data value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getParameter($key)
|
||||
{
|
||||
return $this->data[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set request data.
|
||||
*
|
||||
* @param array $responseData Response data from PayPal.
|
||||
*/
|
||||
public function setData($responseData)
|
||||
{
|
||||
$this->data = $responseData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return request data.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return value from data by given key.
|
||||
*
|
||||
* @param string $key Key of data value.
|
||||
* @param string $value Data value.
|
||||
*/
|
||||
protected function setValue($key, $value)
|
||||
{
|
||||
$this->data[$key] = $value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\PayPalRequest;
|
||||
|
||||
/**
|
||||
* PayPal request builder class
|
||||
*/
|
||||
class PayPalRequestBuilder
|
||||
{
|
||||
/**
|
||||
* Request object
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
|
||||
*/
|
||||
protected $request = null;
|
||||
|
||||
/**
|
||||
* Sets Authorization id
|
||||
*
|
||||
* @param string $authorizationId
|
||||
*/
|
||||
public function setAuthorizationId($authorizationId)
|
||||
{
|
||||
$this->getRequest()->setParameter('AUTHORIZATIONID', $authorizationId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Transaction id
|
||||
*
|
||||
* @param string $transactionId
|
||||
*/
|
||||
public function setTransactionId($transactionId)
|
||||
{
|
||||
$this->getRequest()->setParameter('TRANSACTIONID', $transactionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set amount
|
||||
*
|
||||
* @param double $amount
|
||||
* @param string $currencyCode
|
||||
*/
|
||||
public function setAmount($amount, $currencyCode = null)
|
||||
{
|
||||
$this->getRequest()->setParameter('AMT', $amount);
|
||||
if (!$currencyCode) {
|
||||
$currencyCode = \OxidEsales\Eshop\Core\Registry::getConfig()->getActShopCurrencyObject()->name;
|
||||
}
|
||||
$this->getRequest()->setParameter('CURRENCYCODE', $currencyCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Capture type
|
||||
*
|
||||
* @param string $type
|
||||
*/
|
||||
public function setCompleteType($type)
|
||||
{
|
||||
$this->getRequest()->setParameter('COMPLETETYPE', $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Refund type
|
||||
*
|
||||
* @param string $type
|
||||
*/
|
||||
public function setRefundType($type)
|
||||
{
|
||||
$this->getRequest()->setParameter('REFUNDTYPE', $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Refund type
|
||||
*
|
||||
* @param string $comment
|
||||
*/
|
||||
public function setComment($comment)
|
||||
{
|
||||
$this->getRequest()->setParameter('NOTE', $comment);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return request object.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
if ($this->request === null) {
|
||||
$this->request = oxNew(\OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest::class);
|
||||
}
|
||||
|
||||
return $this->request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Request object.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $request
|
||||
*/
|
||||
public function setRequest($request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,648 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of O3-Shop Paypal module.
|
||||
*
|
||||
* O3-Shop is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* O3-Shop is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with O3-Shop. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
* @copyright Copyright (c) 2022 OXID eSales AG (https://www.oxid-esales.com)
|
||||
* @copyright Copyright (c) 2022 O3-Shop (https://www.o3-shop.com)
|
||||
* @license https://www.gnu.org/licenses/gpl-3.0 GNU General Public License 3 (GPLv3)
|
||||
*/
|
||||
|
||||
namespace OxidEsales\PayPalModule\Model\PayPalRequest;
|
||||
|
||||
/**
|
||||
* PayPal request builder class for set express checkout
|
||||
*/
|
||||
class SetExpressCheckoutRequestBuilder
|
||||
{
|
||||
/**
|
||||
* PayPal Request.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
|
||||
*/
|
||||
protected $payPalRequest = null;
|
||||
|
||||
/**
|
||||
* PayPal Config.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Core\Config
|
||||
*/
|
||||
protected $payPalConfig = null;
|
||||
|
||||
/**
|
||||
* Basket object.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Model\Basket
|
||||
*/
|
||||
protected $basket = null;
|
||||
|
||||
/**
|
||||
* User object.
|
||||
*
|
||||
* @var \OxidEsales\PayPalModule\Model\User
|
||||
*/
|
||||
protected $user = null;
|
||||
|
||||
/**
|
||||
* Language object.
|
||||
*
|
||||
* @var \OxidEsales\Eshop\Core\Language
|
||||
*/
|
||||
protected $lang = null;
|
||||
|
||||
/**
|
||||
* Url to return to after PayPal payment is done.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $returnUrl = null;
|
||||
|
||||
/**
|
||||
* Url to return to if PayPal payment was canceled.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $cancelUrl = null;
|
||||
|
||||
/**
|
||||
* Url for PayPal CallBack.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $callBackUrl = null;
|
||||
|
||||
/**
|
||||
* Show basket items in PayPal.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $showCartInPayPal = false;
|
||||
|
||||
/**
|
||||
* Transaction mode: Sale|Authorization.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $transactionMode;
|
||||
|
||||
/**
|
||||
* Maximum possible delivery costs value.
|
||||
*
|
||||
* @var double
|
||||
*/
|
||||
protected $maxDeliveryAmount = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Sets max delivery amount.
|
||||
*
|
||||
* @param double $maxDeliveryAmount
|
||||
*/
|
||||
public function setMaxDeliveryAmount($maxDeliveryAmount)
|
||||
{
|
||||
$this->maxDeliveryAmount = $maxDeliveryAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return max delivery amount.
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function getMaxDeliveryAmount()
|
||||
{
|
||||
return $this->maxDeliveryAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets PayPal request object.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest $request
|
||||
*/
|
||||
public function setPayPalRequest($request)
|
||||
{
|
||||
$this->payPalRequest = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns PayPal request object; initiates if not set.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
|
||||
*/
|
||||
public function getPayPalRequest()
|
||||
{
|
||||
if ($this->payPalRequest === null) {
|
||||
$this->payPalRequest = oxNew(\OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest::class);
|
||||
}
|
||||
|
||||
return $this->payPalRequest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns config object.
|
||||
*
|
||||
* @param \OxidEsales\PayPalModule\Core\Config $config
|
||||
*/
|
||||
public function setPayPalConfig($config)
|
||||
{
|
||||
$this->payPalConfig = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns config object.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Core\Config
|
||||
*
|
||||
* @throws \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException
|
||||
*/
|
||||
public function getPayPalConfig()
|
||||
{
|
||||
if (!$this->payPalConfig) {
|
||||
/** @var \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException $exception */
|
||||
$exception = oxNew(\OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException::class);
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
return $this->payPalConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Basket object.
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Application\Model\Basket $basket
|
||||
*/
|
||||
public function setBasket($basket)
|
||||
{
|
||||
$this->basket = $basket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns basket object.
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Application\Model\Basket
|
||||
*
|
||||
* @throws \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException
|
||||
*/
|
||||
public function getBasket()
|
||||
{
|
||||
if (is_null($this->basket)) {
|
||||
/** @var \OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException $exception */
|
||||
$exception = oxNew(\OxidEsales\PayPalModule\Core\Exception\PayPalMissingParameterException::class);
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
return $this->basket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets User object
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Application\Model\User $user
|
||||
*/
|
||||
public function setUser($user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns User object
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\User
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Language object
|
||||
*
|
||||
* @param \OxidEsales\Eshop\Core\Language $lang
|
||||
*/
|
||||
public function setLang($lang)
|
||||
{
|
||||
$this->lang = $lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Language object.
|
||||
*
|
||||
* @return \OxidEsales\Eshop\Core\Language
|
||||
*/
|
||||
public function getLang()
|
||||
{
|
||||
if (is_null($this->lang)) {
|
||||
$this->lang = $this->getPayPalConfig()->getLang();
|
||||
}
|
||||
|
||||
return $this->lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets CallBack url.
|
||||
*
|
||||
* @param string $callBackUrl
|
||||
*/
|
||||
public function setCallBackUrl($callBackUrl)
|
||||
{
|
||||
$this->callBackUrl = $callBackUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns CallBack url.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCallBackUrl()
|
||||
{
|
||||
return $this->callBackUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Cancel Url.
|
||||
*
|
||||
* @param string $cancelUrl
|
||||
*/
|
||||
public function setCancelUrl($cancelUrl)
|
||||
{
|
||||
$this->cancelUrl = $cancelUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Cancel Url.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCancelUrl()
|
||||
{
|
||||
return $this->cancelUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Return Url.
|
||||
*
|
||||
* @param string $returnUrl
|
||||
*/
|
||||
public function setReturnUrl($returnUrl)
|
||||
{
|
||||
$this->returnUrl = $returnUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Return Url.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getReturnUrl()
|
||||
{
|
||||
return $this->returnUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether to show basket in PayPal.
|
||||
*
|
||||
* @param string $showCartInPayPal
|
||||
*/
|
||||
public function setShowCartInPayPal($showCartInPayPal)
|
||||
{
|
||||
$this->showCartInPayPal = $showCartInPayPal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether to show basket in PayPal.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getShowCartInPayPal()
|
||||
{
|
||||
return $this->showCartInPayPal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Transaction mode.
|
||||
*
|
||||
* @param string $transactionMode
|
||||
*/
|
||||
public function setTransactionMode($transactionMode)
|
||||
{
|
||||
$this->transactionMode = $transactionMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Transaction mode.
|
||||
*
|
||||
* @return string $transactionMode
|
||||
*/
|
||||
public function getTransactionMode()
|
||||
{
|
||||
return $this->transactionMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds PayPal request for express checkout.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
|
||||
*/
|
||||
public function buildExpressCheckoutRequest()
|
||||
{
|
||||
$this->addBaseParams();
|
||||
$this->addCallBackUrl();
|
||||
$this->addBasketParams();
|
||||
$this->addDescriptionParams();
|
||||
$this->turnOffShippingAddressCollection();
|
||||
$this->setMaximumOrderAmount();
|
||||
|
||||
if ($this->getShowCartInPayPal()) {
|
||||
$this->addBasketItemParams();
|
||||
} else {
|
||||
$this->addBasketGrandTotalParams();
|
||||
}
|
||||
$this->addAddressParams();
|
||||
|
||||
return $this->getPayPalRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds PayPal request for standard checkout.
|
||||
*
|
||||
* @return \OxidEsales\PayPalModule\Model\PayPalRequest\PayPalRequest
|
||||
*/
|
||||
public function buildStandardCheckoutRequest()
|
||||
{
|
||||
$this->addBaseParams();
|
||||
$this->addBasketParams();
|
||||
$this->addDescriptionParams();
|
||||
$this->disableSelectingDifferentAddressInPayPal();
|
||||
$this->setMaximumOrderAmount();
|
||||
|
||||
if ($this->getShowCartInPayPal()) {
|
||||
$this->addBasketItemParams();
|
||||
} else {
|
||||
$this->addBasketGrandTotalParams();
|
||||
}
|
||||
$this->addAddressParams();
|
||||
|
||||
return $this->getPayPalRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets base parameters to request.
|
||||
*/
|
||||
public function addBaseParams()
|
||||
{
|
||||
$request = $this->getPayPalRequest();
|
||||
$payPalConfig = $this->getPayPalConfig();
|
||||
|
||||
$request->setParameter("CALLBACKVERSION", "84.0");
|
||||
$request->setParameter("LOCALECODE", $this->getLang()->translateString("OEPAYPAL_LOCALE"));
|
||||
// enabled guest buy (Buyer does not need to create a PayPal account to check out)
|
||||
$request->setParameter("SOLUTIONTYPE", ($payPalConfig->isGuestBuyEnabled() ? "Sole" : "Mark"));
|
||||
$request->setParameter("BRANDNAME", $payPalConfig->getBrandName());
|
||||
$request->setParameter("CARTBORDERCOLOR", $payPalConfig->getBorderColor());
|
||||
|
||||
$request->setParameter("RETURNURL", $this->getReturnUrl());
|
||||
$request->setParameter("CANCELURL", $this->getCancelUrl());
|
||||
|
||||
if ($logoImage = $payPalConfig->getLogoUrl()) {
|
||||
$request->setParameter("LOGOIMG", $logoImage);
|
||||
}
|
||||
|
||||
$request->setParameter("PAYMENTREQUEST_0_PAYMENTACTION", $this->getTransactionMode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds callback parameters to request.
|
||||
*/
|
||||
public function addCallBackUrl()
|
||||
{
|
||||
$request = $this->getPayPalRequest();
|
||||
|
||||
$request->setParameter("CALLBACK", $this->getCallbackUrl());
|
||||
$request->setParameter("CALLBACKTIMEOUT", 6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn off shipping address collection.
|
||||
*/
|
||||
public function turnOffShippingAddressCollection()
|
||||
{
|
||||
$this->getPayPalRequest()->setParameter("NOSHIPPING", "2");
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables selecting different address in PayPal side.
|
||||
*/
|
||||
public function disableSelectingDifferentAddressInPayPal()
|
||||
{
|
||||
$this->getPayPalRequest()->setParameter("ADDROVERRIDE", "1");
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculating maximum order amount
|
||||
* and adding all used discounts (needed because of bug in PayPal - somehow it substract discount from MAXAMT)
|
||||
* additionally +1 as PayPal recommends this value a little bit greater than original.
|
||||
*/
|
||||
public function setMaximumOrderAmount()
|
||||
{
|
||||
$basket = $this->getBasket();
|
||||
$request = $this->getPayPalRequest();
|
||||
|
||||
$request->setParameter("MAXAMT", $this->formatFloat(($basket->getPrice()->getBruttoPrice() + $basket->getDiscountSumPayPalBasket() + $this->getMaxDeliveryAmount() + 1)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets basket parameters to request.
|
||||
*/
|
||||
public function addBasketParams()
|
||||
{
|
||||
$request = $this->getPayPalRequest();
|
||||
$basket = $this->getBasket();
|
||||
|
||||
$virtualBasket = $basket->isVirtualPayPalBasket();
|
||||
|
||||
// only downloadable products? missing getter on oxBasket yet
|
||||
$request->setParameter("NOSHIPPING", $virtualBasket ? "1" : "0");
|
||||
|
||||
if ($virtualBasket) {
|
||||
$request->setParameter("REQCONFIRMSHIPPING", "0");
|
||||
}
|
||||
// passing basket VAT (tax) value. It is required as in Net mode articles are without VAT, but basket is with VAT.
|
||||
// PayPal need this value to check if all articles sum match basket sum.
|
||||
if ($basket->isCalculationModeNetto()) {
|
||||
$request->setParameter("PAYMENTREQUEST_0_TAXAMT", $this->formatFloat($basket->getPayPalBasketVatValue()));
|
||||
}
|
||||
|
||||
$request->setParameter("PAYMENTREQUEST_0_AMT", $this->formatFloat($basket->getPrice()->getBruttoPrice()));
|
||||
$request->setParameter("PAYMENTREQUEST_0_CURRENCYCODE", $basket->getBasketCurrency()->name);
|
||||
$request->setParameter("PAYMENTREQUEST_0_ITEMAMT", $this->formatFloat($basket->getSumOfCostOfAllItemsPayPalBasket()));
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPPINGAMT", $this->formatFloat($basket->getDeliveryCosts()));
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPDISCAMT", $this->formatFloat($basket->getDiscountSumPayPalBasket() * -1));
|
||||
|
||||
$delivery = oxNew(\OxidEsales\Eshop\Application\Model\DeliverySet::class);
|
||||
$deliveryName = ($delivery->load($basket->getShippingId())) ? $delivery->oxdeliveryset__oxtitle->value : "#1";
|
||||
|
||||
$request->setParameter("L_SHIPPINGOPTIONISDEFAULT0", "true");
|
||||
$request->setParameter("L_SHIPPINGOPTIONNAME0", $deliveryName);
|
||||
$request->setParameter("L_SHIPPINGOPTIONAMOUNT0", $this->formatFloat($basket->getDeliveryCosts()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets transaction description parameters.
|
||||
*/
|
||||
public function addDescriptionParams()
|
||||
{
|
||||
$basket = $this->getBasket();
|
||||
$config = $this->getPayPalConfig();
|
||||
$request = $this->getPayPalRequest();
|
||||
|
||||
// description
|
||||
$shopNameFull = $config->getBrandName();
|
||||
$shopName = substr($shopNameFull, 0, 70);
|
||||
if ($shopNameFull != $shopName) {
|
||||
$shopName .= "...";
|
||||
}
|
||||
|
||||
$subj = sprintf($this->getLang()->translateString("OEPAYPAL_ORDER_SUBJECT"), $shopName, $basket->getFPrice(), $basket->getBasketCurrency()->name);
|
||||
$request->setParameter("PAYMENTREQUEST_0_DESC", $subj);
|
||||
$request->setParameter("PAYMENTREQUEST_0_CUSTOM", $subj);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets basket items parameters to request.
|
||||
*/
|
||||
public function addBasketItemParams()
|
||||
{
|
||||
$basket = $this->getBasket();
|
||||
$lang = $this->getLang();
|
||||
$request = $this->getPayPalRequest();
|
||||
|
||||
$pos = 0;
|
||||
foreach ($basket->getContents() as $basketItem) {
|
||||
$request->setParameter("L_PAYMENTREQUEST_0_NAME{$pos}", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($basketItem->getTitle()));
|
||||
$request->setParameter("L_PAYMENTREQUEST_0_AMT{$pos}", $this->formatFloat($basketItem->getUnitPrice()->getPrice()));
|
||||
$request->setParameter("L_PAYMENTREQUEST_0_QTY{$pos}", (int) $basketItem->getAmount());
|
||||
$request->setParameter("L_PAYMENTREQUEST_0_ITEMURL{$pos}", $basketItem->getLink());
|
||||
|
||||
$basketProduct = $basketItem->getArticle();
|
||||
$request->setParameter("L_PAYMENTREQUEST_0_NUMBER{$pos}", $basketProduct->oxarticles__oxartnum->value);
|
||||
|
||||
$pos++;
|
||||
}
|
||||
|
||||
//adding payment costs as product
|
||||
if ($basket->getPayPalPaymentCosts() > 0) {
|
||||
$paymentTitle = $lang->translateString("OEPAYPAL_SURCHARGE") . " " . $lang->translateString("OEPAYPAL_TYPE_OF_PAYMENT");
|
||||
$request->setParameter("L_PAYMENTREQUEST_0_NAME{$pos}", $paymentTitle);
|
||||
$request->setParameter("L_PAYMENTREQUEST_0_AMT{$pos}", $this->formatFloat($basket->getPayPalPaymentCosts()));
|
||||
$request->setParameter("L_PAYMENTREQUEST_0_QTY{$pos}", 1);
|
||||
|
||||
$pos++;
|
||||
}
|
||||
|
||||
//adding wrapping as product
|
||||
if ($basket->getPayPalWrappingCosts() > 0) {
|
||||
$request->setParameter("L_PAYMENTREQUEST_0_NAME{$pos}", $lang->translateString("OEPAYPAL_GIFTWRAPPER"));
|
||||
$request->setParameter("L_PAYMENTREQUEST_0_AMT{$pos}", $this->formatFloat($basket->getPayPalWrappingCosts()));
|
||||
$request->setParameter("L_PAYMENTREQUEST_0_QTY{$pos}", 1);
|
||||
|
||||
$pos++;
|
||||
}
|
||||
|
||||
//adding greeting card as product
|
||||
if ($basket->getPayPalGiftCardCosts() > 0) {
|
||||
$request->setParameter("L_PAYMENTREQUEST_0_NAME{$pos}", $lang->translateString("OEPAYPAL_GREETING_CARD"));
|
||||
$request->setParameter("L_PAYMENTREQUEST_0_AMT{$pos}", $this->formatFloat($basket->getPayPalGiftCardCosts()));
|
||||
$request->setParameter("L_PAYMENTREQUEST_0_QTY{$pos}", 1);
|
||||
|
||||
$pos++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets basket Grand Total params to request.
|
||||
*/
|
||||
public function addBasketGrandTotalParams()
|
||||
{
|
||||
$basket = $this->getBasket();
|
||||
$request = $this->getPayPalRequest();
|
||||
|
||||
$request->setParameter("L_PAYMENTREQUEST_0_NAME0", $this->getLang()->translateString("OEPAYPAL_GRAND_TOTAL"));
|
||||
$request->setParameter("L_PAYMENTREQUEST_0_AMT0", $this->formatFloat($basket->getSumOfCostOfAllItemsPayPalBasket()));
|
||||
$request->setParameter("L_PAYMENTREQUEST_0_QTY0", 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Address parameters to request.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function addAddressParams()
|
||||
{
|
||||
$user = $this->getUser();
|
||||
if (!$user) {
|
||||
return;
|
||||
}
|
||||
$request = $this->getPayPalRequest();
|
||||
|
||||
$request->setParameter("EMAIL", $user->oxuser__oxusername->value);
|
||||
|
||||
$addressId = $user->getSelectedAddressId();
|
||||
if ($addressId) {
|
||||
$address = oxNew(\OxidEsales\Eshop\Application\Model\Address::class);
|
||||
$address->load($addressId);
|
||||
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTONAME", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($address->oxaddress__oxfname->value . " " . $address->oxaddress__oxlname->value));
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOSTREET", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($address->oxaddress__oxstreet->value . " " . $address->oxaddress__oxstreetnr->value));
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOCITY", $address->oxaddress__oxcity->value);
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOZIP", $address->oxaddress__oxzip->value);
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOPHONENUM", $address->oxaddress__oxfon->value);
|
||||
|
||||
$country = oxNew(\OxidEsales\Eshop\Application\Model\Country::class);
|
||||
$country->load($address->oxaddress__oxcountryid->value);
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE", $country->oxcountry__oxisoalpha2->value);
|
||||
|
||||
if ($address->oxaddress__oxstateid->value) {
|
||||
$state = oxNew(\OxidEsales\Eshop\Application\Model\State::class);
|
||||
$state->load($address->oxaddress__oxstateid->value);
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOSTATE", $state->oxstates__oxisoalpha2->value);
|
||||
}
|
||||
} else {
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTONAME", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($user->oxuser__oxfname->value . " " . $user->oxuser__oxlname->value));
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOSTREET", \OxidEsales\Eshop\Core\Str::getStr()->html_entity_decode($user->oxuser__oxstreet->value . " " . $user->oxuser__oxstreetnr->value));
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOCITY", $user->oxuser__oxcity->value);
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOZIP", $user->oxuser__oxzip->value);
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOPHONENUM", $user->oxuser__oxfon->value);
|
||||
|
||||
$country = oxNew(\OxidEsales\Eshop\Application\Model\Country::class);
|
||||
$country->load($user->oxuser__oxcountryid->value);
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE", $country->oxcountry__oxisoalpha2->value);
|
||||
|
||||
if ($user->oxuser__oxstateid->value) {
|
||||
$state = oxNew(\OxidEsales\Eshop\Application\Model\State::class);
|
||||
$state->load($user->oxuser__oxstateid->value);
|
||||
$request->setParameter("PAYMENTREQUEST_0_SHIPTOSTATE", $state->oxstates__oxisoalpha2->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats given float/int value into PayPal friendly form
|
||||
*
|
||||
* @param float $in value to format
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function formatFloat($in)
|
||||
{
|
||||
return sprintf("%.2f", $in);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user