}
+=item customer_list_svcs OPTION => VALUE, ...
+
+Returns customer service information. Takes a list of keys and values as
+parameters with the following keys: custnum, secret
+
+=cut
+
+sub customer_list_svcs {
+ my( $class, %opt ) = @_;
+ return _shared_secret_error() unless _check_shared_secret($opt{secret});
+
+ my $cust_main = qsearchs('cust_main', { 'custnum' => $opt{custnum} })
+ or return { 'error' => 'Unknown custnum' };
+
+ #$cust_main->API_list_svcs;
+
+ #false laziness w/ClientAPI/list_svcs
+
+ my @cust_svc = ();
+ #my @cust_pkg_usage = ();
+ #foreach my $cust_pkg ( $p->{'ncancelled'}
+ # ? $cust_main->ncancelled_pkgs
+ # : $cust_main->unsuspended_pkgs ) {
+ foreach my $cust_pkg ( $cust_main->all_pkgs ) {
+ #next if $pkgnum && $cust_pkg->pkgnum != $pkgnum;
+ push @cust_svc, @{[ $cust_pkg->cust_svc ]}; #@{[ ]} to force array context
+ #push @cust_pkg_usage, $cust_pkg->cust_pkg_usage;
+ }
+
+ return {
+ 'cust_svc' => [ map $_->API_getinfo, @cust_svc ],
+ };
+
+}
+
=item location_info
Returns location specific information for the customer. Takes a list of keys
}
-#next.. Advertising sources?
+#next.. Delete Advertising sources?
+
+=item list_advertising_sources OPTION => VALUE, ...
+
+Lists all advertising sources.
+
+=over
+
+=item secret
+
+API Secret
+
+=back
+
+Example:
+
+ my $result = FS::API->list_advertising_sources(
+ 'secret' => 'sharingiscaring',
+ );
+
+ if ( $result->{'error'} ) {
+ die $result->{'error'};
+ } else {
+ # list advertising sources returns an array of hashes for sources.
+ print Dumper($result->{'sources'});
+ }
+
+=cut
+
+#list_advertising_sources
+sub list_advertising_sources {
+ my( $class, %opt ) = @_;
+ return _shared_secret_error() unless _check_shared_secret($opt{secret});
+
+ my @sources = qsearch('part_referral', {}, '', "")
+ or return { 'error' => 'No referrals' };
+
+ my $return = {
+ 'sources' => [ map $_->hashref, @sources ],
+ };
+
+ $return;
+}
+
+=item add_advertising_source OPTION => VALUE, ...
+
+Add a new advertising source.
+
+=over
+
+=item secret
+
+API Secret
+
+=item referral
+
+Referral name
+
+=item disabled
+
+Referral disabled, Y for disabled or nothing for enabled
+
+=item agentnum
+
+Agent ID number
+
+=item title
+
+External referral ID
+
+=back
+
+Example:
+
+ my $result = FS::API->add_advertising_source(
+ 'secret' => 'sharingiscaring',
+ 'referral' => 'test referral',
+
+ #optional
+ 'disabled' => 'Y',
+ 'agentnum' => '2', #agent id number
+ 'title' => 'test title',
+ );
+
+ if ( $result->{'error'} ) {
+ die $result->{'error'};
+ } else {
+ # add_advertising_source returns new source upon success.
+ print Dumper($result);
+ }
+
+=cut
+
+#add_advertising_source
+sub add_advertising_source {
+ my( $class, %opt ) = @_;
+ return _shared_secret_error() unless _check_shared_secret($opt{secret});
+
+ use FS::part_referral;
+
+ my $new_source = $opt{source};
+
+ my $source = new FS::part_referral $new_source;
+
+ my $error = $source->insert;
+
+ my $return = {$source->hash};
+ $return = { 'error' => $error, } if $error;
+
+ $return;
+}
+
+=item edit_advertising_source OPTION => VALUE, ...
+
+Edit a advertising source.
+
+=over
+
+=item secret
+
+API Secret
+
+=item refnum
+
+Referral number to edit
+
+=item source
+
+hash of edited source fields.
+
+=over
+
+=item referral
+
+Referral name
+
+=item disabled
+
+Referral disabled, Y for disabled or nothing for enabled
+
+=item agentnum
+
+Agent ID number
+
+=item title
+
+External referral ID
+
+=back
+
+=back
+
+Example:
+
+ my $result = FS::API->edit_advertising_source(
+ 'secret' => 'sharingiscaring',
+ 'refnum' => '4', # referral number to edit
+ 'source' => {
+ #optional
+ 'referral' => 'test referral',
+ 'disabled' => 'Y',
+ 'agentnum' => '2', #agent id number
+ 'title' => 'test title',
+ }
+ );
+
+ if ( $result->{'error'} ) {
+ die $result->{'error'};
+ } else {
+ # edit_advertising_source returns updated source upon success.
+ print Dumper($result);
+ }
+
+=cut
+
+#edit_advertising_source
+sub edit_advertising_source {
+ my( $class, %opt ) = @_;
+ return _shared_secret_error() unless _check_shared_secret($opt{secret});
+
+ use FS::part_referral;
+
+ my $refnum = $opt{refnum};
+ my $source = $opt{source};
+
+ my $old = FS::Record::qsearchs('part_referral', {'refnum' => $refnum,});
+ my $new = new FS::part_referral { $old->hash };
+
+ foreach my $key (keys %$source) {
+ $new->$key($source->{$key});
+ }
+
+ my $error = $new->replace;
+
+ my $return = {$new->hash};
+ $return = { 'error' => $error, } if $error;
+
+ $return;
+}
##