diff options
author | Christopher Burger <burgerc@freeside.biz> | 2017-08-21 11:42:36 -0400 |
---|---|---|
committer | Christopher Burger <burgerc@freeside.biz> | 2017-08-22 06:55:41 -0400 |
commit | bee715764bba15af9ac9868287dc22f648b472bd (patch) | |
tree | b0304de296428b87e06f3e117db6b9d034b6f85b /FS/FS/API.pm | |
parent | ea5ea999cbd41dba4801091a3b096551e69d813d (diff) |
RT# 27969 - created 3 new api functions to add, edit and list advertising sources
Diffstat (limited to 'FS/FS/API.pm')
-rw-r--r-- | FS/FS/API.pm | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/FS/FS/API.pm b/FS/FS/API.pm index fd3793d..735088f 100644 --- a/FS/FS/API.pm +++ b/FS/FS/API.pm @@ -719,7 +719,63 @@ sub bill_now { } -#next.. Advertising sources? +#next.. Delete 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; +} + +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; +} + +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; +} ## |