% include( '/elements/header.html', 'Developer Documentation' ) %> <& /elements/menubar.html, 'Freeside Perl Modules' => $fsurl.'docs/library/FS.html', 'Complete Index' => $fsurl.'docs/library/index.html', &>
FS::SelfService - Freeside self-service API
# password and shell account changes
use FS::SelfService qw(passwd chfn chsh);
# "my account" functionality
use FS::SelfService qw( login customer_info invoice cancel payment_info process_payment );
#new-style login with an email address and password
# can also be used for svc_acct login, set $emailaddress to username@domain
my $rv = login ( { 'email' => $emailaddress,
'password' => $password,
},
);
if ( $rv->{'error'} ) {
#handle login error...
} else {
#successful login
$session_id = $rv->{'session_id'};
}
#classic svc_acct-based login with separate username and password
my $rv = login( { 'username' => $username,
'domain' => $domain,
'password' => $password,
}
);
if ( $rv->{'error'} ) {
#handle login error...
} else {
#successful login
$session_id = $rv->{'session_id'};
}
#svc_phone login with phone number and PIN
my $rv = login( { 'username' => $phone_number,
'domain' => 'svc_phone',
'password' => $pin,
}
);
if ( $rv->{'error'} ) {
#handle login error...
} else {
#successful login
$session_id = $rv->{'session_id'};
}
my $customer_info = customer_info( { 'session_id' => $session_id } );
my $payment_info = payment_info( { 'session_id' => $session_id } );
#!!! process_payment example
#!!! list_pkgs example
#!!! order_pkg example
#quoting a package, then ordering after confirmation
my $rv = quotation_new({ 'session_id' => $session_id });
my $qnum = $rv->{quotationnum};
# add packages to the quotation
$rv = quotation_add_pkg({ 'session_id' => $session_id,
'quotationnum' => $qnum,
'pkgpart' => $pkgpart,
'quantity' => $quantity, # defaults to 1
});
# repeat until all packages are added
# view the pricing information
$rv = quotation_info({ 'session_id' => $session_id,
'quotationnum' => $qnum,
});
print "Total setup charges: ".$rv->{total_setup}."\n".
"Total recurring charges: ".$rv->{total_recur}."\n";
# quotation_info also provides a detailed breakdown of charges, in
# $rv->{sections}.
# ask customer for confirmation, then:
$rv = quotation_order({ 'session_id' => $session_id,
'quotationnum' => $qnum,
});
#!!! cancel_pkg example
# signup functionality
use FS::SelfService qw( signup_info new_customer new_customer_minimal );
my $signup_info = signup_info;
$rv = new_customer( {
'first' => $first,
'last' => $last,
'company' => $company,
'address1' => $address1,
'address2' => $address2,
'city' => $city,
'state' => $state,
'zip' => $zip,
'country' => $country,
'daytime' => $daytime,
'night' => $night,
'fax' => $fax,
'payby' => $payby,
'payinfo' => $payinfo,
'paycvv' => $paycvv,
'paystart_month' => $paystart_month
'paystart_year' => $paystart_year,
'payissue' => $payissue,
'payip' => $payip
'paydate' => $paydate,
'payname' => $payname,
'invoicing_list' => $invoicing_list,
'referral_custnum' => $referral_custnum,
'agentnum' => $agentnum,
'pkgpart' => $pkgpart,
'username' => $username,
'_password' => $password,
'popnum' => $popnum,
#OR
'countrycode' => 1,
'phonenum' => $phonenum,
'pin' => $pin,
}
);
my $error = $rv->{'error'};
if ( $error eq '_decline' ) {
print_decline();
} elsif ( $error ) {
reprint_signup();
} else {
print_success();
}
Use this API to implement your own client "self-service" module.
If you just want to customize the look of the existing "self-service" module, see XXXX instead.
Changes the password for an existing user in svc_acct. Takes a hash reference with the following keys:
Username of the account (required)
Domain of the account (required)
Old password (required)
New password (required)
New gecos
New Shell
Creates a user session. Takes a hash reference as parameter with the following keys:
Email address (username@domain), instead of username and domain. Required for contact-based self-service login, can also be used for svc_acct-based login.
Username
Domain
Password
Returns a hash reference with the following keys:
Empty on success, or an error message on errors.
Session identifier for successful logins
Returns general customer information.
Takes a hash reference as parameter with a single key: session_id
Returns a hash reference with the following keys:
Customer name
Balance owed
Array reference of hash references of open inoices. Each hash reference has the following keys: invnum, date, owed
An HTML fragment containing shipping and billing addresses.
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
Takes a hash reference as parameter with a single key session_id or keys agent_session_id and custnum.
Returns a hash reference with the keys error, custnum and display_recurring.
display_recurring is an arrayref of hashrefs with the following keys:
frequency of charge, in months unless units are specified
frequency of charge, suitable for display
amount charged at this frequency
Takes a hash reference as parameter with any of the following keys:
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 paycvv payname month year invoicing_list postal_invoicing
If a field exists, the customer record is updated with the new value of that field. If a field does not exist, that field is not changed on the customer record.
Returns a hash reference with a single key, error, empty on success, or an error message on errors
Returns an invoice. Takes a hash reference as parameter with two keys: session_id and invnum
Returns a hash reference with the following keys:
Empty on success, or an error message on errors
Invoice number
Invoice text
Returns a list of all customer invoices. Takes a hash reference with a single key, session_id.
Returns a hash reference with the following keys:
Cancels this customer.
Takes a hash reference as parameter with a single key: session_id
Returns a hash reference with a single key, error, which is empty on success or an error message on errors.
Returns information that may be useful in displaying a payment page.
Takes a hash reference as parameter with the following keys:
Required session ID
Optional, pass a true value to omit cust_main_county data for performance.
Returns a hash reference with the following keys:
Empty on success, or an error message on errors
Balance owed
Exact name on credit card (CARD/DCRD)
Address line one
Address line two
City
State
Zip or postal code
Customer's current default payment type.
For CARD/DCRD payment types, the card type (Visa card, MasterCard, Discover card, American Express card, etc.)
For CARD/DCRD payment types, the card number
For CARD/DCRD payment types, expiration month
For CARD/DCRD payment types, expiration year
County/state/country data - array reference of hash references, each of which has the fields of a cust_main_county record (see FS::cust_main_county). Note these are not FS::cust_main_county objects, but hash references of columns and values.
Array reference of all states in the current default country.
Hash reference of card types; keys are card types, values are the exact strings passed to the process_payment function
Processes a payment and possible change of address or payment type. Takes a hash reference as parameter with the following keys:
Session identifier
Amount
If true, address and card information entered will be saved for subsequent transactions.
If true, future credit card payments will be done automatically (sets payby to CARD). If false, future credit card payments will be done on-demand (sets payby to DCRD). This option only has meaning if save is set true.
Name on card
Address line one
Address line two
City
State
Zip or postal code
Two-letter country code
Card number
Card expiration month
Card expiration year
Returns a hash reference with a single key, error, empty on success, or an error message on errors.
Combines the process_payment and order_pkg functions in one step. If the payment processes sucessfully, the package is ordered. Takes a hash reference as parameter with the keys of both methods.
Returns a hash reference with a single key, error, empty on success, or an error message on errors.
Combines the process_payment and change_pkg functions in one step. If the payment processes sucessfully, the package is ordered. Takes a hash reference as parameter with the keys of both methods.
Returns a hash reference with a single key, error, empty on success, or an error message on errors.
Combines the process_payment and order_renew functions in one step. If the payment processes sucessfully, the renewal is processed. Takes a hash reference as parameter with the keys of both methods.
Returns a hash reference with a single key, error, empty on success, or an error message on errors.
Returns package information for this customer. For more detail on services, see "list_svcs".
Takes a hash reference as parameter with a single key: session_id
Returns a hash reference containing customer package information. The hash reference contains the following keys:
Customer number
Empty on success, or an error message on errors.
Array reference of hash references, each of which has the fields of a cust_pkg record (see FS::cust_pkg) as well as the fields below. Note these are not the internal FS:: objects, but hash references of columns and values.
All fields of part_pkg for this specific cust_pkg (be careful with this information - it may reveal more about your available packages than you would like users to know in aggregate)
An array of hash references indicating information on unprovisioned services available for provisioning for this specific cust_pkg. Each has the following keys:
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)
An array of hash references indicating information on the customer services already provisioned for this specific cust_pkg. Each has the following keys:
Array reference with three elements: The first element is the name of this service. The second element is a meaningful user-specific identifier for the service (i.e. username, domain or mail alias). The last element is the table name of this service.
Primary key for this service
Service definition (see FS::part_svc)
Customer package (see FS::cust_pkg)
Blank if the service is not over limit, or the date the service exceeded its usage limit (as a UNIX timestamp).
Returns package information for package.
Takes a hash reference as parameter with the following keys:
Session identifier
Package Number
Returns a hash reference containing customer package information. The hash reference contains the following keys:
=pkg_label
Name of this package
Part package primary key
Package class number
error message if errror.
Returns service information for this customer.
Takes a hash reference as parameter with a single key: session_id
Returns a hash reference containing customer package information. The hash reference contains the following keys:
Customer number
An array of hash references indicating information on all of this customer's services. Each has the following keys:
Primary key for this service
Name of this service
Meaningful user-specific identifier for the service (i.e. username, domain, or mail alias).
Account (svc_acct) services also have the following keys:
Username
username@domain
Seconds remaining
Upload bytes remaining
Download bytes remaining
Total bytes remaining
Cost of a recharge
Number of seconds gained by recharge
Number of upload bytes gained by recharge
Number of download bytes gained by recharge
Number of total bytes gained by recharge
Orders a package for this customer.
If signup_server-realtime is set, bills the new package, attemps to collect payment and (for auto-payment customers) cancels the package if the payment is declined.
Takes a hash reference as parameter with the following keys:
Session identifier
Package to order (see FS::part_pkg).
Quantity for this package order (default 1).
If true, runs billing events for the customer after ordering and billing the package (signup_server-realtime must be set).
Optional locationnum for this package order, for existing locations.
Or, for new locations, pass the following fields: address1*, address2, city*, county, state*, zip*, country. (* = required in this case)
(None of this is required at all if you are just ordering a package at the customer's existing default service location.)
Service to order (see FS::part_svc).
Normally optional; required only to provision a non-svc_acct service, or if the package definition does not contain one svc_acct service definition with quantity 1 (it may contain others with quantity >1). A svcpart of "none" can also be specified to indicate that no initial service should be provisioned.
Fields used when provisioning an svc_acct service:
Username
Password
Optional security phrase
Optional Access number number
Fields used when provisioning an svc_domain service:
Domain
Fields used when provisioning an svc_phone service:
Phone number
Voicemail PIN
SIP password
Fields used when provisioning an svc_external service:
Fields used when provisioning an svc_pbx service:
Returns a hash reference with a single key, error, empty on success, or an error message on errors. The special error '_decline' is returned for declined transactions.
Changes a package for this customer.
Takes a hash reference as parameter with the following keys:
Session identifier
Existing customer package.
New package to order (see FS::part_pkg).
Quantity for this package order (default 1).
Returns a hash reference with the following keys:
Provides useful info for early renewals.
Takes a hash reference as parameter with the following keys:
Session identifier
Returns a hash reference. On errors, it contains a single key, error, with the error message. Otherwise, contains a single key, dates, pointing to an array refernce of hash references. Each hash reference contains the following keys:
(Future) Bill date. Indicates a future date for which billing could be run. Specified as an integer UNIX timestamp. Pass this value to the order_renew function.
(Future) Bill date as a human-readable string. (Convenience for display; subject to change, so best not to parse for the date.)
Base amount which will be charged if renewed early as of this date.
Renewal date; i.e. even-futher future date at which the customer will be paid through if the early renewal is completed with the given bill-date. Specified as an integer UNIX timestamp.
Renewal date as a human-readable string. (Convenience for display; subject to change, so best not to parse for the date.)
Package that will be renewed.
Expiration date of the package that will be renewed.
Expiration date of the package that will be renewed, as a human-readable string. (Convenience for display; subject to change, so best not to parse for the date.)
Renews this customer early; i.e. runs billing for this customer in advance.
Takes a hash reference as parameter with the following keys:
Session identifier
Integer date as returned by the renew_info function, indicating the advance date for which to run billing.
Returns a hash reference with a single key, error, empty on success, or an error message on errors.
Cancels a package for this customer.
Takes a hash reference as parameter with the following keys:
Session identifier
pkgpart of package to cancel
Optional date, for future cancellation (expiration) instead of immediate cancellation. Specified as an integer UNIX timestamp ("epoch time").
Returns a hash reference with a single key, error, empty on success, or an error message on errors.
Provisions an account (svc_acct).
Takes a hash reference as parameter with the following keys:
Provisions a phone number (svc_phone).
Takes a hash reference as parameter with the following keys:
Provisions a customer PBX (svc_pbx).
Takes a hash reference as parameter with the following keys:
Session identifier
pkgnum of package into which this service is provisioned
svcpart or service definition to provision
Provisions an external service (svc_external).
Takes a hash reference as parameter with the following keys:
Session identifier
pkgnum of package into which this service is provisioned
svcpart or service definition to provision
Changes the password for the currently-logged in contact.
Takes a hash reference as parameter with the following keys:
Returns a hash reference with a single parameter, error, which contains an error message, or empty on success.
Takes a hash reference as parameter with a single key, session_id.
Returns a hash reference with two parameters: error, which contains an error message, or empty on success, and contacts, a list of contacts.
contacts is an array reference of hash references (i.e. an array of structs, in XML-RPC). Each hash reference (struct) has the following keys:
Contact class name (contact type).
First name
Last name
Position ("Director of Silly Walks"), NOT honorific ("Mr." or "Mrs.")
Comma-separated list of email addresses
Y when enabled
Updates information for the currently-logged in contact, or (optionally) the specified contact.
Takes a hash reference as parameter with the following keys:
If already logged in as a contact, this is optional.
Returns a hash reference with a single parameter, error, which contains an error message, or empty on success.
Creates a new contact.
Takes a hash reference as parameter with the following keys:
Optional contact classnum (TODO: or name)
Y to enable self-service access
Returns a hash reference with a single parameter, error, which contains an error message, or empty on success.
Deletes a contact. (Note: Cannot at this time delete the currently-logged in contact.)
Takes a hash reference as parameter with the following keys:
Returns a hash reference with a single parameter, error, which contains an error message, or empty on success.
All of these functions require the user to be logged in, and the 'session_id' key to be included in the argument hashref.`
Returns a hashref listing this customer's active self-service quotations. Contents are:
an arrayref containing an element for each quotation.
the primary key
the date it was started
the number of packages
the sum of setup fees
the sum of recurring charges
Creates an empty quotation and returns a hashref containing 'quotationnum', the primary key of the new quotation.
Disables (does not really delete) a quotation. Takes the following arguments:
Returns 'error' => a string, which will be empty on success.
Returns total and detailed pricing information on a quotation.
Takes the following arguments:
Returns a hashref containing:
- total_setup, the total of setup fees (and their taxes) - total_recur, the total of all recurring charges (and their taxes) - sections, an arrayref containing an element for each quotation section. - description, a line of text describing the group of charges - subtotal, the total of charges in this group (if appropriate) - detail_items, an arrayref of line items - pkgnum, the reference number of the package - description, the package name (or tax name) - quantity - amount, the amount charged If the detail item represents a subtotal, it will instead contain: - total_item: description of the subtotal - total_amount: the subtotal amount
Renders the quotation as HTML or PDF. Takes the following arguments:
Returns a hashref containing 'document', the contents of the file.
Adds a package to a quotation. Takes the following arguments:
Returns 'error' => a string, which will be empty on success.
Removes a package from a quotation. Takes the following arguments:
Returns 'error' => a string, which will be empty on success.
Converts the packages in a quotation into real packages. Takes the following arguments:
Takes the following arguments:
Takes a hash reference as parameter with the following keys:
Returns a hash reference containing information that may be useful in displaying a signup page. The hash reference contains the following keys:
County/state/country data - array reference of hash references, each of which has the fields of a cust_main_county record (see FS::cust_main_county). Note these are not FS::cust_main_county objects, but hash references of columns and values.
Available packages - array reference of hash references, each of which has the fields of a part_pkg record (see FS::part_pkg). Each hash reference also has an additional 'payby' field containing an array reference of acceptable payment types specific to this package (see below and "payby" in FS::part_pkg). Note these are not FS::part_pkg objects, but hash references of columns and values. Requires the 'signup_server-default_agentnum' configuration value to be set, or an agentnum specified explicitly via reseller interface session_id in the options.
Array reference of hash references, each of which has the fields of an agent record (see FS::agent). Note these are not FS::agent objects, but hash references of columns and values.
Hash reference; keys are agentnums, values are array references of available packages for that agent, in the same format as the part_pkg arrayref above.
Access numbers - array reference of hash references, each of which has the fields of an svc_acct_pop record (see FS::svc_acct_pop). Note these are not FS::svc_acct_pop objects, but hash references of columns and values.
True if the "security_phrase" feature is enabled
Array reference of acceptable payment types for signup
credit card - automatic
credit card - on-demand - version 1.5+ only
electronic check - automatic
electronic check - on-demand - version 1.5+ only
Phone bill billing
billing, not recommended for signups
free, definitely not recommended for signups
special billing type: applies a credit (see FS::prepay_credit) and sets billing type to BILL
True if CVV features are available (1.5+ or 1.4.2 with CVV schema patch)
Hash reference of message catalog values, to support error message customization. Currently available keys are: passwords_dont_match, invalid_card, unknown_card_type, and not_a (as in "Not a Discover card"). Values are configured in the web interface under "View/Edit message catalog".
Default state
Default country
Creates a new customer.
Current differences from new_customer: An address is not required. promo_code and reg_code are not supported. If invoicing_list and _password is passed, a contact will be created with self-service access (no pkgpart or username is necessary). No initial billing is run (this may change in a future version).
Takes a hash reference as parameter with the following keys:
first name (required)
last name (required)
(not typically collected; mostly used for ACH transactions)
Company name
Address line one
Address line two
City
County
State
Zip or postal code
Daytime phone number
Evening phone number
Fax number
CARD, DCRD, CHEK, DCHK, LECB, BILL, COMP or PREPAY (see "signup_info" (required)
Card number for CARD/DCRD, account_number@aba_number for CHEK/DCHK, prepaid "pin" for PREPAY, purchase order number for BILL
Credit card CVV2 number (1.5+ or 1.4.2 with CVV schema patch)
Expiration date for CARD/DCRD
Exact name on credit card for CARD/DCRD, bank name for CHEK/DCHK
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
Agent number
pkgpart of initial package
Username
Password
Security phrase
Access number (index, not the literal number)
Country code (to be provisioned as a service)
Phone number (to be provisioned as a service)
Voicemail PIN
Returns a hash reference with the following keys:
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)
Creates a new customer. Takes a hash reference as parameter with the following keys:
first name (required)
last name (required)
(not typically collected; mostly used for ACH transactions)
Company name
Address line one
Address line two
City
County
State
Zip or postal code
Optional shipping address fields. If sending an optional shipping address, ship_address1, ship_city, ship_state and ship_zip are required.
Daytime phone number
Evening phone number
Fax number
CARD, DCRD, CHEK, DCHK, LECB, BILL, COMP or PREPAY (see "signup_info" (required)
Card number for CARD/DCRD, account_number@aba_number for CHEK/DCHK, prepaid "pin" for PREPAY, purchase order number for BILL
Credit card CVV2 number (1.5+ or 1.4.2 with CVV schema patch)
Expiration date for CARD/DCRD
Exact name on credit card for CARD/DCRD, bank name for CHEK/DCHK
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
Agent number
pkgpart of initial package
Username
Password
Security phrase
Access number (index, not the literal number)
Country code (to be provisioned as a service)
Phone number (to be provisioned as a service)
Voicemail PIN
Returns a hash reference with the following keys:
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)
Takes as input a hashref or list of key/value pairs with the following keys:
Currently selected county
Currently selected state
Currently selected country
Specify a unique prefix string if you intend to use the HTML output multiple time son one page.
Specify a javascript subroutine to call on changes
Default state
Default country
An arrayref of hash references specifying regions. Normally you can just pass the value of the cust_main_county field returned by signup_info.
Returns a list consisting of three HTML fragments for county selection, state selection and country selection, respectively.
Takes as input a hashref or list of key/value pairs with the following keys:
Current customer session_id
Omit red asterisks from required fields.
Label for first address line.
Returns an HTML fragment for a location form (address, city, state, zip, country)
Takes as input a unique prefix string and the current expiration date, in yyyy-mm-dd or m-d-yyyy format
Returns an HTML fragments for expiration date selection.
Takes as input a hashref or list of key/value pairs with the following keys:
Access number number
An arrayref of hash references specifying access numbers. Normally you can just pass the value of the svc_acct_pop field returned by signup_info.
Returns an HTML fragment for access number selection.
Takes as input a hashref or list of key/value pairs with the following keys:
Returns an HTML fragment for domain selection.
Takes as input a hashref or list of key/value pairs with the following keys:
Field name for the returned HTML fragment.
Service definition (see FS::part_svc)
Returns an HTML fragment for DID selection.
Note: Resellers can also use the signup_info and new_customer functions with their active session, and the customer_info and order_pkg functions with their active session and an additional custnum parameter.
For the most part, development of the reseller web interface has been superceded by agent-virtualized access to the backend.
Agent login
Agent info
List agent's customers.
freeside-selfservice-clientd, freeside-selfservice-server
Hey! The above document had some coding errors, which are explained below:
Unknown directive: =pkgpart
Unknown directive: =classnum
Unknown directive: =error
=back without =over
'=item' outside of any '=over'