Skip to content

Commit

Permalink
Merge pull request #739 from PrestaShopCorp/dev
Browse files Browse the repository at this point in the history
Release v2.12.1
  • Loading branch information
seiwan authored Apr 1, 2021
2 parents 4d90d8f + 01bdcc3 commit 80a240e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>ps_checkout</name>
<displayName><![CDATA[PrestaShop Checkout]]></displayName>
<version><![CDATA[2.12.0]]></version>
<version><![CDATA[2.12.1]]></version>
<description><![CDATA[Provide the most commonly used payment methods to your customers in this all-in-one module, and manage all your sales in a centralized interface.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[payments_gateways]]></tab>
Expand Down
4 changes: 4 additions & 0 deletions controllers/front/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ private function handleException(Exception $exception)
case PsCheckoutException::PRESTASHOP_ORDER_PAYMENT:
$exceptionMessageForCustomer = $this->module->l('OrderPayment cannot be saved');
break;
case PsCheckoutException::DIFFERENCE_BETWEEN_TRANSACTION_AND_CART:
$exceptionMessageForCustomer = $this->module->l('The transaction amount doesn\'t match with the cart amount.');
$notifyCustomerService = false;
break;
}
} elseif ('PrestaShop\Module\PrestashopCheckout\Exception\PayPalException' === $exceptionClass) {
switch ($exception->getCode()) {
Expand Down
4 changes: 2 additions & 2 deletions ps_checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class Ps_checkout extends PaymentModule

// Needed in order to retrieve the module version easier (in api call headers) than instanciate
// the module each time to get the version
const VERSION = '2.12.0';
const VERSION = '2.12.1';

const INTEGRATION_DATE = '2020-07-30';

Expand All @@ -147,7 +147,7 @@ public function __construct()

// We cannot use the const VERSION because the const is not computed by addons marketplace
// when the zip is uploaded
$this->version = '2.12.0';
$this->version = '2.12.1';
$this->author = 'PrestaShop';
$this->need_instance = 0;
$this->currencies = true;
Expand Down
1 change: 1 addition & 0 deletions src/Exception/PsCheckoutException.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ class PsCheckoutException extends \Exception
const PRESTASHOP_VALIDATE_ORDER = 40;
const PRESTASHOP_ORDER_PAYMENT = 41;
const PRESTASHOP_CART_NOT_FOUND = 42;
const DIFFERENCE_BETWEEN_TRANSACTION_AND_CART = 43;
}
17 changes: 16 additions & 1 deletion src/ValidateOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class ValidateOrder
*/
private $merchantId;

/**
* @var \Context
*/
private $context;

/**
* @param string $paypalOrderId
* @param string $merchantId
Expand All @@ -58,6 +63,7 @@ public function __construct($paypalOrderId, $merchantId)
{
$this->merchantId = $merchantId;
$this->paypalOrderId = $paypalOrderId;
$this->context = \Context::getContext();
}

/**
Expand Down Expand Up @@ -95,7 +101,16 @@ public function validateOrder($payload)
/** @var \PsCheckoutCart|false $psCheckoutCart */
$psCheckoutCart = $psCheckoutCartRepository->findOneByCartId((int) $payload['cartId']);

$apiOrder = new Order(\Context::getContext()->link);
// Check if the PayPal order amount is the same than the cart amount
// We tolerate a difference of more or less 0.05
$paypalOrderAmount = number_format($order['purchase_units'][0]['amount']['value'], 2);
$cartAmount = number_format($this->context->cart->getOrderTotal(true, \Cart::BOTH), 2);

if ($paypalOrderAmount + 0.05 < $cartAmount || $paypalOrderAmount - 0.05 > $cartAmount) {
throw new PsCheckoutException('The transaction amount doesn\'t match with the cart amount.', PsCheckoutException::DIFFERENCE_BETWEEN_TRANSACTION_AND_CART);
}

$apiOrder = new Order($this->context->link);

$fundingSource = false === $psCheckoutCart ? 'paypal' : $psCheckoutCart->paypal_funding;

Expand Down

0 comments on commit 80a240e

Please sign in to comment.