diff options
author | ivan <ivan> | 2009-01-22 17:29:22 +0000 |
---|---|---|
committer | ivan <ivan> | 2009-01-22 17:29:22 +0000 |
commit | 2b8e51c711674efa5878354cd17e2875a5ee19b2 (patch) | |
tree | 40a332d8f38ac08a350970cef232ba66e020fdad /FS/FS/ClientAPI | |
parent | 455556cc709f205cb63d42cfe941bb874f36c2f5 (diff) |
add self-service methods renew_info, order_renew and process_payment_order_renew to enable self-renewal through self-service. RT#4623
Diffstat (limited to 'FS/FS/ClientAPI')
-rw-r--r-- | FS/FS/ClientAPI/MyAccount.pm | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index e154761..bd95c28 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -540,6 +540,15 @@ sub process_payment_order_pkg { order_pkg($p); } +sub process_payment_order_renew { + my $p = shift; + + my $hr = process_payment($p); + return $hr if $hr->{'error'}; + + order_renew($p); +} + sub process_prepay { my $p = shift; @@ -1096,6 +1105,64 @@ sub _do_bop_realtime { ''; } +sub renew_info { + my $p = shift; + + my($context, $session, $custnum) = _custoragent_session_custnum($p); + return { 'error' => $session } if $context eq 'error'; + + my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ) + or return { 'error' => "unknown custnum $custnum" }; + + my @cust_pkg = sort { $a->bill <=> $b->bill } + grep { $_->part_pkg->freq ne '0' } + $cust_main->ncancelled_pkgs; + + #return { 'error' => 'No active packages to renew.' } unless @cust_pkg; + + my $total = 0; + + my @array = map { + $total += $_->part_pkg->base_recur; + my $renew_date = $_->part_pkg->add_freq($_->bill); + { + 'bill_date' => $_->bill, + 'bill_date_pretty' => time2str('%x', $_->bill), + 'renew_date' => $renew_date, + 'renew_date_pretty' => time2str('%x', $renew_date), + 'amount' => $total, + }; + } + @cust_pkg; + + return { 'dates' => \@array }; + +} + +sub order_renew { + my $p = shift; + + my($context, $session, $custnum) = _custoragent_session_custnum($p); + return { 'error' => $session } if $context eq 'error'; + + my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ) + or return { 'error' => "unknown custnum $custnum" }; + + my $date = $p->{'date'}; + + my $now = time; + + #freeside-daily -n -d $date fs_daily $custnum + $cust_main->bill_and_collect( 'time' => $date, + 'invoice_time' => $now, + 'actual_time' => $now, + 'check_freq' => '1d', + ); + + return { 'error' => '' }; + +} + sub cancel_pkg { my $p = shift; my $session = _cache->get($p->{'session_id'}) |