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,5 @@
drwxr-xr-x 4 30094 users 5 Oct 6 10:16 .
drwxr-xr-x 11 30094 users 25 Oct 6 10:16 ..
drwxr-xr-x 2 30094 users 11 Oct 6 10:16 admin
drwxr-xr-x 2 30094 users 15 Oct 6 10:16 front
-rw-r--r-- 1 30094 users 1173 Oct 14 2021 index.php

View File

@@ -0,0 +1,11 @@
drwxr-xr-x 2 30094 users 11 Oct 6 10:16 .
drwxr-xr-x 4 30094 users 5 Oct 6 10:16 ..
-rw-r--r-- 1 30094 users 46931 Oct 14 2021 AdminPayPalCustomizeCheckoutController.php
-rw-r--r-- 1 30094 users 3746 Oct 14 2021 AdminPayPalHelpController.php
-rw-r--r-- 1 30094 users 2789 Oct 14 2021 AdminPayPalInstallmentController.php
-rw-r--r-- 1 30094 users 3951 Oct 14 2021 AdminPayPalLogsController.php
-rw-r--r-- 1 30094 users 14770 Oct 14 2021 AdminPayPalSetupController.php
-rw-r--r-- 1 30094 users 1234 Oct 14 2021 AdminPaypalConfigurationController.php
-rw-r--r-- 1 30094 users 1821 Oct 14 2021 AdminPaypalGetCredentialsController.php
-rw-r--r-- 1 30094 users 1235 Oct 14 2021 AdminPaypalProcessLogger.php
-rw-r--r-- 1 30094 users 1399 Oct 14 2021 index.php

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,99 @@
<?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
*/
require_once _PS_MODULE_DIR_ . 'paypal/vendor/autoload.php';
use PaypalAddons\classes\AbstractMethodPaypal;
use PaypalAddons\classes\AdminPayPalController;
use PrestaShop\PrestaShop\Core\Addon\Module\ModuleManagerBuilder;
use Symfony\Component\HttpFoundation\JsonResponse;
class AdminPayPalHelpController extends AdminPayPalController
{
public function init()
{
parent::init();
if (Tools::isSubmit('registerHooks')) {
if ($this->registerHooks()) {
$this->confirmations[] = $this->l('Hooks successfully registered');
}
}
}
public function initContent()
{
parent::initContent();
$countryDefault = new Country((int) \Configuration::get('PS_COUNTRY_DEFAULT'), $this->context->language->id);
$method = AbstractMethodPaypal::load($this->method);
if ($method->isSandbox()) {
$settingLink = 'https://www.sandbox.paypal.com/businessprofile/settings/info/edit';
} else {
$settingLink = 'https://www.paypal.com/businessprofile/settings/info/edit';
}
$this->context->smarty->assign('settingLink', $settingLink);
$tpl_vars = [
'psCheckoutBtnText' => $this->getCheckoutBtnText(),
'showPsCheckout' => in_array($countryDefault->iso_code, $this->module->countriesApiCartUnavailable),
'settingLink' => $settingLink,
];
$this->context->smarty->assign($tpl_vars);
$this->content = $this->context->smarty->fetch($this->getTemplatePath() . 'help.tpl');
$this->context->smarty->assign('content', $this->content);
$this->addJS(_PS_MODULE_DIR_ . $this->module->name . '/views/js/helpAdmin.js');
}
protected function getCheckoutBtnText()
{
$moduleManagerBuilder = ModuleManagerBuilder::getInstance();
$moduleManager = $moduleManagerBuilder->build();
if ($moduleManager->isInstalled('ps_checkout')) {
$psCheckoutBtnText = $this->l('Configure PrestaShop Checkout');
} elseif (is_dir(_PS_MODULE_DIR_ . 'ps_checkout')) {
$psCheckoutBtnText = $this->l('Install PrestaShop Checkout');
} else {
$psCheckoutBtnText = $this->l('Download PrestaShop Checkout');
}
return $psCheckoutBtnText;
}
public function displayAjaxCheckCredentials()
{
$response = new JsonResponse($this->_checkRequirements());
return $response->send();
}
public function registerHooks()
{
return $this->module->registerHooks();
}
}

View File

@@ -0,0 +1,84 @@
<?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
*/
require_once _PS_MODULE_DIR_ . 'paypal/vendor/autoload.php';
use PaypalAddons\classes\AdminPayPalController;
use PaypalAddons\classes\Form\Controller\AdminPayPalInstallment\FormInstallment;
use PaypalAddons\classes\Form\FormInterface;
use PaypalAddons\classes\InstallmentBanner\Banner;
use Symfony\Component\HttpFoundation\JsonResponse;
class AdminPayPalInstallmentController extends AdminPayPalController
{
protected $headerToolBar = true;
/** @var array<string, FormInterface> */
protected $forms;
public function __construct()
{
parent::__construct();
$this->forms['formInstallment'] = new FormInstallment();
}
public function initContent()
{
parent::initContent();
$this->initFormInstallment();
$this->context->smarty->assign('formInstallment', $this->renderForm());
$content = $this->context->smarty->fetch($this->getTemplatePath() . 'installment.tpl');
$this->context->smarty->assign('content', $content);
$this->addJS(_PS_MODULE_DIR_ . $this->module->name . '/views/js/adminInstallment.js');
}
protected function initFormInstallment()
{
$this->fields_form['form']['form'] = $this->forms['formInstallment']->getFields();
$this->tpl_form_vars = array_merge(
$this->tpl_form_vars,
$this->forms['formInstallment']->getValues()
);
}
public function saveForm()
{
return $this->forms['formInstallment']->save();
}
public function displayAjaxGetBanner()
{
$jsonResponse = new JsonResponse();
$banner = new Banner();
$jsonResponse->setData([
'success' => true,
'content' => $banner->render(),
]);
return $jsonResponse->send();
}
}

View File

@@ -0,0 +1,108 @@
<?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
*/
require_once _PS_MODULE_DIR_ . 'paypal/controllers/admin/AdminPaypalProcessLogger.php';
class AdminPayPalLogsController extends AdminPaypalProcessLoggerController
{
public function init()
{
if (\Tools::getValue('action') === 'set_sandbox_mode') {
\Configuration::updateValue('PAYPAL_SANDBOX', (int) \Tools::getValue('sandbox_mode'));
}
$this->page_header_toolbar_title = $this->l('Logs');
$this->filter = true;
parent::init();
}
public function processFilter()
{
if (Tools::isSubmit('submitFilter' . $this->list_id)) {
return parent::processFilter();
}
$isWriteCookie = false;
foreach ($this->getDefaultFilters() as $key => $value) {
if (Tools::isSubmit('submitFilter' . $this->list_id) === false) {
$this->context->cookie->__set($key, $value);
$isWriteCookie = true;
}
}
if ($isWriteCookie) {
$this->context->cookie->write();
}
$this->_filter = sprintf(' AND a.`sandbox` = %d ', (int) \Configuration::get('PAYPAL_SANDBOX'));
}
public function initContent()
{
$this->context->smarty->assign('showWarningForUserBraintree', $this->module->showWarningForUserBraintree());
$this->context->smarty->assign('moduleDir', _MODULE_DIR_);
$this->content = $this->context->smarty->fetch($this->getTemplatePath() . '_partials/headerLogo.tpl');
$this->content .= parent::initContent();
$this->content = $this->context->smarty
->assign('content', $this->content)
->assign('isModeSandbox', (int) \Configuration::get('PAYPAL_SANDBOX'))
->assign('psVersion', _PS_VERSION_)
->fetch($this->getTemplatePath() . 'admin.tpl');
$this->context->smarty->assign('content', $this->content);
}
public function setMedia($isNewTheme = false)
{
parent::setMedia($isNewTheme);
$this->addCSS(_PS_MODULE_DIR_ . $this->module->name . '/views/css/paypal_bo.css');
}
protected function getDefaultFilters()
{
return [
$this->getCookieFilterPrefix() . $this->list_id . 'Filter_a!sandbox' => Configuration::get('PAYPAL_SANDBOX'),
];
}
public function initPageHeaderToolbar()
{
$query = [
'token' => $this->token,
'action' => 'set_sandbox_mode',
'sandbox_mode' => \Configuration::get('PAYPAL_SANDBOX') ? 0 : 1,
];
$this->page_header_toolbar_btn['switch_sandbox'] = [
'desc' => $this->l('Sandbox mode'),
'icon' => 'process-icon-toggle-' . (\Configuration::get('PAYPAL_SANDBOX') ? 'on' : 'off'),
'help' => $this->l('Sandbox mode is the test environment where you\'ll be not able to collect any real payments.'),
'href' => self::$currentIndex . '?' . http_build_query($query),
];
parent::initPageHeaderToolbar();
$this->context->smarty->clearAssign('help_link');
}
}

View File

@@ -0,0 +1,61 @@
<?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\Constants\PUI;
use PaypalAddons\classes\PUI\PsMerchantId;
use PaypalAddons\services\Core\PaypalMerchantId;
class AdminPayPalPUIListenerController extends ModuleAdminController
{
public function init()
{
parent::init();
Configuration::updateValue(PUI::PARTNER_REFERRAL_ACTION_URL, false);
if (Tools::getValue('merchantId') != $this->initPsMerchantId()->get()) {
return $this->redirectToSetup();
}
$this->initPaypalMerchantId()->set(Tools::getValue('merchantIdInPayPal'));
return $this->redirectToSetup();
}
protected function initPsMerchantId()
{
return new PsMerchantId();
}
protected function redirectToSetup()
{
Tools::redirectAdmin($this->context->link->getAdminLink('AdminPayPalSetup'));
}
protected function initPaypalMerchantId()
{
return new PaypalMerchantId();
}
}

View File

@@ -0,0 +1,427 @@
<?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
*/
require_once _PS_MODULE_DIR_ . 'paypal/vendor/autoload.php';
use PaypalAddons\classes\AbstractMethodPaypal;
use PaypalAddons\classes\AdminPayPalController;
use PaypalAddons\classes\API\Onboarding\PaypalGetAuthToken;
use PaypalAddons\classes\API\Onboarding\PaypalGetCredentials;
use PaypalAddons\classes\PUI\SignUpLinkButton;
use PaypalAddons\classes\PuiMethodInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
class AdminPayPalSetupController extends AdminPayPalController
{
protected $headerToolBar = true;
public function __construct()
{
parent::__construct();
$this->parametres = [
'paypal_api_intent',
'paypal_sandbox',
'paypal_ec_secret_sandbox',
'paypal_ec_secret_live',
'paypal_ec_clientid_sandbox',
'paypal_ec_clientid_live',
'paypal_sandbox_clientid',
'paypal_live_clientid',
'paypal_sandbox_secret',
'paypal_live_secret',
'paypal_mb_sandbox_clientid',
'paypal_mb_live_clientid',
'paypal_mb_sandbox_secret',
'paypal_mb_live_secret',
];
}
public function init()
{
parent::init();
if (Tools::getValue('useWithoutBraintree')) {
Configuration::updateValue('PAYPAL_USE_WITHOUT_BRAINTREE', 1);
}
// Don't show somes tabs if a module is not configured
$method = AbstractMethodPaypal::load();
$isShowTabs = $method->isConfigured();
foreach (['AdminPayPalCustomizeCheckout', 'AdminPayPalLogs'] as $adminController) {
$tab = Tab::getInstanceFromClassName($adminController);
if ($isShowTabs != $tab->active) {
$tab->active = $isShowTabs;
$tab->save();
}
}
// Activate/Disactivate AdminPaypalInstallment tab
$this->module->hookActionLocalizationPageSave([]);
}
public function initContent()
{
parent::initContent();
if ($this->module->showWarningForUserBraintree()) {
$this->content = $this->context->smarty->fetch($this->getTemplatePath() . '_partials/messages/forBraintreeUsers.tpl');
$this->context->smarty->assign('content', $this->content);
return;
}
if ($this->method == 'PPP' && $this->module->showWarningForPayPalPlusUsers()) {
$this->warnings[] = $this->context->smarty->fetch($this->getTemplatePath() . '_partials/messages/forPayPalPlusUsers.tpl');
}
$countryDefault = new Country((int) \Configuration::get('PS_COUNTRY_DEFAULT'), $this->context->language->id);
$tpl_vars = [
'country_iso' => $countryDefault->iso_code,
];
$this->initAccountSettingsBlock();
$formAccountSettings = $this->renderForm();
$this->clearFieldsForm();
$tpl_vars['formAccountSettings'] = $formAccountSettings;
if (in_array($this->method, ['EC', 'MB'])) {
$this->initPaymentSettingsBlock();
$formPaymentSettings = $this->renderForm();
$this->clearFieldsForm();
$tpl_vars['formPaymentSettings'] = $formPaymentSettings;
}
$this->initStatusBlock();
$formStatus = $this->renderForm();
$this->clearFieldsForm();
$tpl_vars['formStatus'] = $formStatus;
if ($this->isShowInstallmentPopup()) {
$tpl_vars['installmentController'] = $this->context->link->getAdminLink('AdminPayPalInstallment', true);
$tpl_vars['showInstallmentPopup'] = true;
}
$this->context->smarty->assign($tpl_vars);
$this->content = $this->context->smarty->fetch($this->getTemplatePath() . 'setup.tpl');
$this->context->smarty->assign('content', $this->content);
$this->addJS(_PS_MODULE_DIR_ . $this->module->name . '/views/js/adminSetup.js?v=' . $this->module->version);
}
public function initAccountSettingsBlock()
{
$this->fields_form['form']['form'] = [
'legend' => [
'title' => $this->l('Account settings'),
'icon' => 'icon-cogs',
],
'input' => [
[
'type' => 'html',
'html_content' => $this->getHtmlBlockAccountSetting(),
'name' => '',
'col' => 12,
'label' => '',
],
],
'id_form' => 'pp_config_account',
];
$countryDefault = new Country((int) \Configuration::get('PS_COUNTRY_DEFAULT'), $this->context->language->id);
if ($this->method == 'MB' || in_array($countryDefault->iso_code, ['IN', 'JP'])) {
$this->fields_form['form']['form']['submit'] = [
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right button',
'name' => 'saveMbCredentialsForm',
];
}
}
public function getHtmlBlockAccountSetting()
{
$method = AbstractMethodPaypal::load($this->method);
$tpl_vars = $method->getTplVars();
$tpl_vars['method'] = $this->method;
if ($method instanceof PuiMethodInterface && $method->isConfigured()) {
$tpl_vars['SignUpLinkButton'] = $this->initSignUpLinkButton($method);
}
$this->context->smarty->assign($tpl_vars);
$html_content = $this->context->smarty->fetch($this->getTemplatePath() . '_partials/accountSettingsBlock.tpl');
return $html_content;
}
public function initPaymentSettingsBlock()
{
$inputGroup = [];
if ($this->isPaymentModeSetted() == false) {
$inputGroup[] = [
'type' => 'html',
'html_content' => $this->module->displayWarning($this->l('An error occurred while saving "Payment action" configuration. Please save this configuration again for avoiding any payment errors.')),
'name' => '',
'col' => 12,
'label' => '',
];
}
$paymentModeInput = [
'type' => 'select',
'name' => 'paypal_api_intent',
'options' => [
'query' => [
[
'id' => 'sale',
'name' => $this->l('Sale'),
],
[
'id' => 'authorize',
'name' => $this->l('Authorize'),
],
],
'id' => 'id',
'name' => 'name',
],
];
if ($this->method == 'MB') {
$paymentModeInput['label'] = $this->l('Payment action (for PayPal Express Checkout only)');
$paymentModeInput['hint'] = $this->l('You can change the payment action only for PayPal Express Checkout payments. If you are using PayPal Plus the "Sale" action is the only possible action.');
} else {
$paymentModeInput['label'] = $this->l('Payment action');
}
$inputGroup[] = $paymentModeInput;
$inputGroup[] = [
'type' => 'html',
'name' => '',
'col' => 12,
'label' => '',
'html_content' => $this->module->displayInformation($this->l('We recommend Authorize process only for lean manufacturers and craft products sellers.')),
];
$this->fields_form['form']['form'] = [
'legend' => [
'title' => $this->l('Payment settings'),
'icon' => 'icon-cogs',
],
'input' => $inputGroup,
'submit' => [
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right button',
],
'id_form' => 'pp_config_payment',
];
$values = [
'paypal_api_intent' => Configuration::get('PAYPAL_API_INTENT'),
];
$this->tpl_form_vars = array_merge($this->tpl_form_vars, $values);
}
public function initEnvironmentSettings()
{
$this->context->smarty->assign('sandbox', (int) \Configuration::get('PAYPAL_SANDBOX'));
$html_content = $this->context->smarty->fetch($this->getTemplatePath() . '_partials/switchSandboxBlock.tpl');
$this->fields_form['form']['form'] = [
'legend' => [
'title' => $this->l('Environment Settings'),
'icon' => 'icon-cogs',
],
'input' => [
[
'type' => 'html',
'html_content' => $html_content,
'name' => '',
'col' => 12,
'label' => '',
],
[
'type' => 'hidden',
'name' => 'paypal_sandbox',
'col' => 12,
'label' => '',
],
],
'id_form' => 'pp_config_environment',
];
$values = [
'paypal_sandbox' => !(int) Configuration::get('PAYPAL_SANDBOX'),
];
$this->tpl_form_vars = array_merge($this->tpl_form_vars, $values);
}
public function initStatusBlock()
{
$countryDefault = new \Country((int) \Configuration::get('PS_COUNTRY_DEFAULT'), $this->context->language->id);
$method = AbstractMethodPaypal::load($this->method);
$tpl_vars = [
'merchantCountry' => $countryDefault->name,
'tlsVersion' => $this->_checkTLSVersion(),
'accountConfigured' => $method == null ? false : $method->isConfigured(),
'sslActivated' => $this->module->isSslActive(),
];
if ($this->getWebhookOption()->isEnable() && $this->getWebhookOption()->isEligibleContext()) {
$webhookCheck = $this->_checkWebhook();
$tpl_vars['showWebhookState'] = true;
$tpl_vars['webhookState'] = $webhookCheck['state'];
$tpl_vars['webhookStateMsg'] = $webhookCheck['message'];
}
$this->context->smarty->assign($tpl_vars);
$html_content = $this->context->smarty->fetch($this->getTemplatePath() . '_partials/statusBlock.tpl');
$this->fields_form[]['form'] = [
'legend' => [
'title' => $this->l('Status'),
'icon' => 'icon-cogs',
],
'input' => [
[
'type' => 'html',
'html_content' => $html_content,
'name' => '',
'col' => 12,
'label' => '',
],
],
];
}
public function displayAjaxLogoutAccount()
{
$response = new JsonResponse();
$content = [
'status' => false,
'redirectUrl' => '',
];
if (Tools::getValue('token') == Tools::getAdminTokenLite($this->controller_name)) {
$method = AbstractMethodPaypal::load($this->method);
$method->logOut();
$content['status'] = true;
$content['redirectUrl'] = $this->context->link->getAdminLink($this->controller_name);
}
$response->setContent(\Tools::jsonEncode($content));
return $response->send();
}
public function displayAjaxCheckCredentials()
{
$this->initStatusBlock();
$response = new JsonResponse($this->renderForm());
return $response->send();
}
public function saveForm()
{
$result = parent::saveForm();
$method = AbstractMethodPaypal::load($this->method);
$method->checkCredentials();
if (Tools::isSubmit('paypal_sandbox') == false) {
$this->errors = array_merge($this->errors, $method->errors);
}
// We need use some functionality of EC method, so need also to configure MethodEC
if (Tools::isSubmit('saveMbCredentialsForm')) {
$methodEC = AbstractMethodPaypal::load('EC');
$methodEC->setConfig([
'clientId' => $method->getClientId(),
'secret' => $method->getSecret(),
]);
$methodEC->checkCredentials();
}
return $result;
}
public function displayAjaxHandleOnboardingResponse()
{
$method = AbstractMethodPaypal::load();
$authCode = Tools::getValue('authCode');
$sharedId = Tools::getValue('sharedId');
$sellerNonce = $method->getSellerNonce();
$paypalOnboarding = new PaypalGetAuthToken($authCode, $sharedId, $sellerNonce, $method->isSandbox());
$result = $paypalOnboarding->execute();
if ($result->isSuccess() === false) {
$this->log($result->getError()->getMessage());
return;
}
$partnerId = $method->isSandbox() ? PayPal::PAYPAL_PARTNER_ID_SANDBOX : PayPal::PAYPAL_PARTNER_ID_LIVE;
$paypalGetCredentials = new PaypalGetCredentials($result->getAuthToken(), $partnerId, $method->isSandbox());
$result = $paypalGetCredentials->execute();
if ($result->isSuccess()) {
$params = [
'clientId' => $result->getClientId(),
'secret' => $result->getSecret(),
];
$method->setConfig($params);
} else {
$this->log($result->getError()->getMessage());
}
}
protected function isPaymentModeSetted()
{
return in_array(Configuration::get('PAYPAL_API_INTENT'), ['sale', 'authorize']);
}
protected function isShowInstallmentPopup()
{
$countryDefault = new Country((int) Configuration::get('PS_COUNTRY_DEFAULT', null, null, $this->context->shop->id));
if (Validate::isLoadedObject($countryDefault) === false) {
return false;
}
if (Tools::strtolower($countryDefault->iso_code) != 'fr') {
return false;
}
if (false == (int) Configuration::get('PAYPAL_SHOW_INSTALLMENT_POPUP', null, null, $this->context->shop->id)) {
return false;
}
Configuration::updateValue('PAYPAL_SHOW_INSTALLMENT_POPUP', 0, false, null, $this->context->shop->id);
return true;
}
protected function initSignUpLinkButton(PuiMethodInterface $method)
{
return new SignUpLinkButton($method);
}
}

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 AdminPaypalConfigurationController extends \ModuleAdminController
{
/** @var Module Instance of your module automatically set by ModuleAdminController */
public $module;
public function __construct()
{
parent::__construct();
Tools::redirect($this->context->link->getAdminLink('AdminPayPalSetup', true));
}
}

View File

@@ -0,0 +1,64 @@
<?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
*/
require_once _PS_MODULE_DIR_ . 'paypal/vendor/autoload.php';
use PaypalAddons\classes\AbstractMethodPaypal;
use PaypalAddons\services\Core\PaypalMerchantId;
class AdminPaypalGetCredentialsController extends ModuleAdminController
{
public function init()
{
parent::init();
// We can wait for authToken max 10 sec
$maxDuration = 10;
$start = time();
$wait = true;
$method = AbstractMethodPaypal::load();
do {
Configuration::clearConfigurationCacheForTesting();
if ($method->isCredentialsSetted()) {
$wait = false;
$this->initPaypalMerchantId()->set(Tools::getValue('merchantIdInPayPal'));
}
$duration = time() - $start;
if ($duration > $maxDuration) {
$wait = false;
}
} while ($wait);
Tools::redirectAdmin($this->context->link->getAdminLink('AdminPayPalSetup', true, [], ['checkCredentials' => 1]));
}
protected function initPaypalMerchantId()
{
return new PaypalMerchantId();
}
}

View File

@@ -0,0 +1,37 @@
<?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
*/
require_once _PS_MODULE_DIR_ . 'paypal/vendor/autoload.php';
use PaypalPPBTlib\Extensions\ProcessLogger\Controllers\Admin\AdminProcessLoggerController;
class AdminPaypalProcessLoggerController extends AdminProcessLoggerController
{
public function __construct()
{
parent::__construct();
$this->className = 'PaypalLog';
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* NOTICE OF LICENSE
*
* This source file is subject to a commercial license from SARL 202 ecommence
* Use, copy, modification or distribution of this source file without written
* license agreement from the SARL 202 ecommence is strictly forbidden.
* In order to obtain a license, please contact us: tech@202-ecommerce.com
* ...........................................................................
* INFORMATION SUR LA LICENCE D'UTILISATION
*
* L'utilisation de ce fichier source est soumise a une licence commerciale
* concedee par la societe 202 ecommence
* Toute utilisation, reproduction, modification ou distribution du present
* fichier source sans contrat de licence ecrit de la part de la SARL 202 ecommence est
* expressement interdite.
* Pour obtenir une licence, veuillez contacter 202-ecommerce <tech@202-ecommerce.com>
* ...........................................................................
*
* @author 202-ecommerce <tech@202-ecommerce.com>
* @copyright Copyright (c) 202-ecommerce
* @license Commercial license
*/
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,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();
}
}

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;