Skip to content
Open
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
4 changes: 4 additions & 0 deletions modules/payment/config/schema/commerce_payment.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand Down Expand Up @@ -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' => [],
];
}
Expand All @@ -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'] = [
Expand Down Expand Up @@ -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']);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
12 changes: 12 additions & 0 deletions modules/payment/tests/src/Functional/PaymentGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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']);
}
Expand All @@ -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');
Expand All @@ -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']);
}
Expand Down