MAJ Module Paypal vers 5.1.1 (comme en prod)

This commit is contained in:
2020-02-14 19:42:46 +01:00
parent 188923c03c
commit f00f4207dd
137 changed files with 12999 additions and 5036 deletions

View File

@@ -18,10 +18,11 @@
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
* @author 2007-2019 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @copyright PayPal
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
*/
include_once _PS_MODULE_DIR_.'paypal/classes/AbstractMethodPaypal.php';
@@ -31,6 +32,9 @@ include_once _PS_MODULE_DIR_.'paypal/controllers/front/abstract.php';
*/
class PaypalScInitModuleFrontController extends PaypalAbstarctModuleFrontController
{
/* @var $method AbstractMethodPaypal*/
protected $method;
public function init()
{
parent::init();
@@ -44,6 +48,12 @@ class PaypalScInitModuleFrontController extends PaypalAbstarctModuleFrontControl
$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 postProcess()
@@ -56,13 +66,16 @@ class PaypalScInitModuleFrontController extends PaypalAbstarctModuleFrontControl
$this->prepareProduct();
}
$method = AbstractMethodPaypal::load(Configuration::get('PAYPAL_METHOD'));
if (Validate::isLoadedObject($this->context->cart) == false) {
return false;
}
try {
$method->setParameters($this->values);
$response = $method->init();
$this->method->setParameters($this->values);
$response = $this->method->init();
if ($this->values['getToken']) {
$this->jsonValues = array('success' => true, 'token' => $method->token);
$this->jsonValues = array('success' => true, 'token' => $this->method->token);
} else {
$this->redirectUrl = $response;
}
@@ -88,7 +101,7 @@ class PaypalScInitModuleFrontController extends PaypalAbstarctModuleFrontControl
{
switch ($this->values['source_page']) {
case 'cart':
if ($this->context->cart->checkQuantities()) {
if ($this->context->cart->checkQuantities() && $this->context->cart->hasProducts()) {
$this->jsonValues = array('success' => true);
} else {
$this->jsonValues = array('success' => false);
@@ -136,4 +149,9 @@ class PaypalScInitModuleFrontController extends PaypalAbstarctModuleFrontControl
$this->context->cart->updateQty($this->values['quantity'], $this->values['id_product']);
}
}
public function setMethod($method)
{
$this->method = $method;
}
}

View File

@@ -18,10 +18,11 @@
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
* @author 2007-2019 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @copyright PayPal
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
*/
use PaypalPPBTlib\CommonAbstarctModuleFrontController;

View File

@@ -18,10 +18,11 @@
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
* @author 2007-2019 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @copyright PayPal
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
*/
include_once _PS_MODULE_DIR_.'paypal/classes/AbstractMethodPaypal.php';
@@ -32,34 +33,36 @@ include_once _PS_MODULE_DIR_.'paypal/controllers/front/abstract.php';
*/
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()
{
$paypal = Module::getInstanceByName($this->name);
$method_ec = AbstractMethodPaypal::load('EC');
try {
$method_ec->setParameters($this->values);
$url = $method_ec->init();
$this->method->setParameters($this->values);
$url = $this->method->init();
if ($this->values['getToken']) {
$this->jsonValues = array('success' => true, 'token' => $method_ec->token);
$this->jsonValues = array('success' => true, 'token' => $this->method->token);
} else {
$this->redirectUrl = $url.'&useraction=commit';
}
} catch (PayPal\Exception\PPConnectionException $e) {
$this->errors['error_msg'] = $paypal->l('Error connecting to ', pathinfo(__FILE__)['filename']) . $e->getUrl();
$this->errors['error_msg'] = $this->module->l('Error connecting to ', pathinfo(__FILE__)['filename']) . $e->getUrl();
} catch (PayPal\Exception\PPMissingCredentialException $e) {
$this->errors['error_msg'] = $e->errorMessage();
} catch (PayPal\Exception\PPConfigurationException $e) {
$this->errors['error_msg'] = $paypal->l('Invalid configuration. Please check your configuration file', pathinfo(__FILE__)['filename']);
$this->errors['error_msg'] = $this->module->l('Invalid configuration. Please check your configuration file', pathinfo(__FILE__)['filename']);
} catch (PaypalAddons\classes\PaypalException $e) {
$this->errors['error_code'] = $e->getCode();
$this->errors['error_msg'] = $e->getMessage();
@@ -77,4 +80,9 @@ class PaypalEcInitModuleFrontController extends PaypalAbstarctModuleFrontControl
}
}
}
public function setMethod($method)
{
$this->method = $method;
}
}

View File

@@ -18,10 +18,11 @@
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
* @author 2007-2019 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @copyright PayPal
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
*/
include_once _PS_MODULE_DIR_.'paypal/classes/AbstractMethodPaypal.php';
@@ -47,10 +48,14 @@ class PaypalEcScOrderModuleFrontController extends PaypalAbstarctModuleFrontCont
$paypal = Module::getInstanceByName($this->name);
try {
$this->redirectUrl = $this->context->link->getPageLink('order', null, null, array('step'=>2));
$method->setParameters($this->values);
$info = $method->getInfo();
$this->prepareOrder($info);
$this->redirectUrl = $this->context->link->getPageLink('order', null, null, array('step'=>2));
if (!empty($this->errors)) {
return;
}
} catch (PayPal\Exception\PPConnectionException $e) {
$this->errors['error_msg'] = $paypal->l('Error connecting to ', pathinfo(__FILE__)['filename']) . $e->getUrl();
} catch (PayPal\Exception\PPMissingCredentialException $e) {
@@ -147,10 +152,13 @@ class PaypalEcScOrderModuleFrontController extends PaypalAbstarctModuleFrontCont
}
}
if (!$address_exist) {
$nameArray = explode(" ", $ship_addr->Name);
$firstName = implode(' ', array_slice($nameArray, 0, count($nameArray) - 1));
$lastName = $nameArray[count($nameArray) - 1];
$orderAddress = new Address();
$pos_separator = strpos($ship_addr->Name, ' ');
$orderAddress->firstname = Tools::substr($ship_addr->Name, 0, $pos_separator);
$orderAddress->lastname = Tools::substr($ship_addr->Name, $pos_separator+1);
$orderAddress->firstname = $firstName;
$orderAddress->lastname = $lastName;
$orderAddress->address1 = $ship_addr->Street1;
if (isset($ship_addr->Street2)) {
$orderAddress->address2 = $ship_addr->Street2;
@@ -175,8 +183,9 @@ class PaypalEcScOrderModuleFrontController extends PaypalAbstarctModuleFrontCont
if ($country->active == false) {
$validationMessage = $module->l('Country is not active', pathinfo(__FILE__)['filename']);
}
if (is_string($validationMessage)) {
$var = array(
$vars = array(
'newAddress' => 'delivery',
'address1' => $orderAddress->address1,
'firstname' => $orderAddress->firstname,
@@ -188,10 +197,11 @@ class PaypalEcScOrderModuleFrontController extends PaypalAbstarctModuleFrontCont
'address2' => $orderAddress->address2,
'id_state' => $orderAddress->id_state
);
session_start();
$_SESSION['notifications'] = Tools::jsonEncode(array('error' => $validationMessage));
$url = Context::getContext()->link->getPageLink('order') . '&' . http_build_query($var);
Tools::redirect($url);
$this->errors[] = $validationMessage;
$url = Context::getContext()->link->getPageLink('order', null, null, $vars);
$this->redirectUrl = $url;
return;
}
$orderAddress->save();
$id_address = $orderAddress->id;
@@ -199,6 +209,22 @@ class PaypalEcScOrderModuleFrontController extends PaypalAbstarctModuleFrontCont
$this->context->cart->id_address_delivery = $id_address;
$this->context->cart->id_address_invoice = $id_address;
$addressValidator = new AddressValidator();
$invalidAddressIds = $addressValidator->validateCartAddresses($this->context->cart);
if (empty($invalidAddressIds) == false) {
$vars = array(
'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);

View File

@@ -18,10 +18,11 @@
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
* @author 2007-2019 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @copyright PayPal
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
*/
include_once _PS_MODULE_DIR_.'paypal/classes/AbstractMethodPaypal.php';
@@ -75,7 +76,11 @@ class PaypalEcValidationModuleFrontController extends PaypalAbstarctModuleFrontC
Context::getContext()->cookie->__unset('paypal_ecs_email');
if (!empty($this->errors)) {
$this->redirectUrl = Context::getContext()->link->getModuleLink($this->name, 'error', $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

@@ -18,10 +18,11 @@
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
* @author 2007-2019 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @copyright PayPal
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
*/
/**
@@ -52,7 +53,6 @@ class PaypalErrorModuleFrontController extends ModuleFrontController
'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,
'method' => Configuration::get('PAYPAL_METHOD'),
));
$this->setTemplate('module:paypal/views/templates/front/payment_error.tpl');

View File

@@ -18,10 +18,11 @@
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
* @author 2007-2019 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @copyright PayPal
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

View File

@@ -18,10 +18,11 @@
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
* @author 2007-2019 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @copyright PayPal
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
*/
include_once _PS_MODULE_DIR_.'paypal/classes/AbstractMethodPaypal.php';

View File

@@ -18,10 +18,11 @@
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
* @author 2007-2019 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @copyright PayPal
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
*/
use PayPal\Api\Payment;
@@ -48,9 +49,13 @@ class PaypalPppScOrderModuleFrontController extends PaypalAbstarctModuleFrontCon
$method = AbstractMethodPaypal::load('PPP');
$paypal = Module::getInstanceByName($this->name);
try {
$this->redirectUrl = $this->context->link->getPageLink('order', null, null, array('step'=>2));
$info = Payment::get($this->values['paymentId'], $method->_getCredentialsInfo());
$this->prepareOrder($info);
$this->redirectUrl = $this->context->link->getPageLink('order', null, null, array('step'=>2));
if (!empty($this->errors)) {
return;
}
} catch (PayPal\Exception\PayPalConnectionException $e) {
$decoded_message = Tools::jsonDecode($e->getData());
$this->errors['error_code'] = $e->getCode();
@@ -103,6 +108,10 @@ class PaypalPppScOrderModuleFrontController extends PaypalAbstarctModuleFrontCon
CartRule::autoRemoveFromCart($this->context);
CartRule::autoAddToCart($this->context);
// END Login
$this->context->cookie->__set('paypal_pSc', $info->id);
$this->context->cookie->__set('paypal_pSc_payerid', $payer_info->payer_id);
$this->context->cookie->__set('paypal_pSc_email', $payer_info->email);
$addresses = $this->context->customer->getAddresses($this->context->language->id);
$address_exist = false;
$count = 1;
@@ -126,10 +135,13 @@ class PaypalPppScOrderModuleFrontController extends PaypalAbstarctModuleFrontCon
}
}
if (!$address_exist) {
$nameArray = explode(" ", $ship_addr->recipient_name);
$firstName = implode(' ', array_slice($nameArray, 0, count($nameArray) - 1));
$lastName = $nameArray[count($nameArray) - 1];
$orderAddress = new Address();
$pos_separator = strpos($ship_addr->recipient_name, ' ');
$orderAddress->firstname = Tools::substr($ship_addr->recipient_name, 0, $pos_separator);
$orderAddress->lastname = Tools::substr($ship_addr->recipient_name, $pos_separator+1);
$orderAddress->firstname = $firstName;
$orderAddress->lastname = $lastName;
$orderAddress->address1 = $ship_addr->line1;
if (isset($ship_addr->line2)) {
$orderAddress->address2 = $ship_addr->line2;
@@ -142,6 +154,34 @@ class PaypalPppScOrderModuleFrontController extends PaypalAbstarctModuleFrontCon
$orderAddress->postcode = $ship_addr->postal_code;
$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 = $this->l('State is required in order to process payment. Please fill in state field.');
}
$country = new Country($orderAddress->id_country);
if ($country->active == false) {
$validationMessage = $this->l('Country is not active');
}
if (is_string($validationMessage)) {
$var = array(
'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;
$this->redirectUrl = Context::getContext()->link->getPageLink('order') . '&' . http_build_query($var);
return;
}
$orderAddress->save();
$id_address = $orderAddress->id;
}
@@ -151,9 +191,5 @@ class PaypalPppScOrderModuleFrontController extends PaypalAbstarctModuleFrontCon
$product = $this->context->cart->getProducts();
$this->context->cart->setProductAddressDelivery($product[0]['id_product'], $product[0]['id_product_attribute'], $product[0]['id_address_delivery'], $id_address);
$this->context->cart->save();
$this->context->cookie->__set('paypal_pSc', $info->id);
$this->context->cookie->__set('paypal_pSc_payerid', $payer_info->payer_id);
$this->context->cookie->__set('paypal_pSc_email', $payer_info->email);
}
}

View File

@@ -18,10 +18,11 @@
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
* @author 2007-2019 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @copyright PayPal
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
*/
include_once _PS_MODULE_DIR_.'paypal/classes/AbstractMethodPaypal.php';

View File

@@ -18,10 +18,11 @@
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
* @author 2007-2019 PayPal
* @author 202 ecommerce <tech@202-ecommerce.com>
* @copyright PayPal
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
*/
/**