Skip to content

Commit

Permalink
Merge pull request #1190 from PrestaShopCorp/release/v8.3.5.3
Browse files Browse the repository at this point in the history
Release v8.3.5.3
  • Loading branch information
Matt75 authored Jan 31, 2024
2 parents 0a792c9 + ce7a74e commit 2df76f3
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 3 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[8.3.5.2]]></version>
<version><![CDATA[8.3.5.3]]></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 @@ -402,6 +402,10 @@ private function handleException(Exception $exception)
$exceptionMessageForCustomer = $this->module->l('Transaction expired, please try again.');
$notifyCustomerService = false;
break;
case PayPalException::PAYMENT_SOURCE_CANNOT_BE_USED:
$exceptionMessageForCustomer = $this->module->l('The selected payment method does not support this type of transaction. Please choose another payment method or contact support for assistance.');
$notifyCustomerService = false;
break;
}
}

Expand Down
4 changes: 2 additions & 2 deletions ps_checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,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 = '8.3.5.2';
const VERSION = '8.3.5.3';

const INTEGRATION_DATE = '2022-14-06';

Expand All @@ -144,7 +144,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 = '8.3.5.2';
$this->version = '8.3.5.3';
$this->author = 'PrestaShop';
$this->currencies = true;
$this->currencies_mode = 'checkbox';
Expand Down
55 changes: 55 additions & 0 deletions src/Builder/PayPalSdkLink/PayPalSdkLinkBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class PayPalSdkLinkBuilder
/** @var ExpressCheckoutConfiguration */
private $expressCheckoutConfiguration;

/** @var array */
private static $cache = [];

/**
* @param PayPalConfiguration $configuration
* @param PayPalPayLaterConfiguration $payLaterConfiguration
Expand Down Expand Up @@ -347,6 +350,57 @@ private function getLocale()
return '';
}

// TODO : Remove everything Sofort related after October 2024 when its no longer supported by PayPal
private function isSofortAvailableForMerchant()
{
if (isset(self::$cache['sofortAvailability'])) {
return self::$cache['sofortAvailability'];
}

$query = new \DbQuery();
$query->select('date_add');
$query->from('configuration');
$query->where('name = "PS_CHECKOUT_PAYPAL_ID_MERCHANT"');

$shopId = \Shop::getContextShopID(true);
if ($shopId) {
$query->where('id_shop IS NULL OR id_shop = ' . (int) $shopId);
}

$dateAdd = \Db::getInstance()->getValue($query);

if (empty($dateAdd) || strpos($dateAdd, '0000-00-00') !== false) {
// Sofort is unavailable for merchants who have not onboarded yet.
self::$cache['sofortAvailability'] = false;

return false;
}

$dtZone = new \DateTimeZone('UTC');
$now = new \DateTime('now', $dtZone);
$createdAt = new \DateTime($dateAdd, $dtZone);
$deprecationDate = new \DateTime('2024-02-01', $dtZone);
$unavailabilityDate = new \DateTime('2024-09-30', $dtZone);

if ($now > $unavailabilityDate) {
// Sofort is totally unavailable after September 30, 2024.
self::$cache['sofortAvailability'] = false;

return false;
}

if ($now > $deprecationDate && $createdAt >= $deprecationDate) {
// Sofort is unavailable for merchants onboarded after February 01, 2024.
self::$cache['sofortAvailability'] = false;

return false;
}

self::$cache['sofortAvailability'] = true;

return true;
}

private function getEligibleAlternativePaymentMethods()
{
$fundingSourcesEnabled = [];
Expand Down Expand Up @@ -414,6 +468,7 @@ private function getEligibleAlternativePaymentMethods()
&& $fundingSource['name'] === 'sofort'
&& (($context->currency->iso_code === 'EUR' && in_array($country, ['AT', 'BE', 'DE', 'ES', 'NL'], true))
|| ($context->currency->iso_code === 'GBP' && in_array($country, ['GB', 'UK'], true)))
&& $this->isSofortAvailableForMerchant()
) {
$fundingSourcesEnabled[] = $fundingSource['name'];
}
Expand Down
1 change: 1 addition & 0 deletions src/Exception/PayPalException.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,5 @@ class PayPalException extends PsCheckoutException
const PAYMENT_DENIED = 128;
const CARD_BRAND_NOT_SUPPORTED = 129;
const RESOURCE_NOT_FOUND = 130;
const PAYMENT_SOURCE_CANNOT_BE_USED = 131;
}
2 changes: 2 additions & 0 deletions src/PayPalError.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ public function throwException()
throw new PayPalException('Processing of this card brand is not supported. Use another type of card.', PayPalException::CARD_BRAND_NOT_SUPPORTED);
case 'RESOURCE_NOT_FOUND':
throw new PayPalException('The specified resource does not exist.', PayPalException::RESOURCE_NOT_FOUND);
case 'PAYMENT_SOURCE_CANNOT_BE_USED':
throw new PayPalException('The provided payment source cannot be used to pay for the order. Please try again with a different payment source by creating a new order.', PayPalException::PAYMENT_SOURCE_CANNOT_BE_USED);
default:
throw new PayPalException($this->message, PayPalException::UNKNOWN);
}
Expand Down

0 comments on commit 2df76f3

Please sign in to comment.