Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PT-13154 - Deactivate Sofort payment method #54

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Components/PaymentMethodProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static function getAlternativePaymentMethodNames()
}

/**
* @return array<self::*>
* @return list<self::*>
*/
public static function getAllUnifiedNames()
{
Expand Down Expand Up @@ -187,6 +187,17 @@ public function getPaymentTypeByName($paymentMethodName)
);
}

/**
* @return list<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);

var 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
21 changes: 20 additions & 1 deletion Setup/PaymentModels/PaymentInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public function __construct(

public function installPayments()
{
foreach (PaymentMethodProvider::getAllUnifiedNames() as $paymentMethodName) {
$paymentMethods = $this->getPaymentMethods();

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

if ($payment instanceof Payment) {
Expand All @@ -56,4 +58,21 @@ public function installPayments()
$this->modelManager->flush($payment);
}
}

/**
* @return list<PaymentMethodProvider::*>
*/
private function getPaymentMethods()
{
$deactivatedPaymentMethods = PaymentMethodProvider::getDeactivatedPaymentMethods();
$paymentMethods = \array_filter(
PaymentMethodProvider::getAllUnifiedNames(),
function ($paymentMethodName) use ($deactivatedPaymentMethods) {
return !\in_array($paymentMethodName, $deactivatedPaymentMethods, true);
},
\ARRAY_FILTER_USE_BOTH
);

return $paymentMethods;
}
}
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
23 changes: 15 additions & 8 deletions Subscriber/ApmRiskManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,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, true)) {
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 list<PaymentType::*>
*/
private function getDeactivatedPaymentTypes()
{
$deactivatedPaymentTypes = [];
foreach (PaymentMethodProvider::getDeactivatedPaymentMethods() as $deactivatedPaymentMethod) {
$deactivatedPaymentTypes[] = $this->paymentMethodProvider->getPaymentTypeByName($deactivatedPaymentMethod);
}

return $violationList->count() > 0;
return $deactivatedPaymentTypes;
}
}
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());
mitelg marked this conversation as resolved.
Show resolved Hide resolved
$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 @@ -8,8 +8,11 @@

namespace SwagPaymentPayPalUnified\Tests\Functional\Controller\Frontend;

use Doctrine\DBAL\Connection;
use Generator;
use ReflectionClass;
use Shopware\Components\Model\ModelManager;
use SwagPaymentPayPalUnified\Components\PaymentMethodProvider;
use SwagPaymentPayPalUnified\Components\PaymentMethodProviderInterface;
use SwagPaymentPayPalUnified\Controllers\Frontend\AbstractPaypalPaymentController;
use SwagPaymentPayPalUnified\PayPalBundle\PaymentType;
Expand Down Expand Up @@ -52,80 +55,19 @@ public function testGetPaymentType($paymentName, $expectedResult)
*/
public function getPaymentTypeTestDataProvider()
{
yield 'Expect PAYPAL_SEPA' => [
PaymentMethodProviderInterface::PAYPAL_UNIFIED_SEPA_METHOD_NAME,
PaymentType::PAYPAL_SEPA,
];

yield 'Expect PAYPAL_ADVANCED_CREDIT_DEBIT_CARD' => [
PaymentMethodProviderInterface::PAYPAL_UNIFIED_ADVANCED_CREDIT_DEBIT_CARD_METHOD_NAME,
PaymentType::PAYPAL_ADVANCED_CREDIT_DEBIT_CARD,
];

yield 'Expect PAYPAL_PAY_LATER' => [
PaymentMethodProviderInterface::PAYPAL_UNIFIED_PAY_LATER_METHOD_NAME,
PaymentType::PAYPAL_PAY_LATER,
];

yield 'Expect PAYPAL_CLASSIC_V2' => [
PaymentMethodProviderInterface::PAYPAL_UNIFIED_PAYMENT_METHOD_NAME,
PaymentType::PAYPAL_CLASSIC_V2,
];

yield 'Expect PAYPAL_PAY_UPON_INVOICE_V2' => [
PaymentMethodProviderInterface::PAYPAL_UNIFIED_PAY_UPON_INVOICE_METHOD_NAME,
PaymentType::PAYPAL_PAY_UPON_INVOICE_V2,
];

yield 'Expect APM_BANCONTACT' => [
PaymentMethodProviderInterface::BANCONTACT_METHOD_NAME,
PaymentType::APM_BANCONTACT,
];

yield 'Expect APM_BLIK' => [
PaymentMethodProviderInterface::BLIK_METHOD_NAME,
PaymentType::APM_BLIK,
];

yield 'Expect APM_GIROPAY' => [
PaymentMethodProviderInterface::GIROPAY_METHOD_NAME,
PaymentType::APM_GIROPAY,
];

yield 'Expect APM_IDEAL' => [
PaymentMethodProviderInterface::IDEAL_METHOD_NAME,
PaymentType::APM_IDEAL,
];

yield 'Expect APM_MULTIBANCO' => [
PaymentMethodProviderInterface::MULTIBANCO_METHOD_NAME,
PaymentType::APM_MULTIBANCO,
];

yield 'Expect APM_MYBANK' => [
PaymentMethodProviderInterface::MY_BANK_METHOD_NAME,
PaymentType::APM_MYBANK,
];

yield 'Expect APM_P24' => [
PaymentMethodProviderInterface::P24_METHOD_NAME,
PaymentType::APM_P24,
];

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

yield 'Expect APM_TRUSTLY' => [
PaymentMethodProviderInterface::TRUSTLY_METHOD_NAME,
PaymentType::APM_TRUSTLY,
];

yield 'Expect APM_EPS' => [
PaymentMethodProviderInterface::EPS_METHOD_NAME,
PaymentType::APM_EPS,
];
$paymentMethods = PaymentMethodProvider::getAllUnifiedNames();
$deactivatedPaymentMethods = PaymentMethodProvider::getDeactivatedPaymentMethods();
$paymentMethodProvider = $this->createDummyPaymentMethodProvider();
foreach ($paymentMethods as $paymentMethod) {
if (\in_array($paymentMethod, $deactivatedPaymentMethods, true)) {
continue;
}

yield 'Expect ' . $paymentMethod => [
$paymentMethod,
$paymentMethodProvider->getPaymentTypeByName($paymentMethod),
];
}

yield 'Expect Exception' => [
self::ANY_PAYMENT_NAME,
Expand Down Expand Up @@ -162,4 +104,15 @@ private function prepareSession($paymentName)
]
);
}

/**
* @return PaymentMethodProviderInterface
*/
private function createDummyPaymentMethodProvider()
{
return new PaymentMethodProvider(
$this->createMock(Connection::class),
$this->createMock(ModelManager::class)
);
}
}
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