Commit 75b64d53 authored by bojanz's avatar bojanz

Issue #2958865 by czigor: Call to undefined method...

Issue #2958865 by czigor: Call to undefined method Drupal\commerce_payment\PaymentOptionsBuilder::t()
parent 4250f83f
......@@ -23,4 +23,4 @@ services:
commerce_payment.options_builder:
class: Drupal\commerce_payment\PaymentOptionsBuilder
arguments: ['@entity_type.manager']
arguments: ['@entity_type.manager', '@string_translation']
......@@ -6,9 +6,13 @@ use Drupal\commerce\EntityHelper;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\SupportsStoredPaymentMethodsInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
class PaymentOptionsBuilder implements PaymentOptionsBuilderInterface {
use StringTranslationTrait;
/**
* The entity type manager.
*
......@@ -21,9 +25,12 @@ class PaymentOptionsBuilder implements PaymentOptionsBuilderInterface {
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation) {
$this->entityTypeManager = $entity_type_manager;
$this->stringTranslation = $string_translation;
}
/**
......
......@@ -4,3 +4,4 @@ core: 8.x
type: module
dependencies:
- commerce:commerce_payment
- commerce:commerce_payment_example
commerce_payment.commerce_payment_gateway.plugin.test_onsite:
type: commerce_payment_gateway_configuration
mapping:
api_key:
type: string
label: 'API key'
<?php
namespace Drupal\commerce_payment_test\Plugin\Commerce\PaymentGateway;
use Drupal\commerce_payment_example\Plugin\Commerce\PaymentGateway\Onsite;
/**
* Provides the Test on-site payment gateway.
*
* This is a copy of example_onsite with a different display_label.
*
* @CommercePaymentGateway(
* id = "test_onsite",
* label = "Test (On-site)",
* display_label = "Test",
* forms = {
* "add-payment-method" = "Drupal\commerce_payment_example\PluginForm\Onsite\PaymentMethodAddForm",
* },
* payment_method_types = {"credit_card"},
* credit_card_types = {
* "amex", "dinersclub", "discover", "jcb", "maestro", "mastercard", "visa",
* },
* )
*/
class TestOnsite extends Onsite {}
......@@ -48,6 +48,7 @@ class PaymentOptionsBuilderTest extends CommerceKernelTestBase {
'commerce_order',
'commerce_payment',
'commerce_payment_example',
'commerce_payment_test',
];
/**
......@@ -257,21 +258,42 @@ class PaymentOptionsBuilderTest extends CommerceKernelTestBase {
}
/**
* Tests building options for a specific gateway.
* Tests building options for two different on-site gateways.
*
* Confirms that the payment gateway list can be restricted, and that
* multiple on-site gateways get unique "add" option labels.
*
* @covers ::buildOptions
*/
public function testBuildOptionsForSpecificGateway() {
$payment_gateway = PaymentGateway::load('cash_on_delivery');
$options = $this->paymentOptionsBuilder->buildOptions($this->order, [$payment_gateway]);
$this->assertCount(1, $options);
$option = reset($options);
$this->assertEquals('cash_on_delivery', $option->getId());
$this->assertEquals('Cash on delivery', $option->getLabel());
$this->assertEquals('cash_on_delivery', $option->getPaymentGatewayId());
$this->assertNull($option->getPaymentMethodId());
$this->assertNull($option->getPaymentMethodTypeId());
public function testBuildOptionsWithTwoOnsiteGateways() {
$first_payment_gateway = PaymentGateway::create([
'id' => 'first_onsite',
'label' => 'First (On-site)',
'plugin' => 'example_onsite',
]);
$second_payment_gateway = PaymentGateway::create([
'id' => 'second_onsite',
'label' => 'Second (On-site)',
'plugin' => 'test_onsite',
]);
$second_payment_gateway->save();
$payment_gateways = [$first_payment_gateway, $second_payment_gateway];
$options = $this->paymentOptionsBuilder->buildOptions($this->order, $payment_gateways);
/** @var \Drupal\commerce_payment\PaymentOption[] $options */
$options = array_values($options);
$this->assertCount(2, $options);
$this->assertEquals('new--credit_card--first_onsite', $options[0]->getId());
$this->assertEquals('New credit card (Example)', $options[0]->getLabel());
$this->assertEquals('first_onsite', $options[0]->getPaymentGatewayId());
$this->assertNull($options[0]->getPaymentMethodId());
$this->assertEquals('credit_card', $options[0]->getPaymentMethodTypeId());
$this->assertEquals('new--credit_card--second_onsite', $options[1]->getId());
$this->assertEquals('New credit card (Test)', $options[1]->getLabel());
$this->assertEquals('second_onsite', $options[1]->getPaymentGatewayId());
$this->assertNull($options[1]->getPaymentMethodId());
$this->assertEquals('credit_card', $options[1]->getPaymentMethodTypeId());
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment