-
Notifications
You must be signed in to change notification settings - Fork 0
/
commerce_cardonfile.install
221 lines (203 loc) · 6.24 KB
/
commerce_cardonfile.install
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
/**
* @file
* Installs the tables required by Commerce Card on File.
*/
/**
* Implements hook_schema().
*/
function commerce_cardonfile_schema() {
$schema = array();
$schema['commerce_card_data'] = array(
'description' => 'Stores truncated card data with references to the full card data stored at payment gateways.',
'fields' => array(
'card_id' => array(
'description' => 'Serial numeric ID of the truncated card data in the local database.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
'description' => 'The {users}.uid that supplied this card data.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'payment_method' => array(
'description' => 'The payment method method_id for this transaction.',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
),
'instance_id' => array(
'description' => 'The payment method instance ID for this transaction.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'remote_id' => array(
'description' => 'The remote ID to the full card data at the payment gateway.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'card_type' => array(
'description' => 'The credit card type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'card_name' => array(
'description' => 'The name on the credit card.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'card_number' => array(
'description' => 'Truncated number of the credit card (last 4 digits).',
'type' => 'varchar',
'length' => 4,
'not null' => TRUE,
'default' => '',
),
'card_exp_month' => array(
'description' => 'Expiration month of the credit card.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'card_exp_year' => array(
'description' => 'Expiration year of the credit card.',
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0,
),
'status' => array(
'description' => 'Status of the card data: inactive (0), active (1), or active and not deletable (2).',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'created' => array(
'description' => 'The Unix timestamp when the card data was first stored.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'changed' => array(
'description' => 'The Unix timestamp when the card data was last updated.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'instance_default' => array(
'description' => 'Boolean indicating the default card for a payment instance ID.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array('card_id'),
'indexes' => array(
'uid' => array('uid'),
'instance_id' => array('instance_id'),
),
'foreign keys' => array(
'owner' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
),
);
return $schema;
}
/**
* Implements hook_field_schema().
*/
function commerce_cardonfile_field_schema($field) {
if ($field['type'] == 'commerce_cardonfile_reference') {
return array(
'columns' => array(
'card_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
),
'indexes' => array(
'card_id' => array('card_id'),
),
'foreign keys' => array(
'card_id' => array(
'table' => 'commerce_card_data',
'columns' => array('card_id' => 'card_id'),
),
),
);
}
}
/**
* Add the instance_default column to card data table
*/
function commerce_cardonfile_update_7101(&$sandbox) {
if (!db_field_exists('commerce_card_data', 'instance_default')) {
db_add_field('commerce_card_data', 'instance_default', array(
'description' => 'Boolean indicating the default card for a payment instance ID.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
));
}
return t('Card data table has been updated.');
}
/**
* Create a card on file reference field instance for each order type
*/
function commerce_cardonfile_update_7102(&$sandbox) {
field_info_cache_clear();
drupal_load('module', 'commerce_cardonfile');
module_load_include('module', 'commerce_order');
commerce_cardonfile_configure_order_type();
return t('Card on file order fields have been created.');
}
/**
* Update permission from 'manage' to 'view', 'edit', 'delete'
*/
function commerce_cardonfile_update_7103(&$sandbox) {
// Load utility functions.
module_load_install('commerce');
// Retrieve existing permissions
$result= db_select('role_permission', 'p')
->fields('p')
->condition('permission', 'manage own card data')
->execute();
$records = $result->fetchAll(PDO::FETCH_ASSOC);
if (empty($records)) {
return t('No permissions to update.');
}
// update permission and views access from 'manaage' to 'view'
$map = array(
'manage own card data' => 'view own card data',
);
commerce_update_rename_permissions($map);
// create 'edit' and 'delete' for 'manage' permissions to mimic old access
$inserts = array();
foreach ($records as $record) {
$inserts[] = array('permission' => 'edit own card data') + $record;
$inserts[] = array('permission' => 'delete own card data') + $record;
}
$query = db_insert('role_permission')->fields(array('rid', 'permission', 'module'));
foreach ($inserts as $insert) {
$query->values($insert);
}
$query->execute();
return t('Role and custom View permissions updated to new permissions. Access checks in modules and permissions on default Views must be updated manually.');
}