NG selfservice webpay interface, #23579
[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 XMLRPC::Lite; # for XMLRPC::Data
34 use FS::ClientAPI;
35
36 $DEBUG = 0;
37 $FS::ClientAPI::DEBUG = $DEBUG;
38
39 #false laziness w/FS::SelfService/XMLRPC.pm, same problem as below but worse
40 our %typefix_skin_info = (
41   'logo'              => 'base64',
42   'title_left_image'  => 'base64',
43   'title_right_image' => 'base64',
44   'menu_top_image'    => 'base64',
45   'menu_body_image'   => 'base64',
46   'menu_bottom_image' => 'base64',
47 );
48 our %typefix = (
49   'invoice_pdf'        => { 'invoice_pdf' => 'base64', },
50   'legacy_invoice_pdf' => { 'invoice_pdf' => 'base64', },
51   'skin_info'          => \%typefix_skin_info,
52   'login_info'         => \%typefix_skin_info,
53   'invoice_logo'       => { 'logo' => 'base64', },
54   'login_banner_image' => { 'image' => 'base64', },
55 );
56
57 sub AUTOLOAD {
58   my $call = $AUTOLOAD;
59   $call =~ s/^FS::(SelfService::|ClientAPI_)XMLRPC:://;
60
61   warn "FS::ClientAPI_XMLRPC::AUTOLOAD $call\n" if $DEBUG;
62
63   my $autoload = &ss2clientapi;
64
65   if (exists($autoload->{$call})) {
66
67     shift; #discard package name;
68
69     #$call = "FS::SelfService::$call";
70     #no strict 'refs';
71     #&{$call}(@_);
72     #FS::ClientAPI->dispatch($autoload->{$call}, @_);
73
74     my $return = FS::ClientAPI->dispatch($autoload->{$call}, { @_ } );
75
76     if ( exists($typefix{$call}) ) {
77       my $typefix = $typefix{$call};
78       foreach my $field ( grep exists($return->{$_}), keys %$typefix ) {
79         my $type = $typefix->{$field};
80         $return->{$field} = XMLRPC::Data->value($return->{$field})
81                                         ->type($type);
82       }
83     }
84
85     $return;
86
87   }else{
88     die "No such procedure: $call";
89   }
90 }
91
92 #terrible false laziness w/SelfService.pm
93 # - fix at build time, by including some file in both selfserv and backend libs?
94 # - or fix at runtime, by having selfservice client ask server for the list?
95 sub ss2clientapi {
96   {
97   'passwd'                    => 'passwd/passwd',
98   'chfn'                      => 'passwd/passwd',
99   'chsh'                      => 'passwd/passwd',
100   'login_info'                => 'MyAccount/login_info',
101   'login_banner_image'        => 'MyAccount/login_banner_image',
102   'login'                     => 'MyAccount/login',
103   'logout'                    => 'MyAccount/logout',
104   'switch_acct'               => 'MyAccount/switch_acct',
105   'customer_info'             => 'MyAccount/customer_info',
106   'customer_info_short'       => 'MyAccount/customer_info_short',
107   'billing_history'           => 'MyAccount/billing_history',
108   'edit_info'                 => 'MyAccount/edit_info',     #add to ss cgi!
109   'invoice'                   => 'MyAccount/invoice',
110   'invoice_pdf'               => 'MyAccount/invoice_pdf',
111   'legacy_invoice'            => 'MyAccount/legacy_invoice',
112   'legacy_invoice_pdf'        => 'MyAccount/legacy_invoice_pdf',
113   'invoice_logo'              => 'MyAccount/invoice_logo',
114   'list_invoices'             => 'MyAccount/list_invoices', #?
115   'cancel'                    => 'MyAccount/cancel',        #add to ss cgi!
116   'payment_info'              => 'MyAccount/payment_info',
117   'payment_info_renew_info'   => 'MyAccount/payment_info_renew_info',
118   'process_payment'           => 'MyAccount/process_payment',
119   'store_payment'             => 'MyAccount/store_payment',
120   'process_stored_payment'    => 'MyAccount/process_stored_payment',
121   'process_payment_order_pkg' => 'MyAccount/process_payment_order_pkg',
122   'process_payment_change_pkg' => 'MyAccount/process_payment_change_pkg',
123   'process_payment_order_renew' => 'MyAccount/process_payment_order_renew',
124   'process_prepay'            => 'MyAccount/process_prepay',
125   'start_thirdparty'          => 'MyAccount/start_thirdparty',
126   'finish_thirdparty'         => 'MyAccount/finish_thirdparty',
127   'realtime_collect'          => 'MyAccount/realtime_collect',
128   'list_pkgs'                 => 'MyAccount/list_pkgs',     #add to ss (added?)
129   'list_svcs'                 => 'MyAccount/list_svcs',     #add to ss (added?)
130   'list_svc_usage'            => 'MyAccount/list_svc_usage',   
131   'svc_status_html'           => 'MyAccount/svc_status_html',
132   'svc_status_hash'           => 'MyAccount/svc_status_hash',
133   'set_svc_status_hash'       => 'MyAccount/set_svc_status_hash',
134   'set_svc_status_listadd'    => 'MyAccount/set_svc_status_listadd',
135   'set_svc_status_listdel'    => 'MyAccount/set_svc_status_listdel',
136   'set_svc_status_vacationadd'=> 'MyAccount/set_svc_status_vacationadd',
137   'set_svc_status_vacationdel'=> 'MyAccount/set_svc_status_vacationdel',
138   'acct_forward_info'         => 'MyAccount/acct_forward_info',
139   'process_acct_forward'      => 'MyAccount/process_acct_forward',
140   'list_dsl_devices'          => 'MyAccount/list_dsl_devices',   
141   'add_dsl_device'            => 'MyAccount/add_dsl_device',   
142   'delete_dsl_device'         => 'MyAccount/delete_dsl_device',   
143   'port_graph'                => 'MyAccount/port_graph',   
144   'list_cdr_usage'            => 'MyAccount/list_cdr_usage',   
145   'list_support_usage'        => 'MyAccount/list_support_usage',   
146   'order_pkg'                 => 'MyAccount/order_pkg',     #add to ss cgi!
147   'change_pkg'                => 'MyAccount/change_pkg', 
148   'order_recharge'            => 'MyAccount/order_recharge',
149   'renew_info'                => 'MyAccount/renew_info',
150   'order_renew'               => 'MyAccount/order_renew',
151   'cancel_pkg'                => 'MyAccount/cancel_pkg',    #add to ss cgi!
152   'suspend_pkg'               => 'MyAccount/suspend_pkg',   #add to ss cgi!
153   'charge'                    => 'MyAccount/charge',        #?
154   'part_svc_info'             => 'MyAccount/part_svc_info',
155   'provision_acct'            => 'MyAccount/provision_acct',
156   'provision_phone'           => 'MyAccount/provision_phone',
157   'provision_external'        => 'MyAccount/provision_external',
158   'unprovision_svc'           => 'MyAccount/unprovision_svc',
159   'myaccount_passwd'          => 'MyAccount/myaccount_passwd',
160   'reset_passwd'              => 'MyAccount/reset_passwd',
161   'check_reset_passwd'        => 'MyAccount/check_reset_passwd',
162   'process_reset_passwd'      => 'MyAccount/process_reset_passwd',
163   'list_tickets'              => 'MyAccount/list_tickets',
164   'create_ticket'             => 'MyAccount/create_ticket',
165   'get_ticket'                => 'MyAccount/get_ticket',
166   'adjust_ticket_priority'    => 'MyAccount/adjust_ticket_priority',
167   'did_report'                => 'MyAccount/did_report',
168   'signup_info'               => 'Signup/signup_info',
169   'skin_info'                 => 'MyAccount/skin_info',
170   'access_info'               => 'MyAccount/access_info',
171   'domain_select_hash'        => 'Signup/domain_select_hash',  # expose?
172   'new_customer'              => 'Signup/new_customer',
173   'capture_payment'           => 'Signup/capture_payment',
174   'clear_signup_cache'        => 'Signup/clear_cache',
175   'new_agent'                 => 'Agent/new_agent',
176   'agent_login'               => 'Agent/agent_login',
177   'agent_logout'              => 'Agent/agent_logout',
178   'agent_info'                => 'Agent/agent_info',
179   'agent_list_customers'      => 'Agent/agent_list_customers',
180   'check_username'            => 'Agent/check_username',
181   'suspend_username'          => 'Agent/suspend_username',
182   'unsuspend_username'        => 'Agent/unsuspend_username',
183   'mason_comp'                => 'MasonComponent/mason_comp',
184   'call_time'                 => 'PrepaidPhone/call_time',
185   'call_time_nanpa'           => 'PrepaidPhone/call_time_nanpa',
186   'phonenum_balance'          => 'PrepaidPhone/phonenum_balance',
187   };
188 }
189
190
191 #XXX submit patch to SOAP::Lite
192
193 use XMLRPC::Transport::HTTP;
194
195 package XMLRPC::Transport::HTTP::Server;
196
197 @XMLRPC::Transport::HTTP::Server::ISA = qw(SOAP::Transport::HTTP::Server);
198
199 sub initialize; *initialize = \&XMLRPC::Server::initialize;
200 sub make_fault; *make_fault = \&XMLRPC::Transport::HTTP::CGI::make_fault;
201 sub make_response; *make_response = \&XMLRPC::Transport::HTTP::CGI::make_response;
202
203 1;