MAJ Module Paypal vers 5.1.1 (comme en prod)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user