From: ivan Date: Mon, 19 May 2003 13:38:41 +0000 (+0000) Subject: first crack at payment processing with self-service (step two of the process) X-Git-Tag: freeside_1_5_0pre2~12 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=a1295d0682aa81a408abe06fcaa7c14440f6a2e2 first crack at payment processing with self-service (step two of the process) --- diff --git a/FS/FS/ClientAPI/MyAccount.pm b/FS/FS/ClientAPI/MyAccount.pm index a64cfb5d7..2ce55a8e7 100644 --- a/FS/FS/ClientAPI/MyAccount.pm +++ b/FS/FS/ClientAPI/MyAccount.pm @@ -185,7 +185,30 @@ sub make_payment{ 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->{'month'}. '-'. $p->{'year'} ); + $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->{'month'}. '-'. $p->{'year'}, + map { $_ => $p->{$_} } + qw( payname address1 address2 city state zip payinfo ) + ); + return { 'error' => $error } if $error; + + $cust_main->apply_payments; + return { 'error' => '' }; } diff --git a/FS/FS/cust_main.pm b/FS/FS/cust_main.pm index b162622a4..09c56474c 100644 --- a/FS/FS/cust_main.pm +++ b/FS/FS/cust_main.pm @@ -1411,7 +1411,6 @@ sub collect { =item realtime_bop METHOD AMOUNT [ OPTION => VALUE ... ] - Runs a realtime credit card, ACH (electronic check) or phone bill transaction via a Business::OnlinePayment realtime gateway. See L for supported gateways. @@ -1420,6 +1419,10 @@ Available methods are: I, I and I Available options are: I, I, I +The additional options I, I, I, I, I, +I, I and I are also available. Any of these options, +if set, will override the value from the customer record. + I is a free-text field passed to the gateway. It defaults to "Internet services". @@ -1443,6 +1446,11 @@ sub realtime_bop { eval "use Business::OnlinePayment"; die $@ if $@; + #overrides + $self->set( $_ => $options{$_} ) + foreach grep { exists($options{$_}) } + qw( payname address1 address2 city state zip payinfo paydate ); + #load up config my $bop_config = 'business-onlinepayment'; $bop_config .= '-ach' @@ -1571,7 +1579,8 @@ sub realtime_bop { ); my $cust_pay = new FS::cust_pay ( { - 'invnum' => $self->invnum, #!!!!!!!! + 'custnum' => $self->custnum, + 'invnum' => $options{'invnum'}, 'paid' => $amount, '_date' => '', 'payby' => $method2payby{$method}, diff --git a/fs_selfservice/FS-SelfService/cgi/make_payment.html b/fs_selfservice/FS-SelfService/cgi/make_payment.html index 6adc0bde0..fdb411b11 100644 --- a/fs_selfservice/FS-SelfService/cgi/make_payment.html +++ b/fs_selfservice/FS-SelfService/cgi/make_payment.html @@ -31,7 +31,7 @@ @@ -104,7 +104,7 @@ - NAME="auto" VALUE="1"> + NAME="auto" VALUE="1" onClick="if (this.checked) { document.OneTrueForm.save.checked=true; }"> Charge future payments to this card automatically diff --git a/fs_selfservice/FS-SelfService/cgi/process_payment.html b/fs_selfservice/FS-SelfService/cgi/process_payment.html new file mode 100644 index 000000000..e4946dc8f --- /dev/null +++ b/fs_selfservice/FS-SelfService/cgi/process_payment.html @@ -0,0 +1,18 @@ +MyAccount +MyAccount

+<%= $url = "$selfurl?session=$session_id;action="; ''; %> +
+MyAccount
+ +
+Payment results

+<%= if ( $error ) { + $OUT .= qq!Error processing your payment: $error +
+
+powered by freeside + + diff --git a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi index 2ce2c8b6c..d43df4041 100644 --- a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi +++ b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi @@ -96,6 +96,8 @@ sub make_payment { sub process_payment { + use Business::CreditCard; + $cgi->param('amount') =~ /^\s*(\d+(\.\d{2})?)\s*$/ or die "illegal amount"; #!!! my $amount = $1; @@ -143,7 +145,7 @@ sub process_payment { $auto = 1 if $cgi->param('auto'); $cgi->param('paybatch') =~ /^([\w\-\.]+)$/ or die "illegal paybatch"; - my $patbatch = $1; + my $paybatch = $1; process_payment( 'session_id' => $session_id,