1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Administrative page callbacks for the Payment UI module.
|
6
|
*/
|
7
|
|
8
|
|
9
|
/**
|
10
|
* Displays the payment transaction View in an order's payment tab.
|
11
|
*/
|
12
|
function commerce_payment_ui_order_tab($order) {
|
13
|
// Display the payments View.
|
14
|
return commerce_embed_view('commerce_payment_order', 'defaults', array($order->order_id));
|
15
|
}
|
16
|
|
17
|
/**
|
18
|
* Builds the payment settings page using the Rules UI overview table filtered
|
19
|
* to display payment method rules.
|
20
|
*/
|
21
|
function commerce_payment_ui_admin_page() {
|
22
|
RulesPluginUI::$basePath = 'admin/commerce/config/payment-methods';
|
23
|
$options = array('show plugin' => FALSE);
|
24
|
|
25
|
// Add the table for enabled payment method rules.
|
26
|
$content['enabled']['title']['#markup'] = '<h3>' . t('Enabled payment method rules') . '</h3>';
|
27
|
|
28
|
$conditions = array('event' => 'commerce_payment_methods', 'plugin' => 'reaction rule', 'active' => TRUE);
|
29
|
$content['enabled']['rules'] = RulesPluginUI::overviewTable($conditions, $options);
|
30
|
$content['enabled']['rules']['#empty'] = t('There are no active payment methods.');
|
31
|
|
32
|
// Add the table for disabled payment method rules.
|
33
|
$content['disabled']['title']['#markup'] = '<h3>' . t('Disabled payment method rules') . '</h3>';
|
34
|
|
35
|
$conditions['active'] = FALSE;
|
36
|
$content['disabled']['rules'] = RulesPluginUI::overviewTable($conditions, $options);
|
37
|
$content['disabled']['rules']['#empty'] = t('There are no disabled payment methods.');
|
38
|
|
39
|
// Update the descriptions of items in the tables to show whether or not
|
40
|
// they're enabled for use on the checkout form and payment terminal form.
|
41
|
foreach (array('enabled', 'disabled') as $status) {
|
42
|
foreach ($content[$status]['rules']['#rows'] as &$row) {
|
43
|
// We don't have access to the actual machine-name of the rule each row
|
44
|
// represents, so we must extract the name from the machine-name markup.
|
45
|
$rule_name_markup = $row[0]['data']['description']['settings']['machine_name']['#markup'];
|
46
|
$rule_name = drupal_substr($rule_name_markup, drupal_strlen(t('Machine name') . ': '));
|
47
|
|
48
|
// If we were able to extract a valid name from the markup...
|
49
|
if ($rule = rules_config_load($rule_name)) {
|
50
|
// Loop over the actions to find the first enabled payment method.
|
51
|
foreach ($rule->actions() as $action) {
|
52
|
// Parse the action name into a payment method ID.
|
53
|
if (strpos($action->getElementName(), 'commerce_payment_enable_') === 0) {
|
54
|
$method_id = drupal_substr($action->getElementName(), 24);
|
55
|
|
56
|
// Load the payment method instance and determine availability.
|
57
|
$payment_method = commerce_payment_method_load($method_id);
|
58
|
|
59
|
// Create an items array that describes where the payment method
|
60
|
// will be available for use.
|
61
|
$items = array();
|
62
|
|
63
|
if (empty($payment_method['checkout'])) {
|
64
|
$items[] = t('Not available on the checkout form');
|
65
|
}
|
66
|
else {
|
67
|
$items[] = t('Available on the checkout form');
|
68
|
}
|
69
|
|
70
|
if (empty($payment_method['terminal'])) {
|
71
|
$items[] = t('Not available on the order payment terminal');
|
72
|
}
|
73
|
else {
|
74
|
$items[] = t('Available on the order payment terminal');
|
75
|
}
|
76
|
|
77
|
$row[0]['data']['availability'] = array(
|
78
|
'#theme' => 'item_list',
|
79
|
'#items' => $items,
|
80
|
);
|
81
|
|
82
|
break;
|
83
|
}
|
84
|
}
|
85
|
}
|
86
|
}
|
87
|
}
|
88
|
|
89
|
// Store the function name in the content array to make it easy to alter the
|
90
|
// contents of this page.
|
91
|
$content['#page_callback'] = 'commerce_payment_ui_admin_page';
|
92
|
|
93
|
return $content;
|
94
|
}
|
95
|
|
96
|
/**
|
97
|
* Displays the full details of a payment transaction.
|
98
|
*/
|
99
|
function commerce_payment_ui_payment_transaction_view($order, $transaction, $view_mode) {
|
100
|
return entity_view('commerce_payment_transaction', array($transaction->transaction_id => $transaction), $view_mode, NULL, TRUE);
|
101
|
}
|
102
|
|
103
|
/**
|
104
|
* Form callback wrapper: confirmation form for deleting a payment transaction.
|
105
|
*
|
106
|
* @param $order
|
107
|
* The order object containing the transaction being deleted by the form.
|
108
|
* @param $transaction
|
109
|
* The actual payment transaction that will be deleted.
|
110
|
*
|
111
|
* @see commerce_payment_payment_transaction_delete_form()
|
112
|
*/
|
113
|
function commerce_payment_ui_payment_transaction_delete_form_wrapper($order, $transaction) {
|
114
|
// Include the forms file from the Payment module.
|
115
|
module_load_include('inc', 'commerce_payment', 'includes/commerce_payment.forms');
|
116
|
return drupal_get_form('commerce_payment_ui_payment_transaction_delete_form', $order, $transaction);
|
117
|
}
|