Skip to content

Commit 73e5dbb

Browse files
authored
Merge pull request #54 from shopware5/pt-13154/deactivate-sofort
PT-13154 - Deactivate Sofort payment method
2 parents 79fbc59 + 2d49bd0 commit 73e5dbb

File tree

11 files changed

+127
-94
lines changed

11 files changed

+127
-94
lines changed

Components/PaymentMethodProvider.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public static function getAlternativePaymentMethodNames()
134134
}
135135

136136
/**
137-
* @return array<self::*>
137+
* @return list<self::*>
138138
*/
139139
public static function getAllUnifiedNames()
140140
{
@@ -187,6 +187,17 @@ public function getPaymentTypeByName($paymentMethodName)
187187
);
188188
}
189189

190+
/**
191+
* @return list<self::*>
192+
*/
193+
public static function getDeactivatedPaymentMethods()
194+
{
195+
return [
196+
self::SOFORT_METHOD_NAME,
197+
self::TRUSTLY_METHOD_NAME,
198+
];
199+
}
200+
190201
/**
191202
* {@inheritDoc}
192203
*/

Resources/views/backend/payment/controller/payment_paypal_unified.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Ext.define('Shopware.apps.Payment.controller.PaymentPaypalUnified', {
2929
payUponInvoicePaymentMethodName: 'SwagPaymentPayPalUnifiedPayUponInvoice',
3030
myBankPaymentMethodName: 'SwagPaymentPayPalUnifiedMyBank',
3131
sofortPaymentMethodName: 'SwagPaymentPayPalUnifiedSofort',
32+
trustlyPaymentMethodName: 'SwagPaymentPayPalUnifiedTrustly',
33+
34+
deactivatedPaymentMethods: '{$deactivatedPaymentMethods|json_encode}',
3235

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

51+
onSavePayment: function(generalForm, countryGrid, subShopGrid, surchargeGrid) {
52+
var deactivatedPaymentMethods = JSON.parse(this.deactivatedPaymentMethods);
53+
54+
var index = deactivatedPaymentMethods.indexOf(this.currentRecord.data.name);
55+
if (index > -1) {
56+
this.currentRecord.set('active', false);
57+
58+
generalForm.getForm().setValues({
59+
active: false,
60+
name: deactivatedPaymentMethods[index],
61+
});
62+
}
63+
64+
this.callParent(arguments);
65+
},
66+
4867
_handleDisclaimer: function () {
4968
this._removeDisclaimer();
5069

Setup/PaymentModels/PaymentInstaller.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public function __construct(
4242

4343
public function installPayments()
4444
{
45-
foreach (PaymentMethodProvider::getAllUnifiedNames() as $paymentMethodName) {
45+
$paymentMethods = $this->getPaymentMethods();
46+
47+
foreach ($paymentMethods as $paymentMethodName) {
4648
$payment = $this->paymentMethodProvider->getPaymentMethodModel($paymentMethodName);
4749

4850
if ($payment instanceof Payment) {
@@ -56,4 +58,21 @@ public function installPayments()
5658
$this->modelManager->flush($payment);
5759
}
5860
}
61+
62+
/**
63+
* @return list<PaymentMethodProvider::*>
64+
*/
65+
private function getPaymentMethods()
66+
{
67+
$deactivatedPaymentMethods = PaymentMethodProvider::getDeactivatedPaymentMethods();
68+
$paymentMethods = \array_filter(
69+
PaymentMethodProvider::getAllUnifiedNames(),
70+
function ($paymentMethodName) use ($deactivatedPaymentMethods) {
71+
return !\in_array($paymentMethodName, $deactivatedPaymentMethods, true);
72+
},
73+
\ARRAY_FILTER_USE_BOTH
74+
);
75+
76+
return $paymentMethods;
77+
}
5978
}

Setup/Versions/UpdateTo617.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,20 @@ public function __construct(Connection $connection)
2727
*/
2828
public function update()
2929
{
30+
$this->deactivateSofortPayment();
3031
$this->createOrderTurnoverTable();
3132
}
3233

34+
/**
35+
* @return void
36+
*/
37+
private function deactivateSofortPayment()
38+
{
39+
$this->connection->executeQuery(
40+
'UPDATE s_core_paymentmeans SET active = 0 WHERE name = "SwagPaymentPayPalUnifiedSofort"'
41+
);
42+
}
43+
3344
/**
3445
* @return void
3546
*/

Subscriber/ApmRiskManagement.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,26 @@ public function onExecuteApmRule(Enlight_Event_EventArgs $args)
135135
$values = $this->valueFactory->createValue($paymentType, $basket, $user);
136136
$validator = $this->validatorFactory->createValidator($paymentType);
137137

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

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

146-
$violationList = $this->validator->validate($values, $validator, [$group]);
147-
} else {
148-
$violationList = $this->validator->validate($values, $validator);
145+
return $violationList->count() > 0;
146+
}
147+
148+
/**
149+
* @return list<PaymentType::*>
150+
*/
151+
private function getDeactivatedPaymentTypes()
152+
{
153+
$deactivatedPaymentTypes = [];
154+
foreach (PaymentMethodProvider::getDeactivatedPaymentMethods() as $deactivatedPaymentMethod) {
155+
$deactivatedPaymentTypes[] = $this->paymentMethodProvider->getPaymentTypeByName($deactivatedPaymentMethod);
149156
}
150157

151-
return $violationList->count() > 0;
158+
return $deactivatedPaymentTypes;
152159
}
153160
}

Subscriber/Backend.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public function onPostDispatchPayment(ActionEventArgs $args)
128128
$view->addTemplateDir($this->pluginDir . '/Resources/views/');
129129

130130
if ($args->get('request')->getActionName() === 'load') {
131+
$view->assign('deactivatedPaymentMethods', PaymentMethodProvider::getDeactivatedPaymentMethods());
131132
$view->extendsTemplate('backend/payment/controller/payment_paypal_unified.js');
132133
}
133134
}

Tests/Functional/Components/TransactionReport/TransactionReportTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use GuzzleHttp\Client;
1313
use PDO;
1414
use PHPUnit\Framework\TestCase;
15+
use SwagPaymentPayPalUnified\Components\PaymentMethodProvider;
1516
use SwagPaymentPayPalUnified\Components\TransactionReport\TransactionReport;
1617
use SwagPaymentPayPalUnified\Tests\Functional\ContainerTrait;
1718
use SwagPaymentPayPalUnified\Tests\Functional\DatabaseTestCaseTrait;
@@ -198,7 +199,9 @@ public function testGetPaymentIds()
198199
$reflectionMethod = $this->getReflectionMethod(TransactionReport::class, 'getPaymentIds');
199200
$result = $reflectionMethod->invoke($transactionReport);
200201

201-
static::assertCount(15, $result);
202+
$expected = \count(PaymentMethodProvider::getAllUnifiedNames()) - \count(PaymentMethodProvider::getDeactivatedPaymentMethods());
203+
204+
static::assertCount($expected, $result);
202205
}
203206

204207
/**

Tests/Functional/Components/TransactionReport/_fixtures/orders.sql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ INSERT INTO `s_order` (`ordernumber`, `userID`, `invoice_amount`, `invoice_amoun
9797
('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, '', ''),
9898
('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, '', ''),
9999
('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, '', ''),
100-
('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, '', ''),
101-
('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, '', ''),
102-
('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, '', ''),
103-
('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, '', ''),
104-
('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, '', ''),
105-
('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, '', ''),
106-
('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, '', '');
100+
('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, '', ''),
101+
('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, '', ''),
102+
('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, '', ''),
103+
('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, '', ''),
104+
('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, '', ''),
105+
('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, '', ''),
106+
('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, '', '');

Tests/Functional/Controller/Frontend/AbstractPaypalPaymentControllerGetPaymentTypeTest.php

Lines changed: 27 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88

99
namespace SwagPaymentPayPalUnified\Tests\Functional\Controller\Frontend;
1010

11+
use Doctrine\DBAL\Connection;
1112
use Generator;
1213
use ReflectionClass;
14+
use Shopware\Components\Model\ModelManager;
15+
use SwagPaymentPayPalUnified\Components\PaymentMethodProvider;
1316
use SwagPaymentPayPalUnified\Components\PaymentMethodProviderInterface;
1417
use SwagPaymentPayPalUnified\Controllers\Frontend\AbstractPaypalPaymentController;
1518
use SwagPaymentPayPalUnified\PayPalBundle\PaymentType;
@@ -52,80 +55,19 @@ public function testGetPaymentType($paymentName, $expectedResult)
5255
*/
5356
public function getPaymentTypeTestDataProvider()
5457
{
55-
yield 'Expect PAYPAL_SEPA' => [
56-
PaymentMethodProviderInterface::PAYPAL_UNIFIED_SEPA_METHOD_NAME,
57-
PaymentType::PAYPAL_SEPA,
58-
];
59-
60-
yield 'Expect PAYPAL_ADVANCED_CREDIT_DEBIT_CARD' => [
61-
PaymentMethodProviderInterface::PAYPAL_UNIFIED_ADVANCED_CREDIT_DEBIT_CARD_METHOD_NAME,
62-
PaymentType::PAYPAL_ADVANCED_CREDIT_DEBIT_CARD,
63-
];
64-
65-
yield 'Expect PAYPAL_PAY_LATER' => [
66-
PaymentMethodProviderInterface::PAYPAL_UNIFIED_PAY_LATER_METHOD_NAME,
67-
PaymentType::PAYPAL_PAY_LATER,
68-
];
69-
70-
yield 'Expect PAYPAL_CLASSIC_V2' => [
71-
PaymentMethodProviderInterface::PAYPAL_UNIFIED_PAYMENT_METHOD_NAME,
72-
PaymentType::PAYPAL_CLASSIC_V2,
73-
];
74-
75-
yield 'Expect PAYPAL_PAY_UPON_INVOICE_V2' => [
76-
PaymentMethodProviderInterface::PAYPAL_UNIFIED_PAY_UPON_INVOICE_METHOD_NAME,
77-
PaymentType::PAYPAL_PAY_UPON_INVOICE_V2,
78-
];
79-
80-
yield 'Expect APM_BANCONTACT' => [
81-
PaymentMethodProviderInterface::BANCONTACT_METHOD_NAME,
82-
PaymentType::APM_BANCONTACT,
83-
];
84-
85-
yield 'Expect APM_BLIK' => [
86-
PaymentMethodProviderInterface::BLIK_METHOD_NAME,
87-
PaymentType::APM_BLIK,
88-
];
89-
90-
yield 'Expect APM_GIROPAY' => [
91-
PaymentMethodProviderInterface::GIROPAY_METHOD_NAME,
92-
PaymentType::APM_GIROPAY,
93-
];
94-
95-
yield 'Expect APM_IDEAL' => [
96-
PaymentMethodProviderInterface::IDEAL_METHOD_NAME,
97-
PaymentType::APM_IDEAL,
98-
];
99-
100-
yield 'Expect APM_MULTIBANCO' => [
101-
PaymentMethodProviderInterface::MULTIBANCO_METHOD_NAME,
102-
PaymentType::APM_MULTIBANCO,
103-
];
104-
105-
yield 'Expect APM_MYBANK' => [
106-
PaymentMethodProviderInterface::MY_BANK_METHOD_NAME,
107-
PaymentType::APM_MYBANK,
108-
];
109-
110-
yield 'Expect APM_P24' => [
111-
PaymentMethodProviderInterface::P24_METHOD_NAME,
112-
PaymentType::APM_P24,
113-
];
114-
115-
yield 'Expect APM_SOFORT' => [
116-
PaymentMethodProviderInterface::SOFORT_METHOD_NAME,
117-
PaymentType::APM_SOFORT,
118-
];
119-
120-
yield 'Expect APM_TRUSTLY' => [
121-
PaymentMethodProviderInterface::TRUSTLY_METHOD_NAME,
122-
PaymentType::APM_TRUSTLY,
123-
];
124-
125-
yield 'Expect APM_EPS' => [
126-
PaymentMethodProviderInterface::EPS_METHOD_NAME,
127-
PaymentType::APM_EPS,
128-
];
58+
$paymentMethods = PaymentMethodProvider::getAllUnifiedNames();
59+
$deactivatedPaymentMethods = PaymentMethodProvider::getDeactivatedPaymentMethods();
60+
$paymentMethodProvider = $this->createDummyPaymentMethodProvider();
61+
foreach ($paymentMethods as $paymentMethod) {
62+
if (\in_array($paymentMethod, $deactivatedPaymentMethods, true)) {
63+
continue;
64+
}
65+
66+
yield 'Expect ' . $paymentMethod => [
67+
$paymentMethod,
68+
$paymentMethodProvider->getPaymentTypeByName($paymentMethod),
69+
];
70+
}
12971

13072
yield 'Expect Exception' => [
13173
self::ANY_PAYMENT_NAME,
@@ -162,4 +104,15 @@ private function prepareSession($paymentName)
162104
]
163105
);
164106
}
107+
108+
/**
109+
* @return PaymentMethodProviderInterface
110+
*/
111+
private function createDummyPaymentMethodProvider()
112+
{
113+
return new PaymentMethodProvider(
114+
$this->createMock(Connection::class),
115+
$this->createMock(ModelManager::class)
116+
);
117+
}
165118
}

Tests/Functional/Controller/Widgets/PayPalUnifiedOrderNumberTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private function createController(OrderNumberService $orderNumberService)
8787
return $this->getController(
8888
Shopware_Controllers_Widgets_PaypalUnifiedOrderNumber::class,
8989
[
90-
self::SERVICE_ORDER_NUMBER_SERVICE => $orderNumberService,
90+
self::SERVICE_ORDER_NUMBER_SERVICE => $orderNumberService,
9191
],
9292
new Enlight_Controller_Request_RequestTestCase(),
9393
new Enlight_Controller_Response_ResponseTestCase(),

0 commit comments

Comments
 (0)