REST API, RT#28181
[freeside.git] / FS / FS / cust_main / API.pm
1 package FS::cust_main::API;
2
3 use strict;
4
5 #some false laziness w/ClientAPI::Myaccount customer_info/customer_info_short
6
7 use vars qw(
8   @cust_main_addl_fields @cust_main_editable_fields @location_editable_fields
9 );
10 @cust_main_addl_fields = qw(
11   agentnum salesnum refnum classnum usernum referral_custnum
12 );
13 @cust_main_editable_fields = qw(
14   first last company daytime night fax mobile
15 );
16 #  locale
17 #  payby payinfo payname paystart_month paystart_year payissue payip
18 #  ss paytype paystate stateid stateid_state
19 @location_editable_fields = qw(
20   address1 address2 city county state zip country
21 );
22
23 sub API_getinfo {
24   my( $self, %opt ) = @_;
25
26   my %return = (
27     'error'           => '',
28     'display_custnum' => $self->display_custnum,
29     'name'            => $self->first. ' '. $self->get('last'),
30     'balance'         => $self->balance,
31     'status'          => $self->status,
32     'statuscolor'     => $self->statuscolor,
33   );
34
35   $return{$_} = $self->get($_)
36     foreach @cust_main_editable_fields;
37
38   unless ( $opt{'selfservice'} ) {
39     $return{$_} = $self->get($_)
40       foreach @cust_main_addl_fields;
41   }
42
43   for (@location_editable_fields) {
44     $return{$_} = $self->bill_location->get($_)
45       if $self->bill_locationnum;
46     $return{'ship_'.$_} = $self->ship_location->get($_)
47       if $self->ship_locationnum;
48   }
49
50   my @invoicing_list = $self->invoicing_list;
51   $return{'invoicing_list'} =
52     join(', ', grep { $_ !~ /^(POST|FAX)$/ } @invoicing_list );
53   $return{'postal_invoicing'} =
54     0 < ( grep { $_ eq 'POST' } @invoicing_list );
55
56   #generally, the more useful data from the cust_main record the better.
57   # well, tell me what you want
58
59   return \%return;
60
61 }
62
63 1;