Skip to content

Commit

Permalink
PT-13154 - Deactivate Sofort payment method
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisGarding committed May 24, 2024
1 parent 79fbc59 commit 9b7d6a1
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 28 deletions.
11 changes: 11 additions & 0 deletions Components/PaymentMethodProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,17 @@ public function getPaymentTypeByName($paymentMethodName)
);
}

/**
* @return array<self::*>
*/
public static function getDeactivatedPaymentMethods()
{
return [
self::SOFORT_METHOD_NAME,
self::TRUSTLY_METHOD_NAME,
];
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Ext.define('Shopware.apps.Payment.controller.PaymentPaypalUnified', {
payUponInvoicePaymentMethodName: 'SwagPaymentPayPalUnifiedPayUponInvoice',
myBankPaymentMethodName: 'SwagPaymentPayPalUnifiedMyBank',
sofortPaymentMethodName: 'SwagPaymentPayPalUnifiedSofort',
trustlyPaymentMethodName: 'SwagPaymentPayPalUnifiedTrustly',

deactivatedPaymentMethods: '{$deactivatedPaymentMethods|json_encode}',

/**
* @param { Ext.view.View } view
Expand All @@ -45,6 +48,22 @@ Ext.define('Shopware.apps.Payment.controller.PaymentPaypalUnified', {
this.callParent(arguments);
},

onSavePayment: function(generalForm, countryGrid, subShopGrid, surchargeGrid) {
var deactivatedPaymentMethods = JSON.parse(this.deactivatedPaymentMethods);

const index = deactivatedPaymentMethods.indexOf(this.currentRecord.data.name);
if (index > -1) {
this.currentRecord.set('active', false);

generalForm.getForm().setValues({
active: false,
name: deactivatedPaymentMethods[index],
});
}

this.callParent(arguments);
},

_handleDisclaimer: function () {
this._removeDisclaimer();

Expand Down
10 changes: 9 additions & 1 deletion Setup/PaymentModels/PaymentInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ public function __construct(

public function installPayments()
{
foreach (PaymentMethodProvider::getAllUnifiedNames() as $paymentMethodName) {
$deactivatedPaymentMethods = PaymentMethodProvider::getDeactivatedPaymentMethods();
$paymentMethods = \array_filter(
PaymentMethodProvider::getAllUnifiedNames(),
function ($paymentMethodName) use ($deactivatedPaymentMethods) {
return !\in_array($paymentMethodName, $deactivatedPaymentMethods);
}
);

foreach ($paymentMethods as $paymentMethodName) {
$payment = $this->paymentMethodProvider->getPaymentMethodModel($paymentMethodName);

if ($payment instanceof Payment) {
Expand Down
11 changes: 11 additions & 0 deletions Setup/Versions/UpdateTo617.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,20 @@ public function __construct(Connection $connection)
*/
public function update()
{
$this->deactivateSofortPayment();
$this->createOrderTurnoverTable();
}

/**
* @return void
*/
private function deactivateSofortPayment()
{
$this->connection->executeQuery(
'UPDATE s_core_paymentmeans SET active = 0 WHERE name = "SwagPaymentPayPalUnifiedSofort"'
);
}

/**
* @return void
*/
Expand Down
24 changes: 15 additions & 9 deletions Subscriber/ApmRiskManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use SwagPaymentPayPalUnified\Components\PaymentMethodProviderInterface;
use SwagPaymentPayPalUnified\Components\Services\RiskManagement\Apm\ValidatorFactory;
use SwagPaymentPayPalUnified\Components\Services\RiskManagement\Apm\ValueFactory;
use SwagPaymentPayPalUnified\PayPalBundle\PaymentType;
use Symfony\Component\Validator\Validator\ValidatorInterface;

class ApmRiskManagement implements SubscriberInterface
Expand Down Expand Up @@ -135,19 +134,26 @@ public function onExecuteApmRule(Enlight_Event_EventArgs $args)
$values = $this->valueFactory->createValue($paymentType, $basket, $user);
$validator = $this->validatorFactory->createValidator($paymentType);

// This is temporary to disable Trustly as it will not available until the end of quarter 2 2023.
if ($paymentType === PaymentType::APM_TRUSTLY) {
$deactivatedPaymentTypes = $this->getDeactivatedPaymentTypes();
if (\in_array($paymentType, $deactivatedPaymentTypes)) {
return true;
}

if ($paymentType === PaymentType::APM_SOFORT) {
$group = $user['additional']['country']['countryiso'] === 'GB' ? self::GROUP_UK : self::GROUP_EURO;
$violationList = $this->validator->validate($values, $validator);

$violationList = $this->validator->validate($values, $validator, [$group]);
} else {
$violationList = $this->validator->validate($values, $validator);
return $violationList->count() > 0;
}

/**
* @return array<PaymentMethodProvider::*>
*/
private function getDeactivatedPaymentTypes(): array
{
$deactivatedPaymentTypes = [];
foreach (PaymentMethodProvider::getDeactivatedPaymentMethods() as $deactivatedPaymentMethod) {
$deactivatedPaymentTypes[] = $this->paymentMethodProvider->getPaymentTypeByName($deactivatedPaymentMethod);
}

return $violationList->count() > 0;
return $deactivatedPaymentTypes;

Check failure on line 157 in Subscriber/ApmRiskManagement.php

View workflow job for this annotation

GitHub Actions / PHP / Analyse code for SwagPaymentPayPalUnified / Code analysis for SwagPaymentPayPalUnified

Method SwagPaymentPayPalUnified\Subscriber\ApmRiskManagement::getDeactivatedPaymentTypes() should return array<'SwagPaymentPayPalUn…'|'SwagPaymentPayPalUn…'|'SwagPaymentPayPalUn…'|'SwagPaymentPayPalUn…'|'SwagPaymentPayPalUn…'|'SwagPaymentPayPalUn…'|'SwagPaymentPayPalUn…'|'SwagPaymentPayPalUn…'|'SwagPaymentPayPalUn…'|'SwagPaymentPayPalUn…'|'SwagPaymentPayPalUn…'|'SwagPaymentPayPalUn…'|'SwagPaymentPayPalUn…'|'SwagPaymentPayPalUn…'|'SwagPaymentPayPalUn…'|'SwagPaymentPayPalUn…'> but returns array<int<0, max>, 'bancontact'|'blik'|'eps'|'giropay'|'ideal'|'multibanco'|'mybank'|'p24'|'PayPalAdvancedCredi…'|'PayPalClassic'|'PayPalClassicV2'|'PayPalExpress'|'PayPalExpressV2'|'PayPalPayLater'|'PayPalPayUponInvoic…'|'PayPalPlus'|'PayPalPlusInvoice'|'PayPalSepa'|'PayPalSmartPaymentB…'|'PayPalSmartPaymentB…'|'sofort'|'trustly'>.
}
}
1 change: 1 addition & 0 deletions Subscriber/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public function onPostDispatchPayment(ActionEventArgs $args)
$view->addTemplateDir($this->pluginDir . '/Resources/views/');

if ($args->get('request')->getActionName() === 'load') {
$view->assign('deactivatedPaymentMethods', PaymentMethodProvider::getDeactivatedPaymentMethods());
$view->extendsTemplate('backend/payment/controller/payment_paypal_unified.js');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use GuzzleHttp\Client;
use PDO;
use PHPUnit\Framework\TestCase;
use SwagPaymentPayPalUnified\Components\PaymentMethodProvider;
use SwagPaymentPayPalUnified\Components\TransactionReport\TransactionReport;
use SwagPaymentPayPalUnified\Tests\Functional\ContainerTrait;
use SwagPaymentPayPalUnified\Tests\Functional\DatabaseTestCaseTrait;
Expand Down Expand Up @@ -198,7 +199,9 @@ public function testGetPaymentIds()
$reflectionMethod = $this->getReflectionMethod(TransactionReport::class, 'getPaymentIds');
$result = $reflectionMethod->invoke($transactionReport);

static::assertCount(15, $result);
$expected = \count(PaymentMethodProvider::getAllUnifiedNames()) - \count(PaymentMethodProvider::getDeactivatedPaymentMethods());

static::assertCount($expected, $result);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ INSERT INTO `s_order` (`ordernumber`, `userID`, `invoice_amount`, `invoice_amoun
('SWTest91', 1, 236.62, 170.09, 0, 0, '2012-08-31 08:51:46', 0, 12, 19, '', '', '', '', 0, 0, '', '', '', NULL, '', '1', 9, 'DKK', 1, 1, '', ''),
('SWTest92', 1, 860.96, 170.09, 0, 0, '2012-08-31 08:51:46', 0, 12, 19, '', '', '', '', 0, 0, '', '', '', NULL, '', '1', 9, 'DKK', 1, 1, '', ''),
('SWTest93', 1, 468.87, 170.09, 0, 0, '2012-08-31 08:51:46', 0, 12, 19, '', '', '', '', 0, 0, '', '', '', NULL, '', '1', 9, 'DKK', 1, 1, '', ''),
('SWTest94', 1, 581.9, 170.09, 0, 0, '2012-08-31 08:51:46', 0, 12, 20, '', '', '', '', 0, 0, '', '', '', NULL, '', '1', 9, 'DKK', 1, 1, '', ''),
('SWTest95', 1, 843.29, 170.09, 0, 0, '2012-08-31 08:51:46', 0, 12, 20, '', '', '', '', 0, 0, '', '', '', NULL, '', '1', 9, 'USD', 1, 1, '', ''),
('SWTest96', 1, 265.87, 170.09, 0, 0, '2012-08-31 08:51:46', 0, 12, 20, '', '', '', '', 0, 0, '', '', '', NULL, '', '1', 9, 'DKK', 1, 1, '', ''),
('SWTest97', 1, 996.34, 170.09, 0, 0, '2012-08-31 08:51:46', 0, 12, 21, '', '', '', '', 0, 0, '', '', '', NULL, '', '1', 9, 'CHF', 1, 1, '', ''),
('SWTest98', 1, 797.81, 170.09, 0, 0, '2012-08-31 08:51:46', 0, 12, 21, '', '', '', '', 0, 0, '', '', '', NULL, '', '1', 9, 'DKK', 1, 1, '', ''),
('SWTest99', 1, 747.16, 170.09, 0, 0, '2012-08-31 08:51:46', 0, 12, 21, '', '', '', '', 0, 0, '', '', '', NULL, '', '1', 9, 'USD', 1, 1, '', ''),
('SWTest100', 1, 271.69, 170.09, 0, 0, '2012-08-31 08:51:46', 0, 12, 21, '', '', '', '', 0, 0, '', '', '', NULL, '', '1', 9, 'EUR', 1, 1, '', '');
('SWTest94', 1, 581.9, 170.09, 0, 0, '2012-08-31 08:51:46', 0, 12, 19, '', '', '', '', 0, 0, '', '', '', NULL, '', '1', 9, 'DKK', 1, 1, '', ''),
('SWTest95', 1, 843.29, 170.09, 0, 0, '2012-08-31 08:51:46', 0, 12, 19, '', '', '', '', 0, 0, '', '', '', NULL, '', '1', 9, 'USD', 1, 1, '', ''),
('SWTest96', 1, 265.87, 170.09, 0, 0, '2012-08-31 08:51:46', 0, 12, 19, '', '', '', '', 0, 0, '', '', '', NULL, '', '1', 9, 'DKK', 1, 1, '', ''),
('SWTest97', 1, 996.34, 170.09, 0, 0, '2012-08-31 08:51:46', 0, 12, 19, '', '', '', '', 0, 0, '', '', '', NULL, '', '1', 9, 'CHF', 1, 1, '', ''),
('SWTest98', 1, 797.81, 170.09, 0, 0, '2012-08-31 08:51:46', 0, 12, 19, '', '', '', '', 0, 0, '', '', '', NULL, '', '1', 9, 'DKK', 1, 1, '', ''),
('SWTest99', 1, 747.16, 170.09, 0, 0, '2012-08-31 08:51:46', 0, 12, 19, '', '', '', '', 0, 0, '', '', '', NULL, '', '1', 9, 'USD', 1, 1, '', ''),
('SWTest100', 1, 271.69, 170.09, 0, 0, '2012-08-31 08:51:46', 0, 12, 19, '', '', '', '', 0, 0, '', '', '', NULL, '', '1', 9, 'EUR', 1, 1, '', '');
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,19 @@ public function getPaymentTypeTestDataProvider()
PaymentType::APM_P24,
];

yield 'Expect APM_SOFORT' => [
PaymentMethodProviderInterface::SOFORT_METHOD_NAME,
PaymentType::APM_SOFORT,
yield 'Expect APM_EPS' => [
PaymentMethodProviderInterface::EPS_METHOD_NAME,
PaymentType::APM_EPS,
];

yield 'Expect APM_TRUSTLY' => [
yield 'Expect APM_TRUSTLY but its not installed' => [
PaymentMethodProviderInterface::TRUSTLY_METHOD_NAME,
PaymentType::APM_TRUSTLY,
PaymentType::PAYPAL_CLASSIC_V2,
];

yield 'Expect APM_EPS' => [
PaymentMethodProviderInterface::EPS_METHOD_NAME,
PaymentType::APM_EPS,
yield 'Expect APM_SOFORT but its not installed' => [
PaymentMethodProviderInterface::SOFORT_METHOD_NAME,
PaymentType::PAYPAL_CLASSIC_V2,
];

yield 'Expect Exception' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private function createController(OrderNumberService $orderNumberService)
return $this->getController(
Shopware_Controllers_Widgets_PaypalUnifiedOrderNumber::class,
[
self::SERVICE_ORDER_NUMBER_SERVICE => $orderNumberService,
self::SERVICE_ORDER_NUMBER_SERVICE => $orderNumberService,
],
new Enlight_Controller_Request_RequestTestCase(),
new Enlight_Controller_Response_ResponseTestCase(),
Expand Down
11 changes: 10 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@
<label lang="de">PayPal</label>
<label lang="en">PayPal</label>

<version>6.1.6</version>
<version>6.1.7</version>
<copyright>(c) by shopware AG</copyright>
<license>MIT</license>
<link>http://store.shopware.com</link>
<author>shopware AG</author>
<compatibility minVersion="5.2.27" maxVersion="5.99.99"/>

<changelog version="6.1.7">
<changes lang="de">
PT-13154 - Die Zahlungsart "Sofort" wird deaktiviert kann nicht mehr verwendet werden;
</changes>
<changes lang="en">
PT-13154 - The “Sofort” payment method is deactivated and can no longer be used;
</changes>
</changelog>

<changelog version="6.1.6">
<changes lang="de">
PT-13151 - Verbessert den Bestellabschluss für alternative Zahlungsarten (APMs) in Verbindung mit Session-Timeouts;
Expand Down

0 comments on commit 9b7d6a1

Please sign in to comment.