-
Notifications
You must be signed in to change notification settings - Fork 3
/
stripe.admin.inc
181 lines (160 loc) · 4.76 KB
/
stripe.admin.inc
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
<?php
/**
* @file
* Stripe administration and module settings UI.
*/
/**
* Menu callback: configure Stripe API Keys
*/
function stripe_admin_keys() {
$form['API_Keys'] = array(
'#type' => 'fieldset',
'#title' => t('API Keys'),
'#collapsible' => FALSE,
);
$fields = array(
'publishable_test',
'publishable_live',
'secret_test',
'secret_live',
);
$active_key = variable_get('stripe_active_key', '');
foreach ($fields as $field) {
$title = ucwords(str_replace('_', ' ', $field));
$form['API_Keys']['stripe_' . $field] = array(
'#type' => 'textfield',
'#title' => t($title),
'#size' => 35,
'#default_value' => variable_get('stripe_' . $field, ''),
);
$form['API_Keys']['active_' . $field] = array(
'#prefix' => '<div class="container-inline form-item">',
'#suffix' => '</div>'
);
$form['API_Keys']['active_' . $field][$field] = array(
'#type' => 'radio',
'#title' => t('Activate'),
'#return_value' => $field,
'#default_value' => $active_key == $field,
'#parents' => array('stripe_active_key'),
);
if ($active_key == $field) {
$form['API_Keys']['active_' . $field][$field]['#attributes'] = array('class' => array('active'));
$form['API_Keys']['active_' . $field][$field]['#title'] = t('Active');
}
}
// Attach a little custom css.
$form['#attached']['css'] = array(
drupal_get_path('module', 'stripe') . '/stripe.css',
);
// Attach a little custom js.
$form['#attached']['js'] = array(
drupal_get_path('module', 'stripe') . '/stripe.js',
);
$form['#submit'][] = 'stripe_admin_config_submit';
return system_settings_form($form);
}
/**
* Process result from stripe config form.
*/
function stripe_admin_config_submit($form, &$form_state) {
}
function stripe_admin_test() {
/* From example on https://stripe.com/api
<form action="" method="POST" id="payment-form">
<div class="form-row">
<label>Card Number</label>
<input type="text" size="20" autocomplete="off" class="card-number"/>
</div>
<div class="form-row">
<label>CVC</label>
<input type="text" size="4" autocomplete="off" class="card-cvc"/>
</div>
<div class="form-row">
<label>Expiration (MM/YYYY)</label>
<input type="text" size="2" class="card-expiry-month"/>
<span> / </span>
<input type="text" size="4" class="card-expiry-year"/>
</div>
<button type="submit" class="submit-button">Submit Payment</button>
</form>
*/
$form['card_number'] = array(
'#type' => 'textfield',
'#title' => t('Card Number:'),
'#size' => 20,
'#default_value' => '4242424242424242',
'#attributes' => array(
'autocomplete' => 'off',
'class' => array('card-number'),
),
);
$form['card_cvc'] = array(
'#type' => 'textfield',
'#title' => t('CVC:'),
'#size' => 4,
'#default_value' => '123',
'#attributes' => array(
'autocomplete' => 'off',
'class' => array('card-cvc'),
),
);
$form['card_expiry_month'] = array(
'#type' => 'textfield',
'#title' => t('Expiration (MM/YYYY):'),
'#size' => 2,
'#default_value' => '10',
'#attributes' => array(
'class' => array('card-expiry-month'),
),
);
$form['card_expiry_year'] = array(
'#type' => 'textfield',
'#title' => t('/'),
'#size' => 2,
'#default_value' => '2020',
'#attributes' => array(
'class' => array('card-expiry-year'),
),
);
$form['amount'] = array(
'#type' => 'textfield',
'#title' => t('Amount:'),
'#prefix' => '<div class="container-inline form-item">',
'#suffix' => '<em>cents</em></div>',
'#default_value' => 99,
'#size' => 6,
'#attributes' => array(
'class' => array('amount'),
),
);
// Attach a little custom css.
$form['#attached']['css'] = array(
drupal_get_path('module', 'stripe') . '/stripe.css',
);
// Retrieve the active API Key.
$active_key_name = variable_get('stripe_active_key', '');
$active_key = variable_get('stripe_' . $active_key_name, '');
if ($active_key !== '') {
// Add the submit button. Can't submit without a key.
$form['card_submit'] = array(
'#type' => 'submit',
'#value' => t('Submit Payment'),
'#attributes' => array(
'class' => array('submit-button'),
),
);
// Attach the javascript from Stripe.
$form['#attached']['js'] = array(
'https://js.stripe.com/v1/' => array(
'type' => 'external',
),
drupal_get_path('module', 'stripe') . '/stripe.js',
// And set our key.
'jQuery(document).ready(function () { Stripe.setPublishableKey("' . $active_key . '"); });' => array(
'type' => 'inline', 'scope' => 'footer', 'weight' => 5
),
);
}
return $form;
}