X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FClientAPI%2FMyAccount.pm;h=8d6f6e55a7c9ca4baaea4696514151e8655eff37;hb=9ae101389f2fe652575c6ab314a5e95c2283b72e;hp=c722c9d5f7da5158cdf467388ae1865fe7c8268b;hpb=416dc3b6df09133c4130445008919408f04586c3;p=freeside.git diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index c722c9d5f..8d6f6e55a 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -17,11 +17,12 @@ use FS::cust_main_county; use FS::ClientAPI; #hmm FS::ClientAPI->register_handlers( - 'MyAccount/login' => \&login, - 'MyAccount/customer_info' => \&customer_info, - 'MyAccount/invoice' => \&invoice, - 'MyAccount/cancel' => \&cancel, - 'MyAccount/payment_info' => \&payment_info, + 'MyAccount/login' => \&login, + 'MyAccount/customer_info' => \&customer_info, + 'MyAccount/invoice' => \&invoice, + 'MyAccount/cancel' => \&cancel, + 'MyAccount/payment_info' => \&payment_info, + 'MyAccount/process_payment' => \&process_payment, ); #store in db? @@ -107,7 +108,6 @@ sub customer_info { } - return { 'error' => '', 'custnum' => $custnum, %return, @@ -130,14 +130,14 @@ sub payment_info { $return{balance} = $cust_main->balance; $return{payname} = $cust_main->payname - || $cust_main->first. ' '. $cust_main->get('last'); + || ( $cust_main->first. ' '. $cust_main->get('last') ); $return{$_} = $cust_main->get($_) for qw(address1 address2 city state zip); $return{payby} = $cust_main->payby; if ( $cust_main->payby =~ /^(CARD|DCRD)$/ ) { - $return{card_type} = cardtype($cust_main->payinfo); + warn $return{card_type} = cardtype($cust_main->payinfo); $return{payinfo} = $cust_main->payinfo; if ( $cust_main->paydate =~ /^(\d{4})-(\d{2})-\d{2}$/ ) { #Pg date format @@ -167,12 +167,52 @@ sub payment_info { 'American Express' => 'American Express card', }; + my $_date = time; + $return{paybatch} = "webui-MyAccount-$_date-$$-". rand() * 2**32; + return { 'error' => '', %return, }; }; +sub process_payment { + 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" }; + + if ( $p->{'save'} ) { + my $new = new FS::cust_main { $cust_main->hash }; + $new->set( $_ => $p->{$_} ) + foreach qw( payname 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); + return { 'error' => $error } if $error; + $cust_main = $new; + } + + my $error = $cust_main->realtime_bop( 'CC', $p->{'amount'}, quiet=>1, + 'paydate' => $p->{'year'}. '-'. $p->{'month'}. '-01', + map { $_ => $p->{$_} } + qw( payname address1 address2 city state zip payinfo ) + ); + return { 'error' => $error } if $error; + + $cust_main->apply_payments; + + return { 'error' => '' }; + +} + sub invoice { my $p = shift; my $session = $cache->get($p->{'session_id'}) @@ -205,7 +245,7 @@ sub cancel { my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } ) or return { 'error' => "unknown custnum $custnum" }; - my @errors = $cust_main->cancel; + my @errors = $cust_main->cancel( 'quiet'=>1 ); my $error = scalar(@errors) ? join(' / ', @errors) : '';