Skip to content

Commit

Permalink
Merge pull request #45 from 202-ecommerce/develop
Browse files Browse the repository at this point in the history
5.1.4
  • Loading branch information
202-ecommerce authored Jun 19, 2020
2 parents ceff6e0 + 22efb13 commit db38d2f
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 9 deletions.
2 changes: 1 addition & 1 deletion 202/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<property name="src-dir" value="${basedir}" />
<property name="TARGETNAME" value="paypal" />
<property name="TARGETBRANCH" value="${env.GIT_BRANCH}" />
<property name="TARGETVERSION" value="5.1.3" />
<property name="TARGETVERSION" value="5.1.4" />
<property name="PHPVERSION" value="5.6" />
<property name="PSVERSION" value="1.7.5.x" />

Expand Down
18 changes: 12 additions & 6 deletions classes/MethodEC.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,12 @@ private function _getPaymentDetails()
private function _getProductsList($currency)
{
$products = Context::getContext()->cart->getProducts();

foreach ($products as $product) {
$itemDetails = new PaymentDetailsItemType();
$productObj = new Product((int)$product['id_product'], null, Context::getContext()->cart->id_lang);
$priceIncl = $this->formatPrice($productObj->getPrice(true, $product['id_product_attribute']));
$priceExcl = $this->formatPrice($productObj->getPrice(false, $product['id_product_attribute']));
$priceIncl = $this->formatPrice($productObj->getPrice(true, $product['id_product_attribute'], 6, null, false, true, $product['quantity']));
$priceExcl = $this->formatPrice($productObj->getPrice(false, $product['id_product_attribute'], 6, null, false, true, $product['quantity']));
$productTax = $this->formatPrice($priceIncl - $priceExcl);

$itemAmount = new BasicAmountType($currency, $priceExcl);
Expand Down Expand Up @@ -325,17 +326,22 @@ private function _getDiscountsList($currency)
$order_total = Context::getContext()->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$order_total_with_reduction = $order_total;
if (count($discounts) > 0) {
foreach ($discounts as $discount) {
foreach ($discounts as $discount) {
// It's needed to take a percentage of the order amount, taking into account the others discounts
if ((int)$discount['reduction_percent'] > 0) {
$discount['value_real'] = $order_total_with_reduction * ($discount['value_real'] / $order_total);
}

if ($discount['value_real'] == 0 && $discount['reduction_amount'] > 0) {
$discount['value_real'] = -1 * $this->formatPrice($discount['reduction_amount']);
} else {
$discount['value_real'] = -1 * $this->formatPrice($discount['value_real']);
}

if ((int)$discount['free_shipping'] == false) {
$order_total_with_reduction -= $discount['value_real'];
$order_total_with_reduction += $discount['value_real'];
}

$discount['value_real'] = -1 * $this->formatPrice($discount['value_real']);
$itemDetails = new PaymentDetailsItemType();
$itemDetails->Name = $discount['name'];
$itemDetails->Amount = new BasicAmountType($currency, $discount['value_real']);
Expand Down Expand Up @@ -681,7 +687,7 @@ public function refund($paypal_order)
'error_code' => $response->Errors[0]->ErrorCode,
'error_message' => $response->Errors[0]->LongMessage,
);
if (Validate::isLoadedObject($capture) && $response->Errors[0]->ErrorCode == "10009") {
if ($response->Errors[0]->ErrorCode == "10009") {
$result['already_refunded'] = true;
}
} else {
Expand Down
14 changes: 13 additions & 1 deletion controllers/admin/AdminPayPalHelpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,19 @@ public function initContent()
parent::initContent();

$countryDefault = new Country((int)\Configuration::get('PS_COUNTRY_DEFAULT'), $this->context->language->id);
$need_rounding = (Configuration::get('PS_ROUND_TYPE') != Order::ROUND_ITEM) || (Configuration::get('PS_PRICE_ROUND_MODE') != PS_ROUND_HALF_UP);
$need_rounding = false;

if (Configuration::get('PS_ROUND_TYPE') != Order::ROUND_ITEM) {
$need_rounding = true;
}

if (Configuration::get('PS_PRICE_ROUND_MODE') != PS_ROUND_HALF_UP) {
$need_rounding = true;
}

if (defined('_PS_PRICE_COMPUTE_PRECISION_') && (int)_PS_PRICE_COMPUTE_PRECISION_ != 2) {
$need_rounding = true;
}

$tpl_vars = array(
'need_rounding' => $need_rounding,
Expand Down
92 changes: 91 additions & 1 deletion paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

define('BT_CARD_PAYMENT', 'card-braintree');
define('BT_PAYPAL_PAYMENT', 'paypal-braintree');
define('PAYPAL_PAYMENT_CUSTOMER_CURRENCY', -1);
// Method Alias :
// EC = express checkout
// ECS = express checkout sortcut
Expand Down Expand Up @@ -191,6 +192,9 @@ class PayPal extends \PaymentModule
'displayAdminOrderTabOrder',
'displayAdminOrderContentOrder',
'displayAdminCartsView',
'displayAdminOrderTop',
'displayAdminOrderTabLink',
'displayAdminOrderTabContent'
);

/**
Expand Down Expand Up @@ -1070,6 +1074,21 @@ public function hookActionAdminControllerSetMedia()


public function hookDisplayAdminOrder($params)
{
// Since Ps 1.7.7 this hook is displayed at bottom of a page and we should use a hook DisplayAdminOrderTop
if (version_compare(_PS_VERSION_, '1.7.7', '>=')) {
return false;
}

return $this->getAdminOrderPageMessages($params);
}

public function hookDisplayAdminOrderTop($params)
{
return $this->getAdminOrderPageMessages($params);
}

protected function getAdminOrderPageMessages($params)
{
/* @var $paypal_order PaypalOrder */
$id_order = $params['id_order'];
Expand All @@ -1081,6 +1100,7 @@ public function hookDisplayAdminOrder($params)
if (!Validate::isLoadedObject($paypal_order)) {
return false;
}

if ($paypal_order->method == 'BT' && (Module::isInstalled('braintreeofficial') == false)) {
$tmpMessage = "<p class='paypal-warning'>";
$tmpMessage .= $this->l('This order has been paid via Braintree payment solution provided by PayPal module prior v5.0. ') . "</br>";
Expand All @@ -1090,7 +1110,10 @@ public function hookDisplayAdminOrder($params)
$paypal_msg .= $this->displayWarning($tmpMessage);
}
if ($paypal_order->sandbox) {
$this->context->controller->warnings[] = $this->l('[SANDBOX] Please pay attention that payment for this order was made via PayPal Sandbox mode.');
$tmpMessage = "<p class='paypal-warning'>";
$tmpMessage .= $this->l('[SANDBOX] Please pay attention that payment for this order was made via PayPal Sandbox mode.');
$tmpMessage .= "</p>";
$paypal_msg .= $this->displayWarning($tmpMessage);
}
if (Tools::getValue('not_payed_capture')) {
$paypal_msg .= $this->displayWarning(
Expand Down Expand Up @@ -1133,6 +1156,14 @@ public function hookDisplayAdminOrder($params)
'<a target="_blank" href="' . $preferences . '">' . $this->l('Read more.') . '</a></p>');
}

if (isset($_SESSION['paypal_transaction_already_refunded']) && $_SESSION['paypal_transaction_already_refunded']) {
unset($_SESSION['paypal_transaction_already_refunded']);
$tmpMessage = '<p class="paypal-warning">';
$tmpMessage .= $this->l('The order status was changed but this transaction has already been fully refunded.');
$tmpMessage .= '</p>';
$paypal_msg .= $this->displayWarning($tmpMessage);
}

return $paypal_msg . $this->display(__FILE__, 'views/templates/hook/paypal_order.tpl');
}

Expand Down Expand Up @@ -1465,6 +1496,12 @@ public function hookActionOrderStatusUpdate(&$params)
);
ProcessLoggerHandler::closeLogger();
Tools::redirect($_SERVER['HTTP_REFERER'] . '&error_refund=1');
} elseif (isset($refund_response['already_refunded']) && $refund_response['already_refunded']) {
if (session_status() == PHP_SESSION_NONE) {
session_start();
}

$_SESSION['paypal_transaction_already_refunded'] = true;
}
}

Expand Down Expand Up @@ -1673,13 +1710,30 @@ public static function getPaypalStateCode($address)

public function hookDisplayAdminOrderTabOrder($params)
{
$params['class_logger'] = 'PaypalLog';
if ($result = $this->handleExtensionsHook(__FUNCTION__, $params)) {
if (!is_null($result)) {
return $result;
}
}
}

public function hookDisplayAdminOrderTabLink($params)
{
$order = new Order((int)$params['id_order']);
$params['order'] = $order;
$return = $this->hookDisplayAdminOrderTabOrder($params);

return $return;
}

public function hookDisplayAdminOrderTabContent($params)
{
$order = new Order((int)$params['id_order']);
$params['order'] = $order;
return $this->hookDisplayAdminOrderContentOrder($params);
}

public function hookDisplayAdminOrderContentOrder($params)
{
$params['class_logger'] = 'PaypalLog';
Expand Down Expand Up @@ -1861,6 +1915,42 @@ public function addCheckboxCarrierRestrictionsForModule(array $shops = array())
return true;
}

/**
* Add radio currency restrictions for a new module.
*
* @param array $shops
*
* @return bool
*/
public function addRadioCurrencyRestrictionsForModule(array $shops = array())
{
if (!$shops) {
$shops = Shop::getShops(true, null, true);
}

$query = 'INSERT INTO `' . _DB_PREFIX_ . 'module_currency` (`id_module`, `id_shop`, `id_currency`) VALUES (%d, %d, %d)';

foreach ($shops as $s) {
if (!Db::getInstance()->execute(sprintf($query, $this->id, $s, PAYPAL_PAYMENT_CUSTOMER_CURRENCY))) {
return false;
}
}

return true;
}

/**
* Add checkbox country restrictions for a new module.
*
* @param array $shops
*
* @return bool
*/
public function addCheckboxCountryRestrictionsForModule(array $shops = array())
{
return Country::addModuleRestrictions($shops, array(), array(array('id_module' => (int) $this->id)));
}

/**
* @return array return the unregistered hooks
*/
Expand Down
46 changes: 46 additions & 0 deletions upgrade/Upgrade-5.1.4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* 2007-2019 PrestaShop
*
* 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-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)
*
*/

if (!defined('_PS_VERSION_')) {
exit;
}

/**
* @param $module PayPal
* @return bool
*/
function upgrade_module_5_1_4($module)
{
// Since Ps 1.7.7 we use a hook DisplayAdminOrderTop
$return = $module->registerHook('displayAdminOrderTop');

// Since Ps 1.7.7 we must use the hooks displayAdminOrderTabLink and displayAdminOrderTabContent
$return &= $module->registerHook('displayAdminOrderTabLink');
$return &= $module->registerHook('displayAdminOrderTabContent');

return $return;
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ public function hookDisplayAdminOrderTabOrder($params)
if ($order->module != 'paypal') {
return;
}
if (isset($params['class_logger']) && is_subclass_of($params['class_logger'], ProcessLoggerObjectModel::class)) {
$class_logger = $params['class_logger'];
} else {
$class_logger = ProcessLoggerObjectModel::class;
}
$collectionLogs = new \PrestaShopCollection($class_logger);
$collectionLogs->where('id_cart', '=', $params['order']->id_cart);
\Context::getContext()->smarty->assign('logs', $collectionLogs->getResults());
return \Context::getContext()->smarty->fetch(_PS_MODULE_DIR_ . 'paypal/views/templates/hook/displayAdminOrderTabOrder.tpl');
}

Expand Down
1 change: 1 addition & 0 deletions views/templates/admin/_partials/block_info.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<ul>
<li class="h4">{l s='Round mode: "Round up away from zero, when it is half way there (recommended) "' mod='paypal'}</li>
<li class="h4">{l s='Round type: "Round on each item"' mod='paypal'}</li>
<li class="h4">{l s='Number of decimals' d='Admin.Shopparameters.Feature'}: "2"</li>
</ul>
</div>
</div>

0 comments on commit db38d2f

Please sign in to comment.