doc: amount param to process_payment. just a bit important.
[freeside.git] / fs_selfservice / FS-SelfService / SelfService.pm
index c4befb3..9b3b71a 100644 (file)
@@ -1,7 +1,7 @@
 package FS::SelfService;
 
 use strict;
-use vars qw($VERSION @ISA @EXPORT_OK $dir $socket %autoload $tag);
+use vars qw($VERSION @ISA @EXPORT_OK $DEBUG $dir $socket %autoload $tag);
 use Exporter;
 use Socket;
 use FileHandle;
@@ -13,42 +13,49 @@ $VERSION = '0.03';
 
 @ISA = qw( Exporter );
 
+$DEBUG = 0;
+
 $dir = "/usr/local/freeside";
 $socket =  "$dir/selfservice_socket";
 $socket .= '.'.$tag if defined $tag && length($tag);
 
 #maybe should ask ClientAPI for this list
 %autoload = (
-  'passwd'               => 'passwd/passwd',
-  'chfn'                 => 'passwd/passwd',
-  'chsh'                 => 'passwd/passwd',
-  'login'                => 'MyAccount/login',
-  'logout'               => 'MyAccount/logout',
-  'customer_info'        => 'MyAccount/customer_info',
-  'edit_info'            => 'MyAccount/edit_info',     #add to ss cgi!
-  'invoice'              => 'MyAccount/invoice',
-  'invoice_logo'         => 'MyAccount/invoice_logo',
-  'list_invoices'        => 'MyAccount/list_invoices', #?
-  'cancel'               => 'MyAccount/cancel',        #add to ss cgi!
-  'payment_info'         => 'MyAccount/payment_info',
-  'process_payment'      => 'MyAccount/process_payment',
-  'process_prepay'       => 'MyAccount/process_prepay',
-  'list_pkgs'            => 'MyAccount/list_pkgs',     #add to ss cgi (added?)
-  'list_svcs'            => 'MyAccount/list_svcs',     #add to ss cgi (added?)
-  'order_pkg'            => 'MyAccount/order_pkg',     #add to ss cgi!
-  'cancel_pkg'           => 'MyAccount/cancel_pkg',    #add to ss cgi!
-  'charge'               => 'MyAccount/charge',        #?
-  'part_svc_info'        => 'MyAccount/part_svc_info',
-  'provision_acct'       => 'MyAccount/provision_acct',
-  'provision_external'   => 'MyAccount/provision_external',
-  'unprovision_svc'      => 'MyAccount/unprovision_svc',
-  'myaccount_passwd'     => 'MyAccount/myaccount_passwd',
-  'signup_info'          => 'Signup/signup_info',
-  'new_customer'         => 'Signup/new_customer',
-  'agent_login'          => 'Agent/agent_login',
-  'agent_logout'         => 'Agent/agent_logout',
-  'agent_info'           => 'Agent/agent_info',
-  'agent_list_customers' => 'Agent/agent_list_customers',
+  'passwd'                    => 'passwd/passwd',
+  'chfn'                      => 'passwd/passwd',
+  'chsh'                      => 'passwd/passwd',
+  'login'                     => 'MyAccount/login',
+  'logout'                    => 'MyAccount/logout',
+  'customer_info'             => 'MyAccount/customer_info',
+  'edit_info'                 => 'MyAccount/edit_info',     #add to ss cgi!
+  'invoice'                   => 'MyAccount/invoice',
+  'invoice_logo'              => 'MyAccount/invoice_logo',
+  'list_invoices'             => 'MyAccount/list_invoices', #?
+  'cancel'                    => 'MyAccount/cancel',        #add to ss cgi!
+  'payment_info'              => 'MyAccount/payment_info',
+  'process_payment'           => 'MyAccount/process_payment',
+  'process_payment_order_pkg' => 'MyAccount/process_payment_order_pkg',
+  'process_prepay'            => 'MyAccount/process_prepay',
+  'list_pkgs'                 => 'MyAccount/list_pkgs',     #add to ss (added?)
+  'list_svcs'                 => 'MyAccount/list_svcs',     #add to ss (added?)
+  'list_svc_usage'            => 'MyAccount/list_svc_usage',   
+  'list_support_usage'        => 'MyAccount/list_support_usage',   
+  'order_pkg'                 => 'MyAccount/order_pkg',     #add to ss cgi!
+  'change_pkg'                => 'MyAccount/change_pkg', 
+  'order_recharge'            => 'MyAccount/order_recharge',
+  'cancel_pkg'                => 'MyAccount/cancel_pkg',    #add to ss cgi!
+  'charge'                    => 'MyAccount/charge',        #?
+  'part_svc_info'             => 'MyAccount/part_svc_info',
+  'provision_acct'            => 'MyAccount/provision_acct',
+  'provision_external'        => 'MyAccount/provision_external',
+  'unprovision_svc'           => 'MyAccount/unprovision_svc',
+  'myaccount_passwd'          => 'MyAccount/myaccount_passwd',
+  'signup_info'               => 'Signup/signup_info',
+  'new_customer'              => 'Signup/new_customer',
+  'agent_login'               => 'Agent/agent_login',
+  'agent_logout'              => 'Agent/agent_logout',
+  'agent_info'                => 'Agent/agent_info',
+  'agent_list_customers'      => 'Agent/agent_list_customers',
 );
 @EXPORT_OK = ( keys(%autoload), qw( regionselector expselect popselector ) );
 
@@ -91,6 +98,8 @@ foreach my $autoload ( keys %autoload ) {
 
 sub simple_packet {
   my $packet = shift;
+  warn "sending ". $packet->{_packet}. " to server"
+    if $DEBUG;
   socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
   connect(SOCK, sockaddr_un($socket)) or die "connect to $socket: $!";
   nstore_fd($packet, \*SOCK) or die "can't send packet: $!";
@@ -102,9 +111,16 @@ sub simple_packet {
 #  my $w = new IO::Select;
 #  $w->add(\*SOCK);
 #  my @wait = $w->can_read;
+
+  warn "reading message from server"
+    if $DEBUG;
+
   my $return = fd_retrieve(\*SOCK) or die "error reading result: $!";
   die $return->{'_error'} if defined $return->{_error} && $return->{_error};
 
+  warn "returning message to client"
+    if $DEBUG;
+
   $return;
 }
 
@@ -224,10 +240,16 @@ following keys:
 
 =item username
 
+Username
+
 =item domain
 
+Domain
+
 =item password
 
+Password
+
 =back
 
 Returns a hash reference with the following keys:
@@ -271,7 +293,9 @@ the following keys: invnum, date, owed
 
 An HTML fragment containing shipping and billing addresses.
 
-=item The following fields are also returned: first last company address1 address2 city county state zip country daytime night fax ship_first ship_last ship_company ship_address1 ship_address2 ship_city ship_state ship_zip ship_country ship_daytime ship_night ship_fax payby payinfo payname month year invoicing_list postal_invoicing
+=item The following fields are also returned
+
+first last company address1 address2 city county state zip country daytime night fax ship_first ship_last ship_company ship_address1 ship_address2 ship_city ship_state ship_zip ship_country ship_daytime ship_night ship_fax payby payinfo payname month year invoicing_list postal_invoicing
 
 =back
 
@@ -375,14 +399,24 @@ Exact name on credit card (CARD/DCRD)
 
 =item address1
 
+Address line one
+
 =item address2
 
+Address line two
+
 =item city
 
+City
+
 =item state
 
+State
+
 =item zip
 
+Zip or postal code
+
 =item payby
 
 Customer's current default payment type.
@@ -432,6 +466,12 @@ hash reference as parameter with the following keys:
 
 =item session_id
 
+Session identifier
+
+=item amount
+
+Amount
+
 =item save
 
 If true, address and card information entered will be saved for subsequent
@@ -445,16 +485,28 @@ payby to DCRD).  This option only has meaning if B<save> is set true.
 
 =item payname
 
+Name on card
+
 =item address1
 
+Address line one
+
 =item address2
 
+Address line two
+
 =item city
 
+City
+
 =item state
 
+State
+
 =item zip
 
+Zip or postal code
+
 =item payinfo
 
 Card number
@@ -487,22 +539,39 @@ Returns a hash reference containing customer package information.  The hash refe
 
 =over 4
 
-
 =item cust_pkg HASHREF
 
 Array reference of hash references, each of which has the fields of a cust_pkg
 record (see L<FS::cust_pkg>) as well as the fields below.  Note these are not
 the internal FS:: objects, but hash references of columns and values.
 
-=item all fields of part_pkg (XXXpare this down to a secure subset)
+=over 4
+
+=item part_pkg fields
 
-=item part_svc - An array of hash references, each of which has the following keys:
+All fields of part_pkg (be careful with this information - it may reveal more
+about your available packages than you would like users to know in aggregate) 
+
+=cut
+
+#XXX pare part_pkg fields down to a more secure subset
+
+=item part_svc
+
+An array of hash references, each of which has the following keys:
 
 =over 4
 
-=item all fields of part_svc (XXXpare this down to a secure subset)
+=item part_svc fields
+
+All fields of part_svc (be careful with this information - it may reveal more
+about your available packages than you would like users to know in aggregate) 
 
-=item avail
+=cut
+
+#XXX pare part_svc fields down to a more secure subset
+
+=back
 
 =back
 
@@ -522,8 +591,12 @@ Takes a hash reference as parameter with the following keys:
 
 =item session_id
 
+Session identifier
+
 =item pkgpart
 
+pkgpart of package to order
+
 =item svcpart
 
 optional svcpart, required only if the package definition does not contain
@@ -532,12 +605,20 @@ quantity >1)
 
 =item username
 
+Username
+
 =item _password
 
+Password
+
 =item sec_phrase
 
+Optional security phrase
+
 =item popnum
 
+Optional Access number number
+
 =back
 
 Returns a hash reference with a single key, B<error>, empty on success, or an
@@ -554,8 +635,12 @@ Takes a hash reference as parameter with the following keys:
 
 =item session_id
 
+Session identifier
+
 =item pkgpart
 
+pkgpart of package to cancel
+
 =back
 
 Returns a hash reference with a single key, B<error>, empty on success, or an
@@ -614,21 +699,37 @@ Array reference of acceptable payment types for signup
 
 =over 4
 
-=item CARD (credit card - automatic)
+=item CARD
+
+credit card - automatic
+
+=item DCRD
+
+credit card - on-demand - version 1.5+ only
+
+=item CHEK
+
+electronic check - automatic
+
+=item DCHK
 
-=item DCRD (credit card - on-demand - version 1.5+ only)
+electronic check - on-demand - version 1.5+ only
 
-=item CHEK (electronic check - automatic)
+=item LECB
 
-=item DCHK (electronic check - on-demand - version 1.5+ only)
+Phone bill billing
 
-=item LECB (Phone bill billing)
+=item BILL
 
-=item BILL (billing, not recommended for signups)
+billing, not recommended for signups
 
-=item COMP (free, definately not recommended for signups)
+=item COMP
 
-=item PREPAY (special billing type: applies a credit (see FS::prepay_credit) and sets billing type to BILL)
+free, definitely not recommended for signups
+
+=item PREPAY
+
+special billing type: applies a credit (see FS::prepay_credit) and sets billing type to BILL
 
 =back
 
@@ -657,57 +758,109 @@ following keys:
 
 =over 4
 
-=item first - first name (required)
+=item first
+
+first name (required)
 
-=item last - last name (required)
+=item last
 
-=item ss (not typically collected; mostly used for ACH transactions)
+last name (required)
+
+=item ss
+
+(not typically collected; mostly used for ACH transactions)
 
 =item company
 
+Company name
+
 =item address1 (required)
 
+Address line one
+
 =item address2
 
+Address line two
+
 =item city (required)
 
+City
+
 =item county
 
+County
+
 =item state (required)
 
+State
+
 =item zip (required)
 
-=item daytime - phone
+Zip or postal code
+
+=item daytime
+
+Daytime phone number
+
+=item night
+
+Evening phone number
+
+=item fax
+
+Fax number
+
+=item payby
+
+CARD, DCRD, CHEK, DCHK, LECB, BILL, COMP or PREPAY (see L</signup_info> (required)
+
+=item payinfo
+
+Card number for CARD/DCRD, account_number@aba_number for CHEK/DCHK, prepaid "pin" for PREPAY, purchase order number for BILL
+
+=item paycvv
 
-=item night - phone
+Credit card CVV2 number (1.5+ or 1.4.2 with CVV schema patch)
 
-=item fax - phone
+=item paydate
 
-=item payby - CARD, DCRD, CHEK, DCHK, LECB, BILL, COMP or PREPAY (see L</signup_info> (required)
+Expiration date for CARD/DCRD
 
-=item payinfo - Card number for CARD/DCRD, account_number@aba_number for CHEK/DCHK, prepaid "pin" for PREPAY, purchase order number for BILL
+=item payname
+
+Exact name on credit card for CARD/DCRD, bank name for CHEK/DCHK
 
-=item paycvv - Credit card CVV2 number (1.5+ or 1.4.2 with CVV schema patch)
+=item invoicing_list
 
-=item paydate - Expiration date for CARD/DCRD
+comma-separated list of email addresses for email invoices.  The special value 'POST' is used to designate postal invoicing (it may be specified alone or in addition to email addresses),
 
-=item payname - Exact name on credit card for CARD/DCRD, bank name for CHEK/DCHK
+=item referral_custnum
 
-=item invoicing_list - comma-separated list of email addresses for email invoices.  The special value 'POST' is used to designate postal invoicing (it may be specified alone or in addition to email addresses),
+referring customer number
 
-=item referral_custnum - referring customer number
+=item pkgpart
 
-=item pkgpart - pkgpart of initial package
+pkgpart of initial package
 
 =item username
 
+Username
+
 =item _password
 
-=item sec_phrase - security phrase
+Password
+
+=item sec_phrase
+
+Security phrase
+
+=item popnum
+
+Access number (index, not the literal number)
 
-=item popnum - access number (index, not the literal number)
+=item agentnum
 
-=item agentnum - agent number
+Agent number
 
 =back
 
@@ -715,7 +868,9 @@ Returns a hash reference with the following keys:
 
 =over 4
 
-=item error Empty on success, or an error message on errors.  The special error '_decline' is returned for declined transactions; other error messages should be suitable for display to the user (and are customizable in under Sysadmin | View/Edit message catalog)
+=item error
+
+Empty on success, or an error message on errors.  The special error '_decline' is returned for declined transactions; other error messages should be suitable for display to the user (and are customizable in under Configuration | View/Edit message catalog)
 
 =back
 
@@ -727,19 +882,35 @@ Takes as input a hashref or list of key/value pairs with the following keys:
 
 =item selected_county
 
+Currently selected county
+
 =item selected_state
 
+Currently selected state
+
 =item selected_country
 
-=item prefix - Specify a unique prefix string  if you intend to use the HTML output multiple time son one page.
+Currently selected country
+
+=item prefix
 
-=item onchange - Specify a javascript subroutine to call on changes
+Specify a unique prefix string  if you intend to use the HTML output multiple time son one page.
+
+=item onchange
+
+Specify a javascript subroutine to call on changes
 
 =item default_state
 
+Default state
+
 =item default_country
 
-=item locales - An arrayref of hash references specifying regions.  Normally you can just pass the value of the I<cust_main_county> field returned by B<signup_info>.
+Default country
+
+=item locales
+
+An arrayref of hash references specifying regions.  Normally you can just pass the value of the I<cust_main_county> field returned by B<signup_info>.
 
 =back
 
@@ -937,7 +1108,11 @@ Takes as input a hashref or list of key/value pairs with the following keys:
 
 =item popnum
 
-=item pops - An arrayref of hash references specifying access numbers.  Normally you can just pass the value of the I<svc_acct_pop> field returned by B<signup_info>.
+Access number number
+
+=item pops
+
+An arrayref of hash references specifying access numbers.  Normally you can just pass the value of the I<svc_acct_pop> field returned by B<signup_info>.
 
 =back