Skip to content

Commit

Permalink
Stop displaying Sofort on checkout page
Browse files Browse the repository at this point in the history
  • Loading branch information
btafforeau authored and Matt75 committed Jan 31, 2024
1 parent cd02b04 commit 713afd8
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 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,50 @@ 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_EMAIL_STATUS"');

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

$dateAdd = \Db::getInstance()->getValue($query);
$dtZone = new \DateTimeZone('UTC');

$createdAt = new \DateTime($dateAdd, $dtZone);
$now = new \DateTime('now', $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 +461,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

0 comments on commit 713afd8

Please sign in to comment.