summaryrefslogtreecommitdiff
path: root/FS/FS/API.pm
diff options
context:
space:
mode:
authorChristopher Burger <burgerc@freeside.biz>2017-08-21 11:42:36 -0400
committerChristopher Burger <burgerc@freeside.biz>2017-08-22 06:55:41 -0400
commitbee715764bba15af9ac9868287dc22f648b472bd (patch)
treeb0304de296428b87e06f3e117db6b9d034b6f85b /FS/FS/API.pm
parentea5ea999cbd41dba4801091a3b096551e69d813d (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.pm58
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;
+}
##