Skip to content
Snippets Groups Projects
Commit 81667b0c authored by Primoz Hmeljak's avatar Primoz Hmeljak
Browse files

by Primsi: add configuration form.

parent ba975777
Branches
Tags
No related merge requests found
......@@ -5,6 +5,7 @@ namespace Drupal\commerce_datatrans\Plugin\Commerce\PaymentGateway;
use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OffsitePaymentGatewayBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\HttpFoundation\Request;
/**
......@@ -15,11 +16,14 @@ use Symfony\Component\HttpFoundation\Request;
* label = "Datatrans",
* display_label = "Datatrans",
* forms = {
* "offsite-payment" = "Drupal\commerce_datatrans\PluginForm\Datatrans\DatatransForm",
* "offsite-payment" = "Drupal\commerce_datatrans\PluginForm\DatatransForm",
* },
* payment_method_types = {"credit_card"},
* credit_card_types = {
* "amex", "dinersclub", "discover", "jcb", "maestro", "mastercard", "visa",
* "VIS", "ECA", "AMX", "BPY", "DIN", "DIS", "DEA", "DIB", "DII", "DNK",
* "DVI", "ELV", "ESY", "JCB", "JEL", "MAU", "MDP", "MFA", "MFG", "MFX",
* "MMS", "MNB", "MYO", "PAP", "PEF", "PFC", "PSC", "PYL", "PYO", "REK",
* "SWB", "TWI", "MPW", "ACC", "INT", "PPA", "GPA", "GEP"
* },
* )
*/
......@@ -30,7 +34,13 @@ class Datatrans extends OffsitePaymentGatewayBase {
*/
public function defaultConfiguration() {
return [
'redirect_method' => 'post',
'merchant_id' => '',
'service_url' => ' https://pilot.datatrans.biz/upp/jsp/upStart.jsp',
'req_type' => 'CAA',
'use_alias' => FALSE,
'security_level' => 2,
'sign' => '',
'hmac_key' => '',
] + parent::defaultConfiguration();
}
......@@ -40,16 +50,81 @@ class Datatrans extends OffsitePaymentGatewayBase {
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
// A real gateway would always know which redirect method should be used,
// it's made configurable here for test purposes.
$form['redirect_method'] = [
'#type' => 'radios',
'#title' => $this->t('Redirect method'),
$form['merchant_id'] = [
'#type' => 'textfield',
'#title' => t('Merchant-ID'),
'#default_value' => $this->configuration['merchant_id'],
'#required' => TRUE,
];
$form['service_url'] = [
'#type' => 'textfield',
'#title' => t('Service URL'),
'#default_value' => $this->configuration['service_url'],
'#required' => TRUE,
];
$form['req_type'] = [
'#type' => 'select',
'#title' => t('Request Type'),
'#options' => [
'NOA' => t('Authorization only'),
'CAA' => t('Authorization with immediate settlement'),
// 'conditional' => t('Authorization with conditional settlement'),
'ignore' => t('According to the setting in the Web Admin Tool'),
],
'#default_value' => $this->configuration['req_type'],
];
$form['use_alias'] = [
'#type' => 'checkbox',
'#title' => 'Use Alias',
'#default_value' => $this->configuration['use_alias'],
'#description' => t('Enable this option to always request an alias from datatrans. This is used for recurring payments and should be disabled if not necessary. If the response does not provide an alias, the payment will not be settled (or refunded, in case it was settled immediately) and the payment needs to be repeated.'),
];
$url = Url::fromUri('https://pilot.datatrans.biz/showcase/doc/Technical_Implementation_Guide.pdf', ['external' => TRUE])->toString();
$form['security'] = [
'#type' => 'fieldset',
'#title' => t('Security Settings'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#description' => t('You should not work with anything else than security level 2 on a productive system. Without the HMAC key there is no way to check whether the data really comes from Datatrans. You can find more details about the security levels in your Datatrans account at UPP ADMINISTRATION -> Security. Or check the technical information in the <a href=":url">Technical_Implementation_Guide</a>', [':url' => $url]),
];
$form['security']['security_level'] = [
'#type' => 'select',
'#title' => t('Security Level'),
'#options' => [
'get' => $this->t('Redirect via GET (302 header)'),
'post' => $this->t('Redirect via POST'),
'0' => t('Level 0. No additional security element will be send with payment messages. (not recommended)'),
'1' => t('Level 1. An additional Merchant-Identification will be send with payment messages'),
'2' => t('Level 2. Important parameters will be digitally signed (HMAC-MD5) and sent with payment messages'),
],
'#default_value' => $this->configuration['security_level'],
];
$form['security']['sign'] = [
'#type' => 'textfield',
'#title' => t('Merchant control sign'),
'#default_value' => $this->configuration['sign'],
'#description' => t('Used for security level 1'),
'#states' => [
'visible' => [
':input[name="configuration[security][security_level]"]' => ['value' => '1'],
],
],
];
$form['security']['hmac_key'] = [
'#type' => 'textfield',
'#title' => t('HMAC Key'),
'#default_value' => $this->configuration['hmac_key'],
'#description' => t('Used for security level 2'),
'#states' => [
'visible' => [
':input[name="configuration[security][security_level]"]' => ['value' => '2'],
],
],
'#default_value' => $this->configuration['redirect_method'],
];
return $form;
......@@ -62,7 +137,13 @@ class Datatrans extends OffsitePaymentGatewayBase {
parent::submitConfigurationForm($form, $form_state);
if (!$form_state->getErrors()) {
$values = $form_state->getValue($form['#parents']);
$this->configuration['redirect_method'] = $values['redirect_method'];
$this->configuration['merchant_id'] = $values['merchant_id'];
$this->configuration['service_url'] = $values['service_url'];
$this->configuration['req_type'] = $values['req_type'];
$this->configuration['use_alias'] = $values['use_alias'];
$this->configuration['security_level'] = $values['security']['security_level'];
$this->configuration['sign'] = $values['security']['sign'];
$this->configuration['hmac_key'] = $values['security']['hmac_key'];
}
}
......
<?php
namespace Drupal\commerce_datatrans\PluginForm\OffsiteRedirect;
namespace Drupal\commerce_datatrans\PluginForm;
use Drupal\commerce_payment\PluginForm\PaymentOffsiteForm as BasePaymentOffsiteForm;
use Drupal\commerce_payment\PluginForm\PaymentOffsiteForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class PaymentOffsiteForm extends BasePaymentOffsiteForm {
/**
* Provides a checkout form for the Datatrans gateway.
*/
class DatatransForm extends PaymentOffsiteForm {
/**
* {@inheritdoc}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment