first commit

This commit is contained in:
2024-10-28 22:14:22 +01:00
commit b65352c452
40581 changed files with 5712079 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
drwxr-xr-x 2 30094 users 15 Oct 6 10:16 .
drwxr-xr-x 4 30094 users 5 Oct 6 10:16 ..
-rw-r--r-- 1 30094 users 5471 Oct 14 2021 ScInit.php
-rw-r--r-- 1 30094 users 1091 Oct 14 2021 abstract.php
-rw-r--r-- 1 30094 users 3430 Oct 14 2021 ecInit.php
-rw-r--r-- 1 30094 users 3771 Oct 14 2021 ecValidation.php
-rw-r--r-- 1 30094 users 1943 Oct 14 2021 error.php
-rw-r--r-- 1 30094 users 1173 Oct 14 2021 index.php
-rw-r--r-- 1 30094 users 1348 Oct 14 2021 installment.php
-rw-r--r-- 1 30094 users 7662 Oct 14 2021 ipn.php
-rw-r--r-- 1 30094 users 3639 Oct 14 2021 mbValidation.php
-rw-r--r-- 1 30094 users 2339 Oct 14 2021 pppPatch.php
-rw-r--r-- 1 30094 users 3508 Oct 14 2021 pppValidation.php
-rw-r--r-- 1 30094 users 10352 Oct 14 2021 scOrder.php
-rw-r--r-- 1 30094 users 1105 Oct 14 2021 tlscurltestserver.php

View File

@@ -0,0 +1,169 @@
<?php
/**
* 2007-2022 PayPal
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author 2007-2022 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright PayPal
*/
use PaypalAddons\classes\AbstractMethodPaypal;
/**
* Init payment for EC shortcut
*/
class PaypalScInitModuleFrontController extends PaypalAbstarctModuleFrontController
{
/* @var $method AbstractMethodPaypal*/
protected $method;
public function init()
{
parent::init();
$this->values['source_page'] = Tools::getvalue('source_page');
$this->values['checkAvailability'] = Tools::getvalue('checkAvailability');
$this->values['id_product'] = Tools::getvalue('id_product');
$this->values['product_attribute'] = Tools::getvalue('product_attribute');
$this->values['id_product_attribute'] = Tools::getvalue('id_product_attribute');
$this->values['quantity'] = Tools::getvalue('quantity');
$this->values['combination'] = Tools::getvalue('combination');
$this->values['getToken'] = Tools::getvalue('getToken');
$this->values['credit_card'] = 0;
$this->values['short_cut'] = 1;
if ($this->module->paypal_method == 'MB') {
$methodType = 'EC';
} else {
$methodType = $this->module->paypal_method;
}
$this->setMethod(AbstractMethodPaypal::load($methodType));
}
public function displayAjaxCheckAvailability()
{
$request = $this->getRequest();
switch ($request->page) {
case 'cart':
if ($this->context->cart->checkQuantities() && $this->context->cart->nbProducts()) {
$this->jsonValues = ['success' => true];
} else {
$this->jsonValues = ['success' => false];
}
break;
case 'product':
$product = new Product((int) $request->idProduct);
$group = $this->parseCombination($request->combination);
if (false == empty($group)) {
$product->id_product_attribute = $this->module->getIdProductAttributeByIdAttributes($request->idProduct, $group);
}
if ($product->checkQty($request->quantity)) {
$this->jsonValues = ['success' => true];
} else {
$this->jsonValues = ['success' => false];
}
break;
default:
}
}
protected function parseCombination($combination)
{
$temp_group = explode('|', $combination);
$group = [];
foreach ($temp_group as $item) {
$temp = explode(':', $item);
if (count($temp) == 1) {
continue;
}
$temp = array_map(
function ($value) {
return trim($value);
},
$temp
);
$group[$temp[0]] = $temp[1];
}
return $group;
}
public function prepareProduct()
{
if (empty($this->context->cart->id)) {
$this->context->cart->add();
$this->context->cookie->id_cart = $this->context->cart->id;
$this->context->cookie->write();
} else {
// delete all product in cart
$products = $this->context->cart->getProducts();
foreach ($products as $product) {
$this->context->cart->deleteProduct($product['id_product'], $product['id_product_attribute'], $product['id_customization'], $product['id_address_delivery']);
}
}
if ($this->values['combination']) {
// build group for search product attribute
$group = $this->parseCombination($this->values['combination']);
$this->context->cart->updateQty($this->values['quantity'], $this->values['id_product'], $this->module->getIdProductAttributeByIdAttributes($this->values['id_product'], $group));
} else {
$this->context->cart->updateQty($this->values['quantity'], $this->values['id_product']);
}
}
public function setMethod($method)
{
$this->method = $method;
}
public function displayAjaxCreateOrder()
{
$request = $this->getRequest();
if ($request->page == 'product') {
$this->values['quantity'] = $request->quantity;
$this->values['id_product'] = $request->idProduct;
$this->values['combination'] = $request->combination;
$this->prepareProduct();
}
if (empty($request->addAddress)) {
$this->method->setShortCut(true);
}
if (empty($request->apmMethod)) {
$this->method->init();
} else {
$this->method->initApm($request->apmMethod);
}
$this->jsonValues = ['success' => true, 'idOrder' => $this->method->getPaymentId()];
}
public function getRequest()
{
return json_decode(Tools::file_get_contents('php://input'));
}
}

View File

@@ -0,0 +1,56 @@
<?php
/**
* 2007-2022 PayPal
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author 2007-2022 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright PayPal
*/
use PaypalAddons\services\PaymentData;
use PaypalPPBTlib\CommonAbstarctModuleFrontController;
/**
* Class PaypalAbstarctModuleFrontController
*/
abstract class PaypalAbstarctModuleFrontController extends CommonAbstarctModuleFrontController
{
/**
* @return PaymentData
*/
protected function parsePaymentData($data)
{
$paymentDataObj = new PaymentData();
try {
$paymentData = json_decode($data, true);
} catch (Exception $e) {
$paymentData = [];
}
if (false == is_array($paymentData)) {
return $paymentDataObj;
}
$paymentDataObj->fromArray($paymentData);
return $paymentDataObj;
}
}

View File

@@ -0,0 +1,83 @@
<?php
/**
* 2007-2022 PayPal
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author 2007-2022 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright PayPal
*/
use PaypalAddons\classes\AbstractMethodPaypal;
/**
* Prepare EC payment
*/
class PaypalEcInitModuleFrontController extends PaypalAbstarctModuleFrontController
{
/* @var $method AbstractMethodPaypal*/
protected $method;
public function init()
{
parent::init();
$this->values['getToken'] = Tools::getvalue('getToken');
$this->values['credit_card'] = Tools::getvalue('credit_card');
$this->values['short_cut'] = 0;
$this->setMethod(AbstractMethodPaypal::load('EC'));
}
/**
* @see FrontController::postProcess()
*/
public function postProcess()
{
try {
$this->method->setParameters($this->values);
$url = $this->method->init()->getApproveLink();
if ($this->values['getToken']) {
$this->jsonValues = ['success' => true, 'token' => $this->method->getPaymentId()];
} else {
//$this->redirectUrl = $url.'&useraction=commit';
$this->redirectUrl = $url;
}
} catch (PaypalAddons\classes\PaypalException $e) {
$this->_errors['error_code'] = $e->getCode();
$this->_errors['error_msg'] = $e->getMessage();
$this->_errors['msg_long'] = $e->getMessageLong();
} catch (Exception $e) {
$this->_errors['error_code'] = $e->getCode();
$this->_errors['error_msg'] = $e->getMessage();
}
if (!empty($this->_errors)) {
if ($this->values['getToken']) {
$this->jsonValues = ['success' => false, 'redirect_link' => Context::getContext()->link->getModuleLink($this->name, 'error', $this->_errors)];
} else {
$this->redirectUrl = Context::getContext()->link->getModuleLink($this->name, 'error', $this->_errors);
}
}
}
public function setMethod($method)
{
$this->method = $method;
}
}

View File

@@ -0,0 +1,97 @@
<?php
/**
* 2007-2022 PayPal
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author 2007-2022 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright PayPal
*/
use PaypalAddons\classes\AbstractMethodPaypal;
/**
* Validate EC payment
*/
class PaypalEcValidationModuleFrontController extends PaypalAbstarctModuleFrontController
{
public function init()
{
parent::init();
if (Tools::isSubmit('paymentData')) {
$paymentData = $this->parsePaymentData(Tools::getValue('paymentData'));
$this->values['paymentId'] = $paymentData->getOrderId();
}
$this->values['short_cut'] = Tools::getvalue('short_cut');
if (empty($this->values['paymentId'])) {
$this->values['paymentId'] = Tools::getvalue('token');
}
}
/**
* @see FrontController::postProcess()
*/
public function postProcess()
{
$method_ec = AbstractMethodPaypal::load('EC');
$paypal = Module::getInstanceByName($this->name);
try {
$method_ec->setParameters($this->values);
if ($method_ec->getShortCut()) {
/** @var $resultPath \PaypalAddons\classes\API\Response\Response */
$resultPath = $method_ec->doOrderPatch();
if ($resultPath->isSuccess() == false) {
throw new Exception($resultPath->getError()->getMessage());
}
}
$method_ec->validation();
$cart = Context::getContext()->cart;
$customer = new Customer($cart->id_customer);
$this->redirectUrl = 'index.php?controller=order-confirmation&id_cart=' . $cart->id . '&id_module=' . $paypal->id . '&id_order=' . $paypal->currentOrder . '&key=' . $customer->secure_key;
} catch (PaypalAddons\classes\PaypalException $e) {
$this->_errors['error_code'] = $e->getCode();
$this->_errors['error_msg'] = $e->getMessage();
$this->_errors['msg_long'] = $e->getMessageLong();
} catch (Exception $e) {
$this->_errors['error_code'] = $e->getCode();
$this->_errors['error_msg'] = $e->getMessage();
} finally {
$this->transaction_detail = $method_ec->getDetailsTransaction();
}
//unset cookie of payment init
Context::getContext()->cookie->__unset('paypal_ecs');
Context::getContext()->cookie->__unset('paypal_ecs_email');
if (!empty($this->_errors)) {
if ($this->_errors['error_code'] == 10486) {
$this->redirectUrl = $method_ec->redirectToAPI('SetExpressCheckout');
} else {
$this->redirectUrl = Context::getContext()->link->getModuleLink($this->name, 'error', $this->_errors);
}
}
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* 2007-2022 PayPal
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author 2007-2022 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright PayPal
*/
/**
* Manage errors.
*/
class PaypalErrorModuleFrontController extends ModuleFrontController
{
public $values = [];
/**
* @see ModuleFrontController::init()
*/
public function init()
{
parent::init();
$this->values['error_msg'] = Tools::getvalue('error_msg');
$this->values['msg_long'] = Tools::getvalue('msg_long');
$this->values['error_code'] = Tools::getvalue('error_code');
$this->values['no_retry'] = Tools::getvalue('no_retry');
}
/**
* @see FrontController::initContent()
*/
public function initContent()
{
parent::initContent();
Context::getContext()->smarty->assign([
'error_msg' => $this->values['error_msg'],
'msg_long' => $this->values['msg_long'],
'error_code' => $this->values['error_code'],
'show_retry' => (Context::getContext()->cart->nbProducts() > 0 && !$this->values['no_retry']) ? true : false,
]);
$this->setTemplate('module:paypal/views/templates/front/payment_error.tpl');
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* 2007-2022 PayPal
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author 2007-2022 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright PayPal
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,43 @@
<?php
/**
* 2007-2022 PayPal
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author 2007-2022 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright PayPal
*/
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* Manage errors.
*/
class PaypalInstallmentModuleFrontController extends ModuleFrontController
{
public function displayAjaxGetCartTotal()
{
$response = new JsonResponse();
$response->setData([
'cartTotal' => $this->context->cart->getOrderTotal(true),
]);
return $response->send();
}
}

View File

@@ -0,0 +1,243 @@
<?php
/**
* 2007-2022 PayPal
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author 2007-2022 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright PayPal
*/
use PaypalAddons\services\ServicePaypalIpn;
use PaypalAddons\services\ServicePaypalOrder;
use PaypalPPBTlib\Extensions\ProcessLogger\ProcessLoggerHandler;
class PaypalIpnModuleFrontController extends PaypalAbstarctModuleFrontController
{
/** @var ServicePaypalIpn */
protected $servicePaypalIpn;
/** @var ServicePaypalOrder */
protected $servicePaypalOrder;
public function __construct()
{
parent::__construct();
$this->servicePaypalIpn = new ServicePaypalIpn();
$this->servicePaypalOrder = new ServicePaypalOrder();
}
public function run()
{
try {
if ($this->requestIsValid()) {
if ($this->handleIpn(Tools::getAllValues())) {
header('HTTP/1.1 200 OK');
} else {
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
}
}
} catch (\Exception $e) {
$message = 'Error code: ' . $e->getCode() . '.';
$message .= 'Short message: ' . $e->getMessage() . '.';
ProcessLoggerHandler::openLogger();
ProcessLoggerHandler::logError(
$message,
\Tools::getValue('txn_id') ? \Tools::getValue('txn_id') : null,
null,
null,
null,
null,
(int) \Configuration::get('PAYPAL_SANDBOX'),
null
);
ProcessLoggerHandler::closeLogger();
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
}
}
/**
* @param $data array Ipn message data
*
* @return bool
*/
protected function handleIpn($data)
{
if ($this->alreadyHandled($data)) {
return true;
}
$logResponse = [
'payment_status' => isset($data['payment_status']) ? $data['payment_status'] : null,
'ipn_track_id' => isset($data['ipn_track_id']) ? $data['ipn_track_id'] : null,
];
if ($data['payment_status'] == 'Refunded' && isset($data['parent_txn_id'])) {
$transactionRef = $data['parent_txn_id'];
} else {
$transactionRef = $data['txn_id'];
}
$paypalOrder = $this->servicePaypalOrder->getPaypalOrderByTransaction($transactionRef);
if (Validate::isLoadedObject($paypalOrder) == false) {
return false;
}
$orders = $this->servicePaypalOrder->getPsOrders($paypalOrder);
ProcessLoggerHandler::openLogger();
foreach ($orders as $order) {
ProcessLoggerHandler::logInfo(
'IPN response : ' . $this->jsonEncode($logResponse),
$data['txn_id'],
$order->id,
$order->id_cart,
null,
'PayPal',
(int) Configuration::get('PAYPAL_SANDBOX')
);
}
ProcessLoggerHandler::closeLogger();
$paypalIpn = new PaypalIpn();
$paypalIpn->id_transaction = $data['txn_id'];
$paypalIpn->status = $data['payment_status'];
$paypalIpn->response = $this->jsonEncode($logResponse);
$paypalIpn->save();
$psOrderStatus = $this->getPsOrderStatus($data['payment_status']);
if ($psOrderStatus > 0) {
$this->servicePaypalOrder->setOrderStatus($paypalOrder, $psOrderStatus);
}
return true;
}
protected function getPsOrderStatus($transactionStatus)
{
$orderStatus = 0;
if ((int) Configuration::get('PAYPAL_CUSTOMIZE_ORDER_STATUS')) {
switch ($transactionStatus) {
case 'Completed':
$orderStatus = (int) Configuration::get('PAYPAL_OS_ACCEPTED_TWO');
break;
case 'Refunded':
$orderStatus = (int) Configuration::get('PAYPAL_OS_REFUNDED_PAYPAL');
break;
case 'Failed':
$orderStatus = (int) Configuration::get('PAYPAL_OS_VALIDATION_ERROR');
break;
case 'Reversed':
$orderStatus = (int) Configuration::get('PAYPAL_OS_VALIDATION_ERROR');
break;
case 'Denied':
$orderStatus = (int) Configuration::get('PAYPAL_OS_VALIDATION_ERROR');
break;
}
} else {
switch ($transactionStatus) {
case 'Completed':
$orderStatus = (int) Configuration::get('PS_OS_PAYMENT');
break;
case 'Refunded':
$orderStatus = (int) Configuration::get('PS_OS_REFUND');
break;
case 'Failed':
$orderStatus = (int) Configuration::get('PS_OS_CANCELED');
break;
case 'Reversed':
$orderStatus = (int) Configuration::get('PS_OS_CANCELED');
break;
case 'Denied':
$orderStatus = (int) Configuration::get('PS_OS_CANCELED');
break;
}
}
return $orderStatus;
}
/**
* @return bool
*/
protected function requestIsValid()
{
$curl = curl_init($this->module->getIpnPaypalListener() . '?cmd=_notify-validate&' . http_build_query($_POST));
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 90);
$response = curl_exec($curl);
return trim($response) == 'VERIFIED';
}
protected function alreadyHandled($data)
{
return $this->servicePaypalIpn->exists($data['txn_id'], $data['payment_status']);
}
/**
* @param $orders array
* @param $idState int
*
* @return bool
*/
protected function setOrderStatus($orders, $idState)
{
/** @var $order \Order */
foreach ($orders as $order) {
$order->setCurrentState((int) $idState);
}
return true;
}
/**
* @param $value mixed
*
* @return string
*/
public function jsonEncode($value)
{
$result = json_encode($value);
if (json_last_error() == JSON_ERROR_UTF8) {
$result = json_encode($this->utf8ize($value));
}
return $result;
}
public function utf8ize($mixed)
{
if (is_array($mixed)) {
foreach ($mixed as $key => $value) {
$mixed[$key] = $this->utf8ize($value);
}
} elseif (is_string($mixed)) {
return utf8_encode($mixed);
}
return $mixed;
}
}

View File

@@ -0,0 +1,93 @@
<?php
/**
* 2007-2022 PayPal
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author 2007-2022 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright PayPal
*/
use PaypalAddons\classes\AbstractMethodPaypal;
/**
* Validate PPP payment
*/
class PaypalMbValidationModuleFrontController extends PaypalAbstarctModuleFrontController
{
/* @var $method MethodMB*/
protected $method;
public function init()
{
parent::init();
$this->method = AbstractMethodPaypal::load('MB');
}
/**
* @see FrontController::postProcess()
*/
public function postProcess()
{
$paypal = Module::getInstanceByName($this->name);
$payemtData = Tools::jsonDecode(Tools::getValue('paymentData'));
$this->method->setPaymentId($payemtData->paymentId);
$this->method->setPayerId($payemtData->result->payer->payer_info->payer_id);
$this->method->setRememberedCards($payemtData->result->rememberedCards);
try {
$this->method->validation();
$cart = Context::getContext()->cart;
$customer = new Customer($cart->id_customer);
$this->redirectUrl = 'index.php?controller=order-confirmation&id_cart=' . $cart->id . '&id_module=' . $paypal->id . '&id_order=' . $paypal->currentOrder . '&key=' . $customer->secure_key;
} catch (PayPal\Exception\PayPalConnectionException $e) {
$decoded_message = Tools::jsonDecode($e->getData());
$this->_errors['error_code'] = $e->getCode();
$this->_errors['error_msg'] = $decoded_message->message;
$this->_errors['msg_long'] = $decoded_message->name;
if (!empty($decoded_message->details)) {
$this->_errors['msg_long'] .= ' - ' . $decoded_message->details[0]->issue;
}
} catch (PayPal\Exception\PayPalInvalidCredentialException $e) {
$this->_errors['error_msg'] = $e->errorMessage();
} catch (PayPal\Exception\PayPalMissingCredentialException $e) {
$this->_errors['error_msg'] = $paypal->l('Invalid configuration. Please check your configuration file.', pathinfo(__FILE__)['filename']);
} catch (Exception $e) {
$this->_errors['error_code'] = $e->getCode();
$this->_errors['error_msg'] = $e->getMessage();
} finally {
$this->transaction_detail = $this->method->getDetailsTransaction();
}
if (!empty($this->_errors)) {
$this->redirectUrl = Context::getContext()->link->getModuleLink($this->name, 'error', $this->_errors);
}
}
public function displayAjaxGetPaymentInfo()
{
$paymentInfo = $this->method->getPaymentInfo();
$responseContent = [
'success' => true,
'paymentInfo' => $paymentInfo,
];
$this->jsonValues = $responseContent;
}
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* 2007-2022 PayPal
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author 2007-2022 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright PayPal
*/
use PaypalAddons\classes\AbstractMethodPaypal;
/**
* Update PPP payment request before initialize it.
*/
class PaypalPppPatchModuleFrontController extends PaypalAbstarctModuleFrontController
{
public function postProcess()
{
$method_ppp = AbstractMethodPaypal::load('PPP');
$idPayment = Tools::getValue('idPayment') ? Tools::getValue('idPayment') : Context::getContext()->cookie->paypal_plus_payment;
$method_ppp->setPaymentId($idPayment);
if ($idPayment) {
try {
$resultPath = $method_ppp->doOrderPatch();
if ($resultPath->isSuccess()) {
$this->jsonValues = ['success' => $resultPath->isSuccess()];
Context::getContext()->cookie->__unset('paypal_plus_payment');
} else {
$this->_errors['error_msg'] = $resultPath->getError()->getMessage();
$this->jsonValues = ['success' => false, 'redirect_link' => Context::getContext()->link->getModuleLink($this->name, 'error', $this->_errors)];
}
} catch (Exception $e) {
$this->_errors['error_code'] = $e->getCode();
$this->_errors['error_msg'] = $e->getMessage();
$this->jsonValues = ['success' => false, 'redirect_link' => Context::getContext()->link->getModuleLink($this->name, 'error', $this->_errors)];
}
}
}
}

View File

@@ -0,0 +1,95 @@
<?php
/**
* 2007-2022 PayPal
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author 2007-2022 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright PayPal
*/
use PaypalAddons\classes\AbstractMethodPaypal;
/**
* Validate PPP payment
*/
class PaypalPppValidationModuleFrontController extends PaypalAbstarctModuleFrontController
{
public function init()
{
parent::init();
if (Tools::isSubmit('paymentData')) {
$paymentData = $this->parsePaymentData(Tools::getValue('paymentData'));
$this->values['paymentId'] = $paymentData->getOrderId();
}
$this->values['short_cut'] = Tools::getvalue('short_cut');
if (empty($this->values['paymentId'])) {
$this->values['paymentId'] = Tools::getvalue('token');
}
}
/**
* @see FrontController::postProcess()
*/
public function postProcess()
{
$method_ppp = AbstractMethodPaypal::load('PPP');
$paypal = Module::getInstanceByName($this->name);
try {
$method_ppp->setParameters($this->values);
if ($method_ppp->getShortCut()) {
/** @var $resultPath \PaypalAddons\classes\API\Response\Response */
$resultPath = $method_ppp->doOrderPatch();
if ($resultPath->isSuccess() == false) {
throw new Exception($resultPath->getError()->getMessage());
}
}
$method_ppp->validation();
$cart = Context::getContext()->cart;
$customer = new Customer($cart->id_customer);
$this->redirectUrl = 'index.php?controller=order-confirmation&id_cart=' . $cart->id . '&id_module=' . $paypal->id . '&id_order=' . $paypal->currentOrder . '&key=' . $customer->secure_key;
} catch (PayPal\Exception\PayPalConnectionException $e) {
$decoded_message = Tools::jsonDecode($e->getData());
$this->_errors['error_code'] = $e->getCode();
$this->_errors['error_msg'] = $decoded_message->message;
$this->_errors['msg_long'] = $decoded_message->name . ' - ' . $decoded_message->details[0]->issue;
} catch (PayPal\Exception\PayPalInvalidCredentialException $e) {
$this->_errors['error_msg'] = $e->errorMessage();
} catch (PayPal\Exception\PayPalMissingCredentialException $e) {
$this->_errors['error_msg'] = $paypal->l('Invalid configuration. Please check your configuration file.', pathinfo(__FILE__)['filename']);
} catch (Exception $e) {
$this->_errors['error_code'] = $e->getCode();
$this->_errors['error_msg'] = $e->getMessage();
} finally {
$this->transaction_detail = $method_ppp->getDetailsTransaction();
}
Context::getContext()->cookie->__unset('paypal_pSc');
Context::getContext()->cookie->__unset('paypal_pSc_email');
if (!empty($this->_errors)) {
$this->redirectUrl = Context::getContext()->link->getModuleLink($this->name, 'error', $this->_errors);
}
}
}

View File

@@ -0,0 +1,86 @@
<?php
/**
* 2007-2022 PayPal
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author 2007-2022 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright PayPal
*/
use PaypalAddons\classes\AbstractMethodPaypal;
use PaypalAddons\classes\PUI\DataUserForm;
use PaypalAddons\services\PaypalContext;
/**
* Prepare EC payment
*/
class PaypalPuiValidateModuleFrontController extends PaypalAbstarctModuleFrontController
{
/* @var $method MethodPPP*/
protected $method;
public function init()
{
parent::init();
PaypalContext::getContext()->set('client-session-id', Tools::getValue('sessionId'));
$this->method = AbstractMethodPaypal::load('PPP');
}
/**
* @see FrontController::postProcess()
*/
public function postProcess()
{
try {
$paypal = Module::getInstanceByName($this->name);
$this->method->setPuiDataUser($this->getUserDataFromRequest());
$this->method->initPui();
$cart = Context::getContext()->cart;
$customer = new Customer($cart->id_customer);
$this->redirectUrl = 'index.php?controller=order-confirmation&id_cart=' . $cart->id . '&id_module=' . $paypal->id . '&id_order=' . $paypal->currentOrder . '&key=' . $customer->secure_key;
} catch (PaypalAddons\classes\PaypalException $e) {
$this->_errors['error_code'] = $e->getCode();
$this->_errors['error_msg'] = $e->getMessage();
$this->_errors['msg_long'] = $e->getMessageLong();
} catch (Exception $e) {
$this->_errors['error_code'] = $e->getCode();
$this->_errors['error_msg'] = $e->getMessage();
}
Context::getContext()->cookie->__unset('paypal_pSc');
Context::getContext()->cookie->__unset('paypal_pSc_email');
if (!empty($this->_errors)) {
$this->redirectUrl = Context::getContext()->link->getModuleLink($this->name, 'error', $this->_errors);
}
}
protected function getUserDataFromRequest()
{
$userData = new DataUserForm();
$userData->setFirstName(Tools::getValue('paypal_pui_firstname', ''));
$userData->setLastName(Tools::getValue('paypal_pui_lastname', ''));
$userData->setEmail(Tools::getValue('paypal_pui_email', ''));
$userData->setBirth(Tools::getValue('paypal_pui_birhday', ''));
$userData->setPhone(Tools::getValue('paypal_pui_phone', ''));
return $userData;
}
}

View File

@@ -0,0 +1,242 @@
<?php
/**
* 2007-2022 PayPal
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author 2007-2022 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright PayPal
*/
use PaypalAddons\classes\AbstractMethodPaypal;
/**
* Update PrestaShop Order after return from PayPal
*/
class PaypalScOrderModuleFrontController extends PaypalAbstarctModuleFrontController
{
protected $paymentData;
/** @var AbstractMethodPaypal */
protected $method;
public function init()
{
parent::init();
$this->setPaymentData(json_decode(Tools::getValue('paymentData')));
if ($this->module->paypal_method == 'MB') {
$methodType = 'EC';
} else {
$methodType = $this->module->paypal_method;
}
$this->method = AbstractMethodPaypal::load($methodType);
}
/**
* @see FrontController::postProcess()
*/
public function postProcess()
{
$paypal = Module::getInstanceByName($this->name);
try {
$this->redirectUrl = $this->context->link->getPageLink('order', null, null, ['step' => 2]);
$this->method->setPaymentId($this->paymentData->orderID);
$info = $this->method->getInfo();
$this->prepareOrder($info);
if (!empty($this->_errors)) {
return;
}
} catch (PaypalAddons\classes\PaypalException $e) {
$this->_errors['error_code'] = $e->getCode();
$this->_errors['error_msg'] = $e->getMessage();
$this->_errors['msg_long'] = $e->getMessageLong();
} catch (Exception $e) {
$this->_errors['error_code'] = $e->getCode();
$this->_errors['error_msg'] = $e->getMessage();
}
if (!empty($this->_errors)) {
$this->redirectUrl = Context::getContext()->link->getModuleLink($this->name, 'error', $this->_errors);
}
}
/**
* @param $info \PaypalAddons\classes\API\Response\ResponseOrderGet
*/
public function prepareOrder($info)
{
$module = Module::getInstanceByName($this->name);
if ($this->context->cookie->logged) {
$customer = $this->context->customer;
} elseif ($id_customer = Customer::customerExists($info->getClient()->getEmail(), true)) {
$customer = new Customer($id_customer);
} else {
$customer = new Customer();
$customer->email = $info->getClient()->getEmail();
$customer->firstname = $info->getClient()->getFirstName();
$customer->lastname = $info->getClient()->getLastName();
$customer->passwd = Tools::encrypt(Tools::passwdGen());
$customer->add();
}
$id_cart = $this->context->cart->id; // save id cart
// Login Customer
$this->context->updateCustomer($customer);
$this->context->cart = new Cart($id_cart); // Reload cart
$this->context->cart->id_customer = $customer->id;
$this->context->cart->update();
Hook::exec('actionAuthentication', ['customer' => $this->context->customer]);
// Login information have changed, so we check if the cart rules still apply
CartRule::autoRemoveFromCart($this->context);
CartRule::autoAddToCart($this->context);
// END Login
if ($this->method instanceof MethodEC) {
$this->context->cookie->__set('paypal_ecs', $this->paymentData->orderID);
$this->context->cookie->__set('paypal_ecs_email', $info->getClient()->getEmail());
} elseif ($this->method instanceof MethodPPP) {
$this->context->cookie->__set('paypal_pSc', $this->paymentData->orderID);
$this->context->cookie->__set('paypal_pSc_email', $info->getClient()->getEmail());
}
$addresses = $this->context->customer->getAddresses($this->context->language->id);
$address_exist = false;
$count = 1;
$id_address = 0;
$id_state = PayPal::getIdStateByPaypalCode($info->getAddress()->getStateCode(), $info->getAddress()->getCountryCode());
foreach ($addresses as $address) {
if ($address['firstname'] . ' ' . $address['lastname'] == $info->getAddress()->getFullName()
&& $address['address1'] == $info->getAddress()->getAddress1()
&& $address['address2'] == $info->getAddress()->getAddress2()
&& $address['id_country'] == Country::getByIso($info->getAddress()->getCountryCode())
&& $address['city'] == $info->getAddress()->getCity()
&& (empty($info->getAddress()->getStateCode()) || $address['id_state'] == $id_state)
&& $address['postcode'] == $info->getAddress()->getPostCode()
&& $address['phone'] == $info->getAddress()->getPhone()
) {
$address_exist = true;
$id_address = $address['id_address'];
break;
} else {
if ((strrpos($address['alias'], 'Paypal_Address')) !== false) {
$count = (int) (Tools::substr($address['alias'], -1)) + 1;
}
}
}
if (!$address_exist) {
$nameArray = explode(' ', $info->getAddress()->getFullName());
$firstName = implode(' ', array_slice($nameArray, 0, count($nameArray) - 1));
$lastName = $nameArray[count($nameArray) - 1];
$orderAddress = new Address();
$orderAddress->firstname = $firstName;
$orderAddress->lastname = $lastName;
$orderAddress->address1 = $info->getAddress()->getAddress1();
$orderAddress->address2 = $info->getAddress()->getAddress2();
$orderAddress->id_country = Country::getByIso($info->getAddress()->getCountryCode());
$orderAddress->city = $info->getAddress()->getCity();
if ($id_state) {
$orderAddress->id_state = $id_state;
}
$orderAddress->postcode = $info->getAddress()->getPostCode();
$orderAddress->phone = $info->getAddress()->getPhone();
$orderAddress->id_customer = $customer->id;
$orderAddress->alias = 'Paypal_Address ' . ($count);
$validationMessage = $orderAddress->validateFields(false, true);
if (Country::containsStates($orderAddress->id_country) && $orderAddress->id_state == false) {
$validationMessage = $module->l('State is required in order to process payment. Please fill in state field.', pathinfo(__FILE__)['filename']);
}
$country = new Country($orderAddress->id_country);
if ($country->active == false) {
$validationMessage = $module->l('Country is not active', pathinfo(__FILE__)['filename']);
}
if (is_string($validationMessage)) {
$vars = [
'newAddress' => 'delivery',
'address1' => $orderAddress->address1,
'firstname' => $orderAddress->firstname,
'lastname' => $orderAddress->lastname,
'postcode' => $orderAddress->postcode,
'id_country' => $orderAddress->id_country,
'city' => $orderAddress->city,
'phone' => $orderAddress->phone,
'address2' => $orderAddress->address2,
'id_state' => $orderAddress->id_state,
];
$this->_errors[] = $validationMessage;
$url = Context::getContext()->link->getPageLink('order', null, null, $vars);
$this->redirectUrl = $url;
return;
}
$orderAddress->save();
$id_address = $orderAddress->id;
}
$this->context->cart->id_address_delivery = $id_address;
$this->context->cart->id_address_invoice = $id_address;
$invalidAddressIds = [];
if (version_compare(_PS_VERSION_, '1.7.3.0', '>=')) {
$addressValidator = new AddressValidator();
$invalidAddressIds = $addressValidator->validateCartAddresses($this->context->cart);
}
if (empty($invalidAddressIds) == false) {
$vars = [
'id_address' => $id_address,
'editAddress' => 'delivery',
];
$this->_errors[] = $this->l('Your address is incomplete, please update it.');
$url = Context::getContext()->link->getPageLink('order', null, null, $vars);
$this->redirectUrl = $url;
return;
}
$products = $this->context->cart->getProducts();
foreach ($products as $key => $product) {
$this->context->cart->setProductAddressDelivery($product['id_product'], $product['id_product_attribute'], $product['id_address_delivery'], $id_address);
}
$this->context->cart->save();
}
public function setPaymentData($paymentData)
{
$this->paymentData = $paymentData;
return $this;
}
}

View File

@@ -0,0 +1,36 @@
<?php
/**
* 2007-2022 PayPal
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author 2007-2022 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright PayPal
*/
/**
* Class PayPalTlscurltestserverModuleFrontController. Check TLS
*/
class PayPalTlscurltestserverModuleFrontController extends ModuleFrontController
{
public function initContent()
{
exit('ok');
}
}

View File

@@ -0,0 +1,201 @@
<?php
/**
* 2007-2022 PayPal
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author 2007-2022 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @copyright PayPal
*/
use PayPal\Api\WebhookEvent;
use PaypalAddons\classes\AbstractMethodPaypal;
use PaypalAddons\classes\API\Request\V_1\GetWebhookEvents;
use PaypalAddons\classes\Constants\WebhookHandler;
use PaypalAddons\classes\Webhook\WebhookEventHandler;
use PaypalAddons\services\ServicePaypalOrder;
use PaypalPPBTlib\Extensions\ProcessLogger\ProcessLoggerHandler;
/**
* Class PaypalAbstarctModuleFrontController
*/
class PaypalWebhookhandlerModuleFrontController extends PaypalAbstarctModuleFrontController
{
/** @var ServicePaypalOrder */
protected $servicePaypalOrder;
/** @var array */
protected $requestData;
protected $request;
protected $webhookEventHandler;
public function __construct()
{
parent::__construct();
$this->request = file_get_contents('php://input');
$this->webhookEventHandler = new WebhookEventHandler();
}
public function run()
{
parent::init();
if ($this->isCheckAvailability()) {
header('HTTP/1.1 ' . WebhookHandler::STATUS_AVAILABLE);
exit;
}
if (false == ($this->module->getWebhookOption()->isEnable() && $this->module->getWebhookOption()->isAvailable())) {
return;
}
try {
if ($this->requestIsValid()) {
$webhookEvent = new WebhookEvent();
$webhookEvent->fromArray($this->getRequestData());
if ($this->webhookEventHandler->handle($webhookEvent)) {
header('HTTP/1.1 200 OK');
} else {
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
}
} else {
$paypalOrder = $this->initPaypalOrder($this->getRequest());
ProcessLoggerHandler::openLogger();
ProcessLoggerHandler::logError(
Tools::substr('Invalid webhook event. Data: ' . $this->getRequest(), 0, 999),
$paypalOrder->id_transaction,
Validate::isLoadedObject($paypalOrder) ? $paypalOrder->id_order : null,
Validate::isLoadedObject($paypalOrder) ? $paypalOrder->id_cart : null,
null,
null,
Validate::isLoadedObject($paypalOrder) ? $paypalOrder->sandbox : (int) Configuration::get('PAYPAL_SANDBOX'),
null
);
ProcessLoggerHandler::closeLogger();
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
}
} catch (\Exception $exception) {
} catch (\Throwable $exception) {//for php version > 7
}
if (isset($exception)) {
$message = 'Error code: ' . $exception->getCode() . '.';
$message .= 'Short message: ' . $exception->getMessage() . '.';
$paypalOrder = $this->initPaypalOrder($this->getRequestData());
ProcessLoggerHandler::openLogger();
ProcessLoggerHandler::logError(
$message,
$paypalOrder->id_transaction,
Validate::isLoadedObject($paypalOrder) ? $paypalOrder->id_order : null,
Validate::isLoadedObject($paypalOrder) ? $paypalOrder->id_cart : null,
null,
null,
Validate::isLoadedObject($paypalOrder) ? $paypalOrder->sandbox : (int) Configuration::get('PAYPAL_SANDBOX'),
null
);
ProcessLoggerHandler::closeLogger();
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
}
}
protected function isCheckAvailability()
{
return (bool) Tools::isSubmit('checkAvailability');
}
/**
* @return bool
*/
protected function requestIsValid()
{
try {
if (empty($this->getRequestData()['id'])) {
return false;
}
$params = [
'id' => $this->getRequestData()['id'],
];
$events = $this->getWebhookEventRequest()->setParams($params)->execute()->getData();
if (empty($events)) {
return false;
}
$this->request = $events[0]->toJson();
$this->requestData = $events[0]->toArray();
} catch (Exception $e) {
return false;
}
return true;
}
/** @return GetWebhookEvents*/
protected function getWebhookEventRequest()
{
return new GetWebhookEvents(AbstractMethodPaypal::load());
}
protected function getRequestData()
{
if (false == empty($this->requestData)) {
return $this->requestData;
}
$this->requestData = json_decode($this->getRequest(), true);
return $this->requestData;
}
protected function getRequest()
{
return $this->request;
}
protected static function isInWhitelistForGeolocation()
{
return true;
}
protected function displayMaintenancePage()
{
}
protected function initPaypalOrder($requestData)
{
$event = new WebhookEvent();
$event->fromArray($requestData);
if (false == empty($event->getResource()->supplementary_data->related_ids->order_id)) {
$paymentId = $event->getResource()->supplementary_data->related_ids->order_id;
return $this->servicePaypalOrder->getPaypalOrderByPaymentId($paymentId);
}
return new PaypalOrder();
}
}