Skip to content

Commit

Permalink
Merge pull request #38 from 202-ecommerce/develop
Browse files Browse the repository at this point in the history
5.1.2
  • Loading branch information
202-ecommerce authored Feb 18, 2020
2 parents c83e9ff + efe6278 commit 8e77cca
Show file tree
Hide file tree
Showing 7 changed files with 363 additions and 42 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.1" />
<property name="TARGETVERSION" value="5.1.2" />
<property name="PHPVERSION" value="5.6" />
<property name="PSVERSION" value="1.7.5.x" />

Expand Down
74 changes: 45 additions & 29 deletions classes/MethodEC.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ public function init()
$this->_paymentDetails->ShipToAddress = $address;
}

/** The total cost of the transaction to the buyer. If shipping cost and tax charges are known, include them in this value. If not, this value should be the current subtotal of the order. If the transaction includes one or more one-time purchases, this field must be equal to the sum of the purchases. If the transaction does not include a one-time purchase such as when you set up a billing agreement for a recurring payment, set this field to 0.*/
/** The total cost of the transaction to the buyer. If shipping cost and tax charges are known, include them in this value.
* If not, this value should be the current subtotal of the order. If the transaction includes one or more one-time purchases,
* this field must be equal to the sum of the purchases.
* If the transaction does not include a one-time purchase such as when you set up a billing agreement for a recurring payment, set this field to 0.
*/
$this->_getPaymentDetails();
$this->_paymentDetails->PaymentAction = Tools::ucfirst(Configuration::get('PAYPAL_API_INTENT'));
$setECReqDetails = new SetExpressCheckoutRequestDetailsType();
Expand All @@ -204,7 +208,7 @@ public function init()
$setECReqDetails->AddressOverride = 1;
$setECReqDetails->ReqConfirmShipping = 0;
$setECReqDetails->LandingPage = ($this->credit_card ? 'Billing' : 'Login');


if ($this->short_cut) {
$setECReqDetails->ReturnURL = Context::getContext()->link->getModuleLink($this->name, 'ecScOrder', array(), true);
Expand All @@ -225,6 +229,7 @@ public function init()

$setECReq = new SetExpressCheckoutReq();
$setECReq->SetExpressCheckoutRequest = $setECReqType;

/*
* ## Creating service wrapper object
Creating service wrapper object to make API call and loading
Expand Down Expand Up @@ -272,7 +277,7 @@ private function _getProductsList($currency)
$itemDetails->Name = $product['name'];
$itemDetails->Amount = $itemAmount;
$itemDetails->Quantity = $product['quantity'];
$itemDetails->Tax = new BasicAmountType($currency, $this->formatPrice($product['product_tax']));
$itemDetails->Tax = new BasicAmountType($currency, number_format($product['product_tax'], Paypal::getDecimal(), ".", ''));
$this->_paymentDetails->PaymentDetailsItem[] = $itemDetails;
$this->_itemTotalValue += $this->formatPrice($product['price']) * $product['quantity'];
$this->_taxTotalValue += $product['product_tax'] * $product['quantity'];
Expand All @@ -297,34 +302,45 @@ public function formatPrice($price)
return $price;
}



private function _getDiscountsList($currency)
{
$discounts = Context::getContext()->cart->getCartRules();
$order_total = Context::getContext()->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$order_total_with_reduction = $order_total;
if (count($discounts) > 0) {
foreach ($discounts as $discount) {
if (isset($discount['description']) && !empty($discount['description'])) {
$discount['description'] = Tools::substr(strip_tags($discount['description']), 0, 50).'...';
}
// 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);
}
$discounts = Context::getContext()->cart->getCartRules(CartRule::FILTER_ACTION_SHIPPING);
if (count($discounts)) {
$totalDiscounts = Context::getContext()->cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS);
$totalDiscounts = -1 * $this->formatPrice($totalDiscounts);

if ((int)$discount['free_shipping'] == false) {
$order_total_with_reduction -= $discount['value_real'];
$itemDetails = new PaymentDetailsItemType();
$itemDetails->Name = 'Total discounts';
$itemDetails->Amount = new BasicAmountType($currency, $totalDiscounts);
$itemDetails->Quantity = 1;
$this->_paymentDetails->PaymentDetailsItem[] = $itemDetails;
$this->_itemTotalValue += $totalDiscounts;
} else {
$discounts = Context::getContext()->cart->getCartRules();
$order_total = Context::getContext()->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$order_total_with_reduction = $order_total;
if (count($discounts) > 0) {
foreach ($discounts as $discount) {
if (isset($discount['description']) && !empty($discount['description'])) {
$discount['description'] = Tools::substr(strip_tags($discount['description']), 0, 50).'...';
}
// 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 ((int)$discount['free_shipping'] == false) {
$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']);
$itemDetails->Quantity = 1;
$this->_paymentDetails->PaymentDetailsItem[] = $itemDetails;
$this->_itemTotalValue += $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']);
$itemDetails->Quantity = 1;
$this->_paymentDetails->PaymentDetailsItem[] = $itemDetails;
$this->_itemTotalValue += $discount['value_real'];
}
}
}
Expand Down Expand Up @@ -558,9 +574,9 @@ public function getOrderStatus()
{
if ((int)Configuration::get('PAYPAL_CUSTOMIZE_ORDER_STATUS')) {
if (Configuration::get('PAYPAL_API_INTENT') == "sale") {
$orderStatus = (int)Configuration::get('PAYPAL_OS_WAITING_VALIDATION');
$orderStatus = (int)Configuration::get('PAYPAL_OS_ACCEPTED_TWO');
} else {
$orderStatus = (int)Configuration::get('PAYPAL_OS_WAITING');
$orderStatus = (int)Configuration::get('PAYPAL_OS_WAITING_VALIDATION');
}
} else {
if (Configuration::get('PAYPAL_API_INTENT') == "sale") {
Expand Down
6 changes: 5 additions & 1 deletion classes/MethodMB.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*
*
*/

require_once 'AbstractMethodPaypal.php';
Expand Down Expand Up @@ -186,6 +186,10 @@ public function _getCredentialsInfo($mode_order = null)
*/
public function createWebExperience()
{
$mode = Configuration::get('PAYPAL_SANDBOX') ? 'SANDBOX' : 'LIVE';
if (!Configuration::get('PAYPAL_MB_' . $mode . '_CLIENTID') && !Configuration::get('PAYPAL_MB_' . $mode . '_SECRET')) {
return false;
}
// Parameters for input fields customization.
$inputFields = new \PayPal\Api\InputFields();
// Enables the buyer to enter a note to the merchant on the PayPal page during checkout.
Expand Down
10 changes: 7 additions & 3 deletions controllers/front/ecScOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @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';
Expand Down Expand Up @@ -210,8 +210,12 @@ public function prepareOrder($info)
$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);
$invalidAddressIds = [];

if(version_compare(_PS_VERSION_, '1.7.3.0', '>=')) {
$addressValidator = new AddressValidator();
$invalidAddressIds = $addressValidator->validateCartAddresses($this->context->cart);
}

if (empty($invalidAddressIds) == false) {
$vars = array(
Expand Down
30 changes: 23 additions & 7 deletions paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @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_')) {
Expand Down Expand Up @@ -619,13 +619,16 @@ public function hookPaymentOptions($params)

break;
case 'MB':
if ($method->isConfigured() && in_array($this->context->currency->iso_code, $this->currencyMB)) {
if (in_array($this->context->currency->iso_code, $this->currencyMB)) {
if ((int)Configuration::get('PAYPAL_MB_EC_ENABLED')) {
$paymentOptionsEc = $this->renderEcPaymentOptions($params);
$payments_options = array_merge($payments_options, $paymentOptionsEc);
$methodEC = AbstractMethodPaypal::load('EC');
if ($methodEC->isConfigured()) {
$paymentOptionsEc = $this->renderEcPaymentOptions($params);
$payments_options = array_merge($payments_options, $paymentOptionsEc);
}
}

if ((int)Configuration::get('PAYPAL_API_CARD')) {
if ($method->isConfigured() && (int)Configuration::get('PAYPAL_API_CARD')) {
$payment_option = new PaymentOption();
$action_text = $this->l('Pay with credit or debit card');
$payment_option->setCallToActionText($action_text);
Expand Down Expand Up @@ -708,8 +711,21 @@ public function hookHeader()

$method = AbstractMethodPaypal::load($this->paypal_method);

if ($method->isConfigured() == false) {
return false;
if ($this->paypal_method == 'MB') {
if ((int)Configuration::get('PAYPAL_MB_EC_ENABLED')) {
$methodEC = AbstractMethodPaypal::load('EC');
if (!$methodEC->isConfigured()) {
return false;
}
} else {
if (Configuration::get('PAYPAL_API_CARD') && $method->isConfigured() == false) {
return false;
}
}
} else {
if ($method->isConfigured() == false) {
return false;
}
}

if ((Configuration::get('PAYPAL_EXPRESS_CHECKOUT_SHORTCUT') || Configuration::get('PAYPAL_EXPRESS_CHECKOUT_SHORTCUT_CART')) && (isset($this->context->cookie->paypal_ecs) || isset($this->context->cookie->paypal_pSc))) {
Expand Down
3 changes: 2 additions & 1 deletion translations/es.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
$_MODULE['<{paypal}prestashop>paypal_e02a9cef1018f4c3ff5345af151c0bdf'] = 'Pagar con PayPal Express Checkout';
$_MODULE['<{paypal}prestashop>paypal_553d54e0a3c3e862b45617752052368b'] = 'Pagar con PayPal Plus';
$_MODULE['<{paypal}prestashop>paypal_8f5d16bffc9dc4d54c301c82782916b1'] = 'Acceso directo para pagar con PayPal Plus';
$_MODULE['<{paypal}prestashop>paypal_112cee51bc7d0712033e013bf5154d97'] = 'Pago con tarjeta de crédito o débito';
$_MODULE['<{paypal}prestashop>paypal_a1547872d7311425dfeefcd1983c5add'] = 'Vas a pagar con tu cuenta PayPal ';
$_MODULE['<{paypal}prestashop>paypal_907bfea30d3ce7ffec31c04a4b0110c0'] = 'No hemos podido verificar si el pago se completó correctamente. Comprueba si has recibido algún tipo de confirmación en la cuenta por parte de PayPal.';
$_MODULE['<{paypal}prestashop>paypal_a94e9e59a8274948ecadafc8180dbadf'] = 'Error de validación de pedido: ';
Expand Down Expand Up @@ -276,4 +277,4 @@
$_MODULE['<{paypal}prestashop>pppcredentialsform_76525f0f34b48475e5ca33f71d296f3b'] = 'Id. de cliente';
$_MODULE['<{paypal}prestashop>pppcredentialsform_1e6947ac7fb3a9529a9726eb692c8cc5'] = 'Clave';
$_MODULE['<{paypal}prestashop>pppcredentialsform_955ad3298db330b5ee880c2c9e6f23a0'] = 'En producción';
$_MODULE['<{paypal}prestashop>pppcredentialsform_8914753a79f56d24f12a63c4578e4880'] = 'Puedes cambiar al entorno “En producción” en la parte superior derecha';
$_MODULE['<{paypal}prestashop>pppcredentialsform_8914753a79f56d24f12a63c4578e4880'] = 'Puedes cambiar al entorno “En producción” en la parte superior derecha';
Loading

0 comments on commit 8e77cca

Please sign in to comment.