X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FClientAPI%2FMyAccount.pm;h=163718e13288dbca7c485ead2c43cacb28a4d405;hb=b58e61ac7df612f606c3e68371265e790e0be585;hp=478973396e3436398ddc890807d396bfc4045dff;hpb=18c025613fa052cf4ba8d484f1296cc2a1719a24;p=freeside.git diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index 478973396..163718e13 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -6,6 +6,7 @@ use subs qw(_cache); use Digest::MD5 qw(md5_hex); use Date::Format; use Business::CreditCard; +use Time::Duration; use FS::CGI qw(small_custview); #doh use FS::Conf; use FS::Record qw(qsearch qsearchs); @@ -26,7 +27,7 @@ use vars qw( @cust_main_editable_fields ); 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 + payby payinfo payname paystart_month paystart_year payissue payip ); use subs qw(_provision); @@ -135,12 +136,16 @@ sub customer_info { $return{'postal_invoicing'} = 0 < ( grep { $_ eq 'POST' } $cust_main->invoicing_list ); - } else { #no customer record + } elsif ( $session->{'svcnum'} ) { #no customer record my $svc_acct = qsearchs('svc_acct', { 'svcnum' => $session->{'svcnum'} } ) or die "unknown svcnum"; $return{name} = $svc_acct->email; + } else { + + return { 'error' => 'Expired session' }; #XXX redirect to login w/this err! + } return { 'error' => '', @@ -221,6 +226,8 @@ sub payment_info { 'MasterCard' => 'MasterCard', 'Discover' => 'Discover card', 'American Express' => 'American Express card', + 'Switch' => 'Switch', + 'Solo' => 'Solo', }, }; @@ -336,7 +343,8 @@ sub process_payment { 'payname' => $payname, 'paybatch' => $paybatch, 'paycvv' => $paycvv, - map { $_ => $p->{$_} } qw( address1 address2 city state zip ) + map { $_ => $p->{$_} } qw( paystart_month paystart_year payissue payip + address1 address2 city state zip ) ); return { 'error' => $error } if $error; @@ -345,7 +353,8 @@ sub process_payment { if ( $p->{'save'} ) { my $new = new FS::cust_main { $cust_main->hash }; $new->set( $_ => $p->{$_} ) - foreach qw( payname address1 address2 city state zip payinfo ); + foreach qw( payname paystart_month paystart_year payissue payip + address1 address2 city state zip payinfo ); $new->set( 'paydate' => $p->{'year'}. '-'. $p->{'month'}. '-01' ); $new->set( 'payby' => $p->{'auto'} ? 'CARD' : 'DCRD' ); my $error = $new->replace($cust_main); @@ -357,6 +366,36 @@ sub process_payment { } +sub process_prepay { + + my $p = shift; + + my $session = _cache->get($p->{'session_id'}) + or return { 'error' => "Can't resume session" }; #better error message + + my %return; + + my $custnum = $session->{'custnum'}; + + my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ) + or return { 'error' => "unknown custnum $custnum" }; + + my( $amount, $seconds ) = ( 0, 0 ); + my $error = $cust_main->recharge_prepay( $p->{'prepaid_cardnum'}, + \$amount, + \$seconds + ); + + return { 'error' => $error } if $error; + + return { 'error' => '', + 'amount' => $amount, + 'seconds' => $seconds, + 'duration' => duration_exact($seconds), + }; + +} + sub invoice { my $p = shift; my $session = _cache->get($p->{'session_id'}) @@ -375,10 +414,37 @@ sub invoice { return { 'error' => '', 'invnum' => $invnum, 'invoice_text' => join('', $cust_bill->print_text ), + 'invoice_html' => $cust_bill->print_html, }; } +sub invoice_logo { + my $p = shift; + + #sessioning for this? how do we get the session id to the backend invoice + # template so it can add it to the link, blah + + my $templatename = $p->{'templatename'}; + + #false laziness-ish w/view/cust_bill-logo.cgi + + my $conf = new FS::Conf; + if ( $templatename =~ /^([^\.\/]*)$/ && $conf->exists("logo_$1.png") ) { + $templatename = "_$1"; + } else { + $templatename = ''; + } + + my $filename = "logo$templatename.png"; + + return { 'error' => '', + 'logo' => $conf->config_binary($filename), + 'content_type' => 'image/png', #should allow gif, jpg too + }; +} + + sub list_invoices { my $p = shift; my $session = _cache->get($p->{'session_id'}) @@ -743,7 +809,7 @@ sub _custoragent_session_custnum { $context = 'customer'; $session = _cache->get($p->{'session_id'}) - or return { 'error' => "Can't resume session" }; #better error message + or return ( 'error' => "Can't resume session" ); #better error message $custnum = $session->{'custnum'}; } elsif ( $p->{'agent_session_id'} ) { @@ -753,11 +819,11 @@ sub _custoragent_session_custnum { 'namespace' => 'FS::ClientAPI::Agent', } ); $session = $agent_cache->get($p->{'agent_session_id'}) - or return { 'error' => "Can't resume session" }; #better error message + or return ( 'error' => "Can't resume session" ); #better error message $custnum = $p->{'custnum'}; } else { - return { 'error' => "Can't resume session" }; #better error message + return ( 'error' => "Can't resume session" ); #better error message } ($context, $session, $custnum);