diff --git a/modules/payment/config/schema/commerce_payment.schema.yml b/modules/payment/config/schema/commerce_payment.schema.yml index 56cf9627b0..d43cbf0449 100644 --- a/modules/payment/config/schema/commerce_payment.schema.yml +++ b/modules/payment/config/schema/commerce_payment.schema.yml @@ -44,6 +44,10 @@ commerce_payment_gateway_configuration: mode: type: string label: 'Mode' + details: + type: text_format + label: 'Details' + translatable: true payment_method_types: type: sequence label: 'Payment method types' diff --git a/modules/payment/src/Plugin/Commerce/CheckoutPane/PaymentInformation.php b/modules/payment/src/Plugin/Commerce/CheckoutPane/PaymentInformation.php index 6cce21e053..53eb059592 100644 --- a/modules/payment/src/Plugin/Commerce/CheckoutPane/PaymentInformation.php +++ b/modules/payment/src/Plugin/Commerce/CheckoutPane/PaymentInformation.php @@ -118,6 +118,15 @@ public function buildPaneForm(array $pane_form, FormStateInterface $form_state, $selected_option = $pane_form['payment_method'][$default_option]; $payment_gateway = $payment_gateways[$selected_option['#payment_gateway']]; + + // Add details markup if available. + if (empty($selected_option['#payment_method']) && $details = $payment_gateway->getPlugin()->getDetails()) { + $pane_form['details'] = [ + '#type' => 'item', + '#markup' => check_markup($details['value'], $details['format']), + ]; + } + if ($payment_gateway->getPlugin() instanceof SupportsStoredPaymentMethodsInterface) { if (!empty($selected_option['#payment_method_type'])) { /** @var \Drupal\commerce_payment\PaymentMethodStorageInterface $payment_method_storage */ diff --git a/modules/payment/src/Plugin/Commerce/PaymentGateway/PaymentGatewayBase.php b/modules/payment/src/Plugin/Commerce/PaymentGateway/PaymentGatewayBase.php index b4883d5b8e..0dc4917fa0 100644 --- a/modules/payment/src/Plugin/Commerce/PaymentGateway/PaymentGatewayBase.php +++ b/modules/payment/src/Plugin/Commerce/PaymentGateway/PaymentGatewayBase.php @@ -171,6 +171,14 @@ public function getSupportedModes() { return $this->pluginDefinition['modes']; } + /** + * {@inheritdoc} + */ + public function getDetails() { + return ($this->configuration['details']['value']) ? $this->configuration['details'] : NULL; + + } + /** * {@inheritdoc} */ @@ -251,6 +259,10 @@ public function defaultConfiguration() { return [ 'display_label' => $this->pluginDefinition['display_label'], 'mode' => $modes ? reset($modes) : '', + 'details' => [ + 'value' => '', + 'format' => 'plain_text', + ], 'payment_method_types' => [], ]; } @@ -270,6 +282,14 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta '#description' => t('Shown to customers during checkout.'), '#default_value' => $this->configuration['display_label'], ]; + $form['details'] = [ + '#type' => 'text_format', + '#title' => $this->t('Additional details'), + '#description' => $this->t('Additional details about payment to be shown to the customer on checkout.'), + '#default_value' => $this->configuration['details']['value'], + '#format' => $this->configuration['details']['format'], + '#rows' => 2, + ]; if (count($modes) > 1) { $form['mode'] = [ @@ -323,6 +343,7 @@ public function submitConfigurationForm(array &$form, FormStateInterface $form_s $this->configuration = []; $this->configuration['display_label'] = $values['display_label']; $this->configuration['mode'] = $values['mode']; + $this->configuration['details'] = $values['details']; $this->configuration['payment_method_types'] = array_keys($values['payment_method_types']); } } diff --git a/modules/payment/src/Plugin/Commerce/PaymentGateway/PaymentGatewayInterface.php b/modules/payment/src/Plugin/Commerce/PaymentGateway/PaymentGatewayInterface.php index 0d94eee8d8..40763ba5ed 100644 --- a/modules/payment/src/Plugin/Commerce/PaymentGateway/PaymentGatewayInterface.php +++ b/modules/payment/src/Plugin/Commerce/PaymentGateway/PaymentGatewayInterface.php @@ -51,6 +51,14 @@ public function getMode(); */ public function getSupportedModes(); + /** + * Gets the details of the payment gateway or NULL if not defined.. + * + * @return array|null + * The details definition or NULL. + */ + public function getDetails(); + /** * Gets the JS library ID. * diff --git a/modules/payment/tests/src/Functional/PaymentGatewayTest.php b/modules/payment/tests/src/Functional/PaymentGatewayTest.php index 5a70e81d7a..d257daeea2 100644 --- a/modules/payment/tests/src/Functional/PaymentGatewayTest.php +++ b/modules/payment/tests/src/Functional/PaymentGatewayTest.php @@ -36,11 +36,16 @@ public function testPaymentGatewayCreation() { $this->getSession()->getPage()->clickLink('Add payment gateway'); $this->assertSession()->addressEquals('admin/commerce/config/payment-gateways/add'); + $details = [ + 'value' => 'Test details', + 'format' => 'plain_text', + ]; $values = [ 'label' => 'Example', 'plugin' => 'example_offsite_redirect', 'configuration[example_offsite_redirect][redirect_method]' => 'post', 'configuration[example_offsite_redirect][mode]' => 'test', + 'configuration[example_offsite_redirect][details][value]' => $details['value'], 'status' => '1', // Setting the 'id' can fail if focus switches to another field. // This is a bug in the machine name JS that can be reproduced manually. @@ -60,6 +65,7 @@ public function testPaymentGatewayCreation() { $this->assertEquals(TRUE, $payment_gateway->status()); $payment_gateway_plugin = $payment_gateway->getPlugin(); $this->assertEquals('test', $payment_gateway_plugin->getMode()); + $this->assertEquals($details, $payment_gateway_plugin->getDetails()); $configuration = $payment_gateway_plugin->getConfiguration(); $this->assertEquals('post', $configuration['redirect_method']); } @@ -77,9 +83,14 @@ public function testPaymentGatewayEditing() { $payment_gateway = $this->createEntity('commerce_payment_gateway', $values); $this->drupalGet('admin/commerce/config/payment-gateways/manage/' . $payment_gateway->id()); + $details = [ + 'value' => 'Test details', + 'format' => 'plain_text', + ]; $values += [ 'configuration[example_offsite_redirect][redirect_method]' => 'get', 'configuration[example_offsite_redirect][mode]' => 'live', + 'configuration[example_offsite_redirect][details][value]' => $details['value'], 'conditionOperator' => 'OR', ]; $this->submitForm($values, 'Save'); @@ -94,6 +105,7 @@ public function testPaymentGatewayEditing() { $this->assertEquals(FALSE, $payment_gateway->status()); $payment_gateway_plugin = $payment_gateway->getPlugin(); $this->assertEquals('live', $payment_gateway_plugin->getMode()); + $this->assertEquals($details, $payment_gateway_plugin->getDetails()); $configuration = $payment_gateway_plugin->getConfiguration(); $this->assertEquals('get', $configuration['redirect_method']); }