simple payment receipts in web interface, sorry arnie, RT#2738
authorivan <ivan>
Sat, 27 Oct 2007 04:46:05 +0000 (04:46 +0000)
committerivan <ivan>
Sat, 27 Oct 2007 04:46:05 +0000 (04:46 +0000)
FS/FS/cust_main.pm
FS/FS/cust_pay.pm
httemplate/misc/process/payment.cgi
httemplate/search/cust_pay.cgi
httemplate/view/cust_main/payment_history.html
httemplate/view/cust_pay.html [new file with mode: 0644]

index f043e47..467ddfe 100644 (file)
@@ -2859,7 +2859,7 @@ L<http://420.am/business-onlinepayment> for supported gateways.
 
 Available methods are: I<CC>, I<ECHECK> and I<LEC>
 
-Available options are: I<description>, I<invnum>, I<quiet>
+Available options are: I<description>, I<invnum>, I<quiet>, I<paynum_ref>
 
 The additional options I<payname>, I<address1>, I<address2>, I<city>, I<state>,
 I<zip>, I<payinfo> and I<paydate> are also available.  Any of these options,
@@ -2874,6 +2874,9 @@ call the B<apply_payments> method.
 
 I<quiet> can be set true to surpress email decline notices.
 
+I<paynum_ref> can be set to a scalar reference.  It will be filled in with the
+resulting paynum, if any.
+
 (moved from cust_bill) (probably should get realtime_{card,ach,lec} here too)
 
 =cut
@@ -3237,6 +3240,11 @@ sub realtime_bop {
         return $e;
       }
     }
+
+    if ( $options{'paynum_ref'} ) {
+      ${ $options{'paynum_ref'} } = $cust_pay->paynum;
+    }
+
     return ''; #no error
 
   } else {
@@ -3317,7 +3325,7 @@ sub default_payment_gateway {
   #load up config
   my $bop_config = 'business-onlinepayment';
   $bop_config .= '-ach'
-    if $method eq 'ECHECK' && $conf->exists($bop_config. '-ach');
+    if $method =~ /^(ECHECK|CHEK)$/ && $conf->exists($bop_config. '-ach');
   my ( $processor, $login, $password, $action, @bop_options ) =
     $conf->config($bop_config);
   $action ||= 'normal authorization';
index 5d31d2c..78c09a3 100644 (file)
@@ -7,6 +7,7 @@ use Business::CreditCard;
 use Text::Template;
 use FS::Misc qw(send_email);
 use FS::Record qw( dbh qsearch qsearchs );
+use FS::payby;
 use FS::cust_main_Mixin;
 use FS::payinfo_Mixin;
 use FS::cust_bill;
@@ -548,6 +549,74 @@ sub cust_main {
   qsearchs( 'cust_main', { 'custnum' => $self->custnum } );
 }
 
+=item payby_name
+
+Returns a name for the payby field.
+
+=cut
+
+sub payby_name {
+  my $self = shift;
+  FS::payby->shortname( $self->payby );
+}
+
+=item gatewaynum
+
+Returns a gatewaynum for the processing gateway.
+
+=item processor
+
+Returns a name for the processing gateway.
+
+=item authorization
+
+Returns a name for the processing gateway.
+
+=item order_number
+
+Returns a name for the processing gateway.
+
+=cut
+
+sub gatewaynum    { shift->_parse_paybatch->{'gatewaynum'}; }
+sub processor     { shift->_parse_paybatch->{'processor'}; }
+sub authorization { shift->_parse_paybatch->{'authorization'}; }
+sub order_number  { shift->_parse_paybatch->{'order_number'}; }
+
+#sucks that this stuff is in paybatch like this in the first place,
+#but at least other code can start to use new field names
+#(code nicked from FS::cust_main::realtime_refund_bop)
+sub _parse_paybatch {
+  my $self = shift;
+
+  $self->paybatch =~ /^((\d+)\-)?(\w+):\s*([\w\-\/ ]*)(:([\w\-]+))?$/
+    or return {};
+              #"Can't parse paybatch for paynum $options{'paynum'}: ".
+              #  $cust_pay->paybatch;
+
+  my( $gatewaynum, $processor, $auth, $order_number ) = ( $2, $3, $4, $6 );
+
+  if ( $gatewaynum ) { #gateway for the payment to be refunded
+
+    my $payment_gateway =
+      qsearchs('payment_gateway', { 'gatewaynum' => $gatewaynum } );
+
+    die "payment gateway $gatewaynum not found" #?
+      unless $payment_gateway;
+
+    $processor = $payment_gateway->gateway_module;
+
+  }
+
+  {
+    'gatewaynum'    => $gatewaynum,
+    'processor'     => $processor,
+    'authorization' => $auth,
+    'order_number'  => $order_number,
+  };
+
+}
+
 =back
 
 =head1 CLASS METHODS
index 6377b13..71a4891 100644 (file)
@@ -1,11 +1,18 @@
-<% include( '/elements/header.html', ucfirst($type{$payby}). ' processing successful',
-             include('/elements/menubar.html'),
+% if ( $cgi->param('batch') ) {
 
-    )
-%>
-<% include( '/elements/small_custview.html', $cust_main, '', '', popurl(3). "view/cust_main.cgi" ) %>
+  <% include( '/elements/header.html', ucfirst($type{$payby}). ' processing successful',
+                 include('/elements/menubar.html'),
 
-<% include('/elements/footer.html') %>
+            )
+  %>
+
+  <% include( '/elements/small_custview.html', $cust_main, '', '', popurl(3). "view/cust_main.cgi" ) %>
+
+  <% include('/elements/footer.html') %>
+
+% } else {
+<% $cgi->redirect(popurl(3). "view/cust_pay.html?paynum=$paynum" ) %>
+% }
 <%init>
 
 #some false laziness w/MyAccount::process_payment
@@ -99,6 +106,7 @@ if ( $payby eq 'CHEK' ) {
 }
 
 my $error = '';
+my $paynum = '';
 if ( $cgi->param('batch') ) {
 
   $error = $cust_main->batch_card(
@@ -110,18 +118,19 @@ if ( $cgi->param('batch') ) {
                                    map { $_ => $cgi->param($_) } 
                                      @{$payby2fields{$payby}}
                                  );
-  errotpage($error) if $error;
+  errorpage($error) if $error;
 
 } else {
 
   $error = $cust_main->realtime_bop( $FS::payby::payby2bop{$payby}, $amount,
-    'quiet'     => 1,
-    'manual'    => 1,
-    'payinfo'   => $payinfo,
-    'paydate'   => "$year-$month-01",
-    'payname'   => $payname,
-    'payunique' => $payunique,
-    'paycvv'    => $paycvv,
+    'quiet'      => 1,
+    'manual'     => 1,
+    'payinfo'    => $payinfo,
+    'paydate'    => "$year-$month-01",
+    'payname'    => $payname,
+    'payunique'  => $payunique,
+    'paycvv'     => $paycvv,
+    'paynum_ref' => \$paynum,
     map { $_ => $cgi->param($_) } @{$payby2fields{$payby}}
   );
   errorpage($error) if $error;
index 0eefd2b..2166eb1 100755 (executable)
                  #'align' => 'lrrrll',
                  'align' => 'rrr'.FS::UI::Web::cust_aligns(),
                  'links' => [
-                   '',
-                   '',
-                   '',
-                   ( map { $_ ne 'Cust. Status' ? $link : '' }
+                   $link,
+                   $link,
+                   $link,
+                   ( map { $_ ne 'Cust. Status' ? $cust_link : '' }
                          FS::UI::Web::cust_header()
                    ),
                  ],
@@ -226,7 +226,9 @@ if ( $cgi->param('magic') ) {
 
 }
 
-my $link = sub {
+my $link = [ "${p}view/cust_pay.html?paynum=", 'paynum' ];
+
+my $cust_link = sub {
   my $cust_pay = shift;
   $cust_pay->cust_main_custnum
     ? [ "${p}view/cust_main.cgi?", 'custnum' ] 
index 099bc4f..5af34c0 100644 (file)
 %    }
 %  }
 %
+%  my $view = qq! (<A HREF="javascript:void(0);" onClick="overlib( OLiframeContent('${p}view/cust_pay.html?link=popup;paynum=!.
+%             $cust_pay->paynum.
+%             qq!', 540, 336, 'view_cust_pay_popup' ), CAPTION, 'Payment Receipt', STICKY, AUTOSTATUSCAP, MIDX, 0, MIDY, 0, DRAGGABLE, CLOSECLICK ); return false;">view receipt</A>)!;
+%
 %  my $refund = '';
 %  my $refund_days = $conf->config('card_refund-days') || 120;
 %  if (    $cust_pay->closed !~ /^Y/i
 %  push @history, {
 %    'date'    => $cust_pay->_date,
 %    'desc'    => $pre. "Payment$post$info$desc".
-%                 "$apply$refund$void$delete$unapply",
+%                 "$view$apply$refund$void$delete$unapply",
 %    'payment' => $cust_pay->paid,
 %    'target'  => $target,
 %  };
diff --git a/httemplate/view/cust_pay.html b/httemplate/view/cust_pay.html
new file mode 100644 (file)
index 0000000..2d1a22b
--- /dev/null
@@ -0,0 +1,126 @@
+% if ( $link eq 'popup' ) { 
+
+  <% include('/elements/header-popup.html', "Payment Receipt" ) %>
+
+  <CENTER><A HREF="javascript:self.parent.location = '<% $pr_link %>'">Print</A></CENTER><BR>
+
+% } elsif ( $link eq 'print' ) { 
+
+  <% include('/elements/header-popup.html', "Payment Receipt" ) %>
+
+% } else { 
+
+  <% include('/elements/header.html', "Payment Receipt", menubar(
+       "View this customer (#$custnum)" => "${p}view/cust_main.cgi?$custnum",
+       'Print receipt' => $pr_link,
+     ))
+  %>
+
+% }
+
+% unless ($link eq 'popup' ) {
+  <% include('/elements/small_custview.html',
+               $custnum,
+               scalar($conf->config('countrydefault')),
+               1, #no balance
+            )
+  %>
+  <BR><BR>
+% } 
+
+<% ntable("#cccccc", 2) %>
+
+<TR>
+  <TD ALIGN="right">Payment#</TD>
+  <TD BGCOLOR="#FFFFFF"><B><% $cust_pay->paynum %></B></TD>
+</TR>
+
+<TR>
+  <TD ALIGN="right">Date</TD>
+  <TD BGCOLOR="#FFFFFF"><B><% time2str"%a&nbsp;%b&nbsp;%o,&nbsp;%Y&nbsp;%r", $cust_pay->_date %></B></TD>
+</TR>
+
+<TR>
+  <TD ALIGN="right">Amount</TD>
+  <TD BGCOLOR="#FFFFFF"><B><% $money_char. $cust_pay->paid %></B></TD>
+</TR>
+
+<TR>
+  <TD ALIGN="right">Payment method</TD>
+  <TD BGCOLOR="#FFFFFF"><B><% $cust_pay->payby_name %> #<% $cust_pay->paymask %></B></TD>
+</TR>
+
+% if ( $cust_pay->payby =~ /^(CARD|CHEK|LECB)$/ && $cust_pay->paybatch ) { 
+
+    <TR>
+      <TD ALIGN="right">Processor</TD>
+      <TD BGCOLOR="#FFFFFF"><B><% $cust_pay->processor %></B></TD>
+    </TR>
+
+    <TR>
+      <TD ALIGN="right">Authorization#</TD>
+      <TD BGCOLOR="#FFFFFF"><B><% $cust_pay->authorization %></B></TD>
+    </TR>
+
+%   if ( $cust_pay->order_number ) {
+      <TR>
+        <TD ALIGN="right">Order#</TD>
+        <TD BGCOLOR="#FFFFFF"><B><% $cust_pay->order_number %></B></TD>
+      </TR>
+%   }
+
+% }
+
+</TABLE>
+
+% if ( $link eq 'print' ) {
+
+  <SCRIPT TYPE="text/javascript">
+    window.print();
+  </SCRIPT>
+
+% }
+
+% if ( $link =~ /^(popup|print)$/ ) { 
+    </BODY>
+  </HTML>
+% } else {
+  <% include('/elements/footer.html') %>
+% }
+
+<%init>
+
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+die "access denied"
+  unless $curuser->access_right('View invoices') #remove this in 1.9
+      || $curuser->access_right('View customer payments');
+
+$cgi->param('paynum') =~ /^(\d+)$/ or die "no paynum";
+my $paynum = $1;
+
+my $link = '';
+if ( $cgi->param('link') =~ /^(\w+)$/ ) {
+  $link = $1;
+}
+
+my $cust_pay = qsearchs({
+  'select'    => 'cust_pay.*',
+  'table'     => 'cust_pay',
+  'addl_from' => 'LEFT JOIN cust_main USING ( custnum )',
+  'hashref'   => { 'paynum' => $paynum },
+  'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql,
+});
+die "Payment #$paynum not found!" unless $cust_pay;
+
+my $pr_link = "${p}view/cust_pay.html?link=print;paynum=$paynum";
+
+my $custnum = $cust_pay->custnum;
+
+my $conf = new FS::Conf;
+
+my $money_char = $conf->config('money_char') || '$';
+
+tie my %payby, 'Tie::IxHash', FS::payby->payby2longname;
+
+</%init>