Merge branch 'FREESIDE_3_BRANCH' of git.freeside.biz:/home/git/freeside into FREESIDE...
[freeside.git] / FS / FS / ClientAPI_XMLRPC.pm
1 package FS::ClientAPI_XMLRPC;
2
3 =head1 NAME
4
5 FS::ClientAPI_XMLRPC - Freeside XMLRPC accessible self-service API, on the backend
6
7 =head1 SYNOPSIS
8
9 This module implements the self-service API offered by xmlrpc.cgi and friends,
10 but on a backend machine.
11
12 =head1 DESCRIPTION
13
14 Use this API to implement your own client "self-service" module vi XMLRPC.
15
16 Each routine described in L<FS::SelfService> is available vi XMLRPC as the
17 method FS.SelfService.XMLRPC.B<method>.  All values are passed to the
18 selfservice-server in a struct of strings.  The return values are in a
19 struct as strings, arrays, or structs as appropriate for the values
20 described in L<FS::SelfService>.
21
22 =head1 BUGS
23
24 =head1 SEE ALSO
25
26 L<FS::SelfService::XMLRPC>, L<FS::SelfService>
27
28 =cut
29
30 use strict;
31
32 use vars qw($DEBUG $AUTOLOAD);
33 use Encode;
34 use XMLRPC::Lite; # for XMLRPC::Data
35 use FS::ClientAPI;
36
37 $DEBUG = 0;
38 $FS::ClientAPI::DEBUG = $DEBUG;
39
40 #false laziness w/FS::SelfService/XMLRPC.pm, same problem as below but worse
41 our %typefix_skin_info = (
42   'logo'              => 'base64',
43   'title_left_image'  => 'base64',
44   'title_right_image' => 'base64',
45   'menu_top_image'    => 'base64',
46   'menu_body_image'   => 'base64',
47   'menu_bottom_image' => 'base64',
48 );
49 our %typefix = (
50   'invoice_pdf'        => { 'invoice_pdf' => 'base64', },
51   'legacy_invoice_pdf' => { 'invoice_pdf' => 'base64', },
52   'skin_info'          => \%typefix_skin_info,
53   'login_info'         => \%typefix_skin_info,
54   'invoice_logo'       => { 'logo' => 'base64', },
55   'login_banner_image' => { 'image' => 'base64', },
56   'quotation_print'    => { 'document' => 'base64' },
57 );
58
59 sub AUTOLOAD {
60   my $call = $AUTOLOAD;
61   $call =~ s/^FS::(SelfService::|ClientAPI_)XMLRPC:://;
62
63   warn "FS::ClientAPI_XMLRPC::AUTOLOAD $call\n" if $DEBUG;
64
65   my $autoload = &ss2clientapi;
66
67   if (exists($autoload->{$call})) {
68
69     shift; #discard package name;
70
71
72     #$call = "FS::SelfService::$call";
73     #no strict 'refs';
74     #&{$call}(@_);
75     #FS::ClientAPI->dispatch($autoload->{$call}, @_);
76
77     my %hash = @_;
78     #XXX doesn't handle multi-level data structs
79     $hash{$_} = decode(utf8=>$hash{$_}) foreach keys %hash;
80
81     my $return = FS::ClientAPI->dispatch($autoload->{$call}, \%hash );
82
83     if ( exists($typefix{$call}) ) {
84       my $typefix = $typefix{$call};
85       foreach my $field ( grep exists($return->{$_}), keys %$typefix ) {
86         my $type = $typefix->{$field};
87         $return->{$field} = XMLRPC::Data->value($return->{$field})
88                                         ->type($type);
89       }
90     }
91
92     $return;
93
94   } else {
95     die "No such procedure: $call";
96   }
97 }
98
99 #terrible false laziness w/SelfService.pm
100 # - fix at build time, by including some file in both selfserv and backend libs?
101 # - or fix at runtime, by having selfservice client ask server for the list?
102 sub ss2clientapi {
103   {
104   'passwd'                    => 'passwd/passwd',
105   'chfn'                      => 'passwd/passwd',
106   'chsh'                      => 'passwd/passwd',
107   'login_info'                => 'MyAccount/login_info',
108   'login_banner_image'        => 'MyAccount/login_banner_image',
109   'login'                     => 'MyAccount/login',
110   'logout'                    => 'MyAccount/logout',
111   'switch_acct'               => 'MyAccount/switch_acct',
112   'customer_info'             => 'MyAccount/customer_info',
113   'customer_info_short'       => 'MyAccount/customer_info_short',
114   'customer_recurring'        => 'MyAccount/customer_recurring',
115
116   'contact_passwd'            => 'MyAccount/contact/contact_passwd',
117   'list_contacts'             => 'MyAccount/contact/list_contacts',
118   'edit_contact'              => 'MyAccount/contact/edit_contact',
119   'delete_contact'            => 'MyAccount/contact/delete_contact',
120   'new_contact'               => 'MyAccount/contact/new_contact',
121
122   'billing_history'           => 'MyAccount/billing_history',
123   'edit_info'                 => 'MyAccount/edit_info',     #add to ss cgi!
124   'invoice'                   => 'MyAccount/invoice',
125   'invoice_pdf'               => 'MyAccount/invoice_pdf',
126   'legacy_invoice'            => 'MyAccount/legacy_invoice',
127   'legacy_invoice_pdf'        => 'MyAccount/legacy_invoice_pdf',
128   'invoice_logo'              => 'MyAccount/invoice_logo',
129   'list_invoices'             => 'MyAccount/list_invoices', #?
130   'cancel'                    => 'MyAccount/cancel',        #add to ss cgi!
131   'payment_info'              => 'MyAccount/payment_info',
132   'payment_info_renew_info'   => 'MyAccount/payment_info_renew_info',
133   'process_payment'           => 'MyAccount/process_payment',
134   'store_payment'             => 'MyAccount/store_payment',
135   'process_stored_payment'    => 'MyAccount/process_stored_payment',
136   'process_payment_order_pkg' => 'MyAccount/process_payment_order_pkg',
137   'process_payment_change_pkg' => 'MyAccount/process_payment_change_pkg',
138   'process_payment_order_renew' => 'MyAccount/process_payment_order_renew',
139   'process_prepay'            => 'MyAccount/process_prepay',
140   'start_thirdparty'          => 'MyAccount/start_thirdparty',
141   'finish_thirdparty'         => 'MyAccount/finish_thirdparty',
142   'realtime_collect'          => 'MyAccount/realtime_collect',
143   'list_pkgs'                 => 'MyAccount/list_pkgs',     #add to ss (added?)
144   'list_svcs'                 => 'MyAccount/list_svcs',     #add to ss (added?)
145   'list_svc_usage'            => 'MyAccount/list_svc_usage',   
146   'svc_status_html'           => 'MyAccount/svc_status_html',
147   'svc_status_hash'           => 'MyAccount/svc_status_hash',
148   'set_svc_status_hash'       => 'MyAccount/set_svc_status_hash',
149   'set_svc_status_listadd'    => 'MyAccount/set_svc_status_listadd',
150   'set_svc_status_listdel'    => 'MyAccount/set_svc_status_listdel',
151   'set_svc_status_vacationadd'=> 'MyAccount/set_svc_status_vacationadd',
152   'set_svc_status_vacationdel'=> 'MyAccount/set_svc_status_vacationdel',
153   'acct_forward_info'         => 'MyAccount/acct_forward_info',
154   'process_acct_forward'      => 'MyAccount/process_acct_forward',
155   'list_dsl_devices'          => 'MyAccount/list_dsl_devices',   
156   'add_dsl_device'            => 'MyAccount/add_dsl_device',   
157   'delete_dsl_device'         => 'MyAccount/delete_dsl_device',   
158   'port_graph'                => 'MyAccount/port_graph',   
159   'list_cdr_usage'            => 'MyAccount/list_cdr_usage',   
160   'list_support_usage'        => 'MyAccount/list_support_usage',   
161   'order_pkg'                 => 'MyAccount/order_pkg',     #add to ss cgi!
162   'change_pkg'                => 'MyAccount/change_pkg', 
163   'order_recharge'            => 'MyAccount/order_recharge',
164   'renew_info'                => 'MyAccount/renew_info',
165   'order_renew'               => 'MyAccount/order_renew',
166   'cancel_pkg'                => 'MyAccount/cancel_pkg',    #add to ss cgi!
167   'suspend_pkg'               => 'MyAccount/suspend_pkg',   #add to ss cgi!
168   'charge'                    => 'MyAccount/charge',        #?
169   'part_svc_info'             => 'MyAccount/part_svc_info',
170   'provision_acct'            => 'MyAccount/provision_acct',
171   'provision_phone'           => 'MyAccount/provision_phone',
172   'provision_pbx'             => 'MyAccount/provision_pbx',
173   'provision_external'        => 'MyAccount/provision_external',
174   'unprovision_svc'           => 'MyAccount/unprovision_svc',
175   'myaccount_passwd'          => 'MyAccount/myaccount_passwd',
176   'reset_passwd'              => 'MyAccount/reset_passwd',
177   'check_reset_passwd'        => 'MyAccount/check_reset_passwd',
178   'process_reset_passwd'      => 'MyAccount/process_reset_passwd',
179   'list_tickets'              => 'MyAccount/list_tickets',
180   'create_ticket'             => 'MyAccount/create_ticket',
181   'get_ticket'                => 'MyAccount/get_ticket',
182   'adjust_ticket_priority'    => 'MyAccount/adjust_ticket_priority',
183   'did_report'                => 'MyAccount/did_report',
184   'signup_info'               => 'Signup/signup_info',
185   'skin_info'                 => 'MyAccount/skin_info',
186   'access_info'               => 'MyAccount/access_info',
187   'domain_select_hash'        => 'Signup/domain_select_hash',  # expose?
188   'new_customer'              => 'Signup/new_customer',
189   'new_customer_minimal'      => 'Signup/new_customer_minimal',
190   'capture_payment'           => 'Signup/capture_payment',
191   'clear_signup_cache'        => 'Signup/clear_cache',
192   'new_agent'                 => 'Agent/new_agent',
193   'agent_login'               => 'Agent/agent_login',
194   'agent_logout'              => 'Agent/agent_logout',
195   'agent_info'                => 'Agent/agent_info',
196   'agent_list_customers'      => 'Agent/agent_list_customers',
197   'check_username'            => 'Agent/check_username',
198   'suspend_username'          => 'Agent/suspend_username',
199   'unsuspend_username'        => 'Agent/unsuspend_username',
200   'mason_comp'                => 'MasonComponent/mason_comp',
201   'call_time'                 => 'PrepaidPhone/call_time',
202   'call_time_nanpa'           => 'PrepaidPhone/call_time_nanpa',
203   'phonenum_balance'          => 'PrepaidPhone/phonenum_balance',
204
205   'list_quotations'           => 'MyAccount/quotation/list_quotations',
206   'quotation_new'             => 'MyAccount/quotation/quotation_new',
207   'quotation_delete'          => 'MyAccount/quotation/quotation_delete',
208   'quotation_info'            => 'MyAccount/quotation/quotation_info',
209   'quotation_print'           => 'MyAccount/quotation/quotation_print',
210   'quotation_add_pkg'         => 'MyAccount/quotation/quotation_add_pkg',
211   'quotation_remove_pkg'      => 'MyAccount/quotation/quotation_remove_pkg',
212   'quotation_order'           => 'MyAccount/quotation/quotation_order',
213
214   'freesideinc_service'       => 'Freeside/freesideinc_service',
215   };
216 }
217
218
219 #XXX submit patch to SOAP::Lite
220
221 use XMLRPC::Transport::HTTP;
222
223 package XMLRPC::Transport::HTTP::Server;
224
225 @XMLRPC::Transport::HTTP::Server::ISA = qw(SOAP::Transport::HTTP::Server);
226
227 sub initialize; *initialize = \&XMLRPC::Server::initialize;
228 sub make_fault; *make_fault = \&XMLRPC::Transport::HTTP::CGI::make_fault;
229 sub make_response; *make_response = \&XMLRPC::Transport::HTTP::CGI::make_response;
230
231 1;