2 function freeside_signup() {
3 return drupal_get_form('freeside_signup_form');
7 /* "debug kpr": Krumo-print $var if debugging is on */
9 if(empty($debug)) $debug = variable_get('freeside_debug','');
15 function signup_info($keys) {
16 /* local cache, because transporting the entire signup_info
17 through XML-RPC is incredibly slow. If you change the config,
18 you can flush the local cache with the "Clear cached data"
19 button on the Drupal "Performance" menu. */
20 $cid = 'FS_signup_info';
21 $info = cache_get($cid);
27 'agentnum' => variable_get('freeside_agentnum',''),
33 $freeside = new FreesideSelfService();
34 $freeside->clear_signup_cache();
35 $info = $freeside->signup_info($packet);
36 cache_set($cid, $info, 'cache', CACHE_TEMPORARY);
41 function subextract($array, $key) {
42 // map { $_->{$key} } (...)
44 foreach ($array as $i) {
50 function freeside_signup_form($form_state) {
53 $agentnum = variable_get('freeside_agentnum','');
54 if( !$agentnum || !(variable_get('freeside_hostname','')) ) {
55 drupal_set_message(t('Freeside self-service is not yet configured.'),'error');
59 $freeside = new FreesideSelfService();
61 // all the signup_info that we need
71 $signup_info = signup_info($keys);
76 $refs = $signup_info['part_referral'];
77 $form['refnum'] = count($refs) > 1 ?
80 '#title' => t('How did you hear about us?'),
81 '#options'=> array_combine(
82 subextract($refs, 'refnum'),
83 subextract($refs, 'referral')
85 '#default_value'=>$signup_info['refnum'],
88 '#value' => $refs[0]['refnum'],
91 $form['contact'] = array(
92 '#type' => 'fieldset',
93 '#title' => t('Contact Information'),
95 '#prefix' => '<div class="container-inline">',
96 '#type' => 'textfield',
97 '#title' => t('Contact name (last, first)'),
102 '#type' => 'textfield',
105 '#suffix' => '</div>',
108 '#type' => 'textfield',
109 '#title' => t('Company'),
113 '#type' => 'textfield',
114 '#title' => t('Address'),
119 '#type' => 'textfield',
123 '#prefix' => '<div class="container-inline">',
124 '#type' => 'textfield',
125 '#title' => t('City'),
130 '#type' => 'textfield',
131 '#title' => t('State'),
134 '#default_value'=>$info['statedefault'],
137 '#type' => 'textfield',
138 '#title' => t('Zip'),
141 '#suffix' => '</div>',
144 '#type' => 'textfield',
145 '#title' => t('Daytime Phone'),
149 '#type' => 'textfield',
150 '#title' => t('Night Phone'),
155 $emailinvoiceonly = $signup_info['emailinvoiceonly'];
157 $form['billing'] = array(
158 'invoicing_list' => array(
159 '#type' => 'textfield',
160 '#title' => t('Email invoice to'),
162 '#required'=>$emailinvoiceonly,
164 '#type' => 'fieldset',
165 '#title' => t('Billing Information'),
166 'invoicing_list_POST' => array(
167 '#type' => $emailinvoiceonly ? 'hidden' : 'checkbox',
168 '#title' => t('Send a paper invoice'),
169 '#default_value' => 0,
173 if( count($signup_info['payby']) > 1 ) {
174 $form['billing']['payby'] = array(
176 '#title' => t('Payment method'),
177 '#options'=> array_combine(
178 $signup_info['payby'],
179 $signup_info['payby_longname']
184 $form['billing']['payby'] = array(
186 '#value' => $signup_info['payby'][0],
189 $form['billing']['payby_CARD'] = array(
190 '#type' => 'fieldset',
192 '#prefix' => '<div class="container-inline">',
193 '#type' => 'textfield',
194 '#title' => t('Credit card number'),
198 '#suffix' => '</div>',
201 '#prefix' => '<div class="container-inline">',
202 '#type' => 'textfield',
203 '#title' => t('Expiration date'),
209 '#field_prefix' => '/',
210 '#type' => 'textfield',
214 '#suffix' => '</div>',
217 '#prefix' => '<div class="container-inline">',
218 '#type' => 'textfield',
223 '#suffix' => '</div>',
226 '#prefix' => '<div class="container-inline">',
227 '#type' => 'textfield',
228 '#title' => t('Exact name on card'),
231 '#suffix' => '</div>',
235 $pkgs = $signup_info['part_pkg'];
236 $form['package'] = array(
237 '#type' => 'fieldset',
238 '#title' => t('First Package'),
239 'pkgpart' => (count($pkgs) > 1 ?
243 '#options'=> array_combine(
244 subextract($pkgs, 'pkgpart'),
245 subextract($pkgs, 'pkg')
247 '#default_value'=>$signup_info['default_pkgpart'],
250 '#value' => $pkgs[0]['pkgpart'],
255 switch($signup_info['signup_service']) {
257 $form['package'] += array(
259 '#type' => 'textfield',
260 '#title' => t('Username'),
265 '#type' => 'password_confirm',
268 '#process'=> array('freeside_expand_password_confirm'),
273 break; // nothing yet implemented
275 $form['package']['pkgpart']['#default_value'] = $signup_info['default_pkgpart'];
277 $form['submit'] = array(
279 '#value' => 'Sign me up!',
284 /* workaround for silly Drupal behavior */
285 function freeside_expand_password_confirm($element) {
286 $element = expand_password_confirm($element);
287 $element['pass1']['#attributes']['value'] = $element['#value']['pass1'];
288 $element['pass2']['#attributes']['value'] = $element['#value']['pass2'];
292 function freeside_signup_form_submit($form, &$form_state) {
293 $freeside = new FreesideSelfService();
294 $values = $form_state['values'];
298 $customer['agentnum'] = variable_get('freeside_agentnum','');
299 foreach( array( 'first',
316 $customer[$field] = $values[$field];
318 if($values['invoicing_list_POST']) {
319 $customer['invoicing_list'] =
320 implode(',', array($customer['invoicing_list'], 'POST'));
322 $customer['_password'] = $values['password'];
323 $customer['country'] = 'US';
324 if($customer['payby'] == 'CARD') {
325 $customer['payinfo'] = preg_replace('/\D/','',$values['cardnum']);
326 $customer['paydate'] = $values['expmonth'] . '/' . $values['expyear'];
327 $customer['payname'] = isset($values['cardname']) ?
328 $values['cardname'] :
329 ($values['first'] . ' ' . $values['last']);
330 $customer['paycvv'] = $values['paycvv'];
332 /* other paybys not implemented */
335 $response = $freeside->new_customer($customer);
337 error_log("[new_customer] received response from Freeside: $response");
338 $error = $response['error'];
341 drupal_set_message(t("Signup error: $error"), 'error');
342 $form_state['redirect'] = FALSE;
345 drupal_set_message(t("Signup successful!"),'status');
346 $form_state['redirect'] = array(
347 variable_get('freeside_redirect_after_signup','/'),
348 //query string would go here
349 //'custnum='.$response['custnum'].'&svcnum='.$response['svcnum'],