First upload
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user