Skip to content

Commit 1c66c41

Browse files
mglamanbojanz
authored andcommitted
Issue #2979649 by mglaman, bojanz: The "New" prefix for payment methods is confusing as an end user
1 parent 217eae0 commit 1c66c41

7 files changed

Lines changed: 25 additions & 11 deletions

File tree

modules/payment/src/Annotation/CommercePaymentMethodType.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,25 @@ class CommercePaymentMethodType extends Plugin {
3434
/**
3535
* The payment method type create label.
3636
*
37+
* Defaults to the main label.
38+
*
3739
* @ingroup plugin_translatable
3840
*
3941
* @var \Drupal\Core\Annotation\Translation
4042
*/
4143
public $create_label;
4244

45+
/**
46+
* Constructs a new CommercePaymentMethodType object.
47+
*
48+
* @param array $values
49+
* The annotation values.
50+
*/
51+
public function __construct(array $values) {
52+
if (empty($values['create_label'])) {
53+
$values['create_label'] = $values['label'];
54+
}
55+
parent::__construct($values);
56+
}
57+
4358
}

modules/payment/src/PaymentMethodTypeManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac
3939
public function processDefinition(&$definition, $plugin_id) {
4040
parent::processDefinition($definition, $plugin_id);
4141

42-
foreach (['id', 'label', 'create_label'] as $required_property) {
42+
foreach (['id', 'label'] as $required_property) {
4343
if (empty($definition[$required_property])) {
4444
throw new PluginException(sprintf('The payment method type %s must define the %s property.', $plugin_id, $required_property));
4545
}

modules/payment/src/Plugin/Commerce/PaymentMethodType/CreditCard.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
* @CommercePaymentMethodType(
1313
* id = "credit_card",
1414
* label = @Translation("Credit card"),
15-
* create_label = @Translation("New credit card"),
1615
* )
1716
*/
1817
class CreditCard extends PaymentMethodTypeBase {

modules/payment/src/Plugin/Commerce/PaymentMethodType/PayPal.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
*
1111
* @CommercePaymentMethodType(
1212
* id = "paypal",
13-
* label = @Translation("PayPal account"),
14-
* create_label = @Translation("New PayPal account"),
13+
* label = @Translation("PayPal"),
1514
* )
1615
*/
1716
class PayPal extends PaymentMethodTypeBase {
@@ -23,7 +22,7 @@ public function buildLabel(PaymentMethodInterface $payment_method) {
2322
$args = [
2423
'@paypal_mail' => $payment_method->paypal_mail->value,
2524
];
26-
return $this->t('PayPal account (@paypal_mail)', $args);
25+
return $this->t('PayPal (@paypal_mail)', $args);
2726
}
2827

2928
/**

modules/payment/tests/src/FunctionalJavascript/PaymentCheckoutTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public function testPaymentInformation() {
199199
$expected_options = [
200200
'Visa ending in 1111',
201201
'Visa ending in 9999',
202-
'New credit card',
202+
'Credit card',
203203
'Example',
204204
];
205205
$page = $this->getSession()->getPage();
@@ -285,7 +285,7 @@ public function testCheckoutWithNewPaymentMethod() {
285285
$this->drupalGet($this->product->toUrl()->toString());
286286
$this->submitForm([], 'Add to cart');
287287
$this->drupalGet('checkout/1');
288-
$radio_button = $this->getSession()->getPage()->findField('New credit card');
288+
$radio_button = $this->getSession()->getPage()->findField('Credit card');
289289
$radio_button->click();
290290
$this->waitForAjaxToFinish();
291291

@@ -330,7 +330,7 @@ public function testCheckoutWithDeclinedPaymentMethod() {
330330
$this->drupalGet($this->product->toUrl()->toString());
331331
$this->submitForm([], 'Add to cart');
332332
$this->drupalGet('checkout/1');
333-
$radio_button = $this->getSession()->getPage()->findField('New credit card');
333+
$radio_button = $this->getSession()->getPage()->findField('Credit card');
334334
$radio_button->click();
335335
$this->waitForAjaxToFinish();
336336

modules/payment/tests/src/Kernel/PaymentOptionsBuilderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public function testBuildOptions() {
237237

238238
// Add new payment method.
239239
$this->assertEquals('new--credit_card--onsite', $options[2]->getId());
240-
$this->assertEquals('New credit card', $options[2]->getLabel());
240+
$this->assertEquals('Credit card', $options[2]->getLabel());
241241
$this->assertEquals('onsite', $options[2]->getPaymentGatewayId());
242242
$this->assertNull($options[2]->getPaymentMethodId());
243243
$this->assertEquals('credit_card', $options[2]->getPaymentMethodTypeId());
@@ -284,13 +284,13 @@ public function testBuildOptionsWithTwoOnsiteGateways() {
284284
$this->assertCount(2, $options);
285285

286286
$this->assertEquals('new--credit_card--first_onsite', $options[0]->getId());
287-
$this->assertEquals('New credit card (Example)', $options[0]->getLabel());
287+
$this->assertEquals('Credit card (Example)', $options[0]->getLabel());
288288
$this->assertEquals('first_onsite', $options[0]->getPaymentGatewayId());
289289
$this->assertNull($options[0]->getPaymentMethodId());
290290
$this->assertEquals('credit_card', $options[0]->getPaymentMethodTypeId());
291291

292292
$this->assertEquals('new--credit_card--second_onsite', $options[1]->getId());
293-
$this->assertEquals('New credit card (Test)', $options[1]->getLabel());
293+
$this->assertEquals('Credit card (Test)', $options[1]->getLabel());
294294
$this->assertEquals('second_onsite', $options[1]->getPaymentGatewayId());
295295
$this->assertNull($options[1]->getPaymentMethodId());
296296
$this->assertEquals('credit_card', $options[1]->getPaymentMethodTypeId());

src/Annotation/CommerceCondition.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class CommerceCondition extends Plugin {
3333
* The condition display label.
3434
*
3535
* Shown in the condition UI when enabling/disabling a condition.
36+
* Defaults to the main label.
3637
*
3738
* @ingroup plugin_translatable
3839
*

0 commit comments

Comments
 (0)