-
Notifications
You must be signed in to change notification settings - Fork 0
/
commerce_novalnet.module
121 lines (112 loc) · 3.88 KB
/
commerce_novalnet.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* @file
* Contains hooks for Commerce Novalnet payment module.
*
* @category PHP
* @package commerce_novalnet
* @author Novalnet AG
* @copyright Copyright by Novalnet
* @license https://www.novalnet.de/payment-plugins/kostenlos/lizenz
* @version 1.2.0
*/
use Drupal\file\FileInterface;
use Drupal\commerce_novalnet\Novalnet;
/**
* Implements hook_preprocess_commerce_checkout_completion_message().
*/
function commerce_novalnet_preprocess_commerce_checkout_completion_message(&$variables) {
$order = $variables['order_entity'];
$variables['payment_instructions'] = [
'#markup' => '<span class="commerce-novalnet-comments">' . $order->getData('transaction_details')['message'] . '</span>',
];
}
/**
* Implements hook_preprocess_commerce_order().
*/
function commerce_novalnet_preprocess_commerce_order(&$variables) {
$order = $variables['order_entity'];
$variables['novalnet_transaction_details'] = [
'#markup' => '<span class="commerce-novalnet-comments">' . $order->getData('transaction_details')['message'] . '</span>',
];
}
/**
* Implements hook_preprocess_commerce_order_receipt().
*/
function commerce_novalnet_preprocess_commerce_order_receipt(&$variables) {
$order = $variables['order_entity'];
$variables['novalnet_transaction_details'] = [
'#markup' => '<span class="commerce-novalnet-comments">' . $order->getData('transaction_details')['message'] . '</span>',
];
}
/**
* Implements hook_form_alter().
*/
function commerce_novalnet_form_alter(&$form, &$variables, $form_id) {
if (!empty($form['#step_id']) && $form['#step_id'] == 'order_information') {
$entity_type_manager = \Drupal::entityTypeManager();
$payment_gateway_storage = $entity_type_manager->getStorage('commerce_payment_gateway');
$gateways = $payment_gateway_storage->loadMultiple();
foreach ($gateways as $gateway) {
if ($gateway->id() == $form['payment_information']['payment_method']['#default_value']) {
$configuration = $gateway->getPluginConfiguration();
if (isset($configuration['notification'])) {
$form['payment_information']['payment_method']['display_title'] = Novalnet::displayPaymentLogo($configuration['display_label'], $gateway->getPluginId());
if ($configuration['mode'] == 'test') {
$form['payment_information']['payment_method']['test_mode'] = [
'inside' => [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => '<br />' . t('Test Mode'),
'#attributes' => [
'style' => 'position: relative;
background-color: #0080c9;
color: #fff;
padding: 10px 20px;
margin-bottom: 8px;
font-size: 10px;
text-align: center;
text-transform: uppercase;
letter-spacing: 1px;
line-height: 0.8px;
border-radius: 0px 0px 5px 5px;
transition: transform 0.5s ease 0.5s;
animation: novalnet-test-mode-blinker 2s linear infinite;
font-weight: bold;
float: right;
top: -0px;'
],
],
];
}
$form['payment_information']['payment_method']['description'] = [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => '<br />' .Novalnet::getDescription($gateway->getPluginId()),
'#attributes' => [
'style' => 'position: relative;
width: 95%;
height: auto;
background: content-box;
font-size: 14px;
color: #333;
margin: 20px 0px;
padding: 1em 1em;
border-left: 5px solid #0080c9;
box-shadow:0 0 8px 0px rgba(0,0,0,.4);
clear: both;
word-break:break-word;'
],
];
if (!empty($configuration['notification'])) {
$form['payment_information']['payment_method']['buyer_notification'] = [
'#prefix' => '<p>',
'#markup' => $configuration['notification'],
'#suffix' => '</p>',
];
}
}
}
}
}
}